Coverage Report - org.kuali.rice.core.util.XmlJotter
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlJotter
0%
0/22
0%
0/2
2
 
 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.util;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.io.StringWriter;
 21  
 
 22  
 import javax.xml.transform.OutputKeys;
 23  
 import javax.xml.transform.Result;
 24  
 import javax.xml.transform.Source;
 25  
 import javax.xml.transform.Transformer;
 26  
 import javax.xml.transform.TransformerException;
 27  
 import javax.xml.transform.TransformerFactory;
 28  
 import javax.xml.transform.dom.DOMSource;
 29  
 import javax.xml.transform.stream.StreamResult;
 30  
 
 31  
 import org.jdom.output.XMLOutputter;
 32  
 
 33  
 /**
 34  
  *
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  0
 public class XmlJotter {
 38  
 
 39  
         
 40  
         public static String jotNode(org.jdom.Element element) {
 41  0
                 XMLOutputter outputer = new XMLOutputter();
 42  0
                 StringWriter writer = new StringWriter();
 43  
                 try {
 44  0
                         outputer.output(element, writer);
 45  0
                 } catch (IOException e) {
 46  0
                         throw new RuntimeException("Could not write XML data export.", e);
 47  0
                 }
 48  0
                 return writer.toString();
 49  
         }
 50  
 
 51  
         public static String jotNode(org.w3c.dom.Node node) {
 52  
                 // default to true since this is used mostly for debugging
 53  0
                 return jotNode(node, true);
 54  
         }
 55  
 
 56  
         public static String jotNode(org.w3c.dom.Node node, boolean indent) {
 57  
                 try {
 58  0
                         return writeNode(node, indent);
 59  0
                 } catch (TransformerException te) {
 60  0
                         return RiceUtilities.collectStackTrace(te);
 61  
                 }
 62  
         }
 63  
 
 64  
         public static String writeNode(org.w3c.dom.Node node) throws TransformerException {
 65  0
                 return writeNode(node, false);
 66  
         }
 67  
 
 68  
         public static String writeNode(org.w3c.dom.Node node, boolean indent) throws TransformerException {
 69  0
                 Source source = new DOMSource(node);
 70  0
                 StringWriter writer = new StringWriter();
 71  0
                 Result result = new StreamResult(writer);
 72  0
                 Transformer transformer = TransformerFactory.newInstance().newTransformer();
 73  0
                 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
 74  0
                 if (indent) {
 75  0
                         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
 76  
                 }
 77  0
                 transformer.transform(source, result);
 78  0
                 return writer.toString();
 79  
         }
 80  
         
 81  
 }