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

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

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

Message.getBodies介绍

[英]Returns a set of all bodies in this Message, including the default message body accessible from #getBody().
[中]返回此消息中所有正文的集合,包括可从#getBody()访问的默认消息正文。

代码示例

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

@Override
protected boolean acceptSpecific(Message message) {
  // Accept only messages which have at least one body
  return !message.getBodies().isEmpty();
}

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

private boolean shouldAcceptMessage(Message message) {
  if (!message.getBodies().isEmpty()) {
    return true;
  }
  // Message has no XMPP-IM bodies, abort here if xhtmlIm is not enabled.
  if (!xhtmlIm) {
    return false;
  }
  XHTMLExtension xhtmlExtension = XHTMLExtension.from(message);
  if (xhtmlExtension == null) {
    // Message has no XHTML-IM extension, abort.
    return false;
  }
  return true;
}

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

private Body getMessageBody(String language) {
  language = determineLanguage(language);
  for (Body body : getBodies()) {
    if (Objects.equals(language, body.language) || (language != null && language.equals(this.language) && body.language == null)) {
      return body;
    }
  }
  return null;
}

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

/**
 * Returns all the languages being used for the bodies, not including the default body.
 *
 * @return the languages being used for the bodies.
 * @since 3.0.2
 */
public List<String> getBodyLanguages() {
  Body defaultBody = getMessageBody(null);
  List<String> languages = new ArrayList<String>();
  for (Body body : getBodies()) {
    if (!body.equals(defaultBody)) {
      languages.add(body.language);
    }
  }
  return Collections.unmodifiableList(languages);
}

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

/**
 * Removes the body with the given language from the message.
 *
 * @param language the language of the body which is to be removed
 * @return true if a body was removed and false if it was not.
 */
public boolean removeBody(String language) {
  language = determineLanguage(language);
  for (Body body : getBodies()) {
    String bodyLanguage = body.getLanguage();
    if (Objects.equals(bodyLanguage, language)) {
      removeExtension(body);
      return true;
    }
  }
  return false;
}

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

@Test
public void removeMessageBodyTest() {
  Message message = getNewMessage();
  message.setBody("test");
  assertTrue(message.getBodies().size() == 1);
  message.setBody(null);
  assertTrue(message.getBodies().size() == 0);
  assertFalse(message.removeBody("sp"));
  Message.Body body = message.addBody("es", "test");
  assertTrue(message.getBodies().size() == 1);
  message.removeBody(body);
  assertTrue(message.getBodies().size() == 0);
}

代码示例来源: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

assertEquals(2, message.getBodies().size());
assertEquals(1, message.getBodyLanguages().size());
assertTrue(message.getBodyLanguages().contains(otherLanguage));
assertEquals(2, message.getBodies().size());
assertEquals(1, message.getBodyLanguages().size());
assertTrue(message.getBodyLanguages().contains(defaultLanguage));

代码示例来源: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: org.igniterealtime.smack/smack-core

@Override
protected boolean acceptSpecific(Message message) {
  // Accept only messages which have at least one body
  return !message.getBodies().isEmpty();
}

代码示例来源:origin: org.igniterealtime.smack/smack-core

private Body getMessageBody(String language) {
  language = determineLanguage(language);
  for (Body body : getBodies()) {
    if (Objects.equals(language, body.language) || (language != null && language.equals(this.language) && body.language == null)) {
      return body;
    }
  }
  return null;
}

代码示例来源:origin: org.igniterealtime.smack/smack-core

/**
 * Returns all the languages being used for the bodies, not including the default body.
 *
 * @return the languages being used for the bodies.
 * @since 3.0.2
 */
public List<String> getBodyLanguages() {
  Body defaultBody = getMessageBody(null);
  List<String> languages = new ArrayList<String>();
  for (Body body : getBodies()) {
    if (!body.equals(defaultBody)) {
      languages.add(body.language);
    }
  }
  return Collections.unmodifiableList(languages);
}

代码示例来源:origin: org.littleshoot/smack-xmpp-3-2-2

for (Body body : getBodies()) {

代码示例来源:origin: org.igniterealtime.smack/smack

for (Body body : getBodies()) {

代码示例来源:origin: org.igniterealtime.smack/smack-core

/**
 * Removes the body with the given language from the message.
 *
 * @param language the language of the body which is to be removed
 * @return true if a body was removed and false if it was not.
 */
public boolean removeBody(String language) {
  language = determineLanguage(language);
  for (Body body : getBodies()) {
    String bodyLanguage = body.getLanguage();
    if (Objects.equals(bodyLanguage, language)) {
      removeExtension(body);
      return true;
    }
  }
  return false;
}

代码示例来源:origin: tiandawu/IotXmpp

for (Body body : getBodies()) {

相关文章