1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.edl.impl.xml.export; |
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.edl.impl.bo.EDocLiteAssociation; |
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 | |
public class EdlDataExporter implements Exporter { |
39 | |
|
40 | 0 | private List<String> supportedFormats = new ArrayList<String>(); |
41 | |
|
42 | 0 | public EdlDataExporter() { |
43 | 0 | supportedFormats.add(KNSConstants.XML_FORMAT); |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public List<String> getSupportedFormats(Class<?> dataObjectClass) { |
48 | 0 | return supportedFormats; |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass, List<? extends Object> dataObjects) { |
55 | 0 | EdlExportDataSet dataSet = new EdlExportDataSet(); |
56 | 0 | for (Object dataObject : dataObjects) { |
57 | 0 | if (dataObjectClass.equals(EDocLiteAssociation.class)) { |
58 | 0 | dataSet.getEdocLites().add((EDocLiteAssociation)dataObject); |
59 | |
} |
60 | |
} |
61 | |
|
62 | 0 | return dataSet.createExportDataSet(); |
63 | |
} |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
@Override |
71 | |
public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat, OutputStream outputStream) throws IOException, |
72 | |
ExportNotSupportedException { |
73 | 0 | if (!KNSConstants.XML_FORMAT.equals(exportFormat)) { |
74 | 0 | throw new ExportNotSupportedException("The given export format of " + exportFormat + " is not supported by the EDocLite XML Exporter!"); |
75 | |
} |
76 | 0 | ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects); |
77 | 0 | outputStream.write(CoreApiServiceLocator.getXmlExporterService().export(dataSet)); |
78 | 0 | outputStream.flush(); |
79 | |
|
80 | 0 | } |
81 | |
} |