use of org.dom4j.io.XPPReader in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterChatMessage.
@Test
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
String chatXML = "<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" + "<body>fox</body>" + "<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" + "<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" + "</html>" + "<x xmlns=\"jabber:x:event\">" + "<composing/>" + "</x>" + "</message>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(chatXML));
Message m = new Message(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = chatXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(m);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, m.toXML());
}
use of org.dom4j.io.XPPReader in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterPresenceXML.
@Test
public void testFilterPresenceXML() throws Exception {
String presenceXML = "<presence from=\"bob@127.0.0.1/frodo\">" + "<show>away</show>" + "<status>fox</status>" + "<priority>0</priority>" + "<x xmlns=\"vcard-temp:x:update\">" + "<photo>f9a514f112c0bcb988d5aa12bc1a9a6f22de5262</photo>" + "</x>" + "<c xmlns=\"http://jabber.org/protocol/caps\" node=\"apple:ichat:caps\" ver=\"392\" ext=\"avavail maudio mvideo avcap audio\"/>" + "<x xmlns=\"http://jabber.org/protocol/tune\"/>" + "</presence>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(presenceXML));
Presence p = new Presence(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(p);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, p.toXML());
}