Package org.xmpp.forms

Examples of org.xmpp.forms.DataForm


   * @return Element, named 'query', escaped by the 'jabber:iq:search'
   *         namespace, filled with a blank dataform.
   */
  private static Element getDataElement()
  {
    final DataForm searchForm = new DataForm(DataForm.Type.form);
    searchForm.setTitle("Chat Rooms Search");
    searchForm.addInstruction("Instructions");

    final FormField typeFF = searchForm.addField();
    typeFF.setVariable("FORM_TYPE");
    typeFF.setType(FormField.Type.hidden);
    typeFF.addValue("jabber:iq:search");

    final FormField nameFF = searchForm.addField();
    nameFF.setVariable("name");
    nameFF.setType(FormField.Type.text_single);
    nameFF.setLabel("Name");
    nameFF.setRequired(false);

    final FormField matchFF = searchForm.addField();
    matchFF.setVariable("name_is_exact_match");
    matchFF.setType(FormField.Type.boolean_type);
    matchFF.setLabel("Name must match exactly");
    matchFF.setRequired(false);

    final FormField subjectFF = searchForm.addField();
    subjectFF.setVariable("subject");
    subjectFF.setType(FormField.Type.text_single);
    subjectFF.setLabel("Subject");
    subjectFF.setRequired(false);

    final FormField userAmountFF = searchForm.addField();
    userAmountFF.setVariable("num_users");
    userAmountFF.setType(FormField.Type.text_single);
    userAmountFF.setLabel("Number of users");
    userAmountFF.setRequired(false);

    final FormField maxUsersFF = searchForm.addField();
    maxUsersFF.setVariable("num_max_users");
    maxUsersFF.setType(FormField.Type.text_single);
    maxUsersFF.setLabel("Max number allowed of users");
    maxUsersFF.setRequired(false);

    final FormField includePasswordProtectedFF = searchForm.addField();
    includePasswordProtectedFF.setVariable("include_password_protected");
    includePasswordProtectedFF.setType(FormField.Type.boolean_type);
    includePasswordProtectedFF.setLabel("Include password protected rooms");
    includePasswordProtectedFF.setRequired(false);

    final Element probeResult = DocumentHelper.createElement(QName.get(
      "query", "jabber:iq:search"));
    probeResult.add(searchForm.getElement());
    return probeResult;
  }
