@Test(expected = DDMFormValuesValidationException.RequiredValue.class)
  public void testUpdateWithInvalidDDMFormValues() throws Exception {
    DDMStructure structure = addStructure(_CLASS_NAME_ID, "Default Structure");

    DDMForm ddmForm = DDMFormTestUtil.createDDMForm();

    DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("text", false, false, true);

    ddmForm.addDDMFormField(ddmFormField);

    DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm);

    DDMFormFieldValue ddmFormFieldValue =
        DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("text", "text value");

    ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue);

    long classPK =
        _jsonStorageAdapter.create(
            TestPropsValues.getCompanyId(),
            structure.getStructureId(),
            ddmFormValues,
            ServiceContextTestUtil.getServiceContext(group.getGroupId()));

    ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm);

    _jsonStorageAdapter.update(
        classPK, ddmFormValues, ServiceContextTestUtil.getServiceContext(group.getGroupId()));
  }
  @Test
  public void testCreateWithValidDDMFieldValue() throws Exception {
    DDMStructure structure = addStructure(_CLASS_NAME_ID, "Default Structure");

    DDMForm ddmForm = DDMFormTestUtil.createDDMForm();

    DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("text", false, false, false);

    DDMFormFieldValidation ddmFormFieldValidation = new DDMFormFieldValidation();

    ddmFormFieldValidation.setExpression("!text.isEmpty()");
    ddmFormFieldValidation.setErrorMessage("custom validation error message");

    ddmFormField.setDDMFormFieldValidation(ddmFormFieldValidation);

    ddmForm.addDDMFormField(ddmFormField);

    DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm);

    DDMFormFieldValue ddmFormFieldValue =
        DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("text", "not empty");

    ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue);

    _jsonStorageAdapter.create(
        TestPropsValues.getCompanyId(),
        structure.getStructureId(),
        ddmFormValues,
        ServiceContextTestUtil.getServiceContext(group.getGroupId()));
  }
  @Test
  public void testGetWithSelectField() {
    ExtendedObjectClassDefinition extendedObjectClassDefinition =
        mock(ExtendedObjectClassDefinition.class);

    ExtendedAttributeDefinition extendedAttributeDefinition =
        mock(ExtendedAttributeDefinition.class);

    whenGetAttributeDefinitions(
        extendedObjectClassDefinition,
        new ExtendedAttributeDefinition[] {extendedAttributeDefinition},
        ExtendedObjectClassDefinition.REQUIRED);

    whenGetCardinality(extendedAttributeDefinition, 0);
    whenGetID(extendedAttributeDefinition, "Select");
    whenGetType(extendedAttributeDefinition, ExtendedAttributeDefinition.STRING);
    whenGetOptionLabels(extendedAttributeDefinition, new String[] {"Label 1", "Label 2"});
    whenGetOptionValues(extendedAttributeDefinition, new String[] {"Value 1", "Value 2"});

    ConfigurationModel configurationModel =
        new ConfigurationModel(extendedObjectClassDefinition, null, null, null, false);

    ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter =
        new ConfigurationModelToDDMFormConverter(
            configurationModel, _enLocale, new EmptyResourceBundle());

    DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm();

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false);

    DDMFormField ddmFormField = ddmFormFieldsMap.get("Select");

    Assert.assertNotNull(ddmFormField);
    Assert.assertEquals(DDMFormFieldType.SELECT, ddmFormField.getType());
    Assert.assertEquals("string", ddmFormField.getDataType());
    Assert.assertFalse(ddmFormField.isRepeatable());
    Assert.assertTrue(ddmFormField.isRequired());

    DDMFormFieldOptions ddmFormFieldOptions = ddmFormField.getDDMFormFieldOptions();

    Assert.assertEquals(_enLocale, ddmFormFieldOptions.getDefaultLocale());

    Set<String> optionValues = ddmFormFieldOptions.getOptionsValues();

    Assert.assertTrue(optionValues.contains("Value 1"));
    Assert.assertTrue(optionValues.contains("Value 2"));

    LocalizedValue value1Labels = ddmFormFieldOptions.getOptionLabels("Value 1");

    Assert.assertEquals(_enLocale, value1Labels.getDefaultLocale());
    Assert.assertEquals("Label 1", value1Labels.getString(_enLocale));

    LocalizedValue value2Labels = ddmFormFieldOptions.getOptionLabels("Value 2");

    Assert.assertEquals(_enLocale, value2Labels.getDefaultLocale());
    Assert.assertEquals("Label 2", value2Labels.getString(_enLocale));
  }
  protected DDMForm createDDMForm() {
    DDMForm ddmForm = new DDMForm();

    ddmForm.setAvailableLocales(
        DDMFormTestUtil.createAvailableLocales(LocaleUtil.BRAZIL, LocaleUtil.US));
    ddmForm.setDDMFormFields(createDDMFormFields());
    ddmForm.setDefaultLocale(LocaleUtil.US);

    return ddmForm;
  }
  protected void validateDDMFormLocales(DDMForm ddmForm) throws DDMFormValidationException {

    Locale defaultLocale = ddmForm.getDefaultLocale();

    if (defaultLocale == null) {
      throw new MustSetDefaultLocale();
    }

    validateDDMFormAvailableLocales(ddmForm.getAvailableLocales(), defaultLocale);
  }
