本文整理汇总了Java中org.jivesoftware.smack.packet.Stanza.getExtension方法的典型用法代码示例。如果您正苦于以下问题:Java Stanza.getExtension方法的具体用法?Java Stanza.getExtension怎么用?Java Stanza.getExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.packet.Stanza
的用法示例。
在下文中一共展示了Stanza.getExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accept
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
public boolean accept(Stanza packet) {
// sender equals remote peer
if (!packet.getFrom().equalsIgnoreCase(remoteJID)) {
return false;
}
DataPacketExtension data;
if (packet instanceof Data) {
data = ((Data) packet).getDataPacketExtension();
} else {
// stanza contains data packet extension
data = packet.getExtension(
DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
if (data == null) {
return false;
}
}
// session ID equals this session ID
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
return false;
}
return true;
}
示例2: getSubscriptionIds
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
private static List<String> getSubscriptionIds(Stanza packet)
{
HeadersExtension headers = (HeadersExtension)packet.getExtension("headers", "http://jabber.org/protocol/shim");
List<String> values = null;
if (headers != null)
{
values = new ArrayList<String>(headers.getHeaders().size());
for (Header header : headers.getHeaders())
{
values.add(header.getValue());
}
}
return values;
}
示例3: processPacket
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
public void processPacket(Stanza packet)
{
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
List<ExtensionElement> extList = event.getExtensions();
if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName()))
{
listener.handlePurge();
}
else
{
ItemsExtension itemsElem = (ItemsExtension)event.getEvent();
@SuppressWarnings("unchecked")
Collection<RetractItem> pubItems = (Collection<RetractItem>) itemsElem.getItems();
List<String> items = new ArrayList<String>(pubItems.size());
for (RetractItem item : pubItems)
{
items.add(item.getId());
}
ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet));
listener.handleDeletedItems(eventItems);
}
}
示例4: processStanza
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Handle incoming messages
*/
@SuppressWarnings("unchecked")
@Override
public void processStanza(Stanza packet) {
logger.log(Level.INFO, "Received: " + packet.toXML());
final FcmPacketExtension fcmPacket = (FcmPacketExtension) packet.getExtension(Util.FCM_NAMESPACE);
final String json = fcmPacket.getJson();
try {
final Map<String, Object> jsonMap = (Map<String, Object>) JSONValue.parseWithException(json);
final Object messageType = jsonMap.get("message_type");
if (messageType == null) { // normal upstream message
final CcsInMessage inMessage = MessageHelper.createCcsInMessage(jsonMap);
handleUpstreamMessage(inMessage);
return;
}
switch (messageType.toString()) {
case "ack":
handleAckReceipt(jsonMap);
break;
case "nack":
handleNackReceipt(jsonMap);
break;
case "receipt":
handleDeliveryReceipt(jsonMap);
break;
case "control":
handleControlMessage(jsonMap);
break;
default:
logger.log(Level.INFO, "Received unknown FCM message type: " + messageType.toString());
}
} catch (ParseException e) {
logger.log(Level.INFO, "Error parsing JSON: " + json, e.getMessage());
}
}
示例5: getPropertiesNames
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Return a collection of the names of all properties of the given packet. If the packet
* contains no properties extension, then an empty collection will be returned.
*
* @param packet
* @return a collection of the names of all properties.
*/
public static Collection<String> getPropertiesNames(Stanza packet) {
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe == null) {
return Collections.emptyList();
}
return jpe.getPropertyNames();
}
示例6: accept
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
public boolean accept(Stanza packet)
{
if (!(packet instanceof Message))
return false;
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
if (event == null)
return false;
NodeExtension embedEvent = event.getEvent();
if (embedEvent == null)
return false;
if (embedEvent.getElementName().equals(firstElement))
{
if (!embedEvent.getNode().equals(getId()))
return false;
if (secondElement == null)
return true;
if (embedEvent instanceof EmbeddedPacketExtension)
{
List<ExtensionElement> secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions();
if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement))
return true;
}
}
return false;
}
示例7: getProperty
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Convenience method to get a property from a packet. Will return null if the stanza(/packet) contains
* not property with the given name.
*
* @param packet
* @param name
* @return the property or <tt>null</tt> if none found.
*/
public static Object getProperty(Stanza packet, String name) {
Object res = null;
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe != null) {
res = jpe.getProperty(name);
}
return res;
}
示例8: parseEmptyTag
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
@Test
public void parseEmptyTag() throws Exception
{
String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
XmlPullParser parser = PacketParserUtils.getParserFor(
"<message from='pubsub.myserver.com' to='[email protected]' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
"<items node='testNode'>" +
"<item id='testid1' >" +
itemContent +
"</item>" +
"</items>" +
"</event>" +
"</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
assertTrue(eventExt instanceof EventElement);
EventElement event = (EventElement) eventExt;
assertEquals(EventElementType.items, event.getEventType());
assertEquals(1, event.getExtensions().size());
assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size());
ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>)itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
assertXMLEqual(itemContent, ((SimplePayload)item.getPayload()).toXML().toString());
}
示例9: parseComplexItem
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
@Test
public void parseComplexItem() throws Exception
{
String itemContent =
"<entry xmlns='http://www.w3.org/2005/Atom'>" +
"<title>Soliloquy</title>" +
"<summary>" +
"To be, or not to be: that is the question:" +
"Whether 'tis nobler in the mind to suffer" +
"The slings and arrows of outrageous fortune," +
"Or to take arms against a sea of troubles," +
"And by opposing end them?" +
"</summary>" +
"<link rel='alternate' type='text/html' href='http://denmark.lit/2003/12/13/atom03'/>" +
"<id>tag:denmark.lit,2003:entry-32397</id>" +
"<published>2003-12-13T18:30:02Z</published>" +
"<updated>2003-12-13T18:30:02Z</updated>" +
"</entry>";
XmlPullParser parser = PacketParserUtils.getParserFor(
"<message from='pubsub.myserver.com' to='[email protected]' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
"<items node='testNode'>" +
"<item id='testid1' >" +
itemContent +
"</item>" +
"</items>" +
"</event>" +
"</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
EventElement event = (EventElement) eventExt;
ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>)itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("entry", payload.getElementName());
assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace());
assertXMLEqual(itemContent, payload.toXML().toString());
}
示例10: from
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
public static RSMSet from(Stanza packet) {
return (RSMSet) packet.getExtension(ELEMENT, NAMESPACE);
}
示例11: getSubscriptions
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Gets the subscriptions on the root node.
*
* @return List of exceptions
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException
{
Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null);
SubscriptionsExtension subElem = reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
return subElem.getSubscriptions();
}
示例12: from
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Retrieve the GCM stanza(/packet) extension from the packet.
*
* @param packet
* @return the GCM stanza(/packet) extension or null.
*/
public static GcmPacketExtension from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
}
示例13: from
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Retrieve the MUCUser PacketExtension from packet, if any.
*
* @param packet
* @return the MUCUser PacketExtension or {@code null}
*/
public static MUCUser from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
}
示例14: from
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Retrieve the MUCInitialPresence PacketExtension from packet, if any.
*
* @param packet
* @return the MUCInitialPresence PacketExtension or {@code null}
*/
public static MUCInitialPresence from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
}
示例15: from
import org.jivesoftware.smack.packet.Stanza; //导入方法依赖的package包/类
/**
* Get the {@link DeliveryReceiptRequest} extension of the packet, if any.
*
* @param packet the packet
* @return the {@link DeliveryReceiptRequest} extension or {@code null}
*/
public static DeliveryReceiptRequest from(Stanza packet) {
return packet.getExtension(ELEMENT, DeliveryReceipt.NAMESPACE);
}