View Full Code Here


      reply.setChildElement(getDataElement());
      return reply;
    }

    // parse params from request.
    final DataForm df = new DataForm(formElement);
    boolean name_is_exact_match = false;
    String subject = null;
    int numusers = -1;
    int numaxusers = -1;
    boolean includePasswordProtectedRooms = true;

    final Set<String> names = new HashSet<String>();
    for (final FormField field : df.getFields())
    {
      if (field.getVariable().equals("name"))
      {
        names.add(field.getFirstValue());
      }
    }

    final FormField matchFF = df.getField("name_is_exact_match");
    if (matchFF != null)
    {
      final String b = matchFF.getFirstValue();
      if (b != null)
      {
        name_is_exact_match = b.equals("1")
            || b.equalsIgnoreCase("true")
            || b.equalsIgnoreCase("yes");
      }
    }

    final FormField subjectFF = df.getField("subject");
    if (subjectFF != null)
    {
      subject = subjectFF.getFirstValue();
    }

    try
    {
      final FormField userAmountFF = df.getField("num_users");
      if (userAmountFF != null)
      {
                String value = userAmountFF.getFirstValue();
                if (value != null && !"".equals(value)) {
                    numusers = Integer.parseInt(value);
                }
      }

      final FormField maxUsersFF = df.getField("num_max_users");
      if (maxUsersFF != null)
      {
                String value = maxUsersFF.getFirstValue();
                if (value != null && !"".equals(value)) {
                    numaxusers = Integer.parseInt(value);
                }
            }
    }
    catch (NumberFormatException e)
    {
      reply.setError(PacketError.Condition.bad_request);
      return reply;
    }

    final FormField includePasswordProtectedRoomsFF = df.getField("include_password_protected");
    if (includePasswordProtectedRoomsFF != null)
    {
      final String b = includePasswordProtectedRoomsFF.getFirstValue();
      if (b != null)
      {
        if (b.equals("0") || b.equalsIgnoreCase("false")
            || b.equalsIgnoreCase("no"))
        {
          includePasswordProtectedRooms = false;
        }
      }
    }

    // search for chatrooms matching the request params.
    final List<MUCRoom> mucs = new ArrayList<MUCRoom>();
    for (MUCRoom room : mucService.getChatRooms())
    {
      boolean find = false;

      if (names.size() > 0)
      {
        for (final String name : names)
        {
          if (name_is_exact_match)
          {
            if (name.equalsIgnoreCase(room.getNaturalLanguageName()))
            {
              find = true;
              break;
            }
          }
          else
          {
            if (room.getNaturalLanguageName().toLowerCase().indexOf(
              name.toLowerCase()) != -1)
            {
              find = true;
              break;
            }
          }
        }
      }

      if (subject != null
          && room.getSubject().toLowerCase().indexOf(
            subject.toLowerCase()) != -1)
      {
        find = true;
      }

      if (numusers > -1 && room.getParticipants().size() < numusers)
      {
        find = false;
      }

      if (numaxusers > -1 && room.getMaxUsers() < numaxusers)
      {
        find = false;
      }

      if (!includePasswordProtectedRooms && room.isPasswordProtected())
      {
        find = false;
      }

      if (find && canBeIncludedInResult(room))
      {
        mucs.add(room);
      }
    }

    final ResultSet<MUCRoom> searchResults = new ResultSetImpl<MUCRoom>(
      sortByUserAmount(mucs));

    // See if the requesting entity would like to apply 'result set
    // management'
    final Element set = iq.getChildElement().element(
      QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));
    final List<MUCRoom> mucrsm;

    // apply RSM only if the element exists, and the (total) results
    // set is not empty.
    final boolean applyRSM = set != null && !mucs.isEmpty();

    if (applyRSM)
    {
      if (!ResultSet.isValidRSMRequest(set))
      {
        reply.setError(Condition.bad_request);
        return reply;
      }

      try
      {
        mucrsm = searchResults.applyRSMDirectives(set);
      }
      catch (NullPointerException e)
      {
        final IQ itemNotFound = IQ.createResultIQ(iq);
        itemNotFound.setError(Condition.item_not_found);
        return itemNotFound;
      }
    }
    else
    {
      // if no rsm, all found rooms are part of the result.
      mucrsm = new ArrayList<MUCRoom>(searchResults);
    }

    final Element res = DocumentHelper.createElement(QName.get("query",
      "jabber:iq:search"));

    final DataForm resultform = new DataForm(DataForm.Type.result);
    boolean atLeastoneResult = false;
    for (MUCRoom room : mucrsm)
    {
      final Map<String, Object> fields = new HashMap<String, Object>();
      fields.put("name", room.getNaturalLanguageName());
      fields.put("subject", room.getSubject());
      fields.put("num_users", room.getOccupantsCount());
      fields.put("num_max_users", room.getMaxUsers());
      fields.put("is_password_protected", room.isPasswordProtected());
      fields.put("is_member_only", room.isMembersOnly());
      fields.put("jid", room.getRole().getRoleAddress().toString());
            resultform.addItemFields(fields);
      atLeastoneResult = true;
    }
    if (atLeastoneResult)
    {
      resultform.addReportedField("name", "Name", FormField.Type.text_single);
      resultform.addReportedField("subject", "Subject", FormField.Type.text_single);
      resultform.addReportedField("num_users", "Number of users", FormField.Type.text_single);
      resultform.addReportedField("num_max_users", "Max number allowed of users", FormField.Type.text_single);
      resultform.addReportedField("is_password_protected", "Is a password protected room.", FormField.Type.boolean_type);
      resultform.addReportedField("is_member_only", "Is a member only room.", FormField.Type.boolean_type);
      resultform.addReportedField("jid", "JID", FormField.Type.jid_single);
    }

    if (applyRSM)
    {
      res.add(searchResults.generateSetElementFromResults(mucrsm));
View Full Code Here

     */
    private static IQ replyDisabled(IQ packet) {
        IQ replyPacket = IQ.createResultIQ(packet);
        Element reply = replyPacket.setChildElement("query",
                NAMESPACE_JABBER_IQ_SEARCH);
        final DataForm unavailableForm = new DataForm(DataForm.Type.cancel);
        unavailableForm.setTitle(LocaleUtils.getLocalizedString(
                "advance.user.search.title", "search"));
        unavailableForm.addInstruction(LocaleUtils.getLocalizedString(
                "search.service_unavailable", "search"));
        reply.add(unavailableForm.getElement());

        return replyPacket;
    }
View Full Code Here

        queryResult.addElement("first");
        queryResult.addElement("last");
        queryResult.addElement("nick");
        queryResult.addElement("email");

        DataForm searchForm = new DataForm(DataForm.Type.form);
        searchForm.setTitle(LocaleUtils.getLocalizedString(
                "advance.user.search.title", "search"));
        searchForm.addInstruction(instructions);

        searchForm.addField("FORM_TYPE", null, FormField.Type.hidden)
            .addValue(NAMESPACE_JABBER_IQ_SEARCH);

        searchForm.addField("search",
            LocaleUtils.getLocalizedString("advance.user.search.search", "search"),
            FormField.Type.text_single)
            .setRequired(true);
       

        for (String searchField : getFilteredSearchFields()) {
          final FormField field = searchForm.addField();
            field.setVariable(searchField);
            field.setType(FormField.Type.boolean_type);
            field.addValue("1");
            field.setLabel(LocaleUtils.getLocalizedString(
                "advance.user.search." + searchField.toLowerCase(), "search"));
            field.setRequired(false);
        }

        queryResult.add(searchForm.getElement());
        replyPacket.setChildElement(queryResult);

        return replyPacket;
    }