Ejemplo n.º 6
0
  public static int addResource(WebDAVRequest webDavRequest, long classNameId) throws Exception {

    String[] pathArray = webDavRequest.getPathArray();

    if (pathArray.length != 4) {
      return HttpServletResponse.SC_FORBIDDEN;
    }

    String type = pathArray[2];
    String typeId = pathArray[3];

    if (type.equals(TYPE_STRUCTURES)) {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      String definition = StringUtil.read(request.getInputStream());

      DDMForm ddmForm = getDDMForm(definition);

      DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

      Map<Locale, String> nameMap = new HashMap<>();

      Locale defaultLocale = ddmForm.getDefaultLocale();

      nameMap.put(defaultLocale, typeId);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      DDMStructureLocalServiceUtil.addStructure(
          webDavRequest.getUserId(),
          webDavRequest.getGroupId(),
          classNameId,
          nameMap,
          null,
          ddmForm,
          ddmFormLayout,
          StorageType.JSON.toString(),
          serviceContext);

      return HttpServletResponse.SC_CREATED;
    } else if (type.equals(TYPE_TEMPLATES)) {

      // DDM templates can not be added via WebDAV because there is no way
      // to know the associated class name or class PK

      return HttpServletResponse.SC_FORBIDDEN;
    }

    return HttpServletResponse.SC_FORBIDDEN;
  }
  public DDMFormValuesToPropertiesConverter(
      ConfigurationModel configurationModel,
      DDMFormValues ddmFormValues,
      JSONFactory jsonFactory,
      Locale locale) {

    DDMForm ddmForm = ddmFormValues.getDDMForm();

    _configurationModel = configurationModel;
    _ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false);
    _ddmFormFieldValuesMap = ddmFormValues.getDDMFormFieldValuesMap();
    _jsonFactory = jsonFactory;
    _locale = locale;
  }
  protected DDMForm getDDMForm(DDMStructure ddmStructure, boolean requireCaptcha) {

    DDMForm ddmForm = ddmStructure.getDDMForm();

    if (requireCaptcha) {
      DDMFormField captchaDDMFormField = new DDMFormField(_DDM_FORM_FIELD_NAME_CAPTCHA, "captcha");

      captchaDDMFormField.setDataType("string");
      captchaDDMFormField.setProperty("url", createCaptchaResourceURL());

      ddmForm.addDDMFormField(captchaDDMFormField);
    }

    return ddmForm;
  }
  @Override
  public void validate(DDMForm ddmForm) throws DDMFormValidationException {
    validateDDMFormLocales(ddmForm);

    List<DDMFormField> ddmFormFields = ddmForm.getDDMFormFields();

    if (ddmFormFields.isEmpty()) {
      throw new MustSetFieldsForForm();
    }

    validateDDMFormFields(
        ddmFormFields,
        new HashSet<String>(),
        ddmForm.getAvailableLocales(),
        ddmForm.getDefaultLocale());
  }
  @Test
  public void testCreateWithInvalidDDMFieldValue() throws Exception {
    DDMStructure structure = addStructure(_CLASS_NAME_ID, "Default Structure");

    DDMForm ddmForm = DDMFormTestUtil.createDDMForm();

    DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("text", false, false, false);

    DDMFormFieldValidation ddmFormFieldValidation = new DDMFormFieldValidation();

    ddmFormFieldValidation.setExpression("text.contains(\"test\")");
    ddmFormFieldValidation.setErrorMessage("custom validation error message");

    ddmFormField.setDDMFormFieldValidation(ddmFormFieldValidation);

    ddmForm.addDDMFormField(ddmFormField);

    DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm);

    DDMFormFieldValue ddmFormFieldValue =
        DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("text", "text value");

    ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue);

    try {
      _jsonStorageAdapter.create(
          TestPropsValues.getCompanyId(),
          structure.getStructureId(),
          ddmFormValues,
          ServiceContextTestUtil.getServiceContext(group.getGroupId()));

      Assert.fail();
    } catch (DDMFormValuesValidationException.MustSetValidValues msvv) {
      List<DDMFormFieldEvaluationResult> ddmFormFieldEvaluationResults =
          msvv.getDDMFormFieldEvaluationResults();

      Assert.assertEquals(1, ddmFormFieldEvaluationResults.size());

      DDMFormFieldEvaluationResult ddmFormFieldEvaluationResult =
          ddmFormFieldEvaluationResults.get(0);

      Assert.assertEquals("text", ddmFormFieldEvaluationResult.getName());
      Assert.assertEquals(
          "custom validation error message", ddmFormFieldEvaluationResult.getErrorMessage());
    }
  }
  protected List<DDMFormFieldValue> getDDMFormFieldValues(
      HttpServletRequest httpServletRequest, DDMForm ddmForm) {

    Map<String, DDMFormFieldValue> ddmFormFieldValuesMap =
        createDDMFormFieldValuesMap(httpServletRequest, ddmForm);

    return getDDMFormFieldValues(ddmFormFieldValuesMap, ddmForm.getDDMFormFields());
  }
