Search in sources :

Example 56 with Element

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

the class ProcessPacketTask method readExternal.

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    if (ExternalizableUtil.getInstance().readBoolean(in)) {
        address = (JID) ExternalizableUtil.getInstance().readSerializable(in);
    }
    if (ExternalizableUtil.getInstance().readBoolean(in)) {
        streamID = BasicStreamIDFactory.createStreamID(ExternalizableUtil.getInstance().readSafeUTF(in));
    }
    sessionType = SessionType.values()[ExternalizableUtil.getInstance().readInt(in)];
    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 57 with Element

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

the class BookmarkInterceptor method addBookmarkElement.

/**
     * Adds a Bookmark to the users defined list of bookmarks.
     *
     * @param jid      the users jid.
     * @param bookmark the bookmark to be added.
     * @param element  the storage element to append to.
     */
private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
    final UserManager userManager = UserManager.getInstance();
    try {
        userManager.getUser(jid.getNode());
    } catch (UserNotFoundException e) {
        return;
    }
    // do not add duplicate bookmarks.
    if (bookmark.getType() == Bookmark.Type.url) {
        Element urlBookmarkElement = urlExists(element, bookmark.getValue());
        if (urlBookmarkElement == null) {
            urlBookmarkElement = element.addElement("url");
            urlBookmarkElement.addAttribute("name", bookmark.getName());
            urlBookmarkElement.addAttribute("url", bookmark.getValue());
            // Add an RSS attribute to the bookmark if it's defined. RSS isn't an
            // official part of the Bookmark JEP, but we define it as a logical
            // extension.
            boolean rss = Boolean.valueOf(bookmark.getProperty("rss"));
            if (rss) {
                urlBookmarkElement.addAttribute("rss", Boolean.toString(rss));
            }
        }
        appendSharedElement(urlBookmarkElement);
    } else // Otherwise it's a conference bookmark.
    {
        try {
            Element conferenceElement = conferenceExists(element, bookmark.getValue());
            // reply.
            if (conferenceElement == null) {
                conferenceElement = element.addElement("conference");
                conferenceElement.addAttribute("name", bookmark.getName());
                boolean autojoin = Boolean.valueOf(bookmark.getProperty("autojoin"));
                conferenceElement.addAttribute("autojoin", Boolean.toString(autojoin));
                conferenceElement.addAttribute("jid", bookmark.getValue());
                boolean nameasnick = Boolean.valueOf(bookmark.getProperty("nameasnick"));
                if (nameasnick) {
                    User currentUser = userManager.getUser(jid.getNode());
                    Element nick = conferenceElement.addElement("nick");
                    nick.addText(currentUser.getName());
                }
            }
            appendSharedElement(conferenceElement);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) UserManager(org.jivesoftware.openfire.user.UserManager) Element(org.dom4j.Element) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 58 with Element

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

the class BroadcastPlugin method processIQ.

private void processIQ(IQ iq, boolean targetAll, Group group, boolean canProceed) {
    IQ reply = IQ.createResultIQ(iq);
    Element childElement = iq.getChildElement();
    String namespace = childElement.getNamespaceURI();
    Element childElementCopy = iq.getChildElement().createCopy();
    reply.setChildElement(childElementCopy);
    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return service identity and features
            Element identity = childElementCopy.addElement("identity");
            identity.addAttribute("category", "component");
            identity.addAttribute("type", "generic");
            identity.addAttribute("name", "Broadcast service");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items");
        } else {
            if (targetAll) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast all connected users");
                childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            } else if (group != null && canProceed) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast " + group.getName());
                childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            } else {
                // Group not found or not allowed to use that group so
                // answer item_not_found error
                reply.setError(PacketError.Condition.item_not_found);
            }
        }
    } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return the list of groups hosted by the service that can be used by the user
            Collection<Group> groups;
            JID address = new JID(iq.getFrom().toBareJID());
            if (allowedUsers.contains(address)) {
                groups = groupManager.getGroups();
            } else {
                groups = groupManager.getGroups(iq.getFrom());
            }
            for (Group userGroup : groups) {
                try {
                    JID groupJID = new JID(userGroup.getName() + "@" + serviceName + "." + componentManager.getServerName());
                    childElementCopy.addElement("item").addAttribute("jid", groupJID.toString());
                } catch (Exception e) {
                // Group name is not valid to be used as a JID
                }
            }
            if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
                // Add the "all" group to the list
                childElementCopy.addElement("item").addAttribute("jid", "all@" + serviceName + "." + componentManager.getServerName());
            }
        }
    } else {
        // Answer an error since the server can't handle the requested namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }
    try {
        componentManager.sendPacket(this, reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Collection(java.util.Collection) ComponentException(org.xmpp.component.ComponentException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 59 with Element

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

the class SparkManager method processPacket.

/**
     * Client features are detected using Service Discovery, allowing
     * for ease of use within the client.  When a client "discovers" the
     * manager, they can query for related features within that discovered item.
     *
     * @param packet the packet
     */
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ iqPacket = (IQ) packet;
        Element childElement = (iqPacket).getChildElement();
        String namespace = null;
        if (childElement != null) {
            namespace = childElement.getNamespaceURI();
        }
        if (IQ.Type.get == iqPacket.getType()) {
            // Handle any disco info requests.
            if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
                handleDiscoInfo(iqPacket);
            } else // Handle any disco item requests.
            if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
                handleDiscoItems(iqPacket);
            } else if ("jabber:iq:version".equals(namespace)) {
                IQ reply = IQ.createResultIQ(iqPacket);
                Element version = reply.setChildElement("query", "jabber:iq:version");
                version.addElement("name").setText("Client Control Manager");
                version.addElement("version").setText("3.5");
                sendPacket(reply);
            } else {
                // Return error since this is an unknown service request
                IQ reply = IQ.createResultIQ(iqPacket);
                reply.setError(PacketError.Condition.service_unavailable);
                sendPacket(reply);
            }
        } else if (IQ.Type.error == iqPacket.getType() || IQ.Type.result == iqPacket.getType()) {
            if ("jabber:iq:version".equals(namespace)) {
                handleClientVersion(iqPacket);
            }
        } else {
            // Return error since this is an unknown service request
            IQ reply = IQ.createResultIQ(iqPacket);
            reply.setError(PacketError.Condition.service_unavailable);
            sendPacket(reply);
        }
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 60 with Element

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

the class DeleteWorkgroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Get requested group
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    // Load the workgroup
    try {
        Workgroup workgroup = workgroupManager.getWorkgroup(new JID(data.getData().get("workgroup").get(0)));
        workgroupManager.deleteWorkgroup(workgroup);
    } catch (UserNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Workgroup not found");
        return;
    } catch (Exception e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Error executing the command");
        return;
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

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