Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. private static final String LOAD_BLOCKED_USER = "SELECT list FROM ofPrivacyList WHERE username=?";
  2.  
  3. public boolean getBlockUser(JID fromJID, JID targetJID) {
  4. Connection con = null;
  5. PreparedStatement pstmt = null;
  6. ResultSet rs = null;
  7.  
  8. boolean isBlocked = false;
  9. String list = null;
  10. try {
  11. con = DbConnectionManager.getConnection();
  12. pstmt = con.prepareStatement(LOAD_BLOCKED_USER);
  13. // list.repl
  14. String fullJID = targetJID.toBareJID();
  15. String jid = fullJID.split("@")[0];
  16.  
  17. pstmt.setString(1, jid);
  18. rs = pstmt.executeQuery();
  19. if (rs.next()) {
  20. list = rs.getString(1);
  21. // System.out.println("Found Blocked user list: "+list);
  22. isBlocked = isBlockedUser(list, fromJID.toBareJID());
  23. }else{
  24. // System.out.println("Not Found Blocked user list");
  25. }
  26. rs.close();
  27. pstmt.close();
  28. } catch (SQLException sqle) {
  29. System.out.println("SQL Exception Blocked user list");
  30.  
  31. Log.error(sqle.getMessage(), sqle);
  32. list = sqle.getMessage();
  33. }
  34. catch (Exception e){
  35. System.out.println("Exception Blocked user list");
  36.  
  37. Log.error(e.getMessage(), e);
  38. }
  39. finally {
  40. DbConnectionManager.closeConnection(rs, pstmt, con);
  41. }
  42. return isBlocked;
  43. }
  44.  
  45. private boolean isBlockedUser(String xmlRecords, String fromJID) throws Exception {
  46. DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  47. InputSource is = new InputSource();
  48. is.setCharacterStream(new StringReader(xmlRecords));
  49.  
  50. Document doc = db.parse(is);
  51. NodeList nodes = doc.getElementsByTagName("item");
  52.  
  53. boolean flag = false;
  54. for(int x=0, size= nodes.getLength(); x<size; x++) {
  55. String blockedJID = nodes.item(x).getAttributes().getNamedItem("value").getNodeValue();
  56. String action = nodes.item(x).getAttributes().getNamedItem("action").getNodeValue();
  57. if (blockedJID.equals(fromJID)){
  58. if(action.equals("deny")){
  59. flag = true;
  60. }else{
  61. flag = false;
  62. }
  63. break;
  64. }
  65. }
  66.  
  67. return flag;
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement