Package tigase.xml

Examples of tigase.xml.Element


      session.queryAuth(query);
      String[] auth_mechs = (String[])query.get(UserAuthRepository.RESULT_KEY);
      Element[] mechs = new Element[auth_mechs.length];
      int idx = 0;
      for (String mech: auth_mechs) {
        mechs[idx++] = new Element("mechanism", mech);
      } // end of for (String mech: mechs)
      return new Element[] {new Element("mechanisms", mechs,
          new String[] {"xmlns"}, new String[] {XMLNS})};
    } // end of if (session.isAuthorized()) else
  }
View Full Code Here


    if (session == null) {
      return;
    } // end of if (session == null)

    Element request = packet.getElement();
//     ElementType type = null;
//     try {
//       type = ElementType.valueOf(request.getName());
//     } catch (IllegalArgumentException e) {
//       log.warning("Incorrect stanza type: " + request.getName());
//       results.offer(packet.swapFromTo(createReply(ElementType.failure,
//             "<temporary-auth-failure/>")));
//       results.offer(Command.CLOSE.getPacket(packet.getTo(), packet.getFrom(),
//           StanzaType.set, packet.getElemId()));
//       return;
//     } // end of try-catch
    Map<String, Object> authProps =
      (Map<String, Object>)(session.getSessionData(XMLNS+"-authProps"));
    if (authProps == null) {
      authProps = new HashMap<String, Object>();
      authProps.put(UserAuthRepository.PROTOCOL_KEY,
        UserAuthRepository.PROTOCOL_VAL_SASL);
      authProps.put(UserAuthRepository.MACHANISM_KEY,
        request.getAttribute("/auth", "mechanism"));
      authProps.put(UserAuthRepository.REALM_KEY, session.getDomain());
      authProps.put(UserAuthRepository.SERVER_NAME_KEY, session.getDomain());
      session.putSessionData(XMLNS+"-authProps", authProps);
    } // end of if (authProps == null)
    //    String user = (String)authProps.get(UserAuthRepository.USER_ID_KEY);
    authProps.put(UserAuthRepository.DATA_KEY, request.getCData());
    try {
      Authorization result = session.loginOther(authProps);
      String challenge_data =
        (String)authProps.get(UserAuthRepository.RESULT_KEY);
      if (result == Authorization.AUTHORIZED) {
View Full Code Here

      }
    } // end of try-catch
  }

  private Element createReply(final ElementType type, final String cdata) {
    Element reply = new Element(type.toString());
    reply.setXMLNS(XMLNS);
    if (cdata != null) {
      reply.setCData(cdata);
    } // end of if (cdata != null)
    return reply;
  }
View Full Code Here

    if (session.isAnonymous()) {
      String[] anon_peers = getBuddies(session);
      if (anon_peers != null) {
        for (String peer: anon_peers) {
          if (peer.equals(JIDUtils.getNodeID(buddy))) {
            Element item = new Element("item", new Element[] {
                new Element("group", "Anonymous peers")},
              new String[] {"jid", "subscription", "name"},
              new String[] {peer, "both", JIDUtils.getNodeNick(peer)});
            return item;
          }
        }
View Full Code Here

    if (session.isAnonymous()) {
      String[] anon_peers = getBuddies(session);
      if (anon_peers != null) {
        ArrayList<Element> al = new ArrayList<Element>();
        for (String peer: anon_peers) {
          Element item = new Element("item", new Element[] {
              new Element("group", "Anonymous peers")},
            new String[] {"jid", "subscription", "name"},
            new String[] {peer, "both", JIDUtils.getNodeNick(peer)});
          al.add(item);
        }
        return al;
View Full Code Here

      this.subscription = subscription;
    }
  }

  public Element getRosterElement() {
    Element elem = new Element(ELEM_NAME,
      new String[] {JID_ATT, SUBS_ATT, NAME_ATT},
      new String[] {jid, subscription.toString(), name});
    if (groups != null && groups.length > 0) {
      String grps = "";
      for (String group: groups) {
        grps += group + ",";
      }
      grps = grps.substring(0, grps.length() - 1);
      elem.setAttribute(GRP_ATT, grps);
    }
    return elem;
  }
View Full Code Here

      // According to JEP-0092 user doesn't need to be logged in to
      // retrieve server version information, so this part is executed
      // after checking if this message is just to local server
      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 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 result = packet.getElement().clone();
        // According to spec we must set proper FROM attribute
        //        result.setAttribute("from", session.getJID());
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
View Full Code Here

    switch (packet.getCommand()) {
    case GETSTATS: {
      log.finest("Command received: " + packet.getStringData());
      //      Element statistics = new Element("statistics");
      Element iq =
        ElementUtils.createIqQuery(packet.getElemTo(), packet.getElemFrom(),
          StanzaType.result, packet.getElemId(), STATS_XMLNS);
      Element query = iq.getChild("query");
      List<StatRecord> stats = getAllStats();
      if (stats != null && stats.size() > 0) {
        for (StatRecord record: stats) {
          Element item = new Element("stat");
          item.addAttribute("name", record.getComponent() + "/"
            + record.getDescription());
          item.addAttribute("units", record.getUnit());
          item.addAttribute("value", record.getValue());
          query.addChild(item);
        } // end of for ()
      } // end of if (stats != null && stats.count() > 0)
      Packet result = new Packet(iq);
      //      Command.setData(result, statistics);
View Full Code Here

      List<Element> items = serviceEntity.getDiscoItems(node, jid);
      log.finest("Processing discoItems for node: " + node + ", result: "
        + (items == null ? null : items.toString()));
      return items;
    } else {
      Element item = serviceEntity.getDiscoItem(null,
        JIDUtils.getNodeID(getName(),  jid));
      log.finest("Processing discoItems, result: "
        + (item == null ? null : item.toString()));
      return Arrays.asList(item);
    }
  }
View Full Code Here

    RosterFactory.getRosterImplementation(true);

  public static Element createRosterPacket(String iq_type, String iq_id,
    String to, String from, String item_jid, String item_name, String item_group,
    String subscription, String item_type) {
    Element iq = new Element("iq",
      new String[] {"type", "id"},
      new String[] {iq_type, iq_id});
    if (from != null) {
      iq.addAttribute("from", from);
    }
    if (to != null) {
      iq.addAttribute("to", to);
    }
    Element query = new Element("query");
    query.setXMLNS(XMLNS);
    iq.addChild(query);
    Element item = new Element("item",
      new String[] {"jid"},
      new String[] {item_jid});
    if (item_type != null) {
      item.addAttribute("type", item_type);
    }
    if (item_name != null) {
      item.addAttribute(RosterAbstract.NAME, item_name);
    }
    if (subscription != null) {
      item.addAttribute(RosterAbstract.SUBSCRIPTION, subscription);
    }
    if (item_group != null) {
      Element group = new Element(RosterAbstract.GROUP, item_group);
      item.addChild(group);
    }
    query.addChild(item);
    return iq;
  }
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.