1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.xml.export;
17
18 import org.jdom.Document;
19 import org.jdom.Element;
20 import org.jdom.input.SAXBuilder;
21 import org.kuali.rice.core.api.impex.ExportDataSet;
22 import org.kuali.rice.core.api.util.xml.XmlHelper;
23 import org.kuali.rice.core.api.util.xml.XmlRenderer;
24 import org.kuali.rice.core.framework.impex.xml.XmlExporter;
25 import org.kuali.rice.kew.api.WorkflowRuntimeException;
26 import org.kuali.rice.kew.export.KewExportDataSet;
27 import org.kuali.rice.kew.rule.bo.RuleAttribute;
28
29 import java.io.StringReader;
30 import java.util.Iterator;
31
32 import static org.kuali.rice.core.api.impex.xml.XmlConstants.*;
33
34
35
36
37
38
39
40
41 public class RuleAttributeXmlExporter implements XmlExporter {
42
43 protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
44
45 private XmlRenderer renderer = new XmlRenderer(RULE_ATTRIBUTE_NAMESPACE);
46
47 @Override
48 public boolean supportPrettyPrint() {
49 return true;
50 }
51
52 public Element export(ExportDataSet exportDataSet) {
53 KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet);
54 if (!dataSet.getRuleAttributes().isEmpty()) {
55 Element rootElement = renderer.renderElement(null, RULE_ATTRIBUTES);
56 rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_ATTRIBUTE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
57 for (Iterator iterator = dataSet.getRuleAttributes().iterator(); iterator.hasNext();) {
58 RuleAttribute template = (RuleAttribute)iterator.next();
59 exportRuleAttribute(rootElement, template);
60 }
61 return rootElement;
62 }
63 return null;
64 }
65
66 private void exportRuleAttribute(Element parent, RuleAttribute ruleAttribute) {
67 Element attributeElement = renderer.renderElement(parent, RULE_ATTRIBUTE);
68 renderer.renderTextElement(attributeElement, NAME, ruleAttribute.getName());
69 renderer.renderTextElement(attributeElement, CLASS_NAME, ruleAttribute.getResourceDescriptor());
70 renderer.renderTextElement(attributeElement, LABEL, ruleAttribute.getLabel());
71 renderer.renderTextElement(attributeElement, DESCRIPTION, ruleAttribute.getDescription());
72 renderer.renderTextElement(attributeElement, TYPE, ruleAttribute.getType());
73 renderer.renderTextElement(attributeElement, APPLICATION_ID, ruleAttribute.getApplicationId());
74 if (!org.apache.commons.lang.StringUtils.isEmpty(ruleAttribute.getXmlConfigData())) {
75 try {
76 Document configDoc = new SAXBuilder().build(new StringReader(ruleAttribute.getXmlConfigData()));
77 XmlHelper.propagateNamespace(configDoc.getRootElement(), RULE_ATTRIBUTE_NAMESPACE);
78 attributeElement.addContent(configDoc.getRootElement().detach());
79 } catch (Exception e) {
80 LOG.error("Error parsing attribute XML configuration.", e);
81 throw new WorkflowRuntimeException("Error parsing attribute XML configuration.");
82 }
83 }
84 }
85
86 }