本文整理汇总了Java中org.xmpp.packet.Presence.toXML方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.toXML方法的具体用法?Java Presence.toXML怎么用?Java Presence.toXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.toXML方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// If the user has any remaining sessions, don't record the offline info.
if (sessionManager.getActiveSessionCount(username) > 0) {
return;
}
String offlinePresence = null;
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>.
if (!presence.getElement().elements().isEmpty()) {
offlinePresence = presence.toXML();
}
// Keep track of the time when the user went offline
java.util.Date offlinePresenceDate = new java.util.Date();
boolean addedToCache;
if (offlinePresence == null) {
addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
}
else {
addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
}
if (!addedToCache) {
return;
}
lastActivityCache.put(username, offlinePresenceDate.getTime());
writeToDatabase(username, offlinePresence, offlinePresenceDate);
}
}
示例2: userUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// If the user has any remaining sessions, don't record the offline info.
if (sessionManager.getActiveSessionCount(username) > 0) {
return;
}
String offlinePresence = null;
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>.
if (!presence.getElement().elements().isEmpty()) {
offlinePresence = presence.toXML();
}
// Keep track of the time when the user went offline
java.util.Date offlinePresenceDate = new java.util.Date();
boolean addedToCache;
if (offlinePresence == null) {
addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
}
else {
addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
}
if (!addedToCache) {
return;
}
lastActivityCache.put(username, offlinePresenceDate.getTime());
writeToDatabase(username, offlinePresence, offlinePresenceDate);
}
}
示例3: userUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// If the user has any remaining sessions, don't record the offline info.
if (sessionManager.getActiveSessionCount(username) > 0) {
return;
}
String offlinePresence = null;
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>.
if (!presence.getElement().elements().isEmpty()) {
offlinePresence = presence.toXML();
}
// Keep track of the time when the user went offline
java.util.Date offlinePresenceDate = new java.util.Date();
boolean addedToCache;
if (offlinePresence == null) {
addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
}
else {
addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
}
if (!addedToCache) {
return;
}
lastActivityCache.put(username, offlinePresenceDate.getTime());
// Insert data into the database.
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_OFFLINE_PRESENCE);
pstmt.setString(1, username);
if (offlinePresence != null) {
DbConnectionManager.setLargeTextField(pstmt, 2, offlinePresence);
}
else {
pstmt.setNull(2, Types.VARCHAR);
}
pstmt.setString(3, StringUtils.dateToMillis(offlinePresenceDate));
pstmt.execute();
}
catch (SQLException sqle) {
Log.error("Error storing offline presence of user: " + username, sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
}