protected Field getTextField(long ddmStructureId) {
    Field field = new Field();

    field.setDDMStructureId(ddmStructureId);
    field.setName("text");

    field.addValue(_enLocale, "one");
    field.addValue(_ptLocale, "um");

    return field;
  }
  protected Field getMultiListField(long ddmStructureId) {
    Field field = new Field();

    field.setDDMStructureId(ddmStructureId);
    field.setName("multi-list");

    field.addValue(_enLocale, "[\"a\",\"b\"]");

    return field;
  }
  protected Field getTextAreaField(long ddmStructureId) {
    Field field = new Field();

    field.setDDMStructureId(ddmStructureId);
    field.setName("text_area");

    field.addValue(_enLocale, "<p>Hello World!</p>");

    return field;
  }
  protected Field getDocumentLibraryField(FileEntry fileEntry, long ddmStructureId) {

    Field docLibraryField = new Field();

    docLibraryField.setDDMStructureId(ddmStructureId);
    docLibraryField.setName("document_library");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("groupId", fileEntry.getGroupId());
    jsonObject.put("title", fileEntry.getTitle());
    jsonObject.put("uuid", fileEntry.getUuid());
    jsonObject.put("version", fileEntry.getVersion());

    docLibraryField.addValue(_enLocale, jsonObject.toString());

    return docLibraryField;
  }
Exemplo n.º 5
0
  @Override
  public Fields getFields(DDMStructure structure, XPath xPath, String xml, List<String> fieldNames)
      throws PortalException {

    Document document = null;

    try {
      document = SAXReaderUtil.read(xml);
    } catch (DocumentException de) {
      return null;
    }

    if ((xPath != null) && !xPath.booleanValueOf(document)) {
      return null;
    }

    Fields fields = new Fields();

    Element rootElement = document.getRootElement();

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

    for (Element dynamicElementElement : dynamicElementElements) {
      String fieldName = dynamicElementElement.attributeValue("name");

      if (!structure.hasField(fieldName)
          || ((fieldNames != null) && !fieldNames.contains(fieldName))) {

        continue;
      }

      String fieldDataType = structure.getFieldDataType(fieldName);

      List<Element> dynamicContentElements = dynamicElementElement.elements("dynamic-content");

      for (Element dynamicContentElement : dynamicContentElements) {
        String fieldValue = dynamicContentElement.getText();

        String languageId = dynamicContentElement.attributeValue("language-id");

        Locale locale = LocaleUtil.fromLanguageId(languageId);

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

        Field field = fields.get(fieldName);

        if (field == null) {
          field = new Field();

          String defaultLanguageId = dynamicElementElement.attributeValue("default-language-id");

          Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId);

          field.setDefaultLocale(defaultLocale);

          field.setDDMStructureId(structure.getStructureId());
          field.setName(fieldName);
          field.setValue(locale, fieldValueSerializable);

          fields.put(field);
        } else {
          field.addValue(locale, fieldValueSerializable);
        }
      }
    }

    return fields;
  }