Search in sources :

Example 46 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class UserRequest method addOfferContent.

@Override
void addOfferContent(Element offerElement) {
    // Flag the offer as a user request
    offerElement.addElement("user-request");
    // anonymous user
    if (isAnonymousUser()) {
        Element element = offerElement.addElement("user", "http://jivesoftware.com/protocol/workgroup");
        element.addAttribute("id", getUserID());
    }
}
Also used : Element(org.dom4j.Element)

Example 47 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class PEPService method sendLastPublishedItems.

/**
     * Sends an event notification for the last published item of each leaf node under the
     * root collection node to the recipient JID. If the recipient has no subscription to
     * the root collection node, has not yet been authorized, or is pending to be
     * configured -- then no notifications are going to be sent.<p>
     *
     * Depending on the subscription configuration the event notifications may or may not have
     * a payload, may not be sent if a keyword (i.e. filter) was defined and it was not matched.
     *
     * @param recipientJID the recipient that is to receive the last published item notifications.
     */
public void sendLastPublishedItems(JID recipientJID) {
    // Ensure the recipient has a subscription to this service's root collection node.
    NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID);
    if (subscription == null) {
        subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID()));
    }
    if (subscription == null) {
        return;
    }
    // Send the last published item of each leaf node to the recipient.
    for (Node leafNode : rootCollectionNode.getNodes()) {
        // Retrieve last published item for the leaf node.
        PublishedItem leafLastPublishedItem = null;
        leafLastPublishedItem = leafNode.getLastPublishedItem();
        if (leafLastPublishedItem == null) {
            continue;
        }
        // Check if the published item can be sent to the subscriber
        if (!subscription.canSendPublicationEvent(leafLastPublishedItem.getNode(), leafLastPublishedItem)) {
            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", leafLastPublishedItem.getNodeID());
        Element item = items.addElement("item");
        if (leafLastPublishedItem.getNode().isItemRequired()) {
            item.addAttribute("id", leafLastPublishedItem.getID());
        }
        if (leafLastPublishedItem.getNode().isPayloadDelivered() && leafLastPublishedItem.getPayload() != null) {
            item.add(leafLastPublishedItem.getPayload().createCopy());
        }
        // Add a message body (if required)
        if (subscription.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", XMPPDateTimeFormat.format(leafLastPublishedItem.getCreationDate()));
        // Send the event notification to the subscriber
        this.sendNotification(subscription.getNode(), notification, subscription.getJID());
    }
}
Also used : JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) NodeSubscription(org.jivesoftware.openfire.pubsub.NodeSubscription) CollectionNode(org.jivesoftware.openfire.pubsub.CollectionNode) Node(org.jivesoftware.openfire.pubsub.Node) Element(org.dom4j.Element) PublishedItem(org.jivesoftware.openfire.pubsub.PublishedItem)

Example 48 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class BroadcastMessage method readExternal.

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    Element packetElement = (Element) ExternalizableUtil.getInstance().readSerializable(in);
    packet = new Message(packetElement, true);
}
Also used : Message(org.xmpp.packet.Message) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element)

Example 49 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class RemotePacketExecution method readExternal.

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    String jid = ExternalizableUtil.getInstance().readSafeUTF(in);
    // Optimization that was avoiding the need to reparse and validate JIDs but cannot be done due
    // to a change in the JID API. We need to bring this constructor back
    //receipient = new JID(jid, true);
    receipient = new JID(jid);
    int packetType = ExternalizableUtil.getInstance().readInt(in);
    Element packetElement = (Element) ExternalizableUtil.getInstance().readSerializable(in);
    switch(packetType) {
        case 1:
            packet = new IQ(packetElement, true);
            break;
        case 2:
            packet = new Message(packetElement, true);
            break;
        case 3:
            packet = new Presence(packetElement, true);
            break;
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element)

Example 50 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class WorkgroupFormProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    FormManager formManager = FormManager.getInstance();
    DataForm dataForm = formManager.getDataForm(workgroup);
    if (dataForm == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element iq = packet.getChildElement();
    if (iq.elements().isEmpty()) {
        reply.setChildElement(iq.createCopy());
        // Send the data form to the requestor
        reply.addExtension(dataForm.createCopy());
        workgroup.send(reply);
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm) PacketError(org.xmpp.packet.PacketError)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64