Skip to content

Commit 46c629a

Browse files
committed
Merge Hibernate Tools into ORM : Fix failing test on Oracle and Graal platforms
1 parent ac62e34 commit 46c629a

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

tooling/hibernate-reveng/src/main/java/org/hibernate/tool/reveng/internal/xml/AbstractXMLPrettyPrinterStrategy.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
import javax.xml.xpath.XPathFactory;
2020
import java.io.ByteArrayInputStream;
2121
import java.io.IOException;
22+
import java.util.logging.Logger;
2223

2324
public abstract class AbstractXMLPrettyPrinterStrategy implements XMLPrettyPrinterStrategy {
2425

25-
protected Document newDocument(String xml, String encoding) throws SAXException, IOException, ParserConfigurationException {
26-
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
27-
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
28-
final Document document = dbf
26+
private static final Logger LOGGER = Logger.getLogger( AbstractXMLPrettyPrinterStrategy.class.getName() );
27+
private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = createDocumentBuilderFactory();
28+
29+
public Document newDocument(String xml, String encoding) throws SAXException, IOException, ParserConfigurationException {
30+
final Document document = DOCUMENT_BUILDER_FACTORY
2931
.newDocumentBuilder()
3032
.parse(new InputSource(new ByteArrayInputStream(xml.getBytes(encoding))));
3133
document.normalize();
@@ -43,4 +45,22 @@ protected void removeWhitespace(final Document document) throws XPathExpressionE
4345
node.getParentNode().removeChild(node);
4446
}
4547
}
48+
49+
private static DocumentBuilderFactory createDocumentBuilderFactory() {
50+
DocumentBuilderFactory result = null;
51+
try {
52+
result = DocumentBuilderFactory.newInstance(
53+
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl",
54+
null);
55+
result.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
56+
}
57+
catch (ParserConfigurationException e) {
58+
LOGGER.severe(
59+
"A ParserConfigurationException happened while setting the " +
60+
"'http://apache.org/xml/features/nonvalidating/load-external-dtd' feature" +
61+
"to false." );
62+
throw new RuntimeException(e);
63+
}
64+
return result;
65+
}
4666
}

tooling/hibernate-reveng/src/main/java/org/hibernate/tool/reveng/internal/xml/TrAXPrettyPrinterStrategy.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
import javax.xml.transform.dom.DOMSource;
1515
import javax.xml.transform.stream.StreamResult;
1616
import java.io.StringWriter;
17+
import java.util.logging.Logger;
1718

1819
public class TrAXPrettyPrinterStrategy extends AbstractXMLPrettyPrinterStrategy {
20+
21+
private static final Logger LOGGER = Logger.getLogger( TrAXPrettyPrinterStrategy.class.getName() );
22+
private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(
23+
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl",
24+
null);
25+
1926
private int indent = 4;
2027
private boolean omitXmlDeclaration;
2128

@@ -32,17 +39,18 @@ public String prettyPrint(String xml) throws Exception {
3239
}
3340

3441
protected Transformer newTransformer(final Document document) throws TransformerConfigurationException {
35-
final TransformerFactory transformerFactory = newTransformerFactory();
3642

37-
final Transformer transformer = transformerFactory.newTransformer();
43+
final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
3844
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
3945
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
4046
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
4147
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, isOmitXmlDeclaration() ? "yes" : "no");
4248
try {
4349
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(getIndent()));
4450
}
45-
catch (IllegalArgumentException ignored) {
51+
catch (IllegalArgumentException e) {
52+
LOGGER.severe( "An IllegalArgumentException happened while adding the 'indent' property." );
53+
throw new RuntimeException(e);
4654
}
4755

4856
final DocumentType doctype = document.getDoctype();
@@ -54,17 +62,6 @@ protected Transformer newTransformer(final Document document) throws Transformer
5462
return transformer;
5563
}
5664

57-
protected TransformerFactory newTransformerFactory() {
58-
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
59-
try {
60-
transformerFactory.setAttribute("indent-number", getIndent());
61-
}
62-
catch (IllegalArgumentException ignored) {
63-
}
64-
65-
return transformerFactory;
66-
}
67-
6865
public int getIndent() {
6966
return indent;
7067
}
@@ -80,4 +77,5 @@ public boolean isOmitXmlDeclaration() {
8077
public void setOmitXmlDeclaration(boolean omitXmlDeclaration) {
8178
this.omitXmlDeclaration = omitXmlDeclaration;
8279
}
80+
8381
}

0 commit comments

Comments
 (0)