Mercurial > dive4elements > river
changeset 8903:7de3837b204c
Minor changes to helper App so it works
author | gernotbelger |
---|---|
date | Thu, 22 Feb 2018 18:14:36 +0100 (2018-02-22) |
parents | be0220889e1f |
children | d9f2ce1d6bef |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java |
diffstat | 1 files changed, 38 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java Tue Feb 20 18:43:32 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java Thu Feb 22 18:14:36 2018 +0100 @@ -13,17 +13,19 @@ import java.io.IOException; import java.io.OutputStream; +import java.net.MalformedURLException; import java.io.File; import java.io.FileOutputStream; import org.dive4elements.river.backend.SessionFactoryProvider; import org.hibernate.Session; - +import org.slf4j.bridge.SLF4JBridgeHandler; import org.w3c.dom.Document; import org.apache.log4j.Logger; - +import org.apache.log4j.PropertyConfigurator; +import org.dive4elements.artifacts.common.utils.Config; import org.dive4elements.artifacts.common.utils.XMLUtils; import org.dive4elements.river.artifacts.datacage.Recommendations; @@ -32,6 +34,12 @@ { private static Logger log = Logger.getLogger(App.class); + /** + * The logging is done via Log4j. To configure the logging + * a file 'log4j.properties' is search in the configuration directory. + */ + private static final String LOG4J_PROPERTIES = "log4j.properties"; + public static final String template = System.getProperty("meta.data.template", "meta-data.xml"); @@ -58,8 +66,28 @@ return map; } + /** + * Trys to load the Log4j configuration from ${config.dir}/log4j.properties. + */ + private static final void configureLogging() { + File configDir = Config.getConfigDirectory(); + File propFile = new File(configDir, LOG4J_PROPERTIES); + + if (propFile.isFile() && propFile.canRead()) { + try { + PropertyConfigurator.configure(propFile.toURI().toURL()); + SLF4JBridgeHandler.install(); + } + catch (MalformedURLException mue) { + mue.printStackTrace(System.err); + } + } + } + public static void main(String [] args) { + configureLogging(); + Recommendations rec = Recommendations.createRecommendations( new File(template)); @@ -71,6 +99,9 @@ final Document result = XMLUtils.newDocument(); final Map<String, Object> parameters = getParameters(); + parameters.put("ARTIFACT-OUTS", new String[] { "LONGITUDINAL_SECTION" }); + parameters.put("PARAMETERS", parameters); + parameters.put("USER-ID", userId); Session session = SessionFactoryProvider .createSessionFactory() @@ -99,7 +130,12 @@ } try { + out.write('\n'); XMLUtils.toStream(result, out); + out.write('\n'); + } + catch (IOException e) { + log.error(e); } finally { if (OUTPUT != null) {