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