@Override public String getXML(Document document, Fields fields) { Element rootElement = null; try { if (document != null) { rootElement = document.getRootElement(); } else { document = _saxReader.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 Map<Locale, List<Serializable>> getMergedFieldValuesMap( Field newField, String[] newFieldsDisplayValues, Field existingField, String[] existingFieldsDisplayValues) { Set<Locale> availableLocales = getMergedAvailableLocales( newField.getAvailableLocales(), existingField.getAvailableLocales()); for (Locale locale : availableLocales) { List<Serializable> newFieldValues = getFieldValues(newField, locale); List<Serializable> existingFieldValues = getFieldValues(existingField, locale); List<Serializable> defaultFieldValues = getFieldValues(newField, newField.getDefaultLocale()); List<Serializable> mergedLocaleValues = getMergedFieldValues( newField.getName(), newFieldValues, newFieldsDisplayValues, existingFieldValues, existingFieldsDisplayValues, defaultFieldValues); existingField.setValues(locale, mergedLocaleValues); } return existingField.getValuesMap(); }
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); } } }
@Override public Fields mergeFields(Fields newFields, Fields existingFields) { String[] newFieldsDisplayValues = splitFieldsDisplayValue(newFields.get(DDMImpl.FIELDS_DISPLAY_NAME)); String[] existingFieldsDisplayValues = splitFieldsDisplayValue(existingFields.get(DDMImpl.FIELDS_DISPLAY_NAME)); Iterator<Field> itr = newFields.iterator(true); while (itr.hasNext()) { Field newField = itr.next(); Field existingField = existingFields.get(newField.getName()); if (existingField == null) { existingFields.put(newField); continue; } if (newField.isPrivate()) { continue; } existingField.setDefaultLocale(newField.getDefaultLocale()); Map<Locale, List<Serializable>> mergedFieldValuesMap = getMergedFieldValuesMap( newField, newFieldsDisplayValues, existingField, existingFieldsDisplayValues); existingField.setValuesMap(mergedFieldValuesMap); } return existingFields; }