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 public class StyleXmlExporter implements XmlExporter, XmlConstants {
42 private static final Logger LOG = Logger.getLogger(StyleXmlExporter.class);
43
44 private XmlRenderer renderer = new XmlRenderer(STYLE_NAMESPACE);
45
46 public Element export(ExportDataSet dataSet) {
47 if (!dataSet.getStyles().isEmpty()) {
48 Element rootElement = renderer.renderElement(null, STYLE_STYLES);
49 rootElement.setAttribute(SCHEMA_LOCATION_ATTR, STYLE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
50 for (Iterator iter = dataSet.getStyles().iterator(); iter.hasNext();) {
51 EDocLiteStyle edocLite = (EDocLiteStyle) iter.next();
52 exportStyle(rootElement, edocLite);
53 }
54 return rootElement;
55 }
56 return null;
57 }
58
59 private void exportStyle(Element parentEl, EDocLiteStyle style) {
60 if (style == null) {
61 LOG.error("Attempted to export style which was not found");
62 return;
63 }
64
65 Element styleWrapperEl = renderer.renderElement(parentEl, STYLE_STYLE);
66 renderer.renderAttribute(styleWrapperEl, "name", style.getName());
67
68 try {
69 Element styleEl = XmlHelper.buildJDocument(new StringReader(style.getXmlContent())).getRootElement();
70 styleWrapperEl.addContent(styleEl.detach());
71 } catch (InvalidXmlException e) {
72 throw new RuntimeException("Error building JDom document for style", e);
73 }
74 }
75 }