Java Code Examples for org.jivesoftware.smack.packet.Message#addExtension()
The following examples show how to use
org.jivesoftware.smack.packet.Message#addExtension() .
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: XHTMLExtensionTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Low level API test. * This is a simple test to use with an XMPP client and check if the client receives the message * 1. User_1 will send a message with formatted text (XHTML) to user_2 */ public void testSendSimpleXHTMLMessage() { // User1 creates a chat with user2 Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); // User1 creates a message to send to user2 Message msg = new Message(); msg.setSubject("Any subject you want"); msg.setBody("Hey John, this is my new green!!!!"); // Create a XHTMLExtension Package and add it to the message XHTMLExtension xhtmlExtension = new XHTMLExtension(); xhtmlExtension.addBody( "<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>"); msg.addExtension(xhtmlExtension); // User1 sends the message that contains the XHTML to user2 try { chat1.sendMessage(msg); Thread.sleep(200); } catch (Exception e) { fail("An error occurred sending the message with XHTML"); } }
Example 2
Source File: OperationSetTypingNotificationsJabberImpl.java From jitsi with Apache License 2.0 | 6 votes |
/** * Creates and sends a packet for the new chat state. * @param chatState the new chat state. * @param jid the JID of the receiver. */ private void setCurrentState(ChatState chatState, Jid jid) throws NotConnectedException, InterruptedException { String threadID = opSetBasicIM.getThreadIDForAddress(jid.asBareJid()); if(threadID == null) return; Message message = new Message(); ChatStateExtension extension = new ChatStateExtension(chatState); message.addExtension(extension); message.setTo(jid); message.setType(Message.Type.chat); message.setThread(threadID); message.setFrom(parentProvider.getConnection().getUser()); parentProvider.getConnection().sendStanza(message); }
Example 3
Source File: GroupChatInvitationTest.java From Smack with Apache License 2.0 | 6 votes |
public void testInvitation() { try { GroupChatInvitation invitation = new GroupChatInvitation("test@" + getChatDomain()); Message message = new Message(getBareJID(1)); message.setBody("Group chat invitation!"); message.addExtension(invitation); getConnection(0).sendStanza(message); Thread.sleep(250); Message result = (Message)collector.pollResult(); assertNotNull("Message not delivered correctly.", result); GroupChatInvitation resultInvite = (GroupChatInvitation)result.getExtension("x", "jabber:x:conference"); assertEquals("Invitation not to correct room", "test@" + getChatDomain(), resultInvite.getRoomAddress()); } catch (Exception e) { fail(e.getMessage()); } }
Example 4
Source File: StableUniqueStanzaIdTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void fromMessageTest() { MessageBuilder messageBuilder = StanzaBuilder.buildMessage(); Message message = messageBuilder.build(); assertFalse(OriginIdElement.hasOriginId(message)); assertFalse(StanzaIdElement.hasStanzaId(message)); OriginIdElement.addTo(messageBuilder); message = messageBuilder.build(); assertTrue(OriginIdElement.hasOriginId(message)); StanzaIdElement stanzaId = new StanzaIdElement("[email protected]"); message.addExtension(stanzaId); assertTrue(StanzaIdElement.hasStanzaId(message)); assertEquals(stanzaId, StanzaIdElement.getStanzaId(message)); }
Example 5
Source File: Workpane.java From Spark with Apache License 2.0 | 6 votes |
private Message getMessage(String messageText, RequestUtils util, boolean transfer) { Map metadata = new HashMap(); metadata.put("messageText", messageText); metadata.put("username", util.getUsername()); metadata.put("userID", util.getUserID()); metadata.put("transfer", Boolean.toString(transfer)); metadata.put("question", util.getQuestion()); metadata.put("email", util.getEmailAddress()); metadata.put("workgroup", util.getWorkgroup()); if (ModelUtil.hasLength(util.getRequestLocation())) { metadata.put("Location", util.getRequestLocation()); } // Add Metadata as message extension final MetaData data = new MetaData(metadata); Message message = new Message(); message.addExtension(data); return message; }
Example 6
Source File: CoBrowser.java From Spark with Apache License 2.0 | 6 votes |
private void navigateUser(String href) { if (followMeButton.isSelected() && hasLoaded) { final Message mes = new Message(); final Map<String, Object> properties = new HashMap<>(); properties.put( "PUSH_URL", href ); mes.addExtension( new JivePropertiesExtension( properties ) ); mes.setBody(""); send(mes); updateLinkLabel(href); hasLoaded = false; } else { updateLinkLabel(href); } hasLoaded = true; }
Example 7
Source File: FakePacketTransmitter.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void sendPacketExtension(JID jid, PacketExtension extension) { Message message = new Message(); message.addExtension(extension); message.setTo(jid.toString()); try { sendPacket(message); } catch (IOException e) { throw new RuntimeException(e); } }
Example 8
Source File: MessageCorrectExtensionTest.java From Smack with Apache License 2.0 | 5 votes |
@Test public void checkStanzas() throws Exception { Message initialMessage = PacketParserUtils.parseStanza(initialMessageXml); MessageCorrectExtension messageCorrectExtension = new MessageCorrectExtension(idInitialMessage); assertEquals(messageCorrectExtension.toXML().toString(), messageCorrectionXml.toString()); initialMessage.addExtension(messageCorrectExtension); assertEquals(initialMessage.toXML().toString(), expectedXml.toString()); }
Example 9
Source File: BuzzRoomDecorator.java From Spark with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { Jid jid; try { jid = JidCreate.from(((ChatRoomImpl)chatRoom).getParticipantJID()); } catch (XmppStringprepException exception) { throw new IllegalStateException(exception); } Message message = new Message(); message.setTo(jid); message.addExtension(new BuzzPacket()); try { SparkManager.getConnection().sendStanza(message); } catch ( SmackException.NotConnectedException | InterruptedException e1 ) { Log.warning( "Unable to send stanza to " + jid, e1 ); } chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR); buzzButton.setEnabled(false); // Enable the button after 30 seconds to prevent abuse. final TimerTask enableTask = new SwingTimerTask() { @Override public void doRun() { buzzButton.setEnabled(true); } }; TaskEngine.getInstance().schedule(enableTask, 30000); }
Example 10
Source File: XHTMLManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Adds an XHTML body to the message. * * @param message the message that will receive the XHTML body * @param xhtmlText the string to add as an XHTML body to the message * @deprecated use {@link #addBody(MessageBuilder, XHTMLText)} instead. */ // TODO: Remove in Smack 4.6 @Deprecated public static void addBody(Message message, XHTMLText xhtmlText) { XHTMLExtension xhtmlExtension = XHTMLExtension.from(message); if (xhtmlExtension == null) { // Create an XHTMLExtension and add it to the message xhtmlExtension = new XHTMLExtension(); message.addExtension(xhtmlExtension); } // Add the required bodies to the message xhtmlExtension.addBody(xhtmlText.toXML()); }
Example 11
Source File: ReversiPanel.java From Spark with Apache License 2.0 | 5 votes |
/** * If the click box is a valid move, register a move in this box. */ public void mouseClicked(MouseEvent e) { super.mouseClicked(e); // Make sure that it's our turn and that it's a valid move. if (reversi.getCurrentPlayer() != otherPlayer && reversi.isValidMove(block.getIndex())) { // Update the game model. reversi.makeMove(block.getIndex()); // Send the move to the other player. Message message = new Message(opponentJID); GameMove move = new GameMove(); move.setGameID(gameID); move.setPosition(block.getIndex()); message.addExtension(move); try { connection.sendStanza(message); } catch ( SmackException.NotConnectedException | InterruptedException e1 ) { Log.warning( "Unable to send move to " + message.getTo(), e1 ); } // Repaint board. ReversiPanel.this.repaint(); // Repaint all blocks. // for (Iterator it = block.getReversiUI().getBlocks().iterator(); it.hasNext();) { // ReversiBlock component = (ReversiBlock)it.next(); // component.repaint(); // } } }
Example 12
Source File: OriginIdElement.java From Smack with Apache License 2.0 | 5 votes |
/** * Add an origin-id element to a message and set the stanzas id to the same id as in the origin-id element. * * @param message message. * @return the added origin-id element. * @deprecated use {@link #addTo(MessageBuilder)} instead. */ @Deprecated // TODO: Remove in Smack 4.5. public static OriginIdElement addOriginId(Message message) { OriginIdElement originId = new OriginIdElement(); message.addExtension(originId); // TODO: Find solution to have both the originIds stanzaId and a nice to look at incremental stanzaID. // message.setStanzaId(originId.getId()); return originId; }
Example 13
Source File: Client.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
public void sendChatState(JID jid, String threadID, ChatState state) { Message message = new Message(jid.toBareSmack(), Message.Type.chat); if (!threadID.isEmpty()) message.setThread(threadID); message.addExtension(new ChatStateExtension(state)); this.sendPacket(message); }
Example 14
Source File: MoodManager.java From Smack with Apache License 2.0 | 4 votes |
public static void addMoodToMessage(Message message, Mood mood, MoodConcretisation concretisation) { MoodElement element = buildMood(mood, concretisation, null); message.addExtension(element); }
Example 15
Source File: KonMessageListener.java From desktopclient-java with GNU General Public License v3.0 | 4 votes |
private void processChatMessage(Message m) { LOGGER.config("message: "+m); // note: thread and subject are null if message comes from the Kontalk // Android client MessageIDs ids = MessageIDs.from(m); Date delayDate = getDelay(m); // process possible chat state notification (XEP-0085) ExtensionElement csExt = m.getExtension(ChatStateExtension.NAMESPACE); ChatState chatState = null; if (csExt != null) { chatState = ((ChatStateExtension) csExt).getChatState(); mControl.onChatStateNotification(ids, Optional.ofNullable(delayDate), chatState); } // must be an incoming message // get content/text from body and/or encryption/url extension MessageContent content = ClientUtils.parseMessageContent(m, false); // make sure not to save a message without content if (content.isEmpty()) { if (chatState == null) { LOGGER.warning("can't find any content in message"); } else if (chatState == ChatState.active) { LOGGER.info("only active chat state"); } return; } // add message mControl.onNewInMessage(ids, Optional.ofNullable(delayDate), content); // send a 'received' for a receipt request (XEP-0184) DeliveryReceiptRequest request = DeliveryReceiptRequest.from(m); if (request != null && !ids.xmppID.isEmpty()) { Message received = new Message(m.getFrom(), Message.Type.chat); received.addExtension(new DeliveryReceipt(ids.xmppID)); mClient.sendPacket(received); } }
Example 16
Source File: MessageEventManager.java From Smack with Apache License 2.0 | 3 votes |
/** * Adds event notification requests to a message. For each event type that * the user wishes event notifications from the message recipient for, <code>true</code> * should be passed in to this method. * * @param message the message to add the requested notifications. * @param offline specifies if the offline event is requested. * @param delivered specifies if the delivered event is requested. * @param displayed specifies if the displayed event is requested. * @param composing specifies if the composing event is requested. */ public static void addNotificationsRequests(Message message, boolean offline, boolean delivered, boolean displayed, boolean composing) { // Create a MessageEvent Package and add it to the message MessageEvent messageEvent = new MessageEvent(); messageEvent.setOffline(offline); messageEvent.setDelivered(delivered); messageEvent.setDisplayed(displayed); messageEvent.setComposing(composing); message.addExtension(messageEvent); }
Example 17
Source File: DeliveryReceiptRequest.java From Smack with Apache License 2.0 | 3 votes |
/** * Add a delivery receipt request to an outgoing packet. * * Only message packets may contain receipt requests as of XEP-0184, * therefore only allow Message as the parameter type. * * @param message Message object to add a request to * @return the Message ID which will be used as receipt ID */ // TODO: Deprecate in favor of addTo(MessageBuilder) once connection's stanza interceptors use StanzaBuilder. public static String addTo(Message message) { message.throwIfNoStanzaId(); message.addExtension(new DeliveryReceiptRequest()); return message.getStanzaId(); }
Example 18
Source File: SpoilerElement.java From Smack with Apache License 2.0 | 2 votes |
/** * Add a SpoilerElement to a message. * * @param message message to add the Spoiler to. */ public static void addSpoiler(Message message) { message.addExtension(SpoilerElement.EMPTY); }
Example 19
Source File: CarbonExtension.java From Smack with Apache License 2.0 | 2 votes |
/** * Marks a message "private", so that it will not be carbon-copied, by adding private packet * extension to the message. * * @param message the message to add the private extension to * @deprecated use {@link #addTo(MessageBuilder)} instead. */ // TODO: Remove in Smack 4.6 @Deprecated public static void addTo(Message message) { message.addExtension(INSTANCE); }
Example 20
Source File: CarbonManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Mark a message as "private", so it will not be carbon-copied. * * @param msg Message object to mark private * @deprecated use {@link Private#addTo(Message)} */ @Deprecated public static void disableCarbons(Message msg) { msg.addExtension(Private.INSTANCE); }