Ejemplo n.º 12
0
  protected JSONArray getDDMFormFieldsJSONArray(DDMForm ddmForm, String script) {

    if (Validator.isNull(script)) {
      return null;
    }

    JSONArray defaultDDMFormFieldsJSONArray = null;

    if (ddmForm != null) {
      defaultDDMFormFieldsJSONArray =
          getDDMFormFieldsJSONArray(
              ddmForm.getDDMFormFields(),
              ddmForm.getAvailableLocales(),
              ddmForm.getDefaultLocale());
    }

    try {
      DDMForm scriptDDMForm = DDMFormJSONDeserializerUtil.deserialize(script);

      return getDDMFormFieldsJSONArray(
          scriptDDMForm.getDDMFormFields(),
          scriptDDMForm.getAvailableLocales(),
          scriptDDMForm.getDefaultLocale());
    } catch (PortalException pe) {
      if (_log.isWarnEnabled()) {
        _log.warn("Unable to deserialize script", pe);
      }

      return defaultDDMFormFieldsJSONArray;
    }
  }
  protected Set<String> createDefaultDDMFormFieldParameterNames(DDMForm ddmForm) {

    Set<String> defaultDDMFormFieldParameterNames = new TreeSet<>();

    poupulateDefaultDDMFormFieldParameterNames(
        ddmForm.getDDMFormFields(), StringPool.BLANK, defaultDDMFormFieldParameterNames);

    return defaultDDMFormFieldParameterNames;
  }
  @Test
  public void testGetWithIntegerField() {
    ExtendedObjectClassDefinition extendedObjectClassDefinition =
        mock(ExtendedObjectClassDefinition.class);

    ExtendedAttributeDefinition extendedAttributeDefinition =
        mock(ExtendedAttributeDefinition.class);

    whenGetAttributeDefinitions(
        extendedObjectClassDefinition,
        new ExtendedAttributeDefinition[] {extendedAttributeDefinition},
        ExtendedObjectClassDefinition.REQUIRED);

    whenGetCardinality(extendedAttributeDefinition, 0);
    whenGetID(extendedAttributeDefinition, "Integer");
    whenGetType(extendedAttributeDefinition, ExtendedAttributeDefinition.INTEGER);

    ConfigurationModel configurationModel =
        new ConfigurationModel(extendedObjectClassDefinition, null, null, null, false);

    ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter =
        new ConfigurationModelToDDMFormConverter(
            configurationModel, _enLocale, new EmptyResourceBundle());

    DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm();

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false);

    DDMFormField ddmFormField = ddmFormFieldsMap.get("Integer");

    Assert.assertNotNull(ddmFormField);
    Assert.assertEquals(DDMFormFieldType.TEXT, ddmFormField.getType());
    Assert.assertEquals("integer", ddmFormField.getDataType());
    Assert.assertFalse(ddmFormField.isRepeatable());
    Assert.assertTrue(ddmFormField.isRequired());

    LocalizedValue predefinedValue = ddmFormField.getPredefinedValue();

    Assert.assertEquals(_enLocale, predefinedValue.getDefaultLocale());
    Assert.assertEquals("0", predefinedValue.getString(_enLocale));
  }
  protected void checkDDMFormFieldParameterNames(
      DDMForm ddmForm, Set<String> ddmFormFieldParameterNames) {

    if (ddmFormFieldParameterNames.isEmpty()) {
      ddmFormFieldParameterNames.addAll(createDefaultDDMFormFieldParameterNames(ddmForm));

      return;
    }

    checkDDMFormFieldParameterNames(
        ddmForm.getDDMFormFields(), StringPool.BLANK, ddmFormFieldParameterNames);
  }
  @Test
  public void testGetWithCheckboxField() {
    ExtendedObjectClassDefinition extendedObjectClassDefinition =
        mock(ExtendedObjectClassDefinition.class);

    ExtendedAttributeDefinition extendedAttributeDefinition =
        mock(ExtendedAttributeDefinition.class);

    whenGetAttributeDefinitions(
        extendedObjectClassDefinition,
        new ExtendedAttributeDefinition[] {extendedAttributeDefinition},
        ExtendedObjectClassDefinition.REQUIRED);

    whenGetCardinality(extendedAttributeDefinition, 0);
    whenGetID(extendedAttributeDefinition, "Boolean");
    whenGetType(extendedAttributeDefinition, ExtendedAttributeDefinition.BOOLEAN);

    ConfigurationModel configurationModel =
        new ConfigurationModel(extendedObjectClassDefinition, null, null, null, false);

    ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter =
        new ConfigurationModelToDDMFormConverter(
            configurationModel, _enLocale, new EmptyResourceBundle());

    DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm();

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false);

    DDMFormField ddmFormField = ddmFormFieldsMap.get("Boolean");

    Assert.assertNotNull(ddmFormField);
    Assert.assertEquals(DDMFormFieldType.CHECKBOX, ddmFormField.getType());
    Assert.assertEquals("boolean", ddmFormField.getDataType());
    Assert.assertFalse(ddmFormField.isRepeatable());
    Assert.assertFalse(ddmFormField.isRequired());

    Value predefinedValue = ddmFormField.getPredefinedValue();

    Assert.assertEquals("false", predefinedValue.getString(_enLocale));
  }
