/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.dynamic.data.lists.exporter.impl; import com.liferay.dynamic.data.lists.model.DDLRecord; import com.liferay.dynamic.data.lists.model.DDLRecordSet; import com.liferay.dynamic.data.lists.model.DDLRecordVersion; import com.liferay.dynamic.data.lists.service.DDLRecordLocalService; import com.liferay.dynamic.data.lists.service.DDLRecordSetService; import com.liferay.dynamic.data.mapping.model.DDMFormField; import com.liferay.dynamic.data.mapping.model.DDMStructure; import com.liferay.dynamic.data.mapping.model.LocalizedValue; import com.liferay.dynamic.data.mapping.storage.DDMFormValues; import com.liferay.dynamic.data.mapping.storage.Field; import com.liferay.dynamic.data.mapping.storage.Fields; import com.liferay.dynamic.data.mapping.storage.StorageEngine; import com.liferay.dynamic.data.mapping.util.DDMFormValuesToFieldsConverter; import com.liferay.portal.kernel.language.LanguageUtil; import com.liferay.portal.kernel.util.OrderByComparator; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.xml.Document; import com.liferay.portal.kernel.xml.Element; import com.liferay.portal.kernel.xml.SAXReaderUtil; import java.io.Serializable; import java.util.List; import org.osgi.service.component.annotations.Reference; /** * @author Marcellus Tavares * @author Manuel de la Peña * @deprecated As of 1.1.0, with no direct replacement */ @Deprecated public class DDLXMLExporter extends BaseDDLExporter { @Override public String getFormat() { return "xml"; } protected void addFieldElement( Element fieldsElement, String label, Serializable value) { Element fieldElement = fieldsElement.addElement("field"); Element labelElement = fieldElement.addElement("label"); labelElement.addText(label); Element valueElement = fieldElement.addElement("value"); valueElement.addText(String.valueOf(value)); } @Override protected byte[] doExport( long recordSetId, int status, int start, int end, OrderByComparator<DDLRecord> orderByComparator) throws Exception { DDLRecordSet recordSet = _ddlRecordSetService.getRecordSet(recordSetId); DDMStructure ddmStructure = recordSet.getDDMStructure(); List<DDMFormField> ddmFormFields = getDDMFormFields(ddmStructure); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); List<DDLRecord> records = _ddlRecordLocalService.getRecords( recordSetId, status, start, end, orderByComparator); for (DDLRecord record : records) { Element fieldsElement = rootElement.addElement("fields"); DDLRecordVersion recordVersion = record.getRecordVersion(); DDMFormValues ddmFormValues = _storageEngine.getDDMFormValues( recordVersion.getDDMStorageId()); Fields fields = _ddmFormValuesToFieldsConverter.convert( ddmStructure, ddmFormValues); for (DDMFormField ddmFormField : ddmFormFields) { LocalizedValue label = ddmFormField.getLabel(); String name = ddmFormField.getName(); String value = StringPool.BLANK; if (fields.contains(name)) { Field field = fields.get(name); value = field.getRenderedValue(getLocale()); } addFieldElement( fieldsElement, label.getString(getLocale()), value); } addFieldElement( fieldsElement, LanguageUtil.get(getLocale(), "status"), getStatusMessage(recordVersion.getStatus())); } String xml = document.asXML(); return xml.getBytes(); } @Reference(unbind = "-") protected void setDDLRecordLocalService( DDLRecordLocalService ddlRecordLocalService) { _ddlRecordLocalService = ddlRecordLocalService; } @Reference(unbind = "-") protected void setDDLRecordSetService( DDLRecordSetService ddlRecordSetService) { _ddlRecordSetService = ddlRecordSetService; } @Reference(unbind = "-") protected void setDDMFormValuesToFieldsConverter( DDMFormValuesToFieldsConverter ddmFormValuesToFieldsConverter) { _ddmFormValuesToFieldsConverter = ddmFormValuesToFieldsConverter; } @Reference(unbind = "-") protected void setStorageEngine(StorageEngine storageEngine) { _storageEngine = storageEngine; } private DDLRecordLocalService _ddlRecordLocalService; private DDLRecordSetService _ddlRecordSetService; private DDMFormValuesToFieldsConverter _ddmFormValuesToFieldsConverter; private StorageEngine _storageEngine; }