Java Code Examples for org.jivesoftware.smack.packet.Message#getExtensionElement()
The following examples show how to use
org.jivesoftware.smack.packet.Message#getExtensionElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmemoService.java From Smack with Apache License 2.0 | 6 votes |
/** * Decrypt a possible OMEMO encrypted messages in a {@link MamManager.MamQuery}. * The returned list contains wrappers that either hold an {@link OmemoMessage} in case the message was decrypted * properly, otherwise it contains the message itself. * * @param managerGuard authenticated OmemoManager. * @param mamQuery Mam archive query * @return list of {@link MessageOrOmemoMessage MessageOrOmemoMessages}. * * @throws IOException if an I/O error occurred. */ List<MessageOrOmemoMessage> decryptMamQueryResult(OmemoManager.LoggedInOmemoManager managerGuard, MamManager.MamQuery mamQuery) throws IOException { List<MessageOrOmemoMessage> result = new ArrayList<>(); for (Message message : mamQuery.getMessages()) { if (OmemoManager.stanzaContainsOmemoElement(message)) { OmemoElement element = (OmemoElement) message.getExtensionElement(OmemoElement.NAME_ENCRYPTED, OmemoConstants.OMEMO_NAMESPACE_V_AXOLOTL); // Decrypt OMEMO messages try { OmemoMessage.Received omemoMessage = decryptMessage(managerGuard, message.getFrom().asBareJid(), element); result.add(new MessageOrOmemoMessage(omemoMessage)); } catch (NoRawSessionException | CorruptedOmemoKeyException | CryptoFailedException e) { LOGGER.log(Level.WARNING, "decryptMamQueryResult failed to decrypt message from " + message.getFrom() + " due to corrupted session/key: " + e.getMessage()); result.add(new MessageOrOmemoMessage(message)); } } else { // Wrap cleartext messages result.add(new MessageOrOmemoMessage(message)); } } return result; }
Example 2
Source File: SpoilerTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void emptySpoilerTest() throws Exception { final String xml = "<spoiler xmlns='urn:xmpp:spoiler:0'/>"; Message message = StanzaBuilder.buildMessage().build(); SpoilerElement.addSpoiler(message); SpoilerElement empty = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0); assertNull(empty.getHint()); assertNull(empty.getLanguage()); assertXmlSimilar(xml, empty.toXML().toString()); XmlPullParser parser = TestUtils.getParser(xml); SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser); assertXmlSimilar(xml, parsed.toXML().toString()); }
Example 3
Source File: SpoilerTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void i18nHintSpoilerTest() throws Exception { final String xml = "<spoiler xml:lang='de' xmlns='urn:xmpp:spoiler:0'>Der Kuchen ist eine Lüge!</spoiler>"; Message message = StanzaBuilder.buildMessage().build(); SpoilerElement.addSpoiler(message, "de", "Der Kuchen ist eine Lüge!"); SpoilerElement i18nHint = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0); assertEquals("Der Kuchen ist eine Lüge!", i18nHint.getHint()); assertEquals("de", i18nHint.getLanguage()); assertXmlSimilar(xml, i18nHint.toXML().toString()); XmlPullParser parser = TestUtils.getParser(xml); SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser); assertEquals(i18nHint.getLanguage(), parsed.getLanguage()); assertXmlSimilar(xml, parsed.toXML().toString()); }
Example 4
Source File: RosterExchangeManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Creates a new roster exchange manager. * * @param connection an XMPPConnection which is used to send and receive messages. */ public RosterExchangeManager(XMPPConnection connection) { weakRefConnection = new WeakReference<>(connection); // Listens for all roster exchange packets and fire the roster exchange listeners. packetListener = new StanzaListener() { @Override public void processStanza(Stanza packet) { Message message = (Message) packet; RosterExchange rosterExchange = (RosterExchange) message.getExtensionElement(ELEMENT, NAMESPACE); // Fire event for roster exchange listeners fireRosterExchangeListeners(message.getFrom(), rosterExchange.getRosterEntries()); } }; connection.addAsyncStanzaListener(packetListener, PACKET_FILTER); }
Example 5
Source File: NoStoreHint.java From Smack with Apache License 2.0 | 4 votes |
public static NoStoreHint from(Message message) { return (NoStoreHint) message.getExtensionElement(ELEMENT, NAMESPACE); }
Example 6
Source File: NoCopyHint.java From Smack with Apache License 2.0 | 4 votes |
public static NoCopyHint from(Message message) { return (NoCopyHint) message.getExtensionElement(ELEMENT, NAMESPACE); }
Example 7
Source File: NoPermanentStoreHint.java From Smack with Apache License 2.0 | 4 votes |
public static NoPermanentStoreHint from(Message message) { return (NoPermanentStoreHint) message.getExtensionElement(ELEMENT, NAMESPACE); }
Example 8
Source File: MUCLightElements.java From Smack with Apache License 2.0 | 4 votes |
public static ConfigurationsChangeExtension from(Message message) { return (ConfigurationsChangeExtension) message.getExtensionElement(ConfigurationsChangeExtension.ELEMENT, ConfigurationsChangeExtension.NAMESPACE); }
Example 9
Source File: MamElements.java From Smack with Apache License 2.0 | 4 votes |
public static MamResultExtension from(Message message) { return (MamResultExtension) message.getExtensionElement(ELEMENT, NAMESPACE); }
Example 10
Source File: SpoilerTest.java From Smack with Apache License 2.0 | 4 votes |
@Test public void hintSpoilerTest() throws Exception { final String xml = "<spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>"; Message message = StanzaBuilder.buildMessage().build(); SpoilerElement.addSpoiler(message, "Love story end"); SpoilerElement withHint = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0); assertEquals("Love story end", withHint.getHint()); assertNull(withHint.getLanguage()); assertXmlSimilar(xml, withHint.toXML().toString()); XmlPullParser parser = TestUtils.getParser(xml); SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser); assertXmlSimilar(xml, parsed.toXML().toString()); }
Example 11
Source File: AgentSession.java From Smack with Apache License 2.0 | 4 votes |
private void handlePacket(Stanza packet) { if (packet instanceof Presence) { Presence presence = (Presence) packet; // The workgroup can send us a number of different presence packets. We // check for different packet extensions to see what type of presence // packet it is. Resourcepart queueName = presence.getFrom().getResourceOrNull(); WorkgroupQueue queue = queues.get(queueName); // If there isn't already an entry for the queue, create a new one. if (queue == null) { queue = new WorkgroupQueue(queueName); queues.put(queueName, queue); } // QueueOverview packet extensions contain basic information about a queue. QueueOverview queueOverview = (QueueOverview) presence.getExtensionElement(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE); if (queueOverview != null) { if (queueOverview.getStatus() == null) { queue.setStatus(WorkgroupQueue.Status.CLOSED); } else { queue.setStatus(queueOverview.getStatus()); } queue.setAverageWaitTime(queueOverview.getAverageWaitTime()); queue.setOldestEntry(queueOverview.getOldestEntry()); // Fire event. fireQueueUsersEvent(queue, queueOverview.getStatus(), queueOverview.getAverageWaitTime(), queueOverview.getOldestEntry(), null); return; } // QueueDetails packet extensions contain information about the users in // a queue. QueueDetails queueDetails = (QueueDetails) packet.getExtensionElement(QueueDetails.ELEMENT_NAME, QueueDetails.NAMESPACE); if (queueDetails != null) { queue.setUsers(queueDetails.getUsers()); // Fire event. fireQueueUsersEvent(queue, null, -1, null, queueDetails.getUsers()); return; } // Notify agent packets gives an overview of agent activity in a queue. StandardExtensionElement notifyAgents = (StandardExtensionElement) presence.getExtensionElement("notify-agents", "http://jabber.org/protocol/workgroup"); if (notifyAgents != null) { int currentChats = Integer.parseInt(notifyAgents.getFirstElement("current-chats", "http://jabber.org/protocol/workgroup").getText()); int maxChats = Integer.parseInt(notifyAgents.getFirstElement("max-chats", "http://jabber.org/protocol/workgroup").getText()); queue.setCurrentChats(currentChats); queue.setMaxChats(maxChats); // Fire event. // TODO: might need another event for current chats and max chats of queue return; } } else if (packet instanceof Message) { Message message = (Message) packet; // Check if a room invitation was sent and if the sender is the workgroup MUCUser mucUser = MUCUser.from(message); MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null; if (invite != null && workgroupJID.equals(invite.getFrom())) { String sessionID = null; Map<String, List<String>> metaData = null; SessionID sessionIDExt = (SessionID) message.getExtensionElement(SessionID.ELEMENT_NAME, SessionID.NAMESPACE); if (sessionIDExt != null) { sessionID = sessionIDExt.getSessionID(); } MetaData metaDataExt = (MetaData) message.getExtensionElement(MetaData.ELEMENT_NAME, MetaData.NAMESPACE); if (metaDataExt != null) { metaData = metaDataExt.getMetaData(); } this.fireInvitationEvent(message.getFrom(), sessionID, message.getBody(), message.getFrom(), metaData); } } }
Example 12
Source File: Workgroup.java From Smack with Apache License 2.0 | 4 votes |
private void handlePacket(Stanza packet) { if (packet instanceof Message) { Message msg = (Message) packet; // Check to see if the user left the queue. ExtensionElement pe = msg.getExtensionElement("depart-queue", "http://jabber.org/protocol/workgroup"); ExtensionElement queueStatus = msg.getExtensionElement("queue-status", "http://jabber.org/protocol/workgroup"); if (pe != null) { fireQueueDepartedEvent(); } else if (queueStatus != null) { QueueUpdate queueUpdate = (QueueUpdate) queueStatus; if (queueUpdate.getPosition() != -1) { fireQueuePositionEvent(queueUpdate.getPosition()); } if (queueUpdate.getRemaingTime() != -1) { fireQueueTimeEvent(queueUpdate.getRemaingTime()); } } else { // Check if a room invitation was sent and if the sender is the workgroup MUCUser mucUser = MUCUser.from(msg); MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null; if (invite != null && workgroupJID.equals(invite.getFrom())) { String sessionID = null; Map<String, List<String>> metaData = null; pe = msg.getExtensionElement(SessionID.ELEMENT_NAME, SessionID.NAMESPACE); if (pe != null) { sessionID = ((SessionID) pe).getSessionID(); } pe = msg.getExtensionElement(MetaData.ELEMENT_NAME, MetaData.NAMESPACE); if (pe != null) { metaData = ((MetaData) pe).getMetaData(); } WorkgroupInvitation inv = new WorkgroupInvitation(connection.getUser(), msg.getFrom(), workgroupJID, sessionID, msg.getBody(), msg.getFrom(), metaData); fireInvitationEvent(inv); } } } }
Example 13
Source File: BoBExtension.java From Smack with Apache License 2.0 | 4 votes |
public static BoBExtension from(Message message) { return (BoBExtension) message.getExtensionElement(ELEMENT, NAMESPACE); }
Example 14
Source File: CarbonExtension.java From Smack with Apache License 2.0 | 3 votes |
/** * Obtain a Carbon from a message, if available. * <p> * Only {@link Message} instances can contain a Carbon extensions. * </p> * * @param msg Message object to check for carbons * * @return a Carbon if available, null otherwise. */ public static CarbonExtension from(Message msg) { CarbonExtension cc = (CarbonExtension) msg.getExtensionElement(Direction.received.name(), NAMESPACE); if (cc == null) cc = (CarbonExtension) msg.getExtensionElement(Direction.sent.name(), NAMESPACE); return cc; }
Example 15
Source File: OriginIdElement.java From Smack with Apache License 2.0 | 2 votes |
/** * Return the origin-id element of a message or null, if absent. * * @param message message * @return origin-id element */ public static OriginIdElement getOriginId(Message message) { return (OriginIdElement) message.getExtensionElement(OriginIdElement.ELEMENT, StableUniqueStanzaIdManager.NAMESPACE); }
Example 16
Source File: XHTMLManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Returns true if the message contains an XHTML extension. * * @param message the message to check if contains an XHTML extension or not * @return a boolean indicating whether the message is an XHTML message */ public static boolean isXHTMLMessage(Message message) { return message.getExtensionElement(XHTMLExtension.ELEMENT, XHTMLExtension.NAMESPACE) != null; }