View Full Code Here

     * @param users set of users that will be used to construct the search results
     * @param packet the IQ packet sent by the client
     * @return the iq packet that contains the search results
     */
    private IQ replyDataFormResult(Collection<User> users, IQ packet) {
        final DataForm searchResults = new DataForm(DataForm.Type.result);

        searchResults.addField("FORM_TYPE", null, FormField.Type.hidden);

        searchResults.addReportedField("jid", "JID", FormField.Type.jid_single);

        for (final String fieldName : getFilteredSearchFields()) {
            searchResults.addReportedField(fieldName,
                LocaleUtils.getLocalizedString("advance.user.search." + fieldName.toLowerCase(), "search"),
                FormField.Type.text_single);
        }

        for (final User user : users) {
            final String username = JID.unescapeNode(user.getUsername());

            final Map<String, Object> item = new HashMap<String, Object>();
            item.put("jid",
                username + "@" + serverName);
           
            item.put(LocaleUtils.getLocalizedString("advance.user.search.username", "search"),
                username);
           
            item.put(LocaleUtils.getLocalizedString("advance.user.search.name", "search"),
                (user.isNameVisible() ? removeNull(user.getName()) : ""));

            item.put(LocaleUtils.getLocalizedString("advance.user.search.email", "search"),
                (user.isEmailVisible() ? removeNull(user.getEmail()) : ""));

            searchResults.addItemFields(item);
        }

        IQ replyPacket = IQ.createResultIQ(packet);
        Element reply = replyPacket.setChildElement("query",
                NAMESPACE_JABBER_IQ_SEARCH);
        reply.add(searchResults.getElement());

        return replyPacket;
    }
