コード例 #1
0
ファイル: DDMImpl.java プロジェクト: hme891/liferay-portal
  protected LocalizedValue getDefaultDDMFormPageTitle(Locale defaultLocale) {
    LocalizedValue title = new LocalizedValue(defaultLocale);

    title.addString(defaultLocale, StringPool.BLANK);

    return title;
  }
コード例 #2
0
ファイル: DDMImpl.java プロジェクト: hme891/liferay-portal
  protected void addDDMFormFieldLocalizedProperty(
      JSONObject jsonObject,
      String propertyName,
      LocalizedValue localizedValue,
      Locale locale,
      Locale defaultLocale,
      String type) {

    String propertyValue = localizedValue.getString(locale);

    if (Validator.isNull(propertyValue)) {
      propertyValue = localizedValue.getString(defaultLocale);
    }

    if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      if (propertyName.equals("predefinedValue")) {
        try {
          jsonObject.put(propertyName, JSONFactoryUtil.createJSONArray(propertyValue));
        } catch (Exception e) {
        }

        return;
      }
    }

    jsonObject.put(propertyName, propertyValue);
  }
コード例 #3
0
  protected LocalizedValue createHTMLDDMFormFieldPredefinedValue() {
    LocalizedValue predefinedValue = new LocalizedValue();

    predefinedValue.addString(LocaleUtil.BRAZIL, "");
    predefinedValue.addString(LocaleUtil.US, "");

    return predefinedValue;
  }
コード例 #4
0
  protected LocalizedValue createHTMLDDMFormFieldLabel() {
    LocalizedValue label = new LocalizedValue();

    label.addString(LocaleUtil.BRAZIL, "HTML");
    label.addString(LocaleUtil.US, "HTML");

    return label;
  }
コード例 #5
0
  protected LocalizedValue createTextDDMFormFieldPredefinedValue() {
    LocalizedValue predefinedValue = new LocalizedValue();

    predefinedValue.addString(LocaleUtil.BRAZIL, "Exemplo");
    predefinedValue.addString(LocaleUtil.US, "Example");

    return predefinedValue;
  }
  @Override
  public String get(DDMFormFieldValue ddmFormFieldValue) {
    String optionValue = _ddmFormFieldValueAccessor.get(ddmFormFieldValue);

    DDMFormFieldOptions ddmFormFieldOptions = getDDMFormFieldOptions(ddmFormFieldValue);

    LocalizedValue optionLabel = ddmFormFieldOptions.getOptionLabels(optionValue);

    return optionLabel.getString(_ddmFormFieldValueAccessor.getLocale());
  }
コード例 #7
0
  protected void setDDMFormFieldValueLocalizedValue(
      HttpServletRequest httpServletRequest,
      String fieldType,
      String ddmFormFieldParameterName,
      LocalizedValue predefinedValue,
      DDMFormFieldValue ddmFormFieldValue) {

    Locale defaultLocale = getDefaultLocale(httpServletRequest);

    Value value = new LocalizedValue(defaultLocale);

    Set<Locale> availableLocales = getAvailableLocales(httpServletRequest);

    for (Locale availableLocale : availableLocales) {
      String ddmFormFieldParameterValue =
          getDDMFormFieldParameterValue(
              httpServletRequest,
              fieldType,
              ddmFormFieldParameterName,
              predefinedValue.getString(availableLocale),
              availableLocale);

      value.addString(availableLocale, ddmFormFieldParameterValue);
    }

    ddmFormFieldValue.setValue(value);
  }
コード例 #8
0
  protected void validateDDMFormFieldPropertyValue(
      String fieldName,
      String propertyName,
      LocalizedValue propertyValue,
      Set<Locale> ddmFormAvailableLocales,
      Locale ddmFormDefaultLocale)
      throws DDMFormValidationException {

    if (!ddmFormDefaultLocale.equals(propertyValue.getDefaultLocale())) {
      throw new MustSetValidDefaultLocaleForProperty(fieldName, propertyName);
    }

    if (!ddmFormAvailableLocales.equals(propertyValue.getAvailableLocales())) {

      throw new MustSetValidAvailableLocalesForProperty(fieldName, propertyName);
    }
  }
  @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));
  }
