1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.xml.export; |
18 | |
|
19 | |
import java.io.StringReader; |
20 | |
import java.util.Iterator; |
21 | |
|
22 | |
import org.apache.log4j.Logger; |
23 | |
import org.jdom.Element; |
24 | |
import org.kuali.rice.kew.edl.bo.EDocLiteStyle; |
25 | |
import org.kuali.rice.kew.exception.InvalidXmlException; |
26 | |
import org.kuali.rice.kew.export.ExportDataSet; |
27 | |
import org.kuali.rice.kew.util.XmlHelper; |
28 | |
import org.kuali.rice.kew.xml.XmlConstants; |
29 | |
import org.kuali.rice.kew.xml.XmlRenderer; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class StyleXmlExporter implements XmlExporter, XmlConstants { |
42 | 0 | private static final Logger LOG = Logger.getLogger(StyleXmlExporter.class); |
43 | |
|
44 | 0 | private XmlRenderer renderer = new XmlRenderer(STYLE_NAMESPACE); |
45 | |
|
46 | |
public Element export(ExportDataSet dataSet) { |
47 | 0 | if (!dataSet.getStyles().isEmpty()) { |
48 | 0 | Element rootElement = renderer.renderElement(null, STYLE_STYLES); |
49 | 0 | rootElement.setAttribute(SCHEMA_LOCATION_ATTR, STYLE_SCHEMA_LOCATION, SCHEMA_NAMESPACE); |
50 | 0 | for (Iterator iter = dataSet.getStyles().iterator(); iter.hasNext();) { |
51 | 0 | EDocLiteStyle edocLite = (EDocLiteStyle) iter.next(); |
52 | 0 | exportStyle(rootElement, edocLite); |
53 | 0 | } |
54 | 0 | return rootElement; |
55 | |
} |
56 | 0 | return null; |
57 | |
} |
58 | |
|
59 | |
private void exportStyle(Element parentEl, EDocLiteStyle style) { |
60 | 0 | if (style == null) { |
61 | 0 | LOG.error("Attempted to export style which was not found"); |
62 | 0 | return; |
63 | |
} |
64 | |
|
65 | 0 | Element styleWrapperEl = renderer.renderElement(parentEl, STYLE_STYLE); |
66 | 0 | renderer.renderAttribute(styleWrapperEl, "name", style.getName()); |
67 | |
|
68 | |
try { |
69 | 0 | Element styleEl = XmlHelper.buildJDocument(new StringReader(style.getXmlContent())).getRootElement(); |
70 | 0 | styleWrapperEl.addContent(styleEl.detach()); |
71 | 0 | } catch (InvalidXmlException e) { |
72 | 0 | throw new RuntimeException("Error building JDom document for style", e); |
73 | 0 | } |
74 | 0 | } |
75 | |
} |