diff options
author | tkellner <tkellner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2014-03-03 20:16:40 +0000 |
---|---|---|
committer | tkellner <tkellner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2014-03-03 20:16:40 +0000 |
commit | 54d3297738cac7c693bdf53094194054782de890 (patch) | |
tree | 2fbe3511f904ed86d0f8c204ef39fe6e3353d207 /utils/src/main/java/at | |
parent | 4163572db6a360e676d2f15c6955eee1bc2ec22c (diff) | |
download | mocca-54d3297738cac7c693bdf53094194054782de890.tar.gz mocca-54d3297738cac7c693bdf53094194054782de890.tar.bz2 mocca-54d3297738cac7c693bdf53094194054782de890.zip |
Allow to initialize IssuerTemplate cache via config
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1302 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'utils/src/main/java/at')
-rw-r--r-- | utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java | 43 |
1 files changed, 20 insertions, 23 deletions
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 153c6d53..af60500a 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java +++ b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java @@ -27,8 +27,6 @@ package at.gv.egiz.idlink; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import javax.xml.transform.Result; @@ -52,20 +50,27 @@ import org.w3c.dom.Text; import at.gv.egiz.bku.utils.urldereferencer.StreamData; import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; -public class IdentityLinkTransformer { - +public abstract class IdentityLinkTransformer { + private final Logger log = LoggerFactory.getLogger(IdentityLinkTransformer.class); /** * The transformer factory. */ - private TransformerFactory factory = SAXTransformerFactory.newInstance(); + protected TransformerFactory factory = SAXTransformerFactory.newInstance(); /** * The URLDereferencer used to dereference style-sheet URLs. */ private URLDereferencer urlDereferencer; - + + /** + * Mapping of issuer template URIs to transformation templates. + */ + private Map<String, Templates> templates = null; + + protected abstract Map<String, Templates> getInitialTemplateMap(); + /** * @return the urlDereferencer */ @@ -102,7 +107,6 @@ public class IdentityLinkTransformer { * @throws NullPointerException if <code>idLink</code> is <code>null</code>. */ public static void setDomainIdentifier(Node idLink, String domainIdentifier) { - Element element; if (idLink instanceof Element) { element = (Element) idLink; @@ -114,7 +118,7 @@ public class IdentityLinkTransformer { } else { throw new NullPointerException("Parameter 'idLink' must no be null."); } - + NodeList nodeList = element.getElementsByTagNameNS( "http://reference.e-government.gv.at/namespace/persondata/20020228#", "Type"); @@ -132,12 +136,7 @@ public class IdentityLinkTransformer { } } - - /** - * Mapping of issuer template URIs to transformation templates. - */ - private Map<String, Templates> templates = Collections.synchronizedMap(new HashMap<String, Templates>()); - + /** * Transforms an identity link <code>source</code> to <code>result</code> with * the given issuer template from the <code>stylesheetURL</code>. @@ -161,32 +160,30 @@ public class IdentityLinkTransformer { * if transforming the identity link fails. */ public void transformIdLink(String stylesheetURL, Source source, Result result) throws IOException, TransformerException { + if (templates == null) + templates = getInitialTemplateMap(); Templates templ = templates.get(stylesheetURL); - - if (templ == null) { + if (templ == null) { // TODO: implement stylesheet cache URL url = new URL(stylesheetURL); if (!"http".equalsIgnoreCase(url.getProtocol()) && !"https".equalsIgnoreCase(url.getProtocol())) { throw new MalformedURLException("Protocol " + url.getProtocol() + " not supported for IssuerTemplate URL."); } - + StreamData data = urlDereferencer.dereference(url.toExternalForm()); - + log.trace("Trying to create issuer template."); templ = factory.newTemplates(new StreamSource(data.getStream())); log.trace("Successfully created issuer template"); templates.put(stylesheetURL, templ); - } - + Transformer transformer = templ.newTransformer(); - transformer.transform(source, result); - + } - } |