Exemplo n.º 1
0
  protected Packet createMessage(
      BareJID roomJID,
      JID senderJID,
      String msgSenderNickname,
      String originalMessage,
      String body,
      String msgSenderJid,
      boolean addRealJids,
      Date msgTimestamp)
      throws TigaseStringprepException {

    Packet message = null;

    if (originalMessage != null) {
      DomBuilderHandler domHandler = new DomBuilderHandler();
      parser.parse(domHandler, originalMessage.toCharArray(), 0, originalMessage.length());
      Queue<Element> queue = domHandler.getParsedElements();

      Element m = queue.poll();
      if (m != null) {
        m.setAttribute("type", "groupchat");
        m.setAttribute("from", JID.jidInstance(roomJID, msgSenderNickname).toString());
        m.setAttribute("to", senderJID.toString());

        message = Packet.packetInstance(m);
        message.setXMLNS(Packet.CLIENT_XMLNS);
      }
    }

    if (message == null) {
      message =
          Packet.packetInstance(
              new Element(
                  "message",
                  new String[] {"type", "from", "to"},
                  new String[] {
                    "groupchat",
                    JID.jidInstance(roomJID, msgSenderNickname).toString(),
                    senderJID.toString()
                  }));
      message.setXMLNS(Packet.CLIENT_XMLNS);
      message.getElement().addChild(new Element("body", body));
    }

    String from = addRealJids ? msgSenderJid : roomJID + "/" + msgSenderNickname;
    Element delay =
        new Element(
            "delay",
            new String[] {"xmlns", "from", "stamp"},
            new String[] {"urn:xmpp:delay", from, DateUtil.formatDatetime(msgTimestamp)});
    Element x =
        new Element(
            "x",
            new String[] {"xmlns", "from", "stamp"},
            new String[] {"jabber:x:delay", from, DateUtil.formatOld(msgTimestamp)});
    message.getElement().addChild(delay);
    message.getElement().addChild(x);

    return message;
  }
Exemplo n.º 2
0
  private Packet parseXMLData(String data, Packet packet) {
    DomBuilderHandler domHandler = new DomBuilderHandler();

    parser.parse(domHandler, data.toCharArray(), 0, data.length());

    Queue<Element> elems = domHandler.getParsedElements();
    Packet result = packet.okResult((Element) null, 0);

    result.setPacketFrom(null);
    result.setPacketTo(null);
    for (Element el : elems) {
      result.getElement().addChild(el);
    } // end of for (Element el: elems)

    return result;
  }