当前位置: 首页>>代码示例>>Java>>正文


Java Presence.addChildElement方法代码示例

本文整理汇总了Java中org.xmpp.packet.Presence.addChildElement方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.addChildElement方法的具体用法?Java Presence.addChildElement怎么用?Java Presence.addChildElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xmpp.packet.Presence的用法示例。


在下文中一共展示了Presence.addChildElement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setPresence

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * Sets the current status.
 *
 * @param newpresence New presence to set to.
 */
public void setPresence(PresenceType newpresence) {
    if (newpresence == null) {
        newpresence = PresenceType.unknown;
    }
    if (newpresence.equals(PresenceType.unavailable)) {
        verboseStatus = "";
    }
    if (!presence.equals(newpresence) && newpresence != PresenceType.unknown) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
        if (!verboseStatus.equals("")) {
            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);
    }
    presence = newpresence;
    lastActivityTimestamp = new Date().getTime();
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:31,代码来源:TransportBuddy.java

示例2: setVerboseStatus

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * Sets the current verbose status.
 *
 * @param newstatus New verbose status.
 */
public void setVerboseStatus(String newstatus) {
    if (newstatus == null) {
        newstatus = "";
    }
    if (!verboseStatus.equals(newstatus)) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, presence);
        if (!newstatus.equals("")) {
            p.setStatus(newstatus);
        }
        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);
    }
    verboseStatus = newstatus;
    lastActivityTimestamp = new Date().getTime();
    lastActivityEvent = verboseStatus;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:29,代码来源:TransportBuddy.java

示例3: sendPresence

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:22,代码来源:TransportBuddy.java

示例4: setAvatar

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * Sets the current avatar for this contact.
 *
 * @param avatar Avatar instance to associate with this contact.
 */
public void setAvatar(Avatar avatar) {
    boolean triggerUpdate = false;
    if (    (avatar != null && this.avatar == null) ||
            (avatar == null && this.avatar != null) ||
            (avatar != null && !this.avatar.getXmppHash().equals(avatar.getXmppHash()))) {
        triggerUpdate = true;
    }
    this.avatar = avatar;
    this.avatarSet = true;
    if (triggerUpdate) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, presence);
        if (!verboseStatus.equals("")) {
            p.setStatus(verboseStatus);
        }
        Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
        if (avatar != null) {
            vcard.addElement("photo").addCDATA(avatar.getXmppHash());
            vcard.addElement("hash").addCDATA(avatar.getXmppHash());
        }
        getManager().sendPacket(p);
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:31,代码来源:TransportBuddy.java

示例5: setPresenceAndStatus

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * Convenience routine to set both presence and verbose status at the same time.
 *
 * @param newpresence New presence to set to.
 * @param newstatus New verbose status.
 */
public void setPresenceAndStatus(PresenceType newpresence, String newstatus) {
    Log.debug("Updating status ["+newpresence+","+newstatus+"] for "+this);
    if (newpresence == null) {
        newpresence = PresenceType.unknown;
    }
    if (newstatus == null) {
        newstatus = "";
    }
    if (newpresence.equals(PresenceType.unavailable)) {
        newstatus = "";
    }
    if ((!presence.equals(newpresence) && newpresence != PresenceType.unknown) || !verboseStatus.equals(newstatus)) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
        if (!newstatus.equals("")) {
            p.setStatus(newstatus);
        }
        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);
    }
    presence = newpresence;
    verboseStatus = newstatus;
    lastActivityTimestamp = new Date().getTime();
    lastActivityEvent = verboseStatus;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:38,代码来源:TransportBuddy.java