Ejemplo n.º 17
0
  @Test
  public void testCreateCheckboxDDMFormFieldTypeSettingsDDMForm() {
    DDMForm ddmForm = DDMFormFactory.create(CheckboxDDMFormFieldTypeSettings.class);

    List<DDMFormRule> ddmFormRules = ddmForm.getDDMFormRules();

    Assert.assertEquals(1, ddmFormRules.size());

    DDMFormRule ddmFormRule = ddmFormRules.get(0);

    Assert.assertEquals("TRUE", ddmFormRule.getCondition());

    List<String> ddmFormRuleActions = ddmFormRule.getActions();

    Assert.assertArrayEquals(
        new String[] {
          "set(fieldAt(\"repeatable\", 0), \"visible\", false)",
          "set(fieldAt(\"validation\", 0), \"visible\", false)"
        },
        ddmFormRuleActions.toArray());

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false);

    DDMFormField predefinedValueDDMFormField = ddmFormFieldsMap.get("predefinedValue");

    Assert.assertNotNull(predefinedValueDDMFormField);
    Assert.assertEquals("boolean", predefinedValueDDMFormField.getDataType());
    Assert.assertEquals("checkbox", predefinedValueDDMFormField.getType());
    Assert.assertEquals(true, predefinedValueDDMFormField.isLocalizable());
    Assert.assertEquals("true", predefinedValueDDMFormField.getProperty("showAsSwitcher"));

    DDMFormField showAsSwitcherDDMFormField = ddmFormFieldsMap.get("showAsSwitcher");

    Assert.assertNotNull(showAsSwitcherDDMFormField);
    Assert.assertEquals("checkbox", showAsSwitcherDDMFormField.getType());
    Assert.assertEquals("boolean", showAsSwitcherDDMFormField.getDataType());
    Assert.assertEquals("true", showAsSwitcherDDMFormField.getProperty("showAsSwitcher"));
  }
