예제 #1
0
  protected Field createField(
      DDMStructure ddmStructure,
      String fieldName,
      List<Serializable> fieldValues,
      ServiceContext serviceContext) {

    Field field = new Field();

    field.setDDMStructureId(ddmStructure.getStructureId());

    String languageId =
        GetterUtil.getString(
            serviceContext.getAttribute("languageId"), serviceContext.getLanguageId());

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    String defaultLanguageId =
        GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId"));

    Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId);

    if (fieldName.startsWith(StringPool.UNDERLINE)) {
      locale = LocaleUtil.getSiteDefault();

      defaultLocale = LocaleUtil.getSiteDefault();
    }

    field.setDefaultLocale(defaultLocale);

    field.setName(fieldName);
    field.setValues(locale, fieldValues);

    return field;
  }
예제 #2
0
  @Override
  public Fields getFields(DDMStructure structure, XPath xPath, String xml, List<String> fieldNames)
      throws PortalException {

    Document document = null;

    try {
      document = _saxReader.read(xml);
    } catch (DocumentException de) {
      if (_log.isDebugEnabled()) {
        _log.debug(de.getMessage(), 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");

          if (Validator.isNull(defaultLanguageId)) {
            defaultLanguageId = rootElement.attributeValue("default-locale");
          }

          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;
  }