1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.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.kew.doctype.bo.DocumentType; |
24 | |
import org.kuali.rice.kew.edl.bo.EDocLiteAssociation; |
25 | |
import org.kuali.rice.kew.edl.bo.EDocLiteStyle; |
26 | |
import org.kuali.rice.kew.help.HelpEntry; |
27 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
28 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
29 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
30 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
31 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
32 | |
import org.kuali.rice.kim.bo.impl.GroupImpl; |
33 | |
import org.kuali.rice.kns.bo.BusinessObject; |
34 | |
import org.kuali.rice.kns.bo.Exporter; |
35 | |
import org.kuali.rice.kns.exception.ExportNotSupportedException; |
36 | |
import org.kuali.rice.kns.util.KNSConstants; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public class DataExporter implements Exporter { |
48 | |
|
49 | 0 | private List<String> supportedFormats = new ArrayList<String>(); |
50 | |
|
51 | 0 | public DataExporter() { |
52 | 0 | supportedFormats.add(KNSConstants.XML_FORMAT); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public void export(Class<? extends BusinessObject> businessObjectClass, List<BusinessObject> businessObjects, String exportFormat, OutputStream outputStream) throws IOException { |
59 | 0 | if (!KNSConstants.XML_FORMAT.equals(exportFormat)) { |
60 | 0 | throw new ExportNotSupportedException("The given export format of " + exportFormat + " is not supported by the KEW XML Exporter!"); |
61 | |
} |
62 | 0 | ExportDataSet dataSet = buildExportDataSet(businessObjectClass, businessObjects); |
63 | 0 | outputStream.write(KEWServiceLocator.getXmlExporterService().export(dataSet)); |
64 | 0 | } |
65 | |
|
66 | |
public List<String> getSupportedFormats(Class<? extends BusinessObject> businessObjectClass) { |
67 | 0 | return supportedFormats; |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
protected ExportDataSet buildExportDataSet(Class<? extends BusinessObject> businessObjectClass, List<BusinessObject> businessObjects) { |
74 | 0 | ExportDataSet dataSet = new ExportDataSet(); |
75 | 0 | for (BusinessObject businessObject : businessObjects) { |
76 | 0 | if (businessObjectClass.equals(RuleAttribute.class)) { |
77 | 0 | dataSet.getRuleAttributes().add((RuleAttribute)businessObject); |
78 | 0 | } else if (businessObjectClass.equals(RuleTemplate.class)) { |
79 | 0 | dataSet.getRuleTemplates().add((RuleTemplate)businessObject); |
80 | 0 | } else if (businessObjectClass.equals(DocumentType.class)) { |
81 | 0 | dataSet.getDocumentTypes().add((DocumentType)businessObject); |
82 | 0 | } else if (businessObjectClass.equals(EDocLiteAssociation.class)) { |
83 | 0 | dataSet.getEdocLites().add((EDocLiteAssociation)businessObject); |
84 | 0 | } else if (businessObjectClass.equals(HelpEntry.class)) { |
85 | 0 | dataSet.getHelp().add((HelpEntry)businessObject); |
86 | 0 | } else if (businessObjectClass.equals(RuleBaseValues.class)) { |
87 | 0 | dataSet.getRules().add((RuleBaseValues)businessObject); |
88 | 0 | } else if (businessObjectClass.equals(RuleDelegation.class)) { |
89 | 0 | dataSet.getRuleDelegations().add((RuleDelegation)businessObject); |
90 | 0 | } else if (businessObjectClass.equals(EDocLiteStyle.class)) { |
91 | 0 | dataSet.getStyles().add((EDocLiteStyle)businessObject); |
92 | 0 | } else if (businessObjectClass.equals(GroupImpl.class)) { |
93 | 0 | dataSet.getGroups().add((GroupImpl)businessObject); |
94 | |
} |
95 | |
} |
96 | 0 | return dataSet; |
97 | |
} |
98 | |
|
99 | |
} |