1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
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 | |
|
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 | |
|
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 | |
} |