From 81eb1e485a03a6bd1efb726892631ab037d59fdb Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 24 Sep 2008 14:04:18 +0000 Subject: Modified IdentityLinkTransformer to use cached Templates instead of cached Transformers. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@67 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/idlink/IdentityLinkTransformer.java | 58 +++++++++++----------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'utils/src/main') diff --git a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java index 7886b07d..060ccef5 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java +++ b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java @@ -16,29 +16,30 @@ */ package at.gv.egiz.idlink; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stream.StreamSource; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.stream.StreamSource; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; public class IdentityLinkTransformer { @@ -77,7 +78,7 @@ public class IdentityLinkTransformer { /** * The stylesheet transformer. */ - private Transformer transformer; + private Templates templates; /** * Stylesheet URL. @@ -103,7 +104,7 @@ public class IdentityLinkTransformer { } StreamSource source = new StreamSource(url.openStream()); - transformer = factory.newTransformer(source); + templates = factory.newTemplates(source); initTime = System.currentTimeMillis() - created; @@ -111,7 +112,8 @@ public class IdentityLinkTransformer { public void transform(Source xmlSource, Result outputTarget) throws TransformerException { long t0 = System.currentTimeMillis(); - try { + try { + Transformer transformer = templates.newTransformer(); transformer.transform(xmlSource, outputTarget); } catch (TransformerException e) { throw e; @@ -146,7 +148,7 @@ public class IdentityLinkTransformer { /** * The transfomer factory. */ - private static TransformerFactory factory; + private static SAXTransformerFactory factory; /** * The instance to be returned by {@link #getInstance()}. @@ -161,7 +163,7 @@ public class IdentityLinkTransformer { public static IdentityLinkTransformer getInstance() { if (instance == null) { instance = new IdentityLinkTransformer(); - factory = TransformerFactory.newInstance(); + factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); } return instance; } -- cgit v1.2.3