private DataForm createDefaultInitiationForm() {
   final DataForm form = new DataForm(Form.TYPE_FORM);
   final FormField field = new FormField(STREAM_DATA_FIELD_NAME);
   field.setType(FormField.TYPE_LIST_SINGLE);
   if (!IBB_ONLY) {
     field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE));
   }
   field.addOption(new FormField.Option(InBandBytestreamManager.NAMESPACE));
   form.addField(field);
   return form;
 }
Exemplo n.º 2
0
 /**
  * Returns a new ReportedData if the packet is used for gathering data and includes an extension
  * that matches the elementName and namespace "x","jabber:x:data".
  *
  * @param packet the packet used for gathering data.
  * @return the data form parsed from the packet or <tt>null</tt> if there was not a form in the
  *     packet.
  */
 public static Form getFormFrom(Packet packet) {
   // Check if the packet includes the DataForm extension
   final PacketExtension packetExtension = packet.getExtension("x", "jabber:x:data");
   if (packetExtension != null) {
     // Check if the existing DataForm is not a result of a search
     final DataForm dataForm = (DataForm) packetExtension;
     if (dataForm.getReportedData() == null) {
       return new Form(dataForm);
     }
   }
   // Otherwise return null
   return null;
 }
Exemplo n.º 3
0
 /**
  * Returns a DataForm that serves to send this Form to the server. If the form is of type submit,
  * it may contain fields with no value. These fields will be removed since they only exist to
  * assist the user while editing/completing the form in a UI.
  *
  * @return the wrapped DataForm.
  */
 public DataForm getDataFormToSend() {
   if (isSubmitType()) {
     // Create a new DataForm that contains only the answered fields
     final DataForm dataFormToSend = new DataForm(getType());
     for (final Iterator<FormField> it = getFields(); it.hasNext(); ) {
       final FormField field = it.next();
       if (field.getValues().hasNext()) {
         dataFormToSend.addField(field);
       }
     }
     return dataFormToSend;
   }
   return dataForm;
 }
 private FormField getStreamMethodField(DataForm form) {
   FormField field = null;
   for (final Iterator<FormField> it = form.getFields(); it.hasNext(); ) {
     field = it.next();
     if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) {
       break;
     }
     field = null;
   }
   return field;
 }
Exemplo n.º 5
0
 /**
  * Sets instructions that explain how to fill out the form and what the form is about.
  *
  * @param instructions instructions that explain how to fill out the form.
  */
 public void setInstructions(String instructions) {
   // Split the instructions into multiple instructions for each existent
   // newline
   final ArrayList<String> instructionsList = new ArrayList<String>();
   final StringTokenizer st = new StringTokenizer(instructions, "\n");
   while (st.hasMoreTokens()) {
     instructionsList.add(st.nextToken());
   }
   // Set the new list of instructions
   dataForm.setInstructions(instructionsList);
 }
Exemplo n.º 6
0
 /**
  * Returns the instructions that explain how to fill out the form and what the form is about.
  *
  * @return instructions that explain how to fill out the form.
  */
 public String getInstructions() {
   final StringBuilder sb = new StringBuilder();
   // Join the list of instructions together separated by newlines
   for (final Iterator<String> it = dataForm.getInstructions(); it.hasNext(); ) {
     sb.append(it.next());
     // If this is not the last instruction then append a newline
     if (it.hasNext()) {
       sb.append("\n");
     }
   }
   return sb.toString();
 }
  public void addFields(final DataForm serviceExtension) {
    for (PermissionType type : PermissionType.values()) {
      FormField field = new FormField(type.getSpecName());
      field.setLabel(type.getLabel());

      switch (type) {
        case readFile:
          field.setType(FormField.TYPE_LIST_MULTI);
          if (null != readPermissions) {
            addPermittedPaths(field, readPermissions);
          }
          break;
        case writeFile:
          field.setType(FormField.TYPE_LIST_MULTI);
          if (null != writePermissions) {
            addPermittedPaths(field, writePermissions);
          }
          break;
        case deleteFile:
          field.setType(FormField.TYPE_LIST_MULTI);
          if (null != deletePermissions) {
            addPermittedPaths(field, deletePermissions);
          }
          break;
        case executeProgram:
          field.setType(FormField.TYPE_LIST_MULTI);
          if (null != execPermissions) {
            addPermittedPaths(field, execPermissions);
          }
          break;
        case createFileLink:
          field.setType(FormField.TYPE_LIST_MULTI);
          if (null != linkPermissions) {
            addPermittedPaths(field, linkPermissions);
          }
          break;
        default:
          // Other types have no special formatting.
          field.setType(FormField.TYPE_BOOLEAN);
          field.addValue(permittedTypes.contains(type) ? "true" : "false");
      }

      serviceExtension.addField(field);
    }
  }
Exemplo n.º 8
0
 /**
  * Sets the description of the data. It is similar to the title on a web page or an X window. You
  * can put a <title/> on either a form to fill out, or a set of data results.
  *
  * @param title description of the data.
  */
 public void setTitle(String title) {
   dataForm.setTitle(title);
 }
