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.jdom.Document; |
23 | |
import org.jdom.Element; |
24 | |
import org.jdom.input.SAXBuilder; |
25 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
26 | |
import org.kuali.rice.kew.export.ExportDataSet; |
27 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
28 | |
import org.kuali.rice.kew.util.Utilities; |
29 | |
import org.kuali.rice.kew.util.XmlHelper; |
30 | |
import org.kuali.rice.kew.xml.XmlConstants; |
31 | |
import org.kuali.rice.kew.xml.XmlRenderer; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class RuleAttributeXmlExporter implements XmlExporter, XmlConstants { |
42 | |
|
43 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
44 | |
|
45 | 0 | private XmlRenderer renderer = new XmlRenderer(RULE_ATTRIBUTE_NAMESPACE); |
46 | |
|
47 | |
public Element export(ExportDataSet dataSet) { |
48 | 0 | if (!dataSet.getRuleAttributes().isEmpty()) { |
49 | 0 | Element rootElement = renderer.renderElement(null, RULE_ATTRIBUTES); |
50 | 0 | rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_ATTRIBUTE_SCHEMA_LOCATION, SCHEMA_NAMESPACE); |
51 | 0 | for (Iterator iterator = dataSet.getRuleAttributes().iterator(); iterator.hasNext();) { |
52 | 0 | RuleAttribute template = (RuleAttribute)iterator.next(); |
53 | 0 | exportRuleAttribute(rootElement, template); |
54 | 0 | } |
55 | 0 | return rootElement; |
56 | |
} |
57 | 0 | return null; |
58 | |
} |
59 | |
|
60 | |
private void exportRuleAttribute(Element parent, RuleAttribute ruleAttribute) { |
61 | 0 | Element attributeElement = renderer.renderElement(parent, RULE_ATTRIBUTE); |
62 | 0 | renderer.renderTextElement(attributeElement, NAME, ruleAttribute.getName()); |
63 | 0 | renderer.renderTextElement(attributeElement, CLASS_NAME, ruleAttribute.getClassName()); |
64 | 0 | renderer.renderTextElement(attributeElement, LABEL, ruleAttribute.getLabel()); |
65 | 0 | renderer.renderTextElement(attributeElement, DESCRIPTION, ruleAttribute.getDescription()); |
66 | 0 | renderer.renderTextElement(attributeElement, TYPE, ruleAttribute.getType()); |
67 | 0 | renderer.renderTextElement(attributeElement, SERVICE_NAMESPACE, ruleAttribute.getServiceNamespace()); |
68 | 0 | if (!Utilities.isEmpty(ruleAttribute.getXmlConfigData())) { |
69 | |
try { |
70 | 0 | Document configDoc = new SAXBuilder().build(new StringReader(ruleAttribute.getXmlConfigData())); |
71 | 0 | XmlHelper.propogateNamespace(configDoc.getRootElement(), RULE_ATTRIBUTE_NAMESPACE); |
72 | 0 | attributeElement.addContent(configDoc.getRootElement().detach()); |
73 | 0 | } catch (Exception e) { |
74 | 0 | LOG.error("Error parsing attribute XML configuration.", e); |
75 | 0 | throw new WorkflowRuntimeException("Error parsing attribute XML configuration."); |
76 | 0 | } |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | |
} |