Coverage Report - org.kuali.rice.kew.xml.export.RuleAttributeXmlExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleAttributeXmlExporter
0%
0/30
0%
0/6
3
 
 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.APPLICATION_ID;
 20  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.CLASS_NAME;
 21  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.DESCRIPTION;
 22  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.LABEL;
 23  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.NAME;
 24  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTE;
 25  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTES;
 26  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTE_NAMESPACE;
 27  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_ATTRIBUTE_SCHEMA_LOCATION;
 28  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.SCHEMA_LOCATION_ATTR;
 29  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.SCHEMA_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.xml.XmlHelper;
 41  
 import org.kuali.rice.core.util.xml.XmlRenderer;
 42  
 import org.kuali.rice.kew.api.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  0
 public class RuleAttributeXmlExporter implements XmlExporter {
 54  
 
 55  0
     protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
 56  
     
 57  0
     private XmlRenderer renderer = new XmlRenderer(RULE_ATTRIBUTE_NAMESPACE);
 58  
     
 59  
         @Override
 60  
         public boolean supportPrettyPrint() {
 61  0
                 return true;
 62  
         }
 63  
 
 64  
     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  0
             }
 73  0
             return rootElement;
 74  
         }
 75  0
         return null;
 76  
     }
 77  
     
 78  
     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, APPLICATION_ID, ruleAttribute.getApplicationId());
 86  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(ruleAttribute.getXmlConfigData())) {
 87  
             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  0
             } catch (Exception e) {
 92  0
                     LOG.error("Error parsing attribute XML configuration.", e);
 93  0
                 throw new WorkflowRuntimeException("Error parsing attribute XML configuration.");
 94  0
             }
 95  
         }
 96  0
     }
 97  
     
 98  
 }