Package org.xmpp.packet

Examples of org.xmpp.packet.Message


        // Check if the published item can be sent to the subscriber
        if (!canSendPublicationEvent(publishedItem.getNode(), publishedItem)) {
            return;
        }
        // Send event notification to the subscriber
        Message notification = new Message();
        Element event = notification.getElement()
                .addElement("event", "http://jabber.org/protocol/pubsub#event");
        Element items = event.addElement("items");
        items.addAttribute("node", node.getNodeID());
        Element item = items.addElement("item");
        if (((LeafNode) node).isItemRequired()) {
            item.addAttribute("id", publishedItem.getID());
        }
        if (node.isPayloadDelivered() && publishedItem.getPayload() != null) {
            item.add(publishedItem.getPayload().createCopy());
        }
        // Add a message body (if required)
        if (isIncludingBody()) {
            notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body"));
        }
        // Include date when published item was created
        notification.getElement().addElement("delay", "urn:xmpp:delay")
                .addAttribute("stamp", fastDateFormat.format(publishedItem.getCreationDate()));
        // Send the event notification to the subscriber
        service.sendNotification(node, notification, jid);
    }
View Full Code Here


     * Sends an request to authorize the pending subscription to the specified owner.
     *
     * @param owner the JID of the user that will get the authorization request.
     */
    public void sendAuthorizationRequest(JID owner) {
        Message authRequest = new Message();
        authRequest.addExtension(node.getAuthRequestForm(this));
        authRequest.setTo(owner);
        authRequest.setFrom(service.getAddress());
        // Send authentication request to node owners
        service.send(authRequest);
    }
View Full Code Here

    /**
     * Sends an request to authorize the pending subscription to all owners. The first
     * answer sent by a owner will be processed. Rest of the answers will be discarded.
     */
    public void sendAuthorizationRequest() {
        Message authRequest = new Message();
        authRequest.addExtension(node.getAuthRequestForm(this));
        // Send authentication request to node owners
        service.broadcast(node, authRequest, node.getOwners());
    }
View Full Code Here

        filter.clearMask();
        assertFalse(filter.isMaskingContent());
    }

    public void testFilterWithEmptyMessage() {
        Message message = new Message();
        boolean matched = filter.filter(message);

        // no matches should be found
        assertFalse(matched);

        // message should not have changed
        assertEquals(new Message().toXML(), message.toXML());
    }
View Full Code Here

    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());
    }
View Full Code Here

        // 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());

    }
View Full Code Here

        // filter on the word fox
        filter.setPatterns("fox");

        // test message
        Message message = new Message();
        message.setBody("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
                .getBody());
        assertNull(message.getSubject());
    }
View Full Code Here

        // filter on the word "fox" and "dog"
        filter.setPatterns("fox,dog");
        filter.setMask("**");

        // test message
        Message message = new Message();
        message.setBody("the quick brown fox jumped over the lazy dog");
        boolean matched = filter.filter(message);

        // matches should not be found
        assertTrue(matched);

        // content has changed
        assertEquals("the quick brown ** jumped over the lazy **", message
                .getBody());
        assertNull(message.getSubject());

    }
View Full Code Here

    public void testFilterWholeWords() {
        filter.setPatterns("at"); //match every instance of "at" in string
        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());
       
        filter.setPatterns("(?i)\\bat\\b"); //match only whole word instances of "at" ignoring case
        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());
    }
View Full Code Here

       
       
       
        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());
       
    }
View Full Code Here

TOP

Related Classes of org.xmpp.packet.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.