當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.setSubject方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Message.setSubject方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.setSubject方法的具體用法?Java Message.setSubject怎麽用?Java Message.setSubject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Message的用法示例。


在下文中一共展示了Message.setSubject方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: changeSubject

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Changes the subject within the room. As a default, only users with a role of "moderator"
 * are allowed to change the subject in a room. Although some rooms may be configured to
 * allow a mere participant or even a visitor to change the subject.
 *
 * @param subject the new room's subject to set.
 * @throws XMPPErrorException if someone without appropriate privileges attempts to change the
 *          room subject will throw an error with code 403 (i.e. Forbidden)
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 */
public void changeSubject(final String subject) throws NoResponseException, XMPPErrorException, NotConnectedException {
    Message message = createMessage();
    message.setSubject(subject);
    // Wait for an error or confirmation message back from the server.
    StanzaFilter responseFilter = new AndFilter(fromRoomGroupchatFilter, new StanzaFilter() {
        @Override
        public boolean accept(Stanza packet) {
            Message msg = (Message) packet;
            return subject.equals(msg.getSubject());
        }
    });
    PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, message);
    // Wait up to a certain number of seconds for a reply.
    response.nextResultOrThrow();
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:27,代碼來源:MultiUserChat.java

示例2: testSendSimpleXHTMLMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
    * 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 occured sending the message with XHTML");
}
   }
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:29,代碼來源:XHTMLExtensionTest.java

示例3: populateXmppMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Populates the given XMPP message from the inbound exchange
 */
public void populateXmppMessage(Message message, Exchange exchange) {
    message.setBody(exchange.getIn().getBody(String.class));

    Set<Map.Entry<String, Object>> entries = exchange.getIn().getHeaders().entrySet();
    for (Map.Entry<String, Object> entry : entries) {
        String name = entry.getKey();
        Object value = entry.getValue();
        if (!headerFilterStrategy.applyFilterToCamelHeaders(name, value, exchange)) {

            if ("subject".equalsIgnoreCase(name)) {
                // special for subject
                String subject = exchange.getContext().getTypeConverter().convertTo(String.class, value);
                message.setSubject(subject);
            } else if ("language".equalsIgnoreCase(name)) {
                // special for language
                String language = exchange.getContext().getTypeConverter().convertTo(String.class, value);
                message.setLanguage(language);
            } else {
                try {
                    JivePropertiesManager.addProperty(message, name, value);
                    LOG.trace("Added property name: {} value: {}", name, value.toString());
                } catch (IllegalArgumentException iae) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Cannot add property " + name + " to XMPP message due: ", iae);
                    }
                }
            }
        }
    }

    String id = exchange.getExchangeId();
    if (id != null) {
        JivePropertiesManager.addProperty(message, "exchangeId", id);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:39,代碼來源:XmppBinding.java

示例4: testProperties

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void testProperties() {
    try {
        Chat newChat = getConnection(0).getChatManager().createChat(getFullJID(1), null);
        PacketCollector collector = getConnection(1)
                .createPacketCollector(new ThreadFilter(newChat.getThreadID()));

        Message msg = new Message();

        msg.setSubject("Subject of the chat");
        msg.setBody("Body of the chat");
        msg.setProperty("favoriteColor", "red");
        msg.setProperty("age", 30);
        msg.setProperty("distance", 30f);
        msg.setProperty("weight", 30d);
        msg.setProperty("male", true);
        msg.setProperty("birthdate", new Date());
        newChat.sendMessage(msg);

        Message msg2 = (Message) collector.nextResult(2000);

        assertNotNull("No message was received", msg2);
        assertEquals("Subjects are different", msg.getSubject(), msg2.getSubject());
        assertEquals("Bodies are different", msg.getBody(), msg2.getBody());
        assertEquals(
                "favoriteColors are different",
                msg.getProperty("favoriteColor"),
                msg2.getProperty("favoriteColor"));
        assertEquals(
                "ages are different",
                msg.getProperty("age"),
                msg2.getProperty("age"));
        assertEquals(
                "distances are different",
                msg.getProperty("distance"),
                msg2.getProperty("distance"));
        assertEquals(
                "weights are different",
                msg.getProperty("weight"),
                msg2.getProperty("weight"));
        assertEquals(
                "males are different",
                msg.getProperty("male"),
                msg2.getProperty("male"));
        assertEquals(
                "birthdates are different",
                msg.getProperty("birthdate"),
                msg2.getProperty("birthdate"));
    }
    catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:54,代碼來源:ChatTest.java


注:本文中的org.jivesoftware.smack.packet.Message.setSubject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。