org.jivesoftware.smack.packet.Message.getBody()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中org.jivesoftware.smack.packet.Message.getBody()方法的一些代码示例,展示了Message.getBody()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getBody()方法的具体详情如下:
包路径:org.jivesoftware.smack.packet.Message
类名称:Message
方法名:getBody

Message.getBody介绍

[英]Returns the default body of the message, or null if the body has not been set. The body is the main message contents.

The default body of a message is the body that corresponds to the message's language. (see #getLanguage()) or if no language is set to the applications default language (see Packet#getDefaultLanguage()).
[中]返回消息的默认正文,如果未设置正文,则返回null。正文是信息的主要内容。
消息的默认正文是与消息语言相对应的正文。(请参阅#getLanguage())或如果没有将任何语言设置为应用程序默认语言(请参阅数据包#getDefaultLanguage())。

代码示例

代码示例来源:origin: igniterealtime/Smack

/**
 * Returns the default body of the message, or null if the body has not been set. The body
 * is the main message contents.
 * <p>
 * The default body of a message is the body that corresponds to the message's language.
 * (see {@link #getLanguage()}) or if no language is set to the applications default
 * language (see {@link Stanza#getDefaultLanguage()}).
 *
 * @return the body of the message.
 */
public String getBody() {
  return getBody(language);
}

代码示例来源:origin: igniterealtime/Smack

@Test
public void messageNoLanguageFirstBodyNoLanguageSecondBodyOtherTest()
    throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
  String defaultLanguage = Stanza.getDefaultLanguage();
  String otherLanguage = determineNonDefaultLanguage();
  // message has no language, first body no language, second body other language
  String control = XMLBuilder.create("message")
    .namespace(StreamOpen.CLIENT_NAMESPACE)
    .a("from", "romeo@montague.lit/orchard")
    .a("to", "juliet@capulet.lit/balcony")
    .a("id", "zid615d9")
    .a("type", "chat")
    .e("body")
    // TODO change default language into something else
      .t(defaultLanguage)
    .up()
    .e("body")
      .a("xml:lang", otherLanguage)
      .t(otherLanguage)
    .asString(outputProperties);
  Message message = PacketParserUtils
          .parseMessage(PacketParserUtils.getParserFor(control));
  assertEquals(defaultLanguage, message.getBody());
  assertEquals(defaultLanguage, message.getBody(null));
  assertEquals(otherLanguage, message.getBody(otherLanguage));
  assertEquals(2, message.getBodies().size());
  assertEquals(1, message.getBodyLanguages().size());
  assertXMLEqual(control, message.toXML(null).toString());
}

代码示例来源:origin: igniterealtime/Smack

@Override
  public void processStanza(Stanza stanza) {
    Message message = (Message) stanza;
    if (message.getBody().equals(lastBody)) {
      allMessagesReceived.signal();
    }
  }
};

代码示例来源:origin: igniterealtime/Smack

.parseMessage(PacketParserUtils.getParserFor(control));
assertEquals(defaultLanguage, message.getBody());
assertEquals(otherLanguage, message.getBody(otherLanguage));
assertEquals(2, message.getBodies().size());
assertEquals(1, message.getBodyLanguages().size());
        .parseMessage(PacketParserUtils.getParserFor(control));
assertEquals(otherLanguage, message.getBody());
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertEquals(2, message.getBodies().size());
assertEquals(1, message.getBodyLanguages().size());

代码示例来源:origin: igniterealtime/Smack

@Override
  public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
    if (body.equals(message.getBody())) {
      syncPoint.signal();
    }
  }
};

代码示例来源:origin: igniterealtime/Smack

assertEquals(defaultLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertNull(message.getBody(otherLanguage));
assertXMLEqual(control, message.toXML(null).toString());
assertEquals(otherLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(otherLanguage, message.getBody(otherLanguage));
assertNull(message.getBody(defaultLanguage));
assertXMLEqual(control, message.toXML(null).toString());
assertEquals(defaultLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(defaultLanguage, message.getBody(null));
assertNull(message.getBody(otherLanguage));
assertXMLEqual(control, message.toXML(null).toString());
assertNull(message.getBody());
assertFalse(message.getBodyLanguages().isEmpty());
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertNull(message.getBody(otherLanguage));
assertNull(message.getBody());
assertFalse(message.getBodyLanguages().isEmpty());
assertTrue(message.getBodyLanguages().contains(otherLanguage));
assertEquals(otherLanguage, message.getBody(otherLanguage));
assertNull(message.getBody(defaultLanguage));
assertXMLEqual(control, message.toXML(null).toString());

代码示例来源:origin: igniterealtime/Smack

@Override
  public void processStanza(Stanza stanza) {
    Message message = (Message) stanza;
    if (message.getBody().equals(messageBody)) {
      messageReceived.signal();
    }
  }
};

代码示例来源:origin: igniterealtime/Smack

@Ignore
@Test
public void duplicateMessageBodiesTest()
    throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
  String defaultLanguage = Stanza.getDefaultLanguage();
  // message has default language, first body no language, second body default language
  String control = XMLBuilder.create("message")
    .namespace(StreamOpen.CLIENT_NAMESPACE)
    .a("from", "romeo@montague.lit/orchard")
    .a("to", "juliet@capulet.lit/balcony")
    .a("id", "zid615d9")
    .a("type", "chat")
    .a("xml:lang", defaultLanguage)
    .e("body")
      .t(defaultLanguage)
    .up()
    .e("body")
      .a("xml:lang", defaultLanguage)
      .t(defaultLanguage + "2")
    .asString(outputProperties);
  Message message = PacketParserUtils
          .parseMessage(PacketParserUtils.getParserFor(control));
  assertEquals(defaultLanguage, message.getBody());
  assertEquals(defaultLanguage, message.getBody(defaultLanguage));
  assertEquals(1, message.getBodies().size());
  assertEquals(0, message.getBodyLanguages().size());
  assertXMLNotEqual(control, message.toXML(null).toString());
}

代码示例来源:origin: igniterealtime/Smack

@Override
  public void processMessage(Message message) {
    String body = message.getBody();
    if (mucMessage.equals(body)) {
      resultSyncPoint.signal(body);
    }
  }
});

