Search in sources :

Example 1 with XPPReader

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());
}
Also used : Message(org.xmpp.packet.Message) StringReader(java.io.StringReader) XPPReader(org.dom4j.io.XPPReader) Document(org.dom4j.Document) Test(org.junit.Test)

Example 2 with XPPReader

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());
}
Also used : StringReader(java.io.StringReader) Presence(org.xmpp.packet.Presence) XPPReader(org.dom4j.io.XPPReader) Document(org.dom4j.Document) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)2 Document (org.dom4j.Document)2 XPPReader (org.dom4j.io.XPPReader)2 Test (org.junit.Test)2 Message (org.xmpp.packet.Message)1 Presence (org.xmpp.packet.Presence)1