Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java @ 957:e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
flys-artifacts/trunk@2376 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 20 Jul 2011 14:59:25 +0000 |
parents | 22bc87a42a0d |
children | a63d79107289 |
line wrap: on
line source
package de.intevation.flys.artifacts.services; import java.sql.Connection; import java.sql.SQLException; import org.w3c.dom.Document; import org.apache.log4j.Logger; import java.util.Map; import java.util.HashMap; import de.intevation.artifacts.CallMeta; import de.intevation.artifactdatabase.DefaultService; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.common.ArtifactNamespaceContext; import de.intevation.flys.artifacts.services.meta.Builder; import de.intevation.flys.artifacts.services.meta.DataCage; import de.intevation.flys.backend.SessionHolder; import org.hibernate.Session; import org.hibernate.jdbc.Work; public class MetaDataService extends DefaultService { private static Logger log = Logger.getLogger(MetaDataService.class); public static final String XPATH_RIVER = "/art:river/text()"; public MetaDataService() { } protected static Map<String, Object> extractParameters(Document data) { HashMap<String, Object> parameters = new HashMap<String, Object>(); String river = XMLUtils.xpathString( data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE); if (river == null || (river = river.trim()).length() == 0) { river = "%"; // matches all rivers } parameters.put("river", river); return parameters; } @Override public Document process( Document data, Object globalContext, CallMeta callMeta ) { log.debug("MetaDataService.process"); final Document result = XMLUtils.newDocument(); final Builder builder = DataCage.getInstance().getBuilder(); if (builder == null) { log.error("MetaDataService is not setup properly."); return result; } final Map<String, Object> parameters = extractParameters(data); Session session = SessionHolder.acquire(); try { session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { log.debug("MetaDataService.execute"); builder.build(connection, result, parameters); } }); } finally { session.close(); SessionHolder.release(); } return result; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :