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