Esempio n. 1
0
  private void recursivelyAddGroup(
      Map<String, FormElement> formElementMap,
      NodeList nodeList,
      String uri,
      List<FormElement> group,
      FormElement parent) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node element = nodeList.item(i);

      if (element.hasChildNodes()) {

        if (element.hasAttributes()) {
          String localUri = uri + SLASH + element.getNodeName();
          FormElement formElement =
              new FormElementBuilder()
                  .setName(localUri)
                  .setLabel(localUri)
                  .setChildren(new ArrayList<FormElement>())
                  .setType(FieldTypeConstants.REPEAT_GROUP)
                  .setPartOfRepeatGroup(parent.isRepeatGroup() || parent.isPartOfRepeatGroup())
                  .createFormElement();
          formElementMap.put(formElement.getName(), formElement);
          group.add(formElement);
          recursivelyAddGroup(
              formElementMap,
              element.getChildNodes(),
              uri + SLASH + element.getNodeName(),
              formElement.getChildren(),
              formElement);

        } else {
          recursivelyAddFormElements(
              formElementMap, element.getChildNodes(), uri + SLASH + element.getNodeName());
        }

      } else if (element.getNodeType() == Node.ELEMENT_NODE) {
        String localUri = uri + SLASH + element.getNodeName();
        FormElement formElement =
            new FormElementBuilder()
                .setName(localUri)
                .setLabel(localUri)
                .setPartOfRepeatGroup(parent.isRepeatGroup() || parent.isPartOfRepeatGroup())
                .createFormElement();
        group.add(formElement);
        formElementMap.put(formElement.getName(), formElement);
      }
    }
  }
Esempio n. 2
0
 private List<FormElement> createFormElementListFromMap(Map<String, FormElement> formElementMap) {
   List<FormElement> formElements = new ArrayList<>();
   for (FormElement formElement : formElementMap.values()) {
     if (formElement.getType().equals(FieldTypeConstants.REPEAT_GROUP)
         || !formElement.isPartOfRepeatGroup()) {
       formElements.add(formElement);
     }
   }
   return formElements;
 }