本文整理汇总了Java中org.xmpp.packet.Message.getChildElement方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getChildElement方法的具体用法?Java Message.getChildElement怎么用?Java Message.getChildElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Message
的用法示例。
在下文中一共展示了Message.getChildElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAnnotated
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Override
public boolean isAnnotated(Message message) {
boolean rv = false;
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String currentInternalMetaJSON = internalMeta != null ? internalMeta.getText() : null;
if (currentInternalMetaJSON != null && !currentInternalMetaJSON.isEmpty()) {
JsonParser parser = new JsonParser();
JsonElement jsonElement = parser.parse(currentInternalMetaJSON).getAsJsonObject();
JsonObject jsonObject = jsonElement.isJsonObject() ? jsonElement.getAsJsonObject() : null;
if (jsonObject != null) {
rv = jsonObject.has(MMXServerConstants.DISTRIBUTED_KEY);
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Checking if message :{} result:{}", message, rv);
}
return rv;
}
示例2: receivePacket
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Override
public void receivePacket(final Packet packet) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Received incoming XMPP packet:\n" + packet);
}
if (packet instanceof IQ) {
IQ iq = (IQ) packet;
if (iq.getType().equals(IQ.Type.result) || iq.getType().equals(IQ.Type.error)) {
// Result type, hand off to callback handler.
response(packet);
} else {
processIqGetSet(iq);
}
} else if (packet instanceof Message) {
Message message = (Message) packet;
if (message.getType().equals(Message.Type.error)
|| message.getChildElement("received", XmppNamespace.NAMESPACE_XMPP_RECEIPTS) != null) {
// Response type, hand off to callback handler.
response(packet);
} else {
processMessage(message);
}
} else {
sendErrorResponse(packet, FederationError.Code.BAD_REQUEST, "Unhandled packet type: "
+ packet.getElement().getQName().getName());
}
}
示例3: processMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Processes Message stanzas. This encompasses wavelet updates, update acks,
* and ping messages.
*/
private void processMessage(Message message) {
if (message.getChildElement("event", XmppNamespace.NAMESPACE_PUBSUB_EVENT) != null) {
remote.update(message, new IncomingCallback(message));
} else if (message.getChildElement("ping", XmppNamespace.NAMESPACE_WAVE_SERVER) != null) {
// Respond inline to the ping.
LOG.info("Responding to ping from: " + message.getFrom());
Message response = XmppUtil.createResponseMessage(message);
response.addChildElement("received", XmppNamespace.NAMESPACE_XMPP_RECEIPTS);
transport.sendPacket(response);
} else {
sendErrorResponse(message, FederationError.Code.BAD_REQUEST, "Unhandled message type");
}
}
示例4: annotate
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Override
public void annotate(Message message) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Annotating a message with id:{}", message.getID());
}
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String currentInternalMetaJSON = internalMeta != null ? internalMeta.getText() : null;
JsonObject jsonObject = null;
if (currentInternalMetaJSON != null && !currentInternalMetaJSON.isEmpty()) {
JsonParser parser = new JsonParser();
try {
jsonObject = parser.parse(currentInternalMetaJSON).getAsJsonObject();
} catch (JsonSyntaxException e) {
LOGGER.warn("Failed to parse mmxmeta string:{} as JSON string", currentInternalMetaJSON, e);
//assume that the mmxmeta was some invalid JSON.
jsonObject = new JsonObject();
}
} else {
jsonObject = new JsonObject();
}
jsonObject.addProperty(MMXServerConstants.DISTRIBUTED_KEY, true);;
String updatedInternalMetaJSON = jsonObject.toString();
if (internalMeta == null) {
internalMeta = mmx.addElement(Constants.MMX_MMXMETA);
}
internalMeta.setText(updatedInternalMetaJSON);
}
示例5: testSendWithDeviceIdSpecifiedButNotRecipientId
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Test
public void testSendWithDeviceIdSpecifiedButNotRecipientId() throws Exception {
SendMessageRequest request = new SendMessageRequest();
request.setDeviceId("12345678987654322");
String message = "Simple Message";
request.setReceipt(true);
request.setReplyTo("login3");
Map<String, String> content = new HashMap<String, String>();
content.put("textContent", message);
request.setContent(content);
String appId = "AAABSNIBKOstQST7";
MessageSenderImpl sender = new MessageReturningStubMessageSenderImpl();
SendMessageResult result = sender.send("bogus-sender-user-id", appId, request);
assertNotNull("message result is null", result);
assertNotNull("Message Id is expected to be not null", result.getSentList().get(0).getMessageId());
/**
* validate the message contents
*/
Message builtMessage = ((MessageReturningStubMessageSenderImpl) sender).messageList.get(0);
JID to = builtMessage.getTo();
String expectedUserId = "magnet.way";
String expectedTo = expectedUserId + JIDUtil.APP_ID_DELIMITER + appId.toLowerCase() + "@" + sender.getDomain() + "/" + request.getDeviceId(); //importantuser%[email protected]/12345678987654322
String builtMessageXML = builtMessage.toXML();
assertNotNull(builtMessageXML);
assertEquals("Non matching to", expectedTo, to.toString());
Element receipt = builtMessage.getChildElement(Constants.XMPP_REQUEST, Constants.XMPP_NS_RECEIPTS);
assertNotNull("Receipt element is missing", receipt);
}
示例6: test2Annotate
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Case where the incoming message has no mmxmeta
* @throws Exception
*/
public void test2Annotate() throws Exception {
String appId = "testapp1";
String domain = "mmx";
String user = "rahul";
Message myMessage = new Message();
myMessage.setType(Message.Type.chat);
myMessage.setFrom(appId + "%" + appId + "@" + domain);
myMessage.setTo(user + "%" + appId + "@" + domain);
myMessage.setID("10");
Element mmxElement = myMessage.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element payloadElement = mmxElement.addElement(Constants.MMX_PAYLOAD);
DateFormat fmt = Utils.buildISO8601DateFormat();
String formattedDateTime = fmt.format(new Date());
payloadElement.addAttribute(Constants.MMX_ATTR_STAMP, formattedDateTime);
String text = ".";
payloadElement.setText(text);
payloadElement.addAttribute(Constants.MMX_ATTR_CHUNK, MessageBuilder.buildChunkAttributeValue(text));
myMessage.setBody(MMXServerConstants.MESSAGE_BODY_DOT);
MessageDistributedAnnotator messageDistributedAnnotator = new MessageDistributedAnnotator();
messageDistributedAnnotator.annotate(myMessage);
Element mmx = myMessage.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String revisedJSON = internalMeta.getText();
assertNotNull(revisedJSON);
String expected = "{\"mmxdistributed\":true}";
assertEquals("Non matching mmxmeta json", expected, revisedJSON);
}
示例7: processIncoming
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Override
public void processIncoming(Packet packet) {
if (packet instanceof Message) {
LOGGER.debug("Sending the same message back");
Message message = (Message) packet;
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
boolean receiptRequested = message.getChildElement(Constants.XMPP_REQUEST, Constants.XMPP_NS_RECEIPTS) != null;
JID fromJID = message.getFrom();
JID toJID = message.getTo();
message.setTo(fromJID);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String userId = JIDUtil.getUserId(fromJID);
String devId = fromJID.getResource();
String mmxMetaJSON = MMXMetaBuilder.build(userId, devId);
if (internalMeta != null) {
mmx.remove(internalMeta);
}
Element revisedMeta = mmx.addElement(Constants.MMX_MMXMETA);
revisedMeta.setText(mmxMetaJSON);
if (receiptRequested) {
//remove the receipt requested element to ensure we don't have a loop
message.deleteExtension(Constants.XMPP_REQUEST, Constants.XMPP_NS_RECEIPTS);
}
try {
//add a little sleep to differentiate between the send and recvd time.
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
}
autoRespondingConnection.sendPacket(message);
/*
* Acknowledge the receipt by sending an IQ
*/
String originalMessageId = message.getID();
String from = fromJID.toString();
String to = toJID.toString();
LOGGER.debug("Attempting to deliver ack");
IQ ackIQ = buildAckIQ(from, to, originalMessageId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ack IQ:{}", ackIQ.toXML());
}
autoRespondingConnection.sendPacket(ackIQ);
if (receiptRequested) {
LOGGER.debug("Sending delivery receipt for message with id:{}", originalMessageId);
String appId = JIDUtil.getAppId(to);
Message receipt = buildDeliveryReceipt(appId, from, to, originalMessageId);
autoRespondingConnection.sendPacket(receipt);
} else {
LOGGER.debug("Not sending delivery receipt for message with id:{}", originalMessageId);
}
}
}
示例8: processIncoming
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Override
public void processIncoming(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
JID fromJID = packet.getFrom();
JID toJID = packet.getTo();
packet.setTo(fromJID);
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element meta = mmx.element(Constants.MMX_META);
if (meta == null) {
LOGGER.info("No meta in the message with id:{}", message.getID());
return;
}
//Simulate SDK ack
String originalMessageId = packet.getID();
String from = fromJID.toString();
String to = toJID.toString();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Attempting to deliver ack");
}
IQ ackIQ = BotRegistrationImpl.buildAckIQ(from, to, originalMessageId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ack IQ:{}", ackIQ.toXML());
}
connection.sendPacket(ackIQ);
String metaJSON = meta.getText();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Meta JSON:{}", metaJSON);
}
RPSLSGameInfo gameInfo = GsonData.getGson().fromJson(metaJSON, RPSLSGameInfo.class);
if (gameInfo.getType() == RPSLSMessageType.INVITATION) {
//process an invitation
//step 1. Send an acceptance
//step 2. Send a choice after 2 seconds.
processRPSLSInvitationMessage(fromJID, toJID, gameInfo);
} else {
//ignore the other types
LOGGER.info("Ignoring a message with type:{} message:{}", gameInfo.getType(), message);
}
}
}
示例9: test2Build
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Test with content containing XML characters.
* @throws Exception
*/
@Test
public void test2Build() throws Exception {
SendMessageRequest request = new SendMessageRequest();
request.setRecipientUserIds(Collections.singletonList("test"));
String message = "<message><subject>This is a test</subject><content>Tell me a story</content></message>";
Map<String, String> contentMap = new HashMap<String, String>();
contentMap.put("content", message);
contentMap.put("contentType", "text");
request.setContent(contentMap);
request.setReceipt(true);
AppEntity app = new AppEntity();
app.setAppId("i1cglsw8dsa");
app.setServerUserId("admin");
String msgId = new MessageIdGeneratorImpl().generateItemIdentifier(app.getAppId());
MessageBuilder builder = new MessageBuilder();
builder.setAppId(app.getAppId());
builder.setDomain("localhost");
builder.setMetadata(request.getContent());
builder.setUtcTime(System.currentTimeMillis());
builder.setId(msgId);
builder.setSenderId(app.getServerUserId());
builder.setUserId(request.getRecipientUserIds().get(0));
Message m = builder.build();
assertNotNull("Message shouldn't be null", m);
Element mmx = m.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
assertNotNull("mmx element is null", mmx);
Element payload = mmx.element(Constants.MMX_PAYLOAD);
assertNotNull("payload element is null", payload);
String content = payload.getText();
assertNotNull("payload content is null", content);
assertEquals("Non matching content", "", content);
JID from = m.getFrom();
assertEquals ("Non matching from jid", "admin%[email protected]", from.toString());
String body = m.getBody();
assertEquals("Message body is not expected", MMXServerConstants.MESSAGE_BODY_DOT, body);
}
示例10: test3BuildWithNameAndValue
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Test
public void test3BuildWithNameAndValue() throws Exception {
SendMessageRequest request = new SendMessageRequest();
request.setRecipientUserIds(Collections.singletonList("test"));
String message = "Simple Test";
Map<String, String> contentMap = new HashMap<String, String>();
contentMap.put("content", message);
contentMap.put("contentType", "text");
contentMap.put("apple", "washington");
contentMap.put("avocado", "california");
request.setContent(contentMap);
request.setReceipt(true);
AppEntity app = new AppEntity();
app.setAppId("i1cglsw8dsa");
app.setServerUserId("admin");
String msgId = new MessageIdGeneratorImpl().generateItemIdentifier(app.getAppId());
MessageBuilder builder = new MessageBuilder();
builder.setAppId(app.getAppId());
builder.setDomain("localhost");
builder.setSenderId(app.getServerUserId());
builder.setUserId(request.getRecipientUserIds().get(0));
builder.setMetadata(request.getContent());
builder.setUtcTime(System.currentTimeMillis());
builder.setId(msgId);
Message m = builder.build();
assertNotNull("Message shouldn't be null", m);
Element mmx = m.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
assertNotNull("mmx element is null", mmx);
Element meta = mmx.element(Constants.MMX_META);
assertNotNull("meta element is null", meta);
String json = meta.getText();
assertNotNull("meta json is null", json);
JsonParser parser = new JsonParser();
JsonObject jsonObject = null;
try {
jsonObject = parser.parse(json).getAsJsonObject();
} catch (JsonSyntaxException e) {
fail("JsonSyntax exception");
}
for (String key : contentMap.keySet()) {
JsonElement entry = jsonObject.get(key);
assertNotNull("No entry found for key:" + key, entry);
String value = entry.getAsString();
assertEquals("Non match value for key:"+key, contentMap.get(key), value);
}
Element payload = mmx.element(Constants.MMX_PAYLOAD);
assertNotNull("payload element is null", payload);
String content = payload.getText();
assertNotNull("payload content is null", content);
assertEquals("Non matching content", "", content);
}
示例11: test1Annotate
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void test1Annotate() throws Exception {
String appId = "testapp1";
String domain = "mmx";
String user = "rahul";
Message myMessage = new Message();
myMessage.setType(Message.Type.chat);
myMessage.setFrom(appId + "%" + appId + "@" + domain);
myMessage.setTo(user + "%" + appId + "@" + domain);
myMessage.setID("10");
Element mmxElement = myMessage.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element mmxMetaElement = mmxElement.addElement(Constants.MMX_MMXMETA);
Map<String, String> mmxMetaMap = new HashMap<String, String>();
mmxMetaMap.put("txId", "2010");
mmxMetaMap.put("node", "test1_node");
String mmxMetaJSON = GsonData.getGson().toJson(mmxMetaMap);
mmxMetaElement.setText(mmxMetaJSON);
Element payloadElement = mmxElement.addElement(Constants.MMX_PAYLOAD);
DateFormat fmt = Utils.buildISO8601DateFormat();
String formattedDateTime = fmt.format(new Date());
payloadElement.addAttribute(Constants.MMX_ATTR_STAMP, formattedDateTime);
String text = ".";
payloadElement.setText(text);
payloadElement.addAttribute(Constants.MMX_ATTR_CHUNK, MessageBuilder.buildChunkAttributeValue(text));
myMessage.setBody(MMXServerConstants.MESSAGE_BODY_DOT);
MessageDistributedAnnotator messageDistributedAnnotator = new MessageDistributedAnnotator();
messageDistributedAnnotator.annotate(myMessage);
Element mmx = myMessage.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String revisedJSON = internalMeta.getText();
assertNotNull(revisedJSON);
String expected = "{\"node\":\"test1_node\",\"txId\":\"2010\",\"mmxdistributed\":true}";
assertEquals("Non matching mmxmeta json", expected, revisedJSON);
}
示例12: test3Annotate
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Test the case where we already have the distributed flag set.
* @throws Exception
*/
public void test3Annotate() throws Exception {
String appId = "testapp1";
String domain = "mmx";
String user = "rahul";
Message myMessage = new Message();
myMessage.setType(Message.Type.chat);
myMessage.setFrom(appId + "%" + appId + "@" + domain);
myMessage.setTo(user + "%" + appId + "@" + domain);
myMessage.setID("10");
Element mmxElement = myMessage.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element mmxMetaElement = mmxElement.addElement(Constants.MMX_MMXMETA);
Map<String, String> mmxMetaMap = new HashMap<String, String>();
mmxMetaMap.put("txId", "2010");
mmxMetaMap.put("node", "test1_node");
mmxMetaMap.put(MMXServerConstants.DISTRIBUTED_KEY, "false");
String mmxMetaJSON = GsonData.getGson().toJson(mmxMetaMap);
mmxMetaElement.setText(mmxMetaJSON);
Element payloadElement = mmxElement.addElement(Constants.MMX_PAYLOAD);
DateFormat fmt = Utils.buildISO8601DateFormat();
String formattedDateTime = fmt.format(new Date());
payloadElement.addAttribute(Constants.MMX_ATTR_STAMP, formattedDateTime);
String text = ".";
payloadElement.setText(text);
payloadElement.addAttribute(Constants.MMX_ATTR_CHUNK, MessageBuilder.buildChunkAttributeValue(text));
myMessage.setBody(MMXServerConstants.MESSAGE_BODY_DOT);
MessageDistributedAnnotator messageDistributedAnnotator = new MessageDistributedAnnotator();
messageDistributedAnnotator.annotate(myMessage);
Element mmx = myMessage.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String revisedJSON = internalMeta.getText();
assertNotNull(revisedJSON);
String expected = "{\"node\":\"test1_node\",\"txId\":\"2010\",\"mmxdistributed\":true}";
assertEquals("Non matching mmxmeta json", expected, revisedJSON);
}
示例13: sendHistory
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Sends the smallest amount of traffic that meets any combination of the requested criteria.
*
* @param joinRole the user that will receive the history.
* @param roomHistory the history of the room.
*/
public void sendHistory(LocalMUCRole joinRole, MUCRoomHistory roomHistory) {
if (!isConfigured()) {
Iterator<Message> history = roomHistory.getMessageHistory();
while (history.hasNext()) {
joinRole.send(history.next());
}
}
else {
if (getMaxChars() == 0) {
// The user requested to receive no history
return;
}
int accumulatedChars = 0;
int accumulatedStanzas = 0;
Element delayInformation;
LinkedList<Message> historyToSend = new LinkedList<>();
ListIterator<Message> iterator = roomHistory.getReverseMessageHistory();
while (iterator.hasPrevious()) {
Message message = iterator.previous();
// Update number of characters to send
String text = message.getBody() == null ? message.getSubject() : message.getBody();
if (text == null) {
// Skip this message since it has no body and no subject
continue;
}
accumulatedChars += text.length();
if (getMaxChars() > -1 && accumulatedChars > getMaxChars()) {
// Stop collecting history since we have exceded a limit
break;
}
// Update number of messages to send
accumulatedStanzas ++;
if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) {
// Stop collecting history since we have exceded a limit
break;
}
if (getSeconds() > -1 || getSince() != null) {
delayInformation = message.getChildElement("delay", "urn:xmpp:delay");
try {
// Get the date when the historic message was sent
Date delayedDate = xmppDateTime.parseString(delayInformation.attributeValue("stamp"));
if (getSince() != null && delayedDate != null && delayedDate.before(getSince())) {
// Stop collecting history since we have exceded a limit
break;
}
if (getSeconds() > -1) {
Date current = new Date();
long diff = (current.getTime() - delayedDate.getTime()) / 1000;
if (getSeconds() <= diff) {
// Stop collecting history since we have exceded a limit
break;
}
}
}
catch (Exception e) {
Log.error("Error parsing date from historic message", e);
}
}
historyToSend.addFirst(message);
}
// Send the smallest amount of traffic to the user
for (Object aHistoryToSend : historyToSend) {
joinRole.send((Message) aHistoryToSend);
}
}
}
示例14: shouldStoreMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Decide whether a message should be stored offline according to XEP-0160 and XEP-0334.
*
* @param message
* @return <code>true</code> if the message should be stored offline, <code>false</code> otherwise.
*/
static boolean shouldStoreMessage(final Message message) {
// XEP-0334: Implement the <no-store/> hint to override offline storage
if (message.getChildElement("no-store", "urn:xmpp:hints") != null) {
return false;
}
switch (message.getType()) {
case chat:
// XEP-0160: Messages with a 'type' attribute whose value is "chat" SHOULD be stored offline, with the exception of messages that contain only Chat State Notifications (XEP-0085) [7] content
// Iterate through the child elements to see if we can find anything that's not a chat state notification or
// real time text notification
Iterator<?> it = message.getElement().elementIterator();
while (it.hasNext()) {
Object item = it.next();
if (item instanceof Element) {
Element el = (Element) item;
if (Namespace.NO_NAMESPACE.equals(el.getNamespace())) {
continue;
}
if (!el.getNamespaceURI().equals("http://jabber.org/protocol/chatstates")
&& !(el.getQName().equals(QName.get("rtt", "urn:xmpp:rtt:0")))
) {
return true;
}
}
}
return message.getBody() != null && !message.getBody().isEmpty();
case groupchat:
case headline:
// XEP-0160: "groupchat" message types SHOULD NOT be stored offline
// XEP-0160: "headline" message types SHOULD NOT be stored offline
return false;
case error:
// XEP-0160: "error" message types SHOULD NOT be stored offline,
// although a server MAY store advanced message processing errors offline
if (message.getChildElement("amp", "http://jabber.org/protocol/amp") == null) {
return false;
}
break;
default:
// XEP-0160: Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.
break;
}
return true;
}
示例15: shouldStoreMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Decide whether a message should be stored offline according to XEP-0160 and XEP-0334.
*
* @param message
* @return <code>true</code> if the message should be stored offline, <code>false</code> otherwise.
*/
static boolean shouldStoreMessage(final Message message) {
// XEP-0334: Implement the <no-store/> hint to override offline storage
if (message.getChildElement("no-store", "urn:xmpp:hints") != null) {
return false;
}
switch (message.getType()) {
case chat:
// XEP-0160: Messages with a 'type' attribute whose value is "chat" SHOULD be stored offline, with the exception of messages that contain only Chat State Notifications (XEP-0085) [7] content
// Iterate through the child elements to see if we can find anything that's not a chat state notification or
// real time text notification
Iterator<?> it = message.getElement().elementIterator();
while (it.hasNext()) {
Object item = it.next();
if (item instanceof Element) {
Element el = (Element) item;
if (!el.getNamespaceURI().equals("http://jabber.org/protocol/chatstates")
&& !(el.getQName().equals(QName.get("rtt", "urn:xmpp:rtt:0")))
) {
return true;
}
}
}
return false;
case groupchat:
case headline:
// XEP-0160: "groupchat" message types SHOULD NOT be stored offline
// XEP-0160: "headline" message types SHOULD NOT be stored offline
return false;
case error:
// XEP-0160: "error" message types SHOULD NOT be stored offline,
// although a server MAY store advanced message processing errors offline
if (message.getChildElement("amp", "http://jabber.org/protocol/amp") == null) {
return false;
}
break;
default:
// XEP-0160: Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.
break;
}
return true;
}