2016-04-29 5 views

Antwort

0

Ich fand die Antwort. Ich kann den Blockbenutzer aus der Klasse ApnsDBHandler.java holen.

Abfrage

private static final String LOAD_BLOCKED_USER = "SELECT list FROM ofPrivacyList WHERE username=?"; 

Methode

public boolean getBlockUser(JID fromJID, JID targetJID) { 
     Connection con = null; 
     PreparedStatement pstmt = null; 
     ResultSet rs = null; 

     boolean isBlocked = false; 
     String list = null; 
     try { 
      con = DbConnectionManager.getConnection(); 
      pstmt = con.prepareStatement(LOAD_BLOCKED_USER); 
//   list.repl 
      String fullJID = targetJID.toBareJID(); 
      String jid = fullJID.split("@")[0]; 

      pstmt.setString(1, jid); 
      rs = pstmt.executeQuery(); 
      if (rs.next()) { 
       list = rs.getString(1); 
//    System.out.println("Found Blocked user list: "+list); 
       isBlocked = isBlockedUser(list, fromJID.toBareJID()); 
      }else{ 
//    System.out.println("Not Found Blocked user list"); 
      } 
      rs.close(); 
      pstmt.close(); 
     } catch (SQLException sqle) { 
      System.out.println("SQL Exception Blocked user list"); 

      Log.error(sqle.getMessage(), sqle); 
      list = sqle.getMessage(); 
     } 
     catch (Exception e){ 
      System.out.println("Exception Blocked user list"); 

      Log.error(e.getMessage(), e); 
     } 
     finally { 
      DbConnectionManager.closeConnection(rs, pstmt, con); 
     } 
     return isBlocked; 
    } 

    private boolean isBlockedUser(String xmlRecords, String fromJID) throws Exception { 
     DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
     InputSource is = new InputSource(); 
     is.setCharacterStream(new StringReader(xmlRecords)); 

     Document doc = db.parse(is); 
     NodeList nodes = doc.getElementsByTagName("item"); 

     boolean flag = false; 
     for(int x=0, size= nodes.getLength(); x<size; x++) { 
      String blockedJID = nodes.item(x).getAttributes().getNamedItem("value").getNodeValue(); 
      String action = nodes.item(x).getAttributes().getNamedItem("action").getNodeValue(); 
      if (blockedJID.equals(fromJID)){ 
       if(action.equals("deny")){ 
        flag = true; 
       }else{ 
        flag = false; 
       } 
       break; 
      } 
     } 

     return flag; 

    } 

Ich hoffe, dies anderen zu helfen. :)