Exemplo n.º 1
0
  @Override
  public String getXML(Document document, Fields fields) {
    Element rootElement = null;

    try {
      if (document != null) {
        rootElement = document.getRootElement();
      } else {
        document = SAXReaderUtil.createDocument();

        rootElement = document.addElement("root");
      }

      Iterator<Field> itr = fields.iterator(true);

      while (itr.hasNext()) {
        Field field = itr.next();

        List<Node> nodes = getElementsByName(document, field.getName());

        for (Node node : nodes) {
          document.remove(node);
        }

        appendField(rootElement, field);
      }

      return document.formattedString();
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
  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 HashMap<String, Fields> getFieldsMap(
      ServiceContext serviceContext, long fileEntryTypeId) throws PortalException, SystemException {

    HashMap<String, Fields> fieldsMap = new HashMap<String, Fields>();

    if (fileEntryTypeId <= 0) {
      return fieldsMap;
    }

    DLFileEntryType fileEntryType =
        DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      String namespace = String.valueOf(ddmStructure.getStructureId());

      Set<String> fieldNames = ddmStructure.getFieldNames();

      Fields fields =
          (Fields)
              serviceContext.getAttribute(Fields.class.getName() + ddmStructure.getStructureId());

      if (fields == null) {
        fields = new Fields();

        for (String name : fieldNames) {
          Field field = new Field();

          field.setName(name);

          String value = ParamUtil.getString(serviceContext, namespace + name);

          field.setValue(value);

          fields.put(field);
        }
      }

      fieldsMap.put(ddmStructure.getStructureKey(), fields);
    }

    return fieldsMap;
  }
Exemplo n.º 10
0
  protected void appendField(Element element, Field field) {
    Element dynamicElementElement = element.addElement("dynamic-element");

    dynamicElementElement.addAttribute(
        "default-language-id", LocaleUtil.toLanguageId(field.getDefaultLocale()));
    dynamicElementElement.addAttribute("name", field.getName());

    for (Locale locale : field.getAvailableLocales()) {
      List<Serializable> values = field.getValues(locale);

      for (Serializable value : values) {
        Element dynamicContentElement = dynamicElementElement.addElement("dynamic-content");

        dynamicContentElement.addAttribute("language-id", LocaleUtil.toLanguageId(locale));

        updateField(dynamicContentElement, value);
      }
    }
  }
Exemplo n.º 11
0
  protected void updateServiceContext(String expando, long fileEntryTypeId, String metadata)
      throws PortalException {

    Map<String, Serializable> expandoBridgeAttributes =
        _serviceContext.getExpandoBridgeAttributes();

    expandoBridgeAttributes.put(_EXPANDO_ATTRIBUTE_NAME, expando);

    _serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);

    _serviceContext.setAttribute("fileEntryTypeId", fileEntryTypeId);

    if (fileEntryTypeId <= 0) {
      return;
    }

    DLFileEntryType fileEntryType =
        DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      Fields fields =
          (Fields)
              _serviceContext.getAttribute(Fields.class.getName() + ddmStructure.getStructureId());

      for (Field field : fields) {
        String type = field.getType();

        if (!field.isPrivate() && type.equals("text")) {
          field.setValue(metadata);
        }
      }

      _serviceContext.setAttribute(Fields.class.getName() + ddmStructure.getStructureId(), fields);
    }
  }
Exemplo n.º 12
0
  protected ServiceContext getServiceContext() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    serviceContext.setAttribute("fileEntryTypeId", _contractDLFileEntryTypeId);

    Map<String, Serializable> expandoBridgeAttributes = serviceContext.getExpandoBridgeAttributes();

    expandoBridgeAttributes.put(_EXPANDO_ATTRIBUTE_NAME, StringPool.BLANK);

    serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);

    DLFileEntryType fileEntryType =
        DLFileEntryTypeLocalServiceUtil.getFileEntryType(_contractDLFileEntryTypeId);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      Fields fields = new Fields();

      Set<String> names = ddmStructure.getFieldNames();

      for (String name : names) {
        Field field = new Field(ddmStructure.getStructureId(), name, StringPool.BLANK);

        if (ddmStructure.isFieldPrivate(name)) {
          field.setValue(RandomTestUtil.randomString());
        }

        fields.put(field);
      }

      serviceContext.setAttribute(Fields.class.getName() + ddmStructure.getStructureId(), fields);
    }

    return serviceContext;
  }
  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.º 14
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;
  }
Exemplo n.º 15
0
  public void addAttributes(Document document, DDMStructure ddmStructure, Fields fields) {

    Iterator<Field> itr = fields.iterator();

    while (itr.hasNext()) {
      Field field = itr.next();

      try {
        String indexType = ddmStructure.getFieldProperty(field.getName(), "indexType");

        if (Validator.isNull(indexType)) {
          continue;
        }

        for (Locale locale : LanguageUtil.getAvailableLocales()) {
          String name = encodeName(ddmStructure.getStructureId(), field.getName(), locale);

          Serializable value = field.getValue(locale);

          if (value instanceof Boolean) {
            document.addKeyword(name, (Boolean) value);
          } else if (value instanceof Boolean[]) {
            document.addKeyword(name, (Boolean[]) value);
          } else if (value instanceof Date) {
            document.addDate(name, (Date) value);
          } else if (value instanceof Date[]) {
            document.addDate(name, (Date[]) value);
          } else if (value instanceof Double) {
            document.addKeyword(name, (Double) value);
          } else if (value instanceof Double[]) {
            document.addKeyword(name, (Double[]) value);
          } else if (value instanceof Integer) {
            document.addKeyword(name, (Integer) value);
          } else if (value instanceof Integer[]) {
            document.addKeyword(name, (Integer[]) value);
          } else if (value instanceof Object[]) {
            String[] valuesString = ArrayUtil.toStringArray((Object[]) value);

            if (indexType.equals("keyword")) {
              document.addKeyword(name, valuesString);
            } else {
              document.addText(name, valuesString);
            }
          } else {
            String valueString = String.valueOf(value);

            String type = field.getType();

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

              JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

              String[] stringArray = ArrayUtil.toStringArray(jsonArray);

              if (indexType.equals("keyword")) {
                document.addKeyword(name, stringArray);
              } else {
                document.addText(name, stringArray);
              }
            } else {
              if (indexType.equals("keyword")) {
                document.addKeyword(name, valueString);
              } else {
                document.addText(name, valueString);
              }
            }
          }
        }
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }
    }
  }
  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;
  }