Skip to content

Commit 56e2a2d

Browse files
committed
#172 static TFACTORY
1 parent 33d8b82 commit 56e2a2d

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

src/main/java/com/jcabi/xml/XMLDocument.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import javax.xml.xpath.XPathConstants;
6060
import javax.xml.xpath.XPathExpressionException;
6161
import javax.xml.xpath.XPathFactory;
62-
import lombok.EqualsAndHashCode;
6362
import org.w3c.dom.Document;
6463
import org.w3c.dom.Node;
6564
import org.w3c.dom.NodeList;

src/main/java/com/jcabi/xml/XSLDocument.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public final class XSLDocument implements XSL {
112112
private static final DocumentBuilderFactory DFACTORY =
113113
DocumentBuilderFactory.newInstance();
114114

115+
/**
116+
* Transformer factory.
117+
*/
118+
private static final TransformerFactory TFACTORY =
119+
TransformerFactory.newInstance();
120+
115121
/**
116122
* XSL document.
117123
*/
@@ -411,24 +417,22 @@ private void transformInto(final XML xml, final Result result) {
411417
* @return The transformer
412418
*/
413419
private Transformer transformer() {
414-
final TransformerFactory factory;
415-
synchronized (XSLDocument.class) {
416-
factory = TransformerFactory.newInstance();
417-
}
418-
factory.setURIResolver(this.sources);
419420
final Transformer trans;
420-
try {
421-
trans = factory.newTransformer(
422-
new StreamSource(new StringReader(this.xsl), this.sid)
423-
);
424-
} catch (final TransformerConfigurationException ex) {
425-
throw new IllegalArgumentException(
426-
String.format(
427-
"Failed to create transformer by %s",
428-
factory.getClass().getName()
429-
),
430-
ex
431-
);
421+
synchronized (XSLDocument.TFACTORY) {
422+
XSLDocument.TFACTORY.setURIResolver(this.sources);
423+
try {
424+
trans = XSLDocument.TFACTORY.newTransformer(
425+
new StreamSource(new StringReader(this.xsl), this.sid)
426+
);
427+
} catch (final TransformerConfigurationException ex) {
428+
throw new IllegalArgumentException(
429+
String.format(
430+
"Failed to create transformer by %s",
431+
XSLDocument.TFACTORY.getClass().getName()
432+
),
433+
ex
434+
);
435+
}
432436
}
433437
XSLDocument.prepare(trans);
434438
for (final Map.Entry<String, Object> ent : this.params.entrySet()) {

0 commit comments

Comments
 (0)