Search in sources :

Example 36 with Element

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

the class ClientToComponentUpdateProcessor method process.

@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
    Log.debug("Processing packet in ClientToComponentUpdateProcessor: " + packet.toString());
    Element query = ((IQ) packet).getChildElement();
    List<Node> nodes = findNodesInDocument(query.getDocument(), "//roster:item");
    if (nodes.size() > 0) {
        // against our valid subdomains.
        for (Node n : nodes) {
            String jid = n.valueOf("@jid");
            // TODO: We ignore remove iq packets for now. There might be
            // conflicts
            // when we remove our legacy network registration.
            String found_subdomain = searchJIDforSubdomain(jid);
            if (found_subdomain.length() > 0 && !n.valueOf("@subscription").equals("remove")) {
                Log.debug("Mirroring packet from local network to legacy component " + found_subdomain);
                IQ forward = (IQ) packet.createCopy();
                forward.setTo(found_subdomain);
                dispatchPacket(forward);
            }
        }
    }
}
Also used : Element(org.dom4j.Element) Node(org.dom4j.Node) IQ(org.xmpp.packet.IQ)

Example 37 with Element

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

the class DiscoIQRegisteredProcessor method process.

@Override
public void process(Packet packet, final String subdomain, String to, String from) throws PacketRejectedException {
    Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
    // Check if the jabber:iq:register is enabled in admin panel
    boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
    if (!isFeatureEnabled) {
        Log.debug("Spark extension is deactivated. Won't change the disco#info");
        return;
    }
    final InterceptorManager interceptorManager = InterceptorManager.getInstance();
    final PacketInterceptor interceptor = new PacketInterceptor() {

        public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
            if (!processed && incoming) {
                if (packet instanceof IQ) {
                    IQ iqPacket = (IQ) packet;
                    Element packetElement = iqPacket.getChildElement();
                    if (packetElement == null)
                        return;
                    String ns = iqPacket.getChildElement().getNamespace().getURI();
                    if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") && iqPacket.getFrom().toString().equals(subdomain)) {
                        // Check if we are already registered
                        setRegistered(iqPacket.toString().contains("<registered/>"));
                        throw new PacketRejectedException();
                    } else if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("http://jabber.org/protocol/disco#info") && iqPacket.getFrom().toString().equals(subdomain)) {
                        /*
							 * This is the answer of the disco#info from spark
							 * to our component. add the jabber:iq:register
							 * feature if we are registered
							 */
                        if (isRegistered()) {
                            Log.debug("Modifying disco#info packge to send registered iq feature to Spark user " + iqPacket.getTo().toString());
                            Attribute attribut = new DefaultAttribute("var", "jabber:iq:registered");
                            iqPacket.getChildElement().addElement("feature").add(attribut);
                        }
                    }
                }
            }
        }
    };
    Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
    interceptorManager.addInterceptor(interceptor);
    IQ askComponent = new IQ();
    askComponent.setTo(to);
    askComponent.setFrom(from);
    askComponent.setType(IQ.Type.get);
    Element query = new DefaultElement(QName.get("query", "jabber:iq:register"));
    askComponent.setChildElement(query);
    // Remove the package intercepter in 1sec
    TimerTask removeInterceptorTask = new TimerTask() {

        @Override
        public void run() {
            Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
            interceptorManager.removeInterceptor(interceptor);
        }
    };
    Timer timer = new Timer();
    timer.schedule(removeInterceptorTask, 1000);
    // Send the register query to component
    dispatchPacket(askComponent);
}
Also used : Packet(org.xmpp.packet.Packet) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Attribute(org.dom4j.Attribute) DefaultElement(org.dom4j.tree.DefaultElement) InterceptorManager(org.jivesoftware.openfire.interceptor.InterceptorManager) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketInterceptor(org.jivesoftware.openfire.interceptor.PacketInterceptor) TimerTask(java.util.TimerTask) Timer(java.util.Timer) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Session(org.jivesoftware.openfire.session.Session)

Example 38 with Element

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

the class IQRosterPayloadProcessor method sendRosterToComponent.

private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
    IQ response = IQ.createResultIQ(requestPacket);
    response.setTo(subdomain);
    Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
    for (RosterItem i : items) {
        String jid = i.getJid().toString();
        if (!jid.equals(subdomain) && jid.contains(subdomain)) {
            Log.debug("Roster exchange for external component " + subdomain + ". Sending user " + i.getJid().toString());
            Element item = new DefaultElement("item", null);
            item.add(new DefaultAttribute("jid", i.getJid().toString()));
            item.add(new DefaultAttribute("name", i.getNickname()));
            item.add(new DefaultAttribute("subscription", "both"));
            for (String s : i.getGroups()) {
                Element group = new DefaultElement("group");
                group.setText(s);
                item.add(group);
            }
            query.add(item);
        }
    }
    response.setChildElement(query);
    dispatchPacket(response);
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DefaultAttribute(org.dom4j.tree.DefaultAttribute)

Example 39 with Element

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

the class WorkgroupPresence method sendPresence.

/**
     * Sends the presence of the workgroup to the specified JID address.
     *
     * @param address the XMPP address that will receive the presence of the workgroup.
     */
public void sendPresence(JID address) {
    Presence presence = new Presence();
    presence.setTo(address);
    presence.setFrom(workgroup.getJID());
    Presence.Type type;
    if (workgroup.isAvailable()) {
        type = null;
        // Add the a child element that will contain information about the workgroup
        Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
        // Add the last modification date of the workgroup
        child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
    } else {
        type = Presence.Type.unavailable;
        // Add the a child element that will contain information about the workgroup
        Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
        // Add the last modification date of the workgroup
        child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
    }
    presence.setType(type);
    workgroup.send(presence);
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 40 with Element

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

the class IQRosterPayloadProcessor method sendEmptyRoster.

private void sendEmptyRoster(Packet requestPacket, String subdomain) {
    IQ iq = (IQ) requestPacket;
    IQ response = IQ.createResultIQ(iq);
    response.setTo(subdomain);
    Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
    response.setChildElement(query);
    dispatchPacket(response);
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

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