Package tigase.xml

Examples of tigase.xml.Element


          String list)
          throws NotAuthorizedException, TigaseDBException {
    String lNode = listNode(list);
    String[] items = session.getDataGroups(lNode);
    if (items != null) {
      Element eList = new Element(LIST,
        new String[] {NAME}, new String[] {list});
      for (String item: items) {
        String iNode = lNode + "/" + item;
        String type = session.getData(iNode, TYPE, null);
        String value = session.getData(iNode, VALUE, null);
        String action = session.getData(iNode, ACTION, null);
        String[] stanzas = session.getDataList(iNode, STANZAS);
        Element eItem = new Element(ITEM,
          new String[] {ORDER, ACTION},
          new String[] {item, action});
        if (type != null) {
          eItem.addAttribute(TYPE, type);
        } // end of if (type != null)
        if (value != null) {
          eItem.addAttribute(VALUE, value);
        } // end of if (value != null)
        if (stanzas != null) {
          for (String stanza: stanzas) {
          eItem.addChild(new Element(stanza));
          } // end of for (String stanza: stanzas)
        } // end of if (stanzas != null)
        eList.addChild(eItem);
      } // end of for (String item: items)
      return eList;
View Full Code Here


      if (packet.isCommand()) {
        if (packet.getCommand() == Command.GETSTATS
          && packet.getType() == StanzaType.result) {
          // Send it back to user.
          Element iq =
            ElementUtils.createIqQuery(session.getDomain(), session.getJID(),
              StanzaType.result, packet.getElemId(), XMLNS);
          Element query = iq.getChild("query");
          Element stats = Command.getData(packet, "statistics", null);
          query.addChildren(stats.getChildren());
          Packet result = new Packet(iq);
          result.setTo(session.getConnectionId(packet.getElemTo()));
          results.offer(result);
          log.finest("Sending result: " + result.getStringData());
          return;
        } else {
          return;
        }
      } // end of if (packet.isCommand()


      // Maybe it is message to admininstrator:
      String id = packet.getElemTo() != null ?
        JIDUtils.getNodeID(packet.getElemTo()) : null;

      // If ID part of user account contains only host name
      // and this is local domain it is message to admin
      if (id == null || id.equals("")
        || id.equalsIgnoreCase(session.getDomain())) {
        Packet result =
          Command.GETSTATS.getPacket(packet.getElemFrom(),
          session.getDomain(), StanzaType.get, packet.getElemId());
        results.offer(result);
        log.finest("Sending result: " + result.getStringData());
        return;
      }

      if (id.equals(session.getUserId())) {
        // Yes this is message to 'this' client
        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId(packet.getElemTo()));
        result.setFrom(packet.getTo());
        results.offer(result);
        log.finest("Sending result: " + result.getStringData());
      } else {
        // This is message to some other client so I need to
        // set proper 'from' attribute whatever it is set to now.
        // Actually processor should not modify request but in this
        // case it is absolutely safe and recommended to set 'from'
        // attribute
        Element el_res = packet.getElement().clone();
        // Not needed anymore. Packet filter does it for all stanzas.
//         // According to spec we must set proper FROM attribute
//         el_res.setAttribute("from", session.getJID());
        Packet result = new Packet(el_res);
        results.offer(result);
View Full Code Here

      String id = JIDUtils.getNodeID(packet.getElemTo());

      if (id.equals(session.getUserId())) {
        // Yes this is message to 'this' client
        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId(packet.getElemTo()));
        result.setFrom(packet.getTo());
        results.offer(result);
      } else {
        // This is message to some other client
        Element result = packet.getElement().clone();
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      log.warning("NotAuthorizedException for packet: "  + packet.getStringData());
      results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
View Full Code Here

  public static void stopped(final XMPPResourceConnection session,
    final Queue<Packet> results, final Map<String, Object> settings) {
    // Synchronization to avoid conflict with login/logout events
    // processed in the SessionManager asynchronously
    synchronized (session) {
      Element pres = (Element)session.getSessionData(PRESENCE_KEY);
      // According to the spec and logic actually offline status should
      // not be broadcasted if initial presence was not sent by the client.
      if (pres != null && (pres.getAttribute("type") == null
          || !pres.getAttribute("type").equals("unavailable"))) {
        try {
          sendPresenceBroadcast(StanzaType.unavailable, session,
            FROM_SUBSCRIBED, results, null, settings);
          updateOfflineChange(session, results);
        } catch (NotAuthorizedException e) {
View Full Code Here

    final Queue<Packet> results)
    throws NotAuthorizedException, TigaseDBException {
    String[] buddies = roster_util.getBuddies(session, RosterAbstract.PENDING_IN);
    if (buddies != null) {
      for (String buddy: buddies) {
        Element presence = new Element(PRESENCE_ELEMENT_NAME);
        presence.setAttribute("type", StanzaType.subscribe.toString());
        presence.setAttribute("from", buddy);
        presence.setXMLNS(XMLNS);
        updatePresenceChange(presence, session, results);
      }
    }
  }
View Full Code Here

    for (XMPPResourceConnection conn: session.getActiveSessions()) {
      log.finer("Update presence change to: " + conn.getJID());
      if (conn != session && conn.getResource() != null
        && !conn.getResource().equals(session.getResource())) {
        // Send to old resource presence about new resource
        Element pres_update = new Element(PRESENCE_ELEMENT_NAME);
        pres_update.setAttribute("from", session.getJID());
        pres_update.setAttribute("to", conn.getJID());
        pres_update.setAttribute("type", StanzaType.unavailable.toString());
        pres_update.setXMLNS(XMLNS);
        Packet pack_update = new Packet(pres_update);
        pack_update.setTo(conn.getConnectionId());
        results.offer(pack_update);
      } else {
        log.finer("Skipping presence update to: " + conn.getJID());
View Full Code Here

    throws NotAuthorizedException {
    for (XMPPResourceConnection conn: session.getActiveSessions()) {
      log.finer("Update presence change to: " + conn.getJID());
      if (conn != session && conn.isResourceSet()) {
        // Send to new resource presence about old resource
        Element pres_update = presence.clone();
        pres_update.setAttribute("from", session.getJID());
        pres_update.setAttribute("to", conn.getJID());
        Packet pack_update = new Packet(pres_update);
        pack_update.setTo(conn.getConnectionId());
        results.offer(pack_update);
        Element presence_el = (Element)conn.getSessionData(PRESENCE_KEY);
        if (presence_el != null) {
          pres_update = presence_el.clone();
          pres_update.setAttribute("to", session.getJID());
          pres_update.setAttribute("from", conn.getJID());
          pack_update = new Packet(pres_update);
          pack_update.setTo(session.getConnectionId());
          results.offer(pack_update);
View Full Code Here

      if (conn.getSessionData(PRESENCE_KEY) != null || !initial_p) {
        // Update presence change only for online resources that is
        // resources which already sent initial presence.
        log.finer("Update presence change to: " + conn.getJID());
        // Send to old resource presence about new resource
        Element pres_update = presence.clone();
        pres_update.setAttribute("to", conn.getJID());
        Packet pack_update = new Packet(pres_update);
        pack_update.setTo(conn.getConnectionId());
        results.offer(pack_update);
      } else {
        // Ignore....
View Full Code Here

    } // end of for (XMPPResourceConnection conn: sessions)
  }

  protected static void forwardPresence(final Queue<Packet> results,
    final Packet packet, final String from) {
    Element result = packet.getElement().clone();
    // Not needed anymore. Packet filter does it for all stanzas.
     // According to spec we must set proper FROM attribute
    // Yes, but packet filter put full JID and we need a subscription
    // presence without resource here.
    result.setAttribute("from", from);
    log.finest("\n\nFORWARD presence: " + result.toString());
    results.offer(new Packet(result));
  }
View Full Code Here

  }

  protected static void sendPresence(final StanzaType t, final String to,
    final String from, final Queue<Packet> results, final Element pres) {

    Element presence = null;
    if (pres == null) {
      presence = new Element(PRESENCE_ELEMENT_NAME);
      if (t != null) {
        presence.setAttribute("type", t.toString());
      } // end of if (t != null)
      else {
        presence.setAttribute("type", StanzaType.unavailable.toString());
      } // end of if (t != null) else
    } // end of if (pres == null)
    else {
      presence = pres.clone();
    } // end of if (pres == null) else
    presence.setAttribute("to", to);
    presence.setAttribute("from", from);
    presence.setXMLNS(XMLNS);
    Packet packet = new Packet(presence);
    log.finest("Sending presence info: " + packet.getStringData());
    results.offer(packet);
  }
View Full Code Here

TOP

Related Classes of tigase.xml.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.