protected Field getFieldsDisplayField(long ddmStructureId, String value) {
    Field fieldsDisplayField = new Field();

    fieldsDisplayField.setDDMStructureId(ddmStructureId);
    fieldsDisplayField.setName(DDMImpl.FIELDS_DISPLAY_NAME);
    fieldsDisplayField.setValue(value);

    return fieldsDisplayField;
  }
  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 getMultiListField(long ddmStructureId) {
    Field field = new Field();

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

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

    return field;
  }
  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 getBooleanField(long ddmStructureId) {
    Field field = new Field();

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

    List<Serializable> enValues = new ArrayList<>();

    enValues.add(true);
    enValues.add(false);

    field.addValues(_enLocale, enValues);

    return field;
  }
  protected Field getLinkToLayoutField(long ddmStructureId, Map<String, Layout> layoutsMap) {

    Field field = new Field();

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

    List<Serializable> enValues = new ArrayList<>();

    for (Layout layout : layoutsMap.values()) {
      enValues.add(getLinkToLayoutFieldValue(layout, false));
      enValues.add(getLinkToLayoutFieldValue(layout, true));
    }

    field.addValues(_enLocale, enValues);

    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;
  }
  protected Field getTextBoxField(long ddmStructureId) {
    Field field = new Field();

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

    List<Serializable> enValues = new ArrayList<>();

    enValues.add("one");
    enValues.add("two");
    enValues.add("three");

    field.addValues(_enLocale, enValues);

    List<Serializable> ptValues = new ArrayList<>();

    ptValues.add("um");
    ptValues.add("dois");
    ptValues.add("tres");

    field.addValues(_ptLocale, ptValues);

    return field;
  }
Exemplo n.º 9
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;
  }
  protected Fields getNestedFields(long ddmStructureId) {
    Fields fields = new Fields();

    // Contact

    Field contact = new Field();

    contact.setDDMStructureId(ddmStructureId);
    contact.setName("contact");

    List<Serializable> enValues = new ArrayList<>();

    enValues.add("joe");
    enValues.add("richard");

    contact.setValues(_enLocale, enValues);

    List<Serializable> ptValues = new ArrayList<>();

    ptValues.add("joao");
    ptValues.add("ricardo");

    contact.addValues(_ptLocale, ptValues);

    fields.put(contact);

    // Phone

    Field phone = new Field();

    phone.setDDMStructureId(ddmStructureId);
    phone.setName("phone");

    List<Serializable> values = new ArrayList<>();

    values.add("123");
    values.add("456");

    phone.setValues(_enLocale, values);
    phone.addValues(_ptLocale, values);

    fields.put(phone);

    // Ext

    Field ext = new Field();

    ext.setDDMStructureId(ddmStructureId);
    ext.setName("ext");

    values = new ArrayList<>();

    values.add("1");
    values.add("2");
    values.add("3");
    values.add("4");
    values.add("5");

    ext.setValues(_enLocale, values);
    ext.addValues(_ptLocale, values);

    fields.put(ext);

    Field fieldsDisplayField =
        new Field(
            ddmStructureId,
            DDMImpl.FIELDS_DISPLAY_NAME,
            "contact_INSTANCE_RF3do1m5,phone_INSTANCE_QK6B0wK9,"
                + "ext_INSTANCE_L67MPqQf,ext_INSTANCE_8uxzZl41,"
                + "ext_INSTANCE_S58K861T,contact_INSTANCE_CUeFxcrA,"
                + "phone_INSTANCE_lVTcTviF,ext_INSTANCE_cZalDSll,"
                + "ext_INSTANCE_HDrK2Um5");

    fields.put(fieldsDisplayField);

    return fields;
  }