View Full Code Here

                Collection<Workgroup> workgroups = WorkgroupManager.getInstance().getWorkgroups();
                JID agentJID = null;
                String queryString = null;

                // Get the search parameters from the completed form
                DataForm submitedForm = (DataForm)packet.getExtension(DataForm.ELEMENT_NAME,
                    DataForm.NAMESPACE);
                for (FormField field : submitedForm.getFields()) {
                    if ("date/start".equals(field.getVariable())) {
                        try {
                            startDate = DataForm.parseDate(field.getValues().get(0));
                        }
                        catch (ParseException e) {
                            Log.debug("Invalid startDate " +
                                field.getValues().get(0), e);
                        }
                    }
                    else if ("date/end".equals(field.getVariable())) {
                        try {
                            endDate = DataForm.parseDate(field.getValues().get(0));
                        }
                        catch (ParseException e) {
                            Log.debug("Invalid endDate " +
                                field.getValues().get(0), e);
                        }
                    }
                    else if ("workgroups".equals(field.getVariable())) {
                        if (!field.getValues().isEmpty()) {
                            workgroups = new ArrayList<Workgroup>();
                            for (String value : field.getValues()) {
                                try {
                                    workgroups.add(
                                        WorkgroupManager.getInstance().getWorkgroup(
                                            new JID(value)));
                                }
                                catch (UserNotFoundException e) {
                                    Log.debug("Invalid workgroup JID " +
                                        value, e);
                                }
                            }
                        }
                        else {
                            // Search in all the workgroups since no one was specified
                            workgroups = WorkgroupManager.getInstance().getWorkgroups();
                        }
                    }
                    else if ("agent".equals(field.getVariable())) {
                        agentJID = new JID(field.getValues().get(0));
                    }
                    else if ("queryString".equals(field.getVariable())) {
                        queryString = field.getValues().get(0);
                    }
                }

                // Build the response
                DataForm searchResults = resultForm.createCopy();
                // Perform the search
                for (Workgroup workgroup : workgroups) {
                    ChatSearch search = new ChatSearch(workgroup, startDate, endDate, agentJID,
                        queryString);
                    for (QueryResult result : search.getResults()) {
                        Map<String, Object> fields = new LinkedHashMap<String, Object>();
                        fields.put("workgroup", result.getWorkgroup().getJID().toBareJID());
                        fields.put("sessionID", result.getSessionID());
                        fields.put("startDate", result.getStartDate());
                        fields.put("agentJIDs", result.getAgentJIDs());
                        fields.put("relevance", result.getRelevance());

                        // Add Metadata
                        Map<String, String> metadata = getMetadataMap(result.getSessionID());
                        if (metadata.containsKey("question")) {
                            fields.put("question", metadata.get("question"));
                        }

                        if (metadata.containsKey("email")) {
                            fields.put("email", metadata.get("email"));
                        }

                        if (metadata.containsKey("username")) {
                            fields.put("username", metadata.get("username"));
                        }

                        searchResults.addItemFields(fields);
                    }
                }
                reply.setChildElement(iq.getName(), iq.getNamespaceURI());
                reply.addExtension(searchResults);
                workgroupManager.send(reply);
View Full Code Here

        }
    }

    private void init() {
        // Configure the search form that will be sent to the agents
        this.searchForm = new DataForm(DataForm.Type.form);
        this.searchForm.setTitle("Chat search");
        this.searchForm.addInstruction("Fill out this form to search for chats");
        // Add starting date
        FormField field = this.searchForm.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel("Starting Date");
        field.setVariable("date/start");
        // Add ending date
        field = this.searchForm.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel("Ending Date");
        field.setVariable("date/end");
        // Add workgroup JID
        field = this.searchForm.addField();
        field.setType(FormField.Type.jid_multi);
        field.setLabel("Workgroup");
        field.setVariable("workgroups");
        // Add agent JID
        field = this.searchForm.addField();
        field.setType(FormField.Type.jid_single);
        field.setLabel("Agent");
        field.setVariable("agent");
        // Add query string
        field = this.searchForm.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel("Search Terms");
        field.setVariable("queryString");
        field.setRequired(true);

        // Configure the form that will hold the search results
        this.resultForm = new DataForm(DataForm.Type.result);
        this.resultForm.addReportedField("workgroup", null, FormField.Type.jid_single);
        this.resultForm.addReportedField("sessionID", null, FormField.Type.text_single);
        this.resultForm.addReportedField("startDate", null, FormField.Type.text_single);
        this.resultForm.addReportedField("agentJIDs", null, FormField.Type.jid_multi);
        this.resultForm.addReportedField("relevance", null, FormField.Type.text_single);
View Full Code Here

                }
            }
        }

        // Create metadata from submitted form.
        DataForm submittedForm = (DataForm)packet.getExtension(DataForm.ELEMENT_NAME,
                DataForm.NAMESPACE);

        for (FormField field : submittedForm.getFields()) {
            metaData.put(field.getVariable(), field.getValues());
        }

        // Omit certain items
        metaData.remove("password");
