Revision 46232
Added by Alessia Bardi about 7 years ago
XMLIndenter.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
private static final Log log = LogFactory.getLog(XMLIndenter.class); |
28 | 28 |
|
29 |
// /** |
|
30 |
// * Static helper Apply. |
|
31 |
// * |
|
32 |
// * @param xml the xml |
|
33 |
// * @return the indented xml string |
|
34 |
// */ |
|
35 |
// public static String indent(final String xml) { |
|
36 |
// return new XMLIndenter().apply(xml); |
|
37 |
// } |
|
38 |
// |
|
39 |
// public static String indent(final Document document) throws Exception { |
|
40 |
// return new XMLIndenter().doIndent(document); |
|
41 |
// } |
|
29 |
private TransformerFactory transformerFactory; |
|
42 | 30 |
|
31 |
//Need also default constructor, otherwise: Exception thrown in method 'update' of class [eu.dnetlib.xml.database.exist.PersistentExistDatabase] |
|
32 |
//java.lang.NoSuchMethodError: eu.dnetlib.miscutils.functional.xml.XMLIndenter: method <init>()V not found |
|
33 |
public XMLIndenter(){ |
|
34 |
this.transformerFactory = TransformerFactory.newInstance(); |
|
35 |
} |
|
36 |
|
|
37 |
public XMLIndenter(final TransformerFactory tf){ |
|
38 |
this.transformerFactory = tf; |
|
39 |
} |
|
40 |
|
|
43 | 41 |
public String indent(final Document document) throws Exception { |
44 | 42 |
return doIndent(document); |
45 | 43 |
} |
... | ... | |
73 | 71 |
|
74 | 72 |
private String doIndent(final Document document) throws Exception { |
75 | 73 |
|
76 |
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
|
74 |
Transformer transformer = transformerFactory.newTransformer();
|
|
77 | 75 |
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
78 | 76 |
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes"); |
79 | 77 |
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); |
Also available in: Unified diff
Changes for Saxon-HE