示例6: getStatusPresence

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public Presence getStatusPresence() {
    Presence queueStatus = new Presence();
    queueStatus.setFrom(address);

    // Add Notify Queue
    Element status = queueStatus.addChildElement("notify-queue", "http://jabber.org/protocol/workgroup");

    Element countElement = status.addElement("count");
    countElement.setText(Integer.toString(getRequestCount()));
    if (getRequestCount() > 0) {
        Element oldestElement = status.addElement("oldest");
        oldestElement.setText(UTC_FORMAT.format(getFirst().getCreationTime()));
    }

    Element timeElement = status.addElement("time");
    timeElement.setText(Integer.toString(getAverageTime()));
    Element statusElement = status.addElement("status");

    if (workgroup.getStatus() == Workgroup.Status.OPEN && presenceAvailable) {
        statusElement.setText("open");
    }
    else {
        queueStatus.setType(Presence.Type.unavailable);
        // TODO: actually active should be a full-blown workgroup state since queues
        // may be empty but still active
        if (getRequestCount() > 0) {
            statusElement.setText("active");
        }
        else {
            if (workgroup.getStatus() == Workgroup.Status.READY) {
                statusElement.setText("ready");
            }
            else {
                statusElement.setText("closed");
            }
        }
    }
    return queueStatus;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:40,代码来源:RequestQueue.java

示例7: destroyRoom

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void destroyRoom(DestroyRoomRequest destroyRequest) {
    JID alternateJID = destroyRequest.getAlternateJID();
    String reason = destroyRequest.getReason();
    Collection<MUCRole> removedRoles = new ArrayList<>();
    lock.writeLock().lock();
    try {
        boolean hasRemoteOccupants = false;
        // Remove each occupant
        for (MUCRole leaveRole : occupantsByFullJID.values()) {

            if (leaveRole != null) {
                // Add the removed occupant to the list of removed occupants. We are keeping a
                // list of removed occupants to process later outside of the lock.
                if (leaveRole.isLocal()) {
                    removedRoles.add(leaveRole);
                }
                else {
                    hasRemoteOccupants = true;
                }
                removeOccupantRole(leaveRole, destroyRequest.isOriginator());
            }
        }
        endTime = System.currentTimeMillis();
        // Set that the room has been destroyed
        isDestroyed = true;
        if (destroyRequest.isOriginator()) {
            if (hasRemoteOccupants) {
                // Ask other cluster nodes to remove occupants since room is being destroyed
                CacheFactory.doClusterTask(new DestroyRoomRequest(this, alternateJID, reason));
            }
            // Removes the room from the list of rooms hosted in the service
            mucService.removeChatRoom(name);
        }
    }
    finally {
        lock.writeLock().unlock();
    }
    // Send an unavailable presence to each removed occupant
    for (MUCRole removedRole : removedRoles) {
        try {
            // Send a presence stanza of type "unavailable" to the occupant
            Presence presence = createPresence(Presence.Type.unavailable);
            presence.setFrom(removedRole.getRoleAddress());

            // A fragment containing the x-extension for room destruction.
            Element fragment = presence.addChildElement("x",
                    "http://jabber.org/protocol/muc#user");
            Element item = fragment.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            if (alternateJID != null) {
                fragment.addElement("destroy").addAttribute("jid", alternateJID.toString());
            }
            if (reason != null && reason.length() > 0) {
                Element destroy = fragment.element("destroy");
                if (destroy == null) {
                    destroy = fragment.addElement("destroy");
                }
                destroy.addElement("reason").setText(reason);
            }
            removedRole.send(presence);
        }
        catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    if (destroyRequest.isOriginator()) {
        // Remove the room from the DB if the room was persistent
        MUCPersistenceManager.deleteFromDB(this);
        // Fire event that the room has been destroyed
        MUCEventDispatcher.roomDestroyed(getRole().getRoleAddress());
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:74,代码来源:LocalMUCRoom.java

示例8: getDetailedStatusPresence

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public Presence getDetailedStatusPresence() {
    Presence queueStatus = new Presence();
    queueStatus.setFrom(address);
    if (workgroup.getStatus() == Workgroup.Status.OPEN && presenceAvailable) {
        queueStatus.setType(null);
    }
    else {
        queueStatus.setType(Presence.Type.unavailable);
    }

    Element details = queueStatus.addChildElement("notify-queue-details", "http://jabber.org/protocol/workgroup");
    int i = 0;
    for (UserRequest request : getRequests()) {
        Element user = details.addElement("user", "http://jabber.org/protocol/workgroup");
        try {
            user.addAttribute("jid", request.getUserJID().toString());

            // Add Sub-Elements
            Element position = user.addElement("position");
            position.setText(Integer.toString(i));

            Element time = user.addElement("time");
            time.setText(Integer.toString(request.getTimeStatus()));

            Element joinTime = user.addElement("join-time");
            joinTime.setText(UTC_FORMAT.format(request.getCreationTime()));
            i++;
        }
        catch (Exception e) {
            // Since we are not locking the list of requests while doing this operation (for
            // performance reasons) it is possible that the request got accepted or cancelled
            // thus generating a NPE

            // Remove the request that generated the exception
            details.remove(user);
            // Log an error if the request still belongs to this queue
            if (this.equals(request.getRequestQueue())) {
                Log.error(e.getMessage(), e);
            }
        }
    }
    return queueStatus;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:44,代码来源:RequestQueue.java

示例9: destroyRoom

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void destroyRoom(DestroyRoomRequest destroyRequest) {
    String alternateJID = destroyRequest.getAlternateJID();
    String reason = destroyRequest.getReason();
    MUCRole leaveRole;
    Collection<MUCRole> removedRoles = new ArrayList<MUCRole>();
    lock.writeLock().lock();
    try {
        boolean hasRemoteOccupants = false;
        // Remove each occupant
        for (String nickname: occupants.keySet()) {
            leaveRole = occupants.remove(nickname);

            if (leaveRole != null) {
                // Add the removed occupant to the list of removed occupants. We are keeping a
                // list of removed occupants to process later outside of the lock.
                if (leaveRole.isLocal()) {
                    removedRoles.add(leaveRole);
                }
                else {
                    hasRemoteOccupants = true;
                }
                removeOccupantRole(leaveRole, destroyRequest.isOriginator());
            }
        }
        endTime = System.currentTimeMillis();
        // Set that the room has been destroyed
        isDestroyed = true;
        if (destroyRequest.isOriginator()) {
            if (hasRemoteOccupants) {
                // Ask other cluster nodes to remove occupants since room is being destroyed
                CacheFactory.doClusterTask(new DestroyRoomRequest(this, alternateJID, reason));
            }
            // Removes the room from the list of rooms hosted in the service
            mucService.removeChatRoom(name);
        }
    }
    finally {
        lock.writeLock().unlock();
    }
    // Send an unavailable presence to each removed occupant
    for (MUCRole removedRole : removedRoles) {
        try {
            // Send a presence stanza of type "unavailable" to the occupant
            Presence presence = createPresence(Presence.Type.unavailable);
            presence.setFrom(removedRole.getRoleAddress());

            // A fragment containing the x-extension for room destruction.
            Element fragment = presence.addChildElement("x",
                    "http://jabber.org/protocol/muc#user");
            Element item = fragment.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            if (alternateJID != null && alternateJID.length() > 0) {
                fragment.addElement("destroy").addAttribute("jid", alternateJID);
            }
            if (reason != null && reason.length() > 0) {
                Element destroy = fragment.element("destroy");
                if (destroy == null) {
                    destroy = fragment.addElement("destroy");
                }
                destroy.addElement("reason").setText(reason);
            }
            removedRole.send(presence);
        }
        catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    if (destroyRequest.isOriginator()) {
        // Remove the room from the DB if the room was persistent
        MUCPersistenceManager.deleteFromDB(this);
        // Fire event that the room has been destroyed
        MUCEventDispatcher.roomDestroyed(getRole().getRoleAddress());
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:76,代码来源:LocalMUCRoom.java

示例10: destroyRoom

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void destroyRoom(DestroyRoomRequest destroyRequest) {
    JID alternateJID = destroyRequest.getAlternateJID();
    String reason = destroyRequest.getReason();
    Collection<MUCRole> removedRoles = new ArrayList<MUCRole>();
    lock.writeLock().lock();
    try {
        boolean hasRemoteOccupants = false;
        // Remove each occupant
        for (MUCRole leaveRole : occupantsByFullJID.values()) {

            if (leaveRole != null) {
                // Add the removed occupant to the list of removed occupants. We are keeping a
                // list of removed occupants to process later outside of the lock.
                if (leaveRole.isLocal()) {
                    removedRoles.add(leaveRole);
                }
                else {
                    hasRemoteOccupants = true;
                }
                removeOccupantRole(leaveRole, destroyRequest.isOriginator());
            }
        }
        endTime = System.currentTimeMillis();
        // Set that the room has been destroyed
        isDestroyed = true;
        if (destroyRequest.isOriginator()) {
            if (hasRemoteOccupants) {
                // Ask other cluster nodes to remove occupants since room is being destroyed
                CacheFactory.doClusterTask(new DestroyRoomRequest(this, alternateJID, reason));
            }
            // Removes the room from the list of rooms hosted in the service
            mucService.removeChatRoom(name);
        }
    }
    finally {
        lock.writeLock().unlock();
    }
    // Send an unavailable presence to each removed occupant
    for (MUCRole removedRole : removedRoles) {
        try {
            // Send a presence stanza of type "unavailable" to the occupant
            Presence presence = createPresence(Presence.Type.unavailable);
            presence.setFrom(removedRole.getRoleAddress());

            // A fragment containing the x-extension for room destruction.
            Element fragment = presence.addChildElement("x",
                    "http://jabber.org/protocol/muc#user");
            Element item = fragment.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            if (alternateJID != null) {
                fragment.addElement("destroy").addAttribute("jid", alternateJID.toFullJID());
            }
            if (reason != null && reason.length() > 0) {
                Element destroy = fragment.element("destroy");
                if (destroy == null) {
                    destroy = fragment.addElement("destroy");
                }
                destroy.addElement("reason").setText(reason);
            }
            removedRole.send(presence);
        }
        catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    if (destroyRequest.isOriginator()) {
        // Remove the room from the DB if the room was persistent
        MUCPersistenceManager.deleteFromDB(this);
        // Fire event that the room has been destroyed
        MUCEventDispatcher.roomDestroyed(getRole().getRoleAddress());
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:74,代码来源:LocalMUCRoom.java


注:本文中的org.xmpp.packet.Presence.addChildElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。