예제 #1
0
 /**
  * Add a dropdown menu of lengths
  *
  * @param prompt the prompt explaining the menu
  * @param parent the parnet element to attach it to
  */
 private void addLengthSelector(String prompt, Element parent) {
   Element select = new Element(HTMLNames.SELECT);
   select.addAttribute(HTMLNames.NAME, Params.LENGTH);
   addOption(select, "100", length == 100);
   addOption(select, "150", length == 150);
   addOption(select, "200", length == 200);
   addOption(select, "250", length == 250);
   parent.addText(prompt);
   parent.addChild(select);
 }
예제 #2
0
 private void addCheckBox(
     Element form, boolean flag, String prompt, String paramName, String onclick) {
   Element check = new Element(HTMLNames.INPUT);
   check.addAttribute(HTMLNames.TYPE, HTMLNames.CHECKBOX);
   check.addAttribute(HTMLNames.NAME, paramName);
   if (flag) check.addAttribute(HTMLNames.CHECKED, null);
   if (onclick != null) check.addAttribute(HTMLNames.ONCLICK, onclick);
   Element span = new Element(HTMLNames.SPAN);
   span.addText(prompt);
   form.addChild(span);
   form.addChild(check);
 }
예제 #3
0
 /**
  * Add a dropdown menu of lengths
  *
  * @param prompt the prompt explaining the menu
  * @param parent the parent element to attach it to
  */
 private void addOffsetSelector(String prompt, Element parent) {
   Element select = new Element(HTMLNames.SELECT);
   select.addAttribute(HTMLNames.NAME, Params.OFFSET);
   addOption(select, "0", offset == 0);
   addOption(select, "100", offset == 100);
   addOption(select, "200", offset == 200);
   addOption(select, "300", offset == 300);
   addOption(select, "400", offset == 400);
   addOption(select, "500", offset == 500);
   addOption(select, "600", offset == 600);
   addOption(select, "700", offset == 700);
   parent.addText(prompt);
   parent.addChild(select);
 }
예제 #4
0
  /**
   * Add a dropdown menu containing all the nested versions and groups
   *
   * @param parent the parent element to attach it to
   * @throws Exception
   */
  void addVersionDropdown(Element parent) throws Exception {
    Element select = new Element(HTMLNames.SELECT);
    String versions = getVersions();
    String[] opts = versions.split(",");
    // remove trailing LF-
    HashSet<String> selected = new HashSet<String>();
    if (selectedVersions != null) {
      String[] shortNames = selectedVersions.split(",");
      for (int i = 0; i < shortNames.length; i++) selected.add(shortNames[i]);
    }
    opts[opts.length - 1] = opts[opts.length - 1].trim();
    for (int i = 0; i < opts.length; i++) {
      String[] cols = opts[i].split("/");
      if (cols.length > 0 && cols[0].length() == 0) cols = popArray(cols);
      if (cols.length > 1) {
        HTMLOptGroup group = getGroup(select, cols[0]);
        if (selected.contains(opts[i])) cols[cols.length - 1] += " ×";
        if (group == null) {
          group = new HTMLOptGroup(cols[0]);
          select.addChild(group);
        }
        group.add(opts[i], popArray(cols));

      } else if (cols.length == 1) {
        Element option = new Element(HTMLNames.OPTION);
        select.addChild(option);
        String content = cols[cols.length - 1];
        if (selected.contains(opts[i])) content += " \327";
        option.addText(content);
        option.addAttribute(HTMLNames.VALUE, opts[i]);
      }
    }
    parent.addChild(select);
    if (!someVersions) select.addAttribute(HTMLNames.DISABLED, null);
    select.addAttribute(HTMLNames.ONCHANGE, "checkmark(this)");
    select.addAttribute(HTMLNames.ID, "selector");
    Element hidden = new Element(HTMLNames.INPUT);
    hidden.addAttribute(HTMLNames.TYPE, HTMLNames.HIDDEN);
    hidden.addAttribute(HTMLNames.ID, "versions");
    hidden.addAttribute(HTMLNames.NAME, Params.SELECTED_VERSIONS);
    parent.addChild(hidden);
  }
예제 #5
0
  @Override
  // Implementation methods
  // -------------------------------------------------------------------------
  protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
    DocumentFactory df = getDocumentFactory();
    Document document = df.createDocument();
    Element parent = null;
    XmlPullParser pp = getXPPParser();
    pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

    while (true) {
      int type = pp.nextToken();

      switch (type) {
        case XmlPullParser.PROCESSING_INSTRUCTION:
          {
            String text = pp.getText();
            int loc = text.indexOf(' ');

            if (loc >= 0) {
              String target = text.substring(0, loc);
              String txt = text.substring(loc + 1);
              document.addProcessingInstruction(target, txt);
            } else {
              document.addProcessingInstruction(text, "");
            }

            break;
          }

        case XmlPullParser.COMMENT:
          {
            if (parent != null) {
              parent.addComment(pp.getText());
            } else {
              document.addComment(pp.getText());
            }

            break;
          }

        case XmlPullParser.CDSECT:
          {
            if (parent != null) {
              parent.addCDATA(pp.getText());
            } else {
              String msg = "Cannot have text content outside of the " + "root document";
              throw new DocumentException(msg);
            }

            break;
          }

        case XmlPullParser.END_DOCUMENT:
          return document;

        case XmlPullParser.START_TAG:
          {
            QName qname =
                (pp.getPrefix() == null)
                    ? df.createQName(pp.getName(), pp.getNamespace())
                    : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace());
            Element newElement = df.createElement(qname);
            int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
            int nsEnd = pp.getNamespaceCount(pp.getDepth());

            for (int i = nsStart; i < nsEnd; i++) {
              if (pp.getNamespacePrefix(i) != null) {
                newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i));
              }
            }

            for (int i = 0; i < pp.getAttributeCount(); i++) {
              QName qa =
                  (pp.getAttributePrefix(i) == null)
                      ? df.createQName(pp.getAttributeName(i))
                      : df.createQName(
                          pp.getAttributeName(i),
                          pp.getAttributePrefix(i),
                          pp.getAttributeNamespace(i));
              newElement.addAttribute(qa, pp.getAttributeValue(i));
            }

            if (parent != null) {
              parent.add(newElement);
            } else {
              document.add(newElement);
            }

            parent = newElement;

            break;
          }

        case XmlPullParser.END_TAG:
          {
            if (parent != null) {
              parent = parent.getParent();
            }

            break;
          }

        case XmlPullParser.ENTITY_REF:
        case XmlPullParser.TEXT:
          {
            String text = pp.getText();

            if (parent != null) {
              parent.addText(text);
            } else {
              String msg = "Cannot have text content outside of the " + "root document";
              throw new DocumentException(msg);
            }

            break;
          }

        default:
          break;
      }
    }
  }
예제 #6
0
 /**
  * Add the specified option to the selector
  *
  * @param select the selector element
  * @param value the new value
  */
 private void addOption(Element select, String value, boolean selectit) {
   Element option = new Element(HTMLNames.OPTION);
   option.addText(value);
   if (selectit) option.addAttribute(HTMLNames.SELECTED, HTMLNames.SELECTED);
   select.addChild(option);
 }