Ejemplo n.º 18
0
  @Override
  public DDMFormLayout getDefaultDDMFormLayout(DDMForm ddmForm) {
    DDMFormLayout ddmFormLayout = new DDMFormLayout();

    Locale defaultLocale = ddmForm.getDefaultLocale();

    ddmFormLayout.setDefaultLocale(defaultLocale);
    ddmFormLayout.setPaginationMode(DDMFormLayout.SINGLE_PAGE_MODE);

    DDMFormLayoutPage ddmFormLayoutPage = new DDMFormLayoutPage();

    LocalizedValue title = getDefaultDDMFormPageTitle(defaultLocale);

    ddmFormLayoutPage.setTitle(title);

    for (DDMFormField ddmFormField : ddmForm.getDDMFormFields()) {
      ddmFormLayoutPage.addDDMFormLayoutRow(getDefaultDDMFormLayoutRow(ddmFormField));
    }

    ddmFormLayout.addDDMFormLayoutPage(ddmFormLayoutPage);

    return ddmFormLayout;
  }
  @Test
  public void testGetWithTextField() {
    ExtendedObjectClassDefinition extendedObjectClassDefinition =
        mock(ExtendedObjectClassDefinition.class);

    ExtendedAttributeDefinition extendedAttributeDefinition =
        mock(ExtendedAttributeDefinition.class);

    whenGetAttributeDefinitions(
        extendedObjectClassDefinition,
        new ExtendedAttributeDefinition[] {extendedAttributeDefinition},
        ExtendedObjectClassDefinition.OPTIONAL);

    whenGetCardinality(extendedAttributeDefinition, 0);
    whenGetID(extendedAttributeDefinition, "Text");
    whenGetType(extendedAttributeDefinition, ExtendedAttributeDefinition.STRING);

    ConfigurationModel configurationModel =
        new ConfigurationModel(extendedObjectClassDefinition, null, null, null, false);

    ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter =
        new ConfigurationModelToDDMFormConverter(
            configurationModel, _enLocale, new EmptyResourceBundle());

    DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm();

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false);

    DDMFormField ddmFormField = ddmFormFieldsMap.get("Text");

    Assert.assertNotNull(ddmFormField);
    Assert.assertEquals(DDMFormFieldType.TEXT, ddmFormField.getType());
    Assert.assertEquals("string", ddmFormField.getDataType());
    Assert.assertFalse(ddmFormField.isRepeatable());
    Assert.assertFalse(ddmFormField.isRequired());
  }
  protected Map<String, DDMFormFieldValue> createDDMFormFieldValuesMap(
      HttpServletRequest httpServletRequest, DDMForm ddmForm) {

    Map<String, DDMFormFieldValue> ddmFormFieldValuesMap = new HashMap<>();

    Set<String> ddmFormFieldParameterNames =
        getDDMFormFieldParameterNames(httpServletRequest, ddmForm);

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(true);

    for (String ddmFormFieldParameterName : ddmFormFieldParameterNames) {
      DDMFormFieldValue ddmFormFieldValue =
          createDDMFormFieldValue(httpServletRequest, ddmFormFieldParameterName, ddmFormFieldsMap);

      ddmFormFieldValuesMap.put(ddmFormFieldParameterName, ddmFormFieldValue);
    }

    return ddmFormFieldValuesMap;
  }
