本文整理汇总了Java中org.xmpp.packet.Presence.createCopy方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.createCopy方法的具体用法?Java Presence.createCopy怎么用?Java Presence.createCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.createCopy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Handle presence updates that affect roster subscriptions.
*
* @param presence The presence presence to handle
* @throws PacketException if the packet is null or the packet could not be routed.
*/
public void process(Presence presence) throws PacketException {
try {
process((Packet)presence);
}
catch (UnauthorizedException e) {
try {
LocalSession session = (LocalSession) sessionManager.getSession(presence.getFrom());
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(), null, true));
presence.setTo(session.getAddress());
}
else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.not_authorized);
deliverer.deliver(presence);
}
catch (Exception err) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), err);
}
}
}
示例2: updatePresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Updates the presence of the AgentSession with the new received presence. The max number of
* chats and number of current chats will be updated if that information was included in the presence.
* If no information was provided then default values of queues, workgroups or general settings will
* be used instead.
*
* @param packet the new presence sent by the agent.
*/
public void updatePresence(Presence packet) {
// Create a copy of the received Presence to use as the presence of the AgentSession
Presence sessionPresence = packet.createCopy();
// Remove the "agent-status" element from the new AgentSession's presence
Element child = sessionPresence.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
sessionPresence.getElement().remove(child);
// Set the new presence to the AgentSession
presence = sessionPresence;
// Set the new maximum number of chats and the number of current chats to the
// AgentSession based on the values sent within the presence (if any)
Element elem = packet.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
if (elem != null) {
Iterator<Element> metaIter = elem.elementIterator();
while (metaIter.hasNext()) {
Element agentStatusElement = metaIter.next();
if ("max-chats".equals(agentStatusElement.getName())) {
String maxChats = agentStatusElement.getText();
if (maxChats == null || maxChats.trim().length() == 0) {
setMaxChats(-1);
}
else {
setMaxChats(Integer.parseInt(maxChats));
}
}
}
}
}
示例3: broadcastUnavailableForDirectedPresences
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends an unavailable presence to the entities that received a directed (available) presence
* by the user that is now going offline.
*
* @param update the unavailable presence sent by the user.
*/
private void broadcastUnavailableForDirectedPresences(Presence update) {
JID from = update.getFrom();
if (from == null) {
return;
}
if (localServer.isLocal(from)) {
// Remove the registry of directed presences of this user
Collection<DirectedPresence> directedPresences = null;
Lock lock = CacheFactory.getLock(from.toString(), directedPresencesCache);
try {
lock.lock();
directedPresences = directedPresencesCache.remove(from.toString());
} finally {
lock.unlock();
}
if (directedPresences != null) {
// Iterate over all the entities that the user sent a directed presence
for (DirectedPresence directedPresence : directedPresences) {
for (String receiver : directedPresence.getReceivers()) {
Presence presence = update.createCopy();
presence.setTo(receiver);
localServer.getPresenceRouter().route(presence);
}
}
localDirectedPresences.remove(from.toString());
}
}
}
示例4: broadcastUnavailableForDirectedPresences
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends an unavailable presence to the entities that received a directed (available) presence
* by the user that is now going offline.
*
* @param update the unavailable presence sent by the user.
*/
private void broadcastUnavailableForDirectedPresences(Presence update) {
JID from = update.getFrom();
if (from == null) {
return;
}
if (localServer.isLocal(from)) {
// Remove the registry of directed presences of this user
Collection<DirectedPresence> directedPresences = null;
Lock lock = CacheFactory.getLock(from.toString(), directedPresencesCache);
try {
lock.lock();
directedPresences = directedPresencesCache.remove(from.toString());
} finally {
lock.unlock();
}
if (directedPresences != null) {
// Iterate over all the entities that the user sent a directed presence
for (DirectedPresence directedPresence : directedPresences) {
for (String receiver : directedPresence.getReceivers()) {
Presence presence = update.createCopy();
presence.setTo(receiver);
localServer.getPresenceRouter().route(presence);
}
}
localDirectedPresences.remove(from.toString());
}
}
}
示例5: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* 处理出席数据包
*
* @param packet
*/
public void process(Packet packet) {
ClientSession session = sessionManager.getSession(packet.getFrom());
try {
Presence presence = (Presence) packet;
Presence.Type type = presence.getType();
if (type == null) { // null == available
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
List<Notification> list = notificationService
.findNotificationsByUsername(session.getUsername());
if (list != null && list.size() > 0) {
for (Notification notification : list) {
String apiKey = notification.getApiKey();
String title = notification.getTitle();
String message = notification.getMessage();
String uri = notification.getUri();
String imageUrl = notification.getImageUrl();
notificationManager.sendNotifcationToUser(apiKey,
session.getUsername(), title, message, uri,
imageUrl, false);
notificationService
.deleteNotification(notification);
}
}
}
} else if (Presence.Type.unavailable == type) {// 不可用的
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error("内部服务器错误. Triggered by packet: " + packet, e);
}
}
示例6: broadcast
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void broadcast(BroadcastPresenceRequest presenceRequest) {
String jid = null;
Presence presence = presenceRequest.getPresence();
JID to = presence.getTo();
Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID()) {
jid = frag.element("item").attributeValue("jid");
}
for (MUCRole occupant : occupantsByFullJID.values()) {
if (!occupant.isLocal()) {
continue;
}
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID()) {
if (MUCRole.Role.moderator == occupant.getRole()) {
frag.element("item").addAttribute("jid", jid);
}
else {
frag.element("item").addAttribute("jid", null);
}
}
// Some status codes should only be included in the "self-presence", which is only sent to the user, but not to other occupants.
if (occupant.getPresence().getFrom().equals(to)) {
Presence selfPresence = presence.createCopy();
Element fragSelfPresence = selfPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
fragSelfPresence.addElement("status").addAttribute("code", "110");
// Only in the context of entering the room status code 100, 201 and 210 should be sent.
// http://xmpp.org/registrar/mucstatus.html
if (presenceRequest.isJoinPresence()) {
boolean isRoomNew = isLocked() && creationDate.getTime() == lockedTime;
if (canAnyoneDiscoverJID()) {
// // XEP-0045: Example 26.
// If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
fragSelfPresence.addElement("status").addAttribute("code", "100");
}
if (isRoomNew) {
fragSelfPresence.addElement("status").addAttribute("code", "201");
}
}
occupant.send(selfPresence);
} else {
occupant.send(presence);
}
}
}
示例7: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Processes the presence packet.
*
* @param packet the packet
*/
public void process(Packet packet) {
ClientSession session = sessionManager.getSession(packet.getFrom());
try {
Presence presence = (Presence) packet;
Presence.Type type = presence.getType();
if (type == null) { // null == available
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
}
} else if (Presence.Type.unavailable == type) {
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error("Internal server error. Triggered by packet: " + packet,
e);
}
}
示例8: broadcast
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void broadcast(BroadcastPresenceRequest presenceRequest) {
String jid = null;
Presence presence = presenceRequest.getPresence();
Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID()) {
jid = frag.element("item").attributeValue("jid");
}
for (MUCRole occupant : occupantsByFullJID.values()) {
if (!occupant.isLocal()) {
continue;
}
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID()) {
if (MUCRole.Role.moderator == occupant.getRole()) {
frag.element("item").addAttribute("jid", jid);
}
else {
frag.element("item").addAttribute("jid", null);
}
}
// Some status codes should only be included in the "self-presence", which is only sent to the user, but not to other occupants.
if (occupant.getPresence().getFrom().equals(presence.getTo())) {
Presence selfPresence = presence.createCopy();
Element fragSelfPresence = selfPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
fragSelfPresence.addElement("status").addAttribute("code", "110");
// Only in the context of entering the room status code 100, 201 and 210 should be sent.
// http://xmpp.org/registrar/mucstatus.html
if (presenceRequest.isJoinPresence()) {
boolean isRoomNew = isLocked() && creationDate.getTime() == lockedTime;
if (canAnyoneDiscoverJID()) {
// // XEP-0045: Example 26.
// If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
fragSelfPresence.addElement("status").addAttribute("code", "100");
}
if (isRoomNew) {
fragSelfPresence.addElement("status").addAttribute("code", "201");
}
}
occupant.send(selfPresence);
} else {
occupant.send(presence);
}
}
}
示例9: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void process(Presence presence, ClientSession session)
throws UnauthorizedException, PacketException {
try {
Presence.Type type = presence.getType();
if (type == null) { // null == available
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
}
} else if (Presence.Type.unavailable == type) {
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error(
"Internal server error. Triggered by packet: " + presence,
e);
}
}
示例10: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void process(Presence presence, ClientSession session)
throws UnauthorizedException, PacketException {
try {
Presence.Type type = presence.getType();
// Available
if (type == null) {
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
}
} else if (Presence.Type.unavailable == type) {
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error(
"Internal server error. Triggered by packet: " + presence,
e);
}
}