Changeset 22300 for other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraCommons.java
- Timestamp:
- 2010-06-24T13:45:34+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraCommons.java
r15222 r22300 88 88 } 89 89 90 /** Given a n Element, this will return its String representation properly90 /** Given a DOM node, this will return its String representation properly 91 91 * indented for display. 92 * @return a string representation of e, formatted for display.93 * @param e is the elementto be converted to its string representation.92 * @return a string representation of n, formatted for display. 93 * @param n is the DOM node to be converted to its string representation. 94 94 */ 95 public static String elementToFormattedString(Element e) 96 throws TransformerException 95 public static String displayAsString(Node n) 97 96 { 98 DOMSource domSource = new DOMSource(e); 99 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 100 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 101 //transformer.setOutputProperty(OutputKeys.METHOD, "xml"); 102 //transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); 103 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 104 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 97 try { 98 99 DOMSource domSource = new DOMSource(n); 100 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 101 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 102 //transformer.setOutputProperty(OutputKeys.METHOD, "xml"); 103 //transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); 104 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 105 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 106 107 StringWriter sw = new StringWriter(); 108 transformer.transform(domSource, new StreamResult(sw)); 109 return sw.toString(); 110 } catch(Exception e) { 111 System.err.println("Couldn't display node as String."); 112 return ""; 113 } 114 115 } 105 116 106 StringWriter sw = new StringWriter(); 107 transformer.transform(domSource, new StreamResult(sw)); 108 return sw.toString(); 109 } 117 110 118 }
Note:
See TracChangeset
for help on using the changeset viewer.