Exemplo n.º 9
0
 /**
  * Returns true if the form is a form to submit.
  *
  * @return if the form is a form to submit.
  */
 private boolean isSubmitType() {
   return TYPE_SUBMIT.equals(dataForm.getType());
 }
Exemplo n.º 10
0
 /**
  * Returns true if the form is a form to fill out.
  *
  * @return if the form is a form to fill out.
  */
 private boolean isFormType() {
   return TYPE_FORM.equals(dataForm.getType());
 }
Exemplo n.º 11
0
 /**
  * Returns the meaning of the data within the context. The data could be part of a form to fill
  * out, a form submission or data results.
  *
  * <p>Possible form types are:
  *
  * <ul>
  *   <li>form -> Indicates a form to fill out.
  *   <li>submit -> The form is filled out, and this is the data that is being returned from the
  *       form.
  *   <li>cancel -> The form was cancelled. Tell the asker that piece of information.
  *   <li>result -> Data results being returned from a search, or some other query.
  * </ul>
  *
  * @return the form's type.
  */
 public String getType() {
   return dataForm.getType();
 }
Exemplo n.º 12
0
 /**
  * Returns the description of the data. It is similar to the title on a web page or an X window.
  * You can put a <title/> on either a form to fill out, or a set of data results.
  *
  * @return description of the data.
  */
 public String getTitle() {
   return dataForm.getTitle();
 }
Exemplo n.º 13
0
 /**
  * Returns an Iterator for the fields that are part of the form.
  *
  * @return an Iterator for the fields that are part of the form.
  */
 public Iterator<FormField> getFields() {
   return dataForm.getFields();
 }
Exemplo n.º 14
0
 /**
  * Adds a new field to complete as part of the form.
  *
  * @param field the field to complete.
  */
 public void addField(FormField field) {
   dataForm.addField(field);
 }
Exemplo n.º 15
0
  /**
   * Calculates the <tt>String</tt> for a specific <tt>DiscoverInfo</tt> which is to be hashed in
   * order to compute the ver string for that <tt>DiscoverInfo</tt>.
   *
   * @param discoverInfo the <tt>DiscoverInfo</tt> for which the <tt>String</tt> to be hashed in
   *     order to compute its ver string is to be calculated
   * @return the <tt>String</tt> for <tt>discoverInfo</tt> which is to be hashed in order to compute
   *     its ver string
   */
  private static String calculateEntityCapsString(DiscoverInfo discoverInfo) {
    StringBuilder bldr = new StringBuilder();

    // Add identities
    {
      Iterator<DiscoverInfo.Identity> identities = discoverInfo.getIdentities();
      SortedSet<DiscoverInfo.Identity> is =
          new TreeSet<DiscoverInfo.Identity>(
              new Comparator<DiscoverInfo.Identity>() {
                public int compare(DiscoverInfo.Identity i1, DiscoverInfo.Identity i2) {
                  int category = i1.getCategory().compareTo(i2.getCategory());

                  if (category != 0) return category;

                  int type = i1.getType().compareTo(i2.getType());

                  if (type != 0) return type;

                  /*
                   * TODO Sort by xml:lang.
                   *
                   * Since sort by xml:lang is currently missing,
                   * use the last supported sort criterion i.e.
                   * type.
                   */
                  return type;
                }
              });

      if (identities != null) while (identities.hasNext()) is.add(identities.next());

      for (DiscoverInfo.Identity i : is) {
        bldr.append(i.getCategory())
            .append('/')
            .append(i.getType())
            .append("//")
            .append(i.getName())
            .append('<');
      }
    }

    // Add features
    {
      Iterator<DiscoverInfo.Feature> features = getDiscoverInfoFeatures(discoverInfo);
      SortedSet<String> fs = new TreeSet<String>();

      if (features != null) while (features.hasNext()) fs.add(features.next().getVar());

      for (String f : fs) bldr.append(f).append('<');
    }

    DataForm extendedInfo = (DataForm) discoverInfo.getExtension("x", "jabber:x:data");

    if (extendedInfo != null) {
      synchronized (extendedInfo) {
        SortedSet<FormField> fs =
            new TreeSet<FormField>(
                new Comparator<FormField>() {
                  public int compare(FormField f1, FormField f2) {
                    return f1.getVariable().compareTo(f2.getVariable());
                  }
                });

        FormField formType = null;

        for (Iterator<FormField> fieldsIter = extendedInfo.getFields(); fieldsIter.hasNext(); ) {
          FormField f = fieldsIter.next();
          if (!f.getVariable().equals("FORM_TYPE")) fs.add(f);
          else formType = f;
        }

        // Add FORM_TYPE values
        if (formType != null) formFieldValuesToCaps(formType.getValues(), bldr);

        // Add the other values
        for (FormField f : fs) {
          bldr.append(f.getVariable()).append('<');
          formFieldValuesToCaps(f.getValues(), bldr);
        }
      }
    }

    return bldr.toString();
  }