Java Code Examples for org.jivesoftware.smack.packet.Stanza#getExtension()
The following examples show how to use
org.jivesoftware.smack.packet.Stanza#getExtension() .
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: EligibleForChatMarkerFilter.java From Smack with Apache License 2.0 | 6 votes |
/** * From XEP-0333, Protocol Format: The Chat Marker MUST have an 'id' which is the 'id' of the * message being marked.<br> * In order to make Chat Markers works together with XEP-0085 as it said in * 8.5 Interaction with Chat States, only messages with <code>active</code> chat * state are accepted. * * @param message to be analyzed. * @return true if the message contains a stanza Id. * @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat Markers</a> */ @Override public boolean accept(Stanza message) { if (!message.hasStanzaIdSet()) { return false; } if (super.accept(message)) { ExtensionElement extension = message.getExtension(ChatStateManager.NAMESPACE); String chatStateElementName = extension.getElementName(); ChatState state; try { state = ChatState.valueOf(chatStateElementName); return state == ChatState.active; } catch (Exception ex) { return false; } } return true; }
Example 2
Source File: InBandBytestreamSession.java From Smack with Apache License 2.0 | 6 votes |
@Override public boolean accept(Stanza packet) { // sender equals remote peer if (!packet.getFrom().equals(remoteJID)) { return false; } DataPacketExtension data; if (packet instanceof Data) { data = ((Data) packet).getDataPacketExtension(); } else { // stanza contains data packet extension data = packet.getExtension( DataPacketExtension.class); if (data == null) { return false; } } // session ID equals this session ID if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) { return false; } return true; }
Example 3
Source File: OfflineMessageManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Returns a List of the offline <code>Messages</code> whose stamp matches the specified * request. The request will include the list of stamps that uniquely identifies * the offline messages to retrieve. The returned offline messages will not be deleted * from the server. Use {@link #deleteMessages(java.util.List)} to delete the messages. * * @param nodes the list of stamps that uniquely identifies offline message. * @return a List with the offline <code>Messages</code> that were received as part of * this request. * @throws XMPPErrorException If the user is not allowed to make this request or the server does * not support offline message retrieval. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public List<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<Message> messages = new ArrayList<>(nodes.size()); OfflineMessageRequest request = new OfflineMessageRequest(); for (String node : nodes) { OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node); item.setAction("view"); request.addItem(item); } // Filter offline messages that were requested by this request StanzaFilter messageFilter = new AndFilter(PACKET_FILTER, new StanzaFilter() { @Override public boolean accept(Stanza packet) { OfflineMessageInfo info = packet.getExtension(OfflineMessageInfo.class); return nodes.contains(info.getNode()); } }); int pendingNodes = nodes.size(); try (StanzaCollector messageCollector = connection().createStanzaCollector(messageFilter)) { connection().createStanzaCollectorAndSend(request).nextResultOrThrow(); // Collect the received offline messages Message message; do { message = messageCollector.nextResult(); if (message != null) { messages.add(message); pendingNodes--; } else if (message == null && pendingNodes > 0) { LOGGER.log(Level.WARNING, "Did not receive all expected offline messages. " + pendingNodes + " are missing."); } } while (message != null && pendingNodes > 0); } return messages; }
Example 4
Source File: ExtensionElementFilter.java From Smack with Apache License 2.0 | 5 votes |
@Override public final boolean accept(Stanza stanza) { ExtensionElement extensionElement = stanza.getExtension(extensionElementQName); if (extensionElement == null) { return false; } if (!extensionElementClass.isInstance(extensionElement)) { return false; } E specificExtensionElement = extensionElementClass.cast(extensionElement); return accept(specificExtensionElement); }
Example 5
Source File: JivePropertiesManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Return a map of all properties of the given packet. If the stanza contains no properties * extension, an empty map will be returned. * * @param packet TODO javadoc me please * @return a map of all properties of the given packet. */ public static Map<String, Object> getProperties(Stanza packet) { JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE); if (jpe == null) { return Collections.emptyMap(); } return jpe.getProperties(); }
Example 6
Source File: InBandBytestreamSession.java From Smack with Apache License 2.0 | 5 votes |
@Override protected StanzaListener getDataPacketListener() { return new StanzaListener() { @Override public void processStanza(Stanza packet) { // get data packet extension DataPacketExtension data = packet.getExtension( DataPacketExtension.class); // check if encoded data is valid if (data.getDecodedData() == null) { /* * TODO once a majority of XMPP server implementation support XEP-0079 * Advanced Message Processing the invalid message could be answered with an * appropriate error. For now we just ignore the packet. Subsequent packets * with an increased sequence will cause the input stream to close the * stream/session. */ return; } // data is valid; add to data queue dataQueue.offer(data); // TODO confirm packet once XMPP servers support XEP-0079 } }; }
Example 7
Source File: Node.java From Smack with Apache License 2.0 | 5 votes |
private static List<String> getSubscriptionIds(Stanza packet) { HeadersExtension headers = packet.getExtension(HeadersExtension.class); List<String> values = null; if (headers != null) { values = new ArrayList<>(headers.getHeaders().size()); for (Header header : headers.getHeaders()) { values.add(header.getValue()); } } return values; }
Example 8
Source File: GroupChatRoom.java From Spark with Apache License 2.0 | 4 votes |
/** * Handle all presence packets being sent to this Group Chat Room. * * @param stanza the presence packet. */ private void handlePresencePacket( Stanza stanza ) { final Presence presence = (Presence) stanza; if ( presence.getError() != null ) { return; } final EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible(); if (from == null) { return; } final Resourcepart nickname = from.getResourcepart(); final MUCUser mucUser = stanza.getExtension( "x", "http://jabber.org/protocol/muc#user" ); final Set<MUCUser.Status> status = new HashSet<>(); if ( mucUser != null ) { status.addAll( mucUser.getStatus() ); final Destroy destroy = mucUser.getDestroy(); if ( destroy != null ) { UIManager.put( "OptionPane.okButtonText", Res.getString( "ok" ) ); JOptionPane.showMessageDialog( this, Res.getString( "message.room.destroyed", destroy.getReason() ), Res.getString( "title.room.destroyed" ), JOptionPane.INFORMATION_MESSAGE ); leaveChatRoom(); return; } } if ( presence.getType() == Presence.Type.unavailable && !status.contains( MUCUser.Status.NEW_NICKNAME_303 ) ) { if ( currentUserList.contains( from ) ) { if ( pref.isShowJoinLeaveMessagesEnabled() ) { getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.left.room", nickname ), ChatManager.NOTIFICATION_COLOR ); scrollToBottom(); } currentUserList.remove( from ); } } else { if ( !currentUserList.contains( from ) ) { currentUserList.add( from ); getChatInputEditor().setEnabled( true ); if ( pref.isShowJoinLeaveMessagesEnabled() ) { getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.joined.room", nickname ), ChatManager.NOTIFICATION_COLOR ); scrollToBottom(); } } } }
Example 9
Source File: CapsExtension.java From Smack with Apache License 2.0 | 4 votes |
public static CapsExtension from(Stanza stanza) { return stanza.getExtension(CapsExtension.class); }
Example 10
Source File: EventElement.java From Smack with Apache License 2.0 | 4 votes |
public static EventElement from(Stanza stanza) { return stanza.getExtension(EventElement.class); }
Example 11
Source File: OpenPgpElement.java From Smack with Apache License 2.0 | 4 votes |
public static OpenPgpElement fromStanza(Stanza stanza) { return stanza.getExtension(OpenPgpElement.class); }
Example 12
Source File: HeadersExtension.java From Smack with Apache License 2.0 | 2 votes |
/** * Return the SHIM headers extension of this stanza or null if there is none. * * @param packet TODO javadoc me please * @return the headers extension or null. */ public static HeadersExtension from(Stanza packet) { return packet.getExtension(HeadersExtension.class); }
Example 13
Source File: Forwarded.java From Smack with Apache License 2.0 | 2 votes |
/** * Get the forwarded extension. * @param packet TODO javadoc me please * @return the Forwarded extension or null */ public static Forwarded from(Stanza packet) { return packet.getExtension(Forwarded.class); }
Example 14
Source File: MUCUser.java From Smack with Apache License 2.0 | 2 votes |
/** * Retrieve the MUCUser PacketExtension from packet, if any. * * @param packet TODO javadoc me please * @return the MUCUser PacketExtension or {@code null} */ public static MUCUser from(Stanza packet) { return packet.getExtension(MUCUser.class); }
Example 15
Source File: DelayInformationManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Get Delayed Delivery information as defined in XEP-91 * <p> * Prefer {@link #getDelayInformation(Stanza)} over this method for backwards compatibility. * </p> * @param packet TODO javadoc me please * @return the Delayed Delivery information or <code>null</code> */ public static DelayInformation getLegacyDelayInformation(Stanza packet) { return packet.getExtension(DelayInformation.class); }
Example 16
Source File: DelayInformation.java From Smack with Apache License 2.0 | 2 votes |
/** * Return delay information from the given stanza. * * @param packet TODO javadoc me please * @return the DelayInformation or null */ public static DelayInformation from(Stanza packet) { return packet.getExtension(DelayInformation.class); }
Example 17
Source File: GcmPacketExtension.java From Smack with Apache License 2.0 | 2 votes |
/** * Retrieve the GCM stanza extension from the packet. * * @param packet TODO javadoc me please * @return the GCM stanza extension or null. */ public static GcmPacketExtension from(Stanza packet) { return packet.getExtension(GcmPacketExtension.class); }
Example 18
Source File: MultipleRecipientManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Returns the {@link MultipleRecipientInfo} contained in the specified stanza or * <code>null</code> if none was found. Only packets sent to multiple recipients will * contain such information. * * @param packet the stanza to check. * @return the MultipleRecipientInfo contained in the specified stanza or <code>null</code> * if none was found. */ public static MultipleRecipientInfo getMultipleRecipientInfo(Stanza packet) { MultipleAddresses extension = packet.getExtension(MultipleAddresses.class); return extension == null ? null : new MultipleRecipientInfo(extension); }
Example 19
Source File: DeliveryReceiptRequest.java From Smack with Apache License 2.0 | 2 votes |
/** * 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(DeliveryReceiptRequest.class); }
Example 20
Source File: JsonPacketExtension.java From Smack with Apache License 2.0 | 2 votes |
/** * Retrieve the JSON stanza extension from the packet. * * @param packet TODO javadoc me please * @return the JSON stanza extension or null. */ public static JsonPacketExtension from(Stanza packet) { return packet.getExtension(JsonPacketExtension.class); }