代码示例来源:origin: igniterealtime/Smack

@Override
  public void newOutgoingMessage(EntityBareJid to, Message message, Chat chat) {
    if (message.getBody().equals(body)) {
      syncPoint.signal();
    }
  }
};

代码示例来源:origin: igniterealtime/Smack

private static void assertMessageWithBodyReceived(String body, StanzaCollector collector) throws InterruptedException {
    Message message = collector.nextResult();
    assertNotNull(message);
    assertEquals(body, message.getBody());
  }
}

代码示例来源:origin: igniterealtime/Smack

@Test
public void oneMessageBodyTest() throws IOException, SAXException {
  final String messageBody = "This is a test of the emergency broadcast system.";
  StringBuilder controlBuilder = new StringBuilder();
  controlBuilder.append("<message>")
      .append("<body>")
      .append(messageBody)
      .append("</body>")
      .append("</message>");
  String control = controlBuilder.toString();
  Message message = getNewMessage();
  message.setBody(messageBody);
  assertEquals(messageBody, message.getBody());
  assertXMLEqual(control, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
}

代码示例来源:origin: igniterealtime/Smack

final String lastBody = outgoingMessages.get(outgoingMessages.size() - 1).getBody();
  Message queriedMessage = queriedMessages.get(i);
  assertEquals(outgoingMessage.getBody(), queriedMessage.getBody());

代码示例来源:origin: igniterealtime/Smack

@Test
public void checkResultsParse() throws Exception {
  Message message = PacketParserUtils.parseStanza(exampleResultMessage);
  MamResultExtension mamResultExtension = MamResultExtension.from(message);
  Assert.assertEquals(mamResultExtension.getQueryId(), "f27");
  Assert.assertEquals(mamResultExtension.getId(), "28482-98726-73623");
  GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
  calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
  Date date = calendar.getTime();
  Forwarded forwarded = mamResultExtension.getForwarded();
  Assert.assertEquals(forwarded.getDelayInformation().getStamp(), date);
  Message forwardedMessage = (Message) forwarded.getForwardedStanza();
  Assert.assertEquals(forwardedMessage.getFrom().toString(), "witch@shakespeare.lit");
  Assert.assertEquals(forwardedMessage.getTo().toString(), "macbeth@shakespeare.lit");
  Assert.assertEquals(forwardedMessage.getBody(), "Hail to thee");
}

代码示例来源:origin: igniterealtime/Smack

@Test
public void checkMamResultProvider() throws Exception {
  XmlPullParser parser = PacketParserUtils.getParserFor(exampleMamResultXml);
  MamResultExtension mamResultExtension = new MamResultProvider().parse(parser);
  Assert.assertEquals(mamResultExtension.getQueryId(), "f27");
  Assert.assertEquals(mamResultExtension.getId(), "28482-98726-73623");
  GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
  calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
  Date date = calendar.getTime();
  Forwarded forwarded = mamResultExtension.getForwarded();
  Assert.assertEquals(forwarded.getDelayInformation().getStamp(), date);
  Message message = (Message) forwarded.getForwardedStanza();
  Assert.assertEquals(message.getFrom().toString(), "romeo@montague.lit/orchard");
  Assert.assertEquals(message.getTo().toString(), "juliet@capulet.lit/balcony");
  Assert.assertEquals(message.getBody(),
      "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
}

代码示例来源:origin: igniterealtime/Smack

assertEquals(messageBody, mamMessage.getBody());
assertEquals(conOne.getUser(), mamMessage.getFrom());
assertEquals(userTwo, mamMessage.getTo());

代码示例来源:origin: igniterealtime/Smack

this.fireInvitationEvent(message.getFrom(), sessionID, message.getBody(),
    message.getFrom(), metaData);

代码示例来源:origin: igniterealtime/Smack

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",

代码示例来源:origin: igniterealtime/Smack

workgroupJID, sessionID, msg.getBody(),
msg.getFrom(), metaData);

代码示例来源:origin: igniterealtime/Smack

@Test
public void checkMamQueryResults() throws Exception {
  Message message = new Message();
  message.setStanzaId("iasd207");
  message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
  message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
  GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
  calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
  Date date = calendar.getTime();
  DelayInformation delay = new DelayInformation(date);
  Message forwardedMessage = new Message();
  forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
  forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
  forwardedMessage.setType(Type.chat);
  forwardedMessage.setBody("Thrice the brinded cat hath mew.");
  Forwarded forwarded = new Forwarded(delay, forwardedMessage);
  message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
  // FIXME: The order of assertEquals is reversed, fix it by switching it.
  Assert.assertEquals(message.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), mamQueryResultExample);
  MamResultExtension mamResultExtension = MamResultExtension.from(message);
  Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
  Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
  Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
  Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
  Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
  Assert.assertEquals(resultMessage.getType(), Type.chat);
  Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}

相关文章