예제 #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);
    }
  }
예제 #2
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);
      }
    }
  }
예제 #3
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);
        }
      }
    }
  }