| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.core.impl.style; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
import java.io.OutputStream; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.List; |
| 22 | |
|
| 23 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
| 24 | |
import org.kuali.rice.core.api.services.CoreApiServiceLocator; |
| 25 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 26 | |
import org.kuali.rice.kns.bo.Exporter; |
| 27 | |
import org.kuali.rice.kns.exception.ExportNotSupportedException; |
| 28 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public class StyleDataExporter implements Exporter { |
| 40 | |
|
| 41 | 0 | private List<String> supportedFormats = new ArrayList<String>(); |
| 42 | |
|
| 43 | 0 | public StyleDataExporter() { |
| 44 | 0 | supportedFormats.add(KNSConstants.XML_FORMAT); |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
@Override |
| 48 | |
public void export(Class<? extends BusinessObject> businessObjectClass, List<BusinessObject> businessObjects, String exportFormat, OutputStream outputStream) throws IOException { |
| 49 | 0 | if (!KNSConstants.XML_FORMAT.equals(exportFormat)) { |
| 50 | 0 | throw new ExportNotSupportedException("The given export format of " + exportFormat + " is not supported by the KEW XML Exporter!"); |
| 51 | |
} |
| 52 | 0 | ExportDataSet dataSet = buildExportDataSet(businessObjectClass, businessObjects); |
| 53 | 0 | outputStream.write(CoreApiServiceLocator.getXmlExporterService().export(dataSet)); |
| 54 | 0 | outputStream.flush(); |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
public List<String> getSupportedFormats(Class<? extends BusinessObject> businessObjectClass) { |
| 59 | 0 | return supportedFormats; |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
protected ExportDataSet buildExportDataSet(Class<? extends BusinessObject> businessObjectClass, List<BusinessObject> businessObjects) { |
| 66 | 0 | StyleExportDataSet dataSet = new StyleExportDataSet(); |
| 67 | 0 | for (BusinessObject businessObject : businessObjects) { |
| 68 | 0 | if (businessObjectClass.equals(StyleBo.class)) { |
| 69 | 0 | dataSet.getStyles().add((StyleBo)businessObject); |
| 70 | |
} |
| 71 | |
} |
| 72 | 0 | return dataSet.createExportDataSet(); |
| 73 | |
} |
| 74 | |
|
| 75 | |
} |