Coverage Report - org.kuali.rice.kew.xml.export.StyleXmlExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
StyleXmlExporter
0%
0/23
0%
0/6
4.5
 
 1  
 /*
 2  
  * Copyright 2005-2007 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 java.io.StringReader;
 20  
 import java.util.Iterator;
 21  
 
 22  
 import org.apache.log4j.Logger;
 23  
 import org.jdom.Element;
 24  
 import org.kuali.rice.kew.edl.bo.EDocLiteStyle;
 25  
 import org.kuali.rice.kew.exception.InvalidXmlException;
 26  
 import org.kuali.rice.kew.export.ExportDataSet;
 27  
 import org.kuali.rice.kew.util.XmlHelper;
 28  
 import org.kuali.rice.kew.xml.XmlConstants;
 29  
 import org.kuali.rice.kew.xml.XmlRenderer;
 30  
 
 31  
 
 32  
 /**
 33  
  * Exports Style definitions to XML.
 34  
  *
 35  
  * @see org.kuali.rice.kew.edl.service.StyleService
 36  
  * @see org.kuali.rice.kew.xml.StyleXmlParser
 37  
  * @see EDocLiteStyle
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  0
 public class StyleXmlExporter implements XmlExporter, XmlConstants {
 42  0
         private static final Logger LOG = Logger.getLogger(StyleXmlExporter.class);
 43  
 
 44  0
         private XmlRenderer renderer = new XmlRenderer(STYLE_NAMESPACE);
 45  
         
 46  
         public Element export(ExportDataSet dataSet) {
 47  0
                 if (!dataSet.getStyles().isEmpty()) {
 48  0
                         Element rootElement = renderer.renderElement(null, STYLE_STYLES);
 49  0
                         rootElement.setAttribute(SCHEMA_LOCATION_ATTR, STYLE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
 50  0
                         for (Iterator iter = dataSet.getStyles().iterator(); iter.hasNext();) {
 51  0
                                 EDocLiteStyle edocLite = (EDocLiteStyle) iter.next();
 52  0
                                 exportStyle(rootElement, edocLite);
 53  0
                         }
 54  0
                         return rootElement;
 55  
                 }
 56  0
                 return null;
 57  
         }
 58  
 
 59  
         private void exportStyle(Element parentEl, EDocLiteStyle style) {
 60  0
         if (style == null) {
 61  0
             LOG.error("Attempted to export style which was not found");
 62  0
             return;
 63  
         }
 64  
 
 65  0
         Element styleWrapperEl = renderer.renderElement(parentEl, STYLE_STYLE);
 66  0
         renderer.renderAttribute(styleWrapperEl, "name", style.getName());
 67  
 
 68  
         try {
 69  0
             Element styleEl = XmlHelper.buildJDocument(new StringReader(style.getXmlContent())).getRootElement();
 70  0
             styleWrapperEl.addContent(styleEl.detach());
 71  0
                 } catch (InvalidXmlException e) {
 72  0
                         throw new RuntimeException("Error building JDom document for style", e);
 73  0
                 }
 74  0
         }        
 75  
 }