コード例 #10
0
  protected void validateOptionalDDMFormFieldLocalizedProperty(
      DDMFormField ddmFormField,
      String propertyName,
      Set<Locale> ddmFormAvailableLocales,
      Locale ddmFormDefaultLocale)
      throws DDMFormValidationException {

    LocalizedValue propertyValue =
        (LocalizedValue) BeanPropertiesUtil.getObject(ddmFormField, propertyName);

    if (MapUtil.isEmpty(propertyValue.getValues())) {
      return;
    }

    validateDDMFormFieldPropertyValue(
        ddmFormField.getName(),
        propertyName,
        propertyValue,
        ddmFormAvailableLocales,
        ddmFormDefaultLocale);
  }
  @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));
  }
コード例 #12
0
  protected void setDDMFormFieldValueUnlocalizedValue(
      HttpServletRequest httpServletRequest,
      String fieldType,
      String ddmFormFieldParameterName,
      LocalizedValue predefinedValue,
      DDMFormFieldValue ddmFormFieldValue) {

    Locale defaultLocale = getDefaultLocale(httpServletRequest);

    String ddmFormFieldParameterValue =
        getDDMFormFieldParameterValue(
            httpServletRequest,
            fieldType,
            ddmFormFieldParameterName,
            predefinedValue.getString(defaultLocale),
            defaultLocale);

    Value value = new UnlocalizedValue(ddmFormFieldParameterValue);

    ddmFormFieldValue.setValue(value);
  }
コード例 #13
0
ファイル: DDMImpl.java プロジェクト: hme891/liferay-portal
  protected List<Serializable> getFieldValues(
      DDMStructure ddmStructure,
      String fieldName,
      String fieldNamespace,
      ServiceContext serviceContext)
      throws PortalException {

    DDMFormField ddmFormField = ddmStructure.getDDMFormField(fieldName);

    String fieldDataType = ddmFormField.getDataType();
    String fieldType = ddmFormField.getType();

    LocalizedValue predefinedValue = ddmFormField.getPredefinedValue();

    List<String> fieldNames = getFieldNames(fieldNamespace, fieldName, serviceContext);

    List<Serializable> fieldValues = new ArrayList<>(fieldNames.size());

    for (String fieldNameValue : fieldNames) {
      Serializable fieldValue = serviceContext.getAttribute(fieldNameValue);

      if (Validator.isNull(fieldValue)) {
        fieldValue = predefinedValue.getString(serviceContext.getLocale());
      }

      if (fieldType.equals(DDMImpl.TYPE_CHECKBOX) && Validator.isNull(fieldValue)) {

        fieldValue = "false";
      } else if (fieldDataType.equals(FieldConstants.DATE)) {
        Date fieldValueDate = null;

        if (Validator.isNull(fieldValue)) {
          int fieldValueMonth =
              GetterUtil.getInteger(serviceContext.getAttribute(fieldNameValue + "Month"));
          int fieldValueDay =
              GetterUtil.getInteger(serviceContext.getAttribute(fieldNameValue + "Day"));
          int fieldValueYear =
              GetterUtil.getInteger(serviceContext.getAttribute(fieldNameValue + "Year"));

          fieldValueDate = PortalUtil.getDate(fieldValueMonth, fieldValueDay, fieldValueYear);
        } else {
          try {
            fieldValueDate =
                DateUtil.parseDate(String.valueOf(fieldValue), serviceContext.getLocale());
          } catch (ParseException pe) {
            if (_log.isErrorEnabled()) {
              _log.error("Unable to parse date " + fieldValue);
            }
          }
        }

        if (fieldValueDate != null) {
          fieldValue = String.valueOf(fieldValueDate.getTime());
        }
      } else if (fieldDataType.equals(FieldConstants.IMAGE) && Validator.isNull(fieldValue)) {

        HttpServletRequest request = serviceContext.getRequest();

        if (request instanceof UploadRequest) {
          String imageFieldValue = getImageFieldValue((UploadRequest) request, fieldNameValue);

          if (Validator.isNotNull(imageFieldValue)) {
            fieldValue = imageFieldValue;
          }
        }
      }

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

      if (DDMImpl.TYPE_RADIO.equals(fieldType) || DDMImpl.TYPE_SELECT.equals(fieldType)) {

        String predefinedValueString = predefinedValue.getString(serviceContext.getLocale());

        if (!fieldValue.equals(predefinedValueString) && (fieldValue instanceof String)) {

          fieldValue = new String[] {String.valueOf(fieldValue)};

          fieldValue = JSONFactoryUtil.serialize(fieldValue);
        }
      }

      Serializable fieldValueSerializable =
          FieldConstants.getSerializable(fieldDataType, GetterUtil.getString(fieldValue));

      fieldValues.add(fieldValueSerializable);
    }

    return fieldValues;
  }
コード例 #14
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;
  }