Search in sources :

Example 86 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterPlugin method createServerMessage.

private Message createServerMessage(String subject, String body) {
    Message message = new Message();
    message.setTo(violationContact + "@" + violationNotificationFrom.getDomain());
    message.setFrom(violationNotificationFrom);
    message.setSubject(subject);
    message.setBody(body);
    return message;
}
Also used : Message(org.xmpp.packet.Message)

Example 87 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterTest method testFilterMessageSubjectWithMask.

@Test
public void testFilterMessageSubjectWithMask() {
    // filter on the word fox
    filter.setPatterns("fox");
    // set a content mask
    filter.setMask("**");
    // test message
    Message message = new Message();
    message.setSubject("the quick brown fox jumped over the lazy dog");
    boolean matched = filter.filter(message);
    // matches should be found
    assertTrue(matched);
    // content has changed
    assertEquals("the quick brown ** jumped over the lazy dog", message.getSubject());
    assertNull(message.getBody());
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 88 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterTest method testFilterWholeWords.

@Test
public void testFilterWholeWords() {
    //match every instance of "at" in string
    filter.setPatterns("at");
    filter.setMask("**");
    Message message = new Message();
    message.setBody("At noon the fat cats ate lunch at Rizzos");
    boolean matched = filter.filter(message);
    assertTrue(matched);
    assertEquals("At noon the f** c**s **e lunch ** Rizzos", message.getBody());
    //match only whole word instances of "at" ignoring case 
    filter.setPatterns("(?i)\\bat\\b");
    message.setBody("At noon the fat cats ate lunch at Rizzos");
    matched = filter.filter(message);
    assertTrue(matched);
    assertEquals("** noon the fat cats ate lunch ** Rizzos", message.getBody());
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 89 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterTest method testFilterMessageSubject.

@Test
public void testFilterMessageSubject() {
    // filter on the word fox
    filter.setPatterns("fox");
    // test message
    Message message = new Message();
    message.setSubject("the quick brown fox jumped over the lazy dog");
    boolean matched = filter.filter(message);
    // matches should be found
    assertTrue(matched);
    // content has not changed as there is no content mask
    assertEquals("the quick brown fox jumped over the lazy dog", message.getSubject());
    assertNull(message.getBody());
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 90 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class Workgroup method rejectPacket.

public void rejectPacket(Packet packet, PacketRejectedException e) {
    if (packet instanceof IQ) {
        IQ reply = new IQ();
        reply.setChildElement(((IQ) packet).getChildElement().createCopy());
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_allowed);
        send(reply);
    } else if (packet instanceof Presence) {
        Presence reply = new Presence();
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_allowed);
        send(reply);
    }
    // Check if a message notifying the rejection should be sent
    if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
        // A message for the rejection will be sent to the sender of the rejected packet
        Message notification = new Message();
        notification.setTo(packet.getFrom());
        notification.setFrom(packet.getTo());
        notification.setBody(e.getRejectionMessage());
        send(notification);
    }
    Log.warn("Packet was REJECTED " + "by interceptor: " + packet.toXML(), e);
}
Also used : Message(org.xmpp.packet.Message) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Aggregations

Message (org.xmpp.packet.Message)111 Element (org.dom4j.Element)35 JID (org.xmpp.packet.JID)25 Test (org.junit.Test)23 Presence (org.xmpp.packet.Presence)18 IQ (org.xmpp.packet.IQ)16 ArrayList (java.util.ArrayList)10 Packet (org.xmpp.packet.Packet)10 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)9 Date (java.util.Date)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 NotFoundException (org.jivesoftware.util.NotFoundException)6 StringReader (java.io.StringReader)4 List (java.util.List)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 User (org.jivesoftware.openfire.user.User)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SAXReader (org.dom4j.io.SAXReader)3 DefaultElement (org.dom4j.tree.DefaultElement)3