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 /bkucommon/src/main/java/at/gv | |
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 'bkucommon/src/main/java/at/gv')
3 files changed, 115 insertions, 5 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java index 0e7a7c0d..cc0ad0d3 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java @@ -21,12 +21,8 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - - package at.gv.egiz.bku.slcommands.impl; -import at.gv.egiz.idlink.IdentityLinkTransformer; - public class IdentityLinkInfoboxFactory extends AbstractInfoboxFactory { private IdentityLinkTransformer identityLinkTransformer; diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java index add7a3e1..b2643d8e 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java @@ -60,7 +60,6 @@ import at.gv.egiz.bku.slexceptions.SLCommandException; import at.gv.egiz.bku.slexceptions.SLExceptionMessages; import at.gv.egiz.bku.slexceptions.SLRuntimeException; import at.gv.egiz.idlink.CompressedIdentityLinkFactory; -import at.gv.egiz.idlink.IdentityLinkTransformer; import at.gv.egiz.idlink.ans1.IdentityLink; import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.STALRequest; diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkTransformer.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkTransformer.java new file mode 100644 index 00000000..e24e2f83 --- /dev/null +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkTransformer.java @@ -0,0 +1,115 @@ +/* + * Copyright 2011 by Graz University of Technology, Austria + * MOCCA has been developed by the E-Government Innovation Center EGIZ, a joint + * initiative of the Federal Chancellery Austria and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ + + +package at.gv.egiz.bku.slcommands.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.transform.Templates; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.configuration.Configuration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; + +import at.gv.egiz.bku.conf.MoccaConfigurationFacade; + +public class IdentityLinkTransformer extends at.gv.egiz.idlink.IdentityLinkTransformer implements ResourceLoaderAware { + + private final Logger log = LoggerFactory.getLogger(IdentityLinkTransformer.class); + + /** + * The configuration facade. + */ + protected final ConfigurationFacade configurationFacade = new ConfigurationFacade(); + + private class ConfigurationFacade implements MoccaConfigurationFacade { + + private Configuration configuration; + private ResourceLoader resLoader; + + private final String ISSUER_TEMPLATE_CACHE = + "IssuerTemplateCache"; + private final String ISSUER_TEMPLATE_CACHE_ENTRY = + ISSUER_TEMPLATE_CACHE + ".entry"; + private final String ISSUER_TEMPLATE_CACHE_URLS = + ISSUER_TEMPLATE_CACHE_ENTRY + ".url"; + private final String ISSUER_TEMPLATE_CACHE_RESOURCES = + ISSUER_TEMPLATE_CACHE_ENTRY + ".resource"; + + public Map<String, Templates> getIssuerTemplateCacheMap( + TransformerFactory factory) { + Map<String, Templates> templates = + Collections.synchronizedMap(new HashMap<String, Templates>()); + List<Object> urls = configuration.getList(ISSUER_TEMPLATE_CACHE_URLS); + List<Object> resources = configuration.getList(ISSUER_TEMPLATE_CACHE_RESOURCES); + if (!urls.isEmpty() && (urls.size() == resources.size())) { + for (int i = 0; i < urls.size(); ++i) { + if ((urls.get(i) == null) || (resources.get(i) == null)) + continue; + String url = urls.get(i).toString(); + String resource = resources.get(i).toString(); + Resource templRes = resLoader.getResource(resource); + try { + Templates template = factory.newTemplates(new StreamSource(templRes.getInputStream())); + templates.put(url, template); + } catch (Exception e) { + log.error("Error initializing issuer template cache", e); + } + } + } + return templates; + } + + public void setResourceLoader(ResourceLoader resLoader) { + this.resLoader = resLoader; + } + } + + @Override + protected Map<String, Templates> getInitialTemplateMap() { + Map<String, Templates> templateMap = configurationFacade.getIssuerTemplateCacheMap(factory); + log.debug("IssuerTemplate cache initialized with {} elements", templateMap.size()); + return templateMap; + } + + /** + * @param configuration the configuration to set + */ + public void setConfiguration(Configuration configuration) { + configurationFacade.configuration = configuration; + } + + @Override + public void setResourceLoader(ResourceLoader resLoader) { + configurationFacade.setResourceLoader(resLoader); + } +} |