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