# HG changeset patch # User Ingo Weinzierl # Date 1301568968 0 # Node ID 53c155bfde07acf9e18d6cc329f8d6f6d9c90121 # Parent e5e7af20885773ad23e1b4bdc918b4c32ca14184 Added code to parse the configured OutGenerators in the global configuration and to save a map of such in the FLYSContext. flys-artifacts/trunk@1633 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e5e7af208857 -r 53c155bfde07 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Mar 31 10:54:07 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Mar 31 10:56:08 2011 +0000 @@ -1,3 +1,12 @@ +2011-03-31 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java: + Added code to parse the configured OutGenerators and to save them (in a + map) in the FLYSContext. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java: + Added a key that is used to save the OutGenerators Map in the context. + 2011-03-31 Ingo Weinzierl * src/main/java/de/intevation/flys/exports/OutGenerator.java: diff -r e5e7af208857 -r 53c155bfde07 flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Thu Mar 31 10:54:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Thu Mar 31 10:56:08 2011 +0000 @@ -25,6 +25,11 @@ public static final String STATE_ENGINE_KEY = "artifact.state.engine"; + /** The key that is used to store the Map of OutGenerator classes in the + * context.*/ + public static final String OUTGENERATORS_KEY = + "flys.export.outgenerators"; + /** * The default constructor. diff -r e5e7af208857 -r 53c155bfde07 flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Mar 31 10:54:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Mar 31 10:56:08 2011 +0000 @@ -2,7 +2,9 @@ import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.xml.xpath.XPathConstants; @@ -10,6 +12,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.w3c.dom.NodeList; import de.intevation.artifacts.ArtifactContextFactory; @@ -55,6 +58,9 @@ public static final String XPATH_STATES = "/artifact/states/state"; + public static final String XPATH_OUTPUT_GENERATORS = + "/artifact-database/output-generators/output-generator"; + /** * Creates a new FLYSArtifactContext object and initialize all * components required by the application. @@ -67,6 +73,7 @@ configureTransitions(config, context); configureStates(config, context); + configureOutGenerators(config, context); return context; } @@ -186,5 +193,58 @@ context.put(FLYSContext.STATE_ENGINE_KEY, engine); } + + + /** + * This method intializes the provided output generators. + * + * @param config the config document. + * @param context the FLYSContext. + */ + protected void configureOutGenerators(Document config, FLYSContext context){ + Map generators = new HashMap(); + + NodeList outGenerators = (NodeList) XMLUtils.xpath( + config, + XPATH_OUTPUT_GENERATORS, + XPathConstants.NODESET); + + int num = outGenerators == null ? 0 : outGenerators.getLength(); + + if (num == 0) { + logger.warn("No output generators configured in this application."); + return; + } + + logger.info("Found " + num + " configured output generators."); + + int idx = 0; + + for (int i = 0; i < num; i++) { + Node item = outGenerators.item(i); + + String name = (String) XMLUtils.xpath( + item, "@name", XPathConstants.STRING); + + String clazz = (String) XMLUtils.xpath( + item, "text()", XPathConstants.STRING); + + if (name == null || clazz == null) { + continue; + } + + try { + generators.put(name, Class.forName(clazz)); + + idx++; + } + catch (ClassNotFoundException cnfe) { + logger.warn(cnfe, cnfe); + } + } + + logger.info("Successfully loaded " + idx + " output generators."); + context.put(FLYSContext.OUTGENERATORS_KEY, generators); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :