@@ -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