Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
24   98   7   8
6   65   0.29   3
3     2.33  
1    
 
  RuleAttributeXmlExporter       Line # 53 24 0% 7 33 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2005-2008 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17    package org.kuali.rice.kew.xml.export;
18   
19    import static org.kuali.rice.core.api.impex.xml.XmlConstants.CLASS_NAME;
20    import static org.kuali.rice.core.api.impex.xml.XmlConstants.DESCRIPTION;
21    import static org.kuali.rice.core.api.impex.xml.XmlConstants.LABEL;
22    import static org.kuali.rice.core.api.impex.xml.XmlConstants.NAME;
23    import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTE;
24    import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTES;
25    import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTE_NAMESPACE;
26    import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTE_SCHEMA_LOCATION;
27    import static org.kuali.rice.core.api.impex.xml.XmlConstants.SCHEMA_LOCATION_ATTR;
28    import static org.kuali.rice.core.api.impex.xml.XmlConstants.SCHEMA_NAMESPACE;
29    import static org.kuali.rice.core.api.impex.xml.XmlConstants.SERVICE_NAMESPACE;
30    import static org.kuali.rice.core.api.impex.xml.XmlConstants.TYPE;
31   
32    import java.io.StringReader;
33    import java.util.Iterator;
34   
35    import org.jdom.Document;
36    import org.jdom.Element;
37    import org.jdom.input.SAXBuilder;
38    import org.kuali.rice.core.api.impex.ExportDataSet;
39    import org.kuali.rice.core.framework.impex.xml.XmlExporter;
40    import org.kuali.rice.core.util.XmlHelper;
41    import org.kuali.rice.core.util.XmlRenderer;
42    import org.kuali.rice.kew.exception.WorkflowRuntimeException;
43    import org.kuali.rice.kew.export.KewExportDataSet;
44    import org.kuali.rice.kew.rule.bo.RuleAttribute;
45   
46    /**
47    * Exports {@link RuleAttribute}s to XML.
48    *
49    * @see RuleAttribute
50    *
51    * @author Kuali Rice Team (rice.collab@kuali.org)
52    */
 
53    public class RuleAttributeXmlExporter implements XmlExporter {
54   
55    protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
56   
57    private XmlRenderer renderer = new XmlRenderer(RULE_ATTRIBUTE_NAMESPACE);
58   
 
59  0 toggle @Override
60    public boolean supportPrettyPrint() {
61  0 return true;
62    }
63   
 
64  0 toggle public Element export(ExportDataSet exportDataSet) {
65  0 KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet);
66  0 if (!dataSet.getRuleAttributes().isEmpty()) {
67  0 Element rootElement = renderer.renderElement(null, RULE_ATTRIBUTES);
68  0 rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_ATTRIBUTE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
69  0 for (Iterator iterator = dataSet.getRuleAttributes().iterator(); iterator.hasNext();) {
70  0 RuleAttribute template = (RuleAttribute)iterator.next();
71  0 exportRuleAttribute(rootElement, template);
72    }
73  0 return rootElement;
74    }
75  0 return null;
76    }
77   
 
78  0 toggle private void exportRuleAttribute(Element parent, RuleAttribute ruleAttribute) {
79  0 Element attributeElement = renderer.renderElement(parent, RULE_ATTRIBUTE);
80  0 renderer.renderTextElement(attributeElement, NAME, ruleAttribute.getName());
81  0 renderer.renderTextElement(attributeElement, CLASS_NAME, ruleAttribute.getClassName());
82  0 renderer.renderTextElement(attributeElement, LABEL, ruleAttribute.getLabel());
83  0 renderer.renderTextElement(attributeElement, DESCRIPTION, ruleAttribute.getDescription());
84  0 renderer.renderTextElement(attributeElement, TYPE, ruleAttribute.getType());
85  0 renderer.renderTextElement(attributeElement, SERVICE_NAMESPACE, ruleAttribute.getServiceNamespace());
86  0 if (!org.apache.commons.lang.StringUtils.isEmpty(ruleAttribute.getXmlConfigData())) {
87  0 try {
88  0 Document configDoc = new SAXBuilder().build(new StringReader(ruleAttribute.getXmlConfigData()));
89  0 XmlHelper.propagateNamespace(configDoc.getRootElement(), RULE_ATTRIBUTE_NAMESPACE);
90  0 attributeElement.addContent(configDoc.getRootElement().detach());
91    } catch (Exception e) {
92  0 LOG.error("Error parsing attribute XML configuration.", e);
93  0 throw new WorkflowRuntimeException("Error parsing attribute XML configuration.");
94    }
95    }
96    }
97   
98    }