View Full Code Here

     * edit the subscription configuration.
     *
     * @return data form used by the subscriber to edit the subscription configuration.
     */
    public DataForm getConfigurationForm() {
        DataForm form = new DataForm(DataForm.Type.form);
        form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.subscription.title"));
        List<String> params = new ArrayList<String>();
        params.add(node.getNodeID());
        form.addInstruction(LocaleUtils.getLocalizedString("pubsub.form.subscription.instruction", params));
        // Add the form fields and configure them for edition
        FormField formField = form.addField();
        formField.setVariable("FORM_TYPE");
        formField.setType(FormField.Type.hidden);
        formField.addValue("http://jabber.org/protocol/pubsub#subscribe_options");

        formField = form.addField();
        formField.setVariable("pubsub#deliver");
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.deliver"));
        formField.addValue(deliverNotifications);

        formField = form.addField();
        formField.setVariable("pubsub#digest");
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest"));
        formField.addValue(usingDigest);

        formField = form.addField();
        formField.setVariable("pubsub#digest_frequency");
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest_frequency"));
        formField.addValue(digestFrequency);

        formField = form.addField();
        formField.setVariable("pubsub#expire");
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.expire"));
        if (expire != null) {
            formField.addValue(fastDateFormat.format(expire));
        }

        formField = form.addField();
        formField.setVariable("pubsub#include_body");
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.include_body"));
        formField.addValue(includingBody);

        formField = form.addField();
        formField.setVariable("pubsub#show-values");
        formField.setType(FormField.Type.list_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.show-values"));
        formField.addOption(null, Presence.Show.away.name());
        formField.addOption(null, Presence.Show.chat.name());
        formField.addOption(null, Presence.Show.dnd.name());
        formField.addOption(null, "online");
        formField.addOption(null, Presence.Show.xa.name());
        for (String value : presenceStates) {
            formField.addValue(value);
        }

        if (node.isCollectionNode()) {
            formField = form.addField();
            formField.setVariable("pubsub#subscription_type");
            formField.setType(FormField.Type.list_single);
            formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_type"));
            formField.addOption(null, Type.items.name());
            formField.addOption(null, Type.nodes.name());
            formField.addValue(type);

            formField = form.addField();
            formField.setVariable("pubsub#subscription_depth");
            formField.setType(FormField.Type.list_single);
            formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_depth"));
            formField.addOption(null, "1");
            formField.addOption(null, "all");
            formField.addValue(depth == 1 ? "1" : "all");
        }

        if (!node.isCollectionNode() || type == Type.items) {
            formField = form.addField();
            formField.setVariable("x-pubsub#keywords");
            formField.setType(FormField.Type.text_single);
            formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.keywords"));
            if (keyword != null) {
                formField.addValue(keyword);
View Full Code Here

    public void initialize() {
        if (probeResult == null) {
            // Create the registration form of the room which contains information
            // such as: first name, last name and  nickname.
            final DataForm registrationForm = new DataForm(DataForm.Type.form);
            registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
            registrationForm.addInstruction(LocaleUtils
                    .getLocalizedString("muc.form.reg.instruction"));

            final FormField fieldForm = registrationForm.addField();
            fieldForm.setVariable("FORM_TYPE");
            fieldForm.setType(FormField.Type.hidden);
            fieldForm.addValue("http://jabber.org/protocol/muc#register");

            final FormField fieldReg = registrationForm.addField();
            fieldReg.setVariable("muc#register_first");
            fieldReg.setType(FormField.Type.text_single);
            fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
            fieldReg.setRequired(true);

            final FormField fieldLast = registrationForm.addField();
            fieldLast.setVariable("muc#register_last");
            fieldLast.setType(FormField.Type.text_single);
            fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
            fieldLast.setRequired(true);

            final FormField fieldNick = registrationForm.addField();
            fieldNick.setVariable("muc#register_roomnick");
            fieldNick.setType(FormField.Type.text_single);
            fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
            fieldNick.setRequired(true);

            final FormField fieldUrl = registrationForm.addField();
            fieldUrl.setVariable("muc#register_url");
            fieldUrl.setType(FormField.Type.text_single);
            fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));

            final FormField fieldMail = registrationForm.addField();
            fieldMail.setVariable("muc#register_email");
            fieldMail.setType(FormField.Type.text_single);
            fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));

            final FormField fieldFaq = registrationForm.addField();
            fieldFaq.setVariable("muc#register_faqentry");
            fieldFaq.setType(FormField.Type.text_single);
            fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));

            // Create the probeResult and add the registration form
            probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
            probeResult.add(registrationForm.getElement());
        }
    }
View Full Code Here

TOP

Related Classes of org.xmpp.forms.DataForm

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.