1 20 21 package org.jivesoftware.smack.filter; 22 23 import org.jivesoftware.smack.packet.Packet; 24 import org.jivesoftware.smack.util.StringUtils; 25 26 34 public class FromMatchesFilter implements PacketFilter { 35 36 private String address; 37 40 private boolean matchBareJID = false; 41 42 50 public FromMatchesFilter(String address) { 51 if (address == null) { 52 throw new IllegalArgumentException ("Parameter cannot be null."); 53 } 54 this.address = address.toLowerCase(); 55 matchBareJID = "".equals(StringUtils.parseResource(address)); 56 } 57 58 public boolean accept(Packet packet) { 59 if (packet.getFrom() == null) { 60 return false; 61 } 62 else if (matchBareJID) { 63 return packet.getFrom().toLowerCase().startsWith(address); 65 } 66 else { 67 return address.equals(packet.getFrom().toLowerCase()); 69 } 70 } 71 } 72 | Popular Tags |