Ejemplo n.º 21
0
  protected List<TemplateNode> getTemplateNodes(
      ThemeDisplay themeDisplay, Element element, long ddmStructureId) throws Exception {

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(ddmStructureId);

    DDMForm ddmForm = ddmStructure.getDDMForm();

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(true);

    List<TemplateNode> templateNodes = new ArrayList<>();

    Map<String, TemplateNode> prototypeTemplateNodes = new HashMap<>();

    List<Element> dynamicElementElements = element.elements("dynamic-element");

    for (Element dynamicElementElement : dynamicElementElements) {
      Element dynamicContentElement = dynamicElementElement.element("dynamic-content");

      String data = StringPool.BLANK;

      if (dynamicContentElement != null) {
        data = dynamicContentElement.getText();
      }

      String name = dynamicElementElement.attributeValue("name", StringPool.BLANK);

      if (name.length() == 0) {
        throw new TransformException("Element missing \"name\" attribute");
      }

      String type = dynamicElementElement.attributeValue("type", StringPool.BLANK);

      Map<String, String> attributes = new HashMap<>();

      if (dynamicContentElement != null) {
        for (Attribute attribute : dynamicContentElement.attributes()) {
          attributes.put(attribute.getName(), attribute.getValue());
        }
      }

      TemplateNode templateNode =
          new TemplateNode(themeDisplay, name, StringUtil.stripCDATA(data), type, attributes);

      if (dynamicElementElement.element("dynamic-element") != null) {
        templateNode.appendChildren(
            getTemplateNodes(themeDisplay, dynamicElementElement, ddmStructureId));
      } else if ((dynamicContentElement != null)
          && (dynamicContentElement.element("option") != null)) {

        List<Element> optionElements = dynamicContentElement.elements("option");

        for (Element optionElement : optionElements) {
          templateNode.appendOption(StringUtil.stripCDATA(optionElement.getText()));
        }
      }

      DDMFormField ddmFormField = ddmFormFieldsMap.get(name);

      if (ddmFormField != null) {
        DDMFormFieldOptions ddmFormFieldOptions = ddmFormField.getDDMFormFieldOptions();

        Map<String, LocalizedValue> options = ddmFormFieldOptions.getOptions();

        for (Entry<String, LocalizedValue> entry : options.entrySet()) {
          String optionValue = StringUtil.stripCDATA(entry.getKey());

          LocalizedValue localizedLabel = entry.getValue();

          String optionLabel = localizedLabel.getString(themeDisplay.getLocale());

          templateNode.appendOptionMap(optionValue, optionLabel);
        }
      }

      TemplateNode prototypeTemplateNode = prototypeTemplateNodes.get(name);

      if (prototypeTemplateNode == null) {
        prototypeTemplateNode = templateNode;

        prototypeTemplateNodes.put(name, prototypeTemplateNode);

        templateNodes.add(templateNode);
      }

      prototypeTemplateNode.appendSibling(templateNode);
    }

    return templateNodes;
  }