Search in sources :

Example 26 with Element

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

the class TransportBuddy method sendPresence.

/**
     * Sends the current presence to the session user.
     *
     * @param to JID to send presence updates to.
     */
public void sendPresence(JID to) {
    // TODO: Should figure out best way to handle unknown here.
    Presence p = new Presence();
    p.setTo(to);
    p.setFrom(jid);
    getManager().getSession().getTransport().setUpPresencePacket(p, presence);
    if (verboseStatus != null && verboseStatus.length() > 0) {
        p.setStatus(verboseStatus);
    }
    if (avatarSet && avatar != null) {
        Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
        vcard.addElement("photo").addCDATA(avatar.getXmppHash());
        vcard.addElement("hash").addCDATA(avatar.getXmppHash());
    }
    getManager().sendPacket(p);
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 27 with Element

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

the class ConfigManager method saveSettings.

/**
     * Saves settings from options screen.
     *
     * @param transportName Name of the transport to have it's options saved (type of transport)
     * @param options Options passed from options form.
     */
public void saveSettings(String transportName, HashMap<String, String> options) {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
    Document optConfig = plugin.getOptionsConfig(TransportType.valueOf(transportName));
    Element leftPanel = optConfig.getRootElement().element("leftpanel");
    if (leftPanel != null && leftPanel.nodeCount() > 0) {
        for (Object nodeObj : leftPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element rightPanel = optConfig.getRootElement().element("rightpanel");
    if (rightPanel != null && rightPanel.nodeCount() > 0) {
        for (Object nodeObj : rightPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element bottomPanel = optConfig.getRootElement().element("bottompanel");
    if (bottomPanel != null && bottomPanel.nodeCount() > 0) {
        for (Object nodeObj : bottomPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Element(org.dom4j.Element) KrakenPlugin(net.sf.kraken.KrakenPlugin) Document(org.dom4j.Document)

Example 28 with Element

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

the class LocalMUCRoom method leaveRoom.

@Override
public void leaveRoom(MUCRole leaveRole) {
    if (leaveRole.isLocal()) {
        // Ask other cluster nodes to remove occupant from room
        OccupantLeftEvent event = new OccupantLeftEvent(this, leaveRole);
        CacheFactory.doClusterTask(event);
    }
    try {
        Presence originalPresence = leaveRole.getPresence();
        Presence presence = originalPresence.createCopy();
        presence.setType(Presence.Type.unavailable);
        presence.setStatus(null);
        // Change (or add) presence information about roles and affiliations
        Element childElement = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
        if (childElement == null) {
            childElement = presence.addChildElement("x", "http://jabber.org/protocol/muc#user");
        }
        Element item = childElement.element("item");
        if (item == null) {
            item = childElement.addElement("item");
        }
        item.addAttribute("role", "none");
        // set the role to "none" above, which is always broadcast.
        if (!shouldBroadcastPresence(originalPresence)) {
            // Inform the leaving user that he/she has left the room
            leaveRole.send(presence);
        } else {
            if (getOccupantsByNickname(leaveRole.getNickname()).size() <= 1) {
                // Inform the rest of the room occupants that the user has left the room
                broadcastPresence(presence, false);
            }
        }
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
    // Remove occupant from room and destroy room if empty and not persistent
    OccupantLeftEvent event = new OccupantLeftEvent(this, leaveRole);
    event.setOriginator(true);
    event.run();
}
Also used : OccupantLeftEvent(org.jivesoftware.openfire.muc.cluster.OccupantLeftEvent) Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence) ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) RoomLockedException(org.jivesoftware.openfire.muc.RoomLockedException) CannotBeInvitedException(org.jivesoftware.openfire.muc.CannotBeInvitedException) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NotFoundException(org.jivesoftware.util.NotFoundException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) RegistrationRequiredException(org.jivesoftware.openfire.muc.RegistrationRequiredException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) NotAcceptableException(org.jivesoftware.openfire.muc.NotAcceptableException) ServiceUnavailableException(org.jivesoftware.openfire.muc.ServiceUnavailableException)

Example 29 with Element

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

the class LocalMUCRoom method sendInvitationRejection.

@Override
public void sendInvitationRejection(JID to, String reason, JID sender) {
    if (((MultiUserChatServiceImpl) mucService).getMUCDelegate() != null) {
        switch(((MultiUserChatServiceImpl) mucService).getMUCDelegate().sendingInvitationRejection(this, to, sender, reason)) {
            case HANDLED_BY_DELEGATE:
                //if the delegate is taking care of it, there's nothing for us to do
                return;
            case HANDLED_BY_OPENFIRE:
                //continue as normal if we're asked to handle it
                break;
        }
    }
    Message message = new Message();
    message.setFrom(role.getRoleAddress());
    message.setTo(to);
    Element frag = message.addChildElement("x", "http://jabber.org/protocol/muc#user");
    frag.addElement("decline").addAttribute("from", sender.toBareJID());
    if (reason != null && reason.length() > 0) {
        frag.element("decline").addElement("reason").setText(reason);
    }
    // Send the message with the invitation
    router.route(message);
}
Also used : Message(org.xmpp.packet.Message) Element(org.dom4j.Element)

Example 30 with Element

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

the class LocalMUCRoom method changeOccupantAffiliation.

/**
     * Updates all the presences of the given user with the new affiliation and role information. Do
     * nothing if the given jid is not present in the room. If the user has joined the room from
     * several client resources, all his/her occupants' presences will be updated.
     *
     * @param jid the bare jid of the user to update his/her role.
     * @param newAffiliation the new affiliation for the JID.
     * @param newRole the new role for the JID.
     * @return the list of updated presences of all the client resources that the client used to
     *         join the room.
     * @throws NotAllowedException If trying to change the moderator role to an owner or an admin or
     *         if trying to ban an owner or an administrator.
     */
private List<Presence> changeOccupantAffiliation(MUCRole senderRole, JID jid, MUCRole.Affiliation newAffiliation, MUCRole.Role newRole) throws NotAllowedException {
    List<Presence> presences = new ArrayList<>();
    // Get all the roles (i.e. occupants) of this user based on his/her bare JID
    JID bareJID = jid.asBareJID();
    List<MUCRole> roles = occupantsByBareJID.get(bareJID);
    if (roles == null) {
        return presences;
    }
    // Collect all the updated presences of these roles
    for (MUCRole role : roles) {
        // Update the presence with the new affiliation and role
        if (role.isLocal()) {
            role.setAffiliation(newAffiliation);
            role.setRole(newRole);
            // Notify the other cluster nodes to update the occupant
            CacheFactory.doClusterTask(new UpdateOccupant(this, role));
            // Prepare a new presence to be sent to all the room occupants
            presences.add(role.getPresence().createCopy());
        } else {
            // Ask the cluster node hosting the occupant to make the changes. Note that if the change
            // is not allowed a NotAllowedException will be thrown
            Element element = (Element) CacheFactory.doSynchronousClusterTask(new UpdateOccupantRequest(this, role.getNickname(), newAffiliation, newRole), role.getNodeID().toByteArray());
            if (element != null) {
                // Prepare a new presence to be sent to all the room occupants
                presences.add(new Presence(element, true));
            } else {
                throw new NotAllowedException();
            }
        }
    }
    // Answer all the updated presences
    return presences;
}
Also used : UpdateOccupant(org.jivesoftware.openfire.muc.cluster.UpdateOccupant) MUCRole(org.jivesoftware.openfire.muc.MUCRole) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) UpdateOccupantRequest(org.jivesoftware.openfire.muc.cluster.UpdateOccupantRequest) Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence)

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