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