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-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Exports {@link org.kuali.rice.kew.rule.bo.RuleAttribute}s to XML.
 36  
  * 
 37  
  * @see org.kuali.rice.kew.rule.bo.RuleAttribute
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  0
 public class RuleAttributeXmlExporter implements XmlExporter {
 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  
         @Override
 48  
         public boolean supportPrettyPrint() {
 49  0
                 return true;
 50  
         }
 51  
 
 52  
     public Element export(ExportDataSet exportDataSet) {
 53  0
             KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet);
 54  0
         if (!dataSet.getRuleAttributes().isEmpty()) {
 55  0
             Element rootElement = renderer.renderElement(null, RULE_ATTRIBUTES);
 56  0
             rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_ATTRIBUTE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
 57  0
             for (Iterator iterator = dataSet.getRuleAttributes().iterator(); iterator.hasNext();) {
 58  0
                 RuleAttribute template = (RuleAttribute)iterator.next();
 59  0
                 exportRuleAttribute(rootElement, template);
 60  0
             }
 61  0
             return rootElement;
 62  
         }
 63  0
         return null;
 64  
     }
 65  
     
 66  
     private void exportRuleAttribute(Element parent, RuleAttribute ruleAttribute) {
 67  0
         Element attributeElement = renderer.renderElement(parent, RULE_ATTRIBUTE);
 68  0
         renderer.renderTextElement(attributeElement, NAME, ruleAttribute.getName());
 69  0
         renderer.renderTextElement(attributeElement, CLASS_NAME, ruleAttribute.getResourceDescriptor());
 70  0
         renderer.renderTextElement(attributeElement, LABEL, ruleAttribute.getLabel());
 71  0
         renderer.renderTextElement(attributeElement, DESCRIPTION, ruleAttribute.getDescription());
 72  0
         renderer.renderTextElement(attributeElement, TYPE, ruleAttribute.getType());
 73  0
         renderer.renderTextElement(attributeElement, APPLICATION_ID, ruleAttribute.getApplicationId());
 74  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(ruleAttribute.getXmlConfigData())) {
 75  
             try {
 76  0
                 Document configDoc = new SAXBuilder().build(new StringReader(ruleAttribute.getXmlConfigData()));
 77  0
                 XmlHelper.propagateNamespace(configDoc.getRootElement(), RULE_ATTRIBUTE_NAMESPACE);
 78  0
                 attributeElement.addContent(configDoc.getRootElement().detach());
 79  0
             } catch (Exception e) {
 80  0
                     LOG.error("Error parsing attribute XML configuration.", e);
 81  0
                 throw new WorkflowRuntimeException("Error parsing attribute XML configuration.");
 82  0
             }
 83  
         }
 84  0
     }
 85  
     
 86  
 }