# HG changeset patch # User Felix Wolfsteller # Date 1320397182 0 # Node ID 9562ca537143c7918571644a80fe4920f1e0f2f9 # Parent 03f129fa02560b3d739b7d854bc46672e6edc13f Added new optional condition for theme-mappings: the output name. flys-artifacts/trunk@3158 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 03f129fa0256 -r 9562ca537143 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Nov 04 08:52:33 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Nov 04 08:59:42 2011 +0000 @@ -1,3 +1,22 @@ +2011-11-04 Felix Wolfsteller + + Added new matching condition for theme-mappings: the name of + the output. + + * src/main/java/de/intevation/flys/themes/ThemeMapping.java: + Added output field and function to match it against a given + output name. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java: + Createing ThemeMapping with output attribute from configuration. + + * src/main/java/de/intevation/flys/themes/ThemeFactory.java: + (getTheme(FLYSContext, string)): Removed, never called. + (getTheme): Added outputName argument, match it. + + * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Pass outputs name until it can be matched against mapping. + 2011-11-04 Felix Wolfsteller * doc/conf/themes.xml: Added default themes for other.w(q)kms. diff -r 03f129fa0256 -r 9562ca537143 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 Fri Nov 04 08:52:33 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Fri Nov 04 08:59:42 2011 +0000 @@ -363,6 +363,9 @@ String masterAttrPattern = (String) XMLUtils.xpath( node, "@masterAttr", XPathConstants.STRING); + String outputPattern = (String) XMLUtils.xpath( + node, "@output", XPathConstants.STRING); + if (from != null && to != null) { List tm = mapping.get(from); @@ -372,7 +375,7 @@ } tm.add(new ThemeMapping( - from, to, pattern, masterAttrPattern)); + from, to, pattern, masterAttrPattern, outputPattern)); } } diff -r 03f129fa0256 -r 9562ca537143 flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java --- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Fri Nov 04 08:52:33 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Fri Nov 04 08:59:42 2011 +0000 @@ -525,7 +525,7 @@ Document attr = db.getCollectionItemAttribute(identifier(), uuid, meta); if (attr == null) { - attr = initItemAttribute(uuid, facet, pattern, index, context); + attr = initItemAttribute(uuid, facet, pattern, index, outName, context); if (attr == null) { return null; @@ -557,7 +557,8 @@ if (theme == null) { log.warn("Could not find the theme in attribute of: " + uuid); - Theme t = getThemeForFacet(uuid, facet, pattern, index, context); + Theme t = getThemeForFacet( + uuid, facet, pattern, index, outName, context); if (t == null) { log.warn("No theme found for facet: " + facet); @@ -565,7 +566,7 @@ } addThemeToAttribute(uuid, attr, t, context); - theme = t.toXML().getFirstChild(); + theme = t.toXML().getFirstChild(); } Document doc = XMLUtils.newDocument(); @@ -652,11 +653,12 @@ String facet, String pattern, int index, + String outName, CallContext context) { log.info("FLYSArtifactCollection.initItemAttribute"); - Theme t = getThemeForFacet(uuid, facet, pattern, index, context); + Theme t = getThemeForFacet(uuid, facet, pattern, index, outName, context); if (t == null) { log.info("Could not find theme for facet. Cancel initialization."); @@ -715,6 +717,7 @@ String facet, String pattern, int index, + String outName, CallContext context) { log.info("FLYSArtifactCollection.getThemeForFacet: " + facet); @@ -734,7 +737,7 @@ log.error("Exception caught when trying to get art.", e); } - Theme t = ThemeFactory.getTheme(flysContext, facet, pattern); + Theme t = ThemeFactory.getTheme(flysContext, facet, pattern, outName); if (t != null) { t.setFacet(facet); diff -r 03f129fa0256 -r 9562ca537143 flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java --- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java Fri Nov 04 08:52:33 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java Fri Nov 04 08:59:42 2011 +0000 @@ -59,29 +59,21 @@ /** - * Returns the theme for a specified output type and facet. - * - * @param c The FLYSContext that stores the mappings and themes. - * @param name The name of the mapping. - * - * @return a theme. - */ - public static Theme getTheme(FLYSContext c, String name) { - return getTheme(c, name, null); - } - - - /** * Get first matching theme for facet. * - * @param name Name to match "from" of theme mapping. + * @param name Name to match "from" of theme mapping. * @param pattern String to 'compare' to pattern in mapping. + * @param output Name of the current output * * @return First matching theme. */ - public static Theme getTheme(FLYSContext c, String name, String pattern) { - - logger.debug("Search theme for: " + name + " - " + pattern); + public static Theme getTheme( + FLYSContext c, + String name, + String pattern, + String output) + { + logger.debug("Search theme for: " + name + " - pattern: " + pattern); if (c == null || name == null) { logger.warn("Cannot search for theme."); @@ -113,7 +105,8 @@ for (ThemeMapping tm: mapping) { if (name.equals(tm.getFrom()) && tm.applyPattern(pattern) - && tm.masterAttrMatches(artifact)) + && tm.masterAttrMatches(artifact) + && tm.outputMatches(output)) { return t.get(tm.getTo()); } @@ -121,7 +114,7 @@ String msg = "No theme found for '" + name + - "' with pattern '" + pattern + "'."; + "' with pattern '" + pattern + "' and output " + output + "."; logger.warn(msg); diff -r 03f129fa0256 -r 9562ca537143 flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeMapping.java --- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeMapping.java Fri Nov 04 08:52:33 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeMapping.java Fri Nov 04 08:59:42 2011 +0000 @@ -28,11 +28,14 @@ /** Given masterAttr pattern (held against masterartifacts attributes). */ protected String masterAttr; + /** Given output for which mapping is valid. */ + protected String output; + protected Pattern pattern; public ThemeMapping(String from, String to) { - this(from, to, null, null); + this(from, to, null, null, null); } @@ -40,12 +43,14 @@ String from, String to, String patternStr, - String masterAttr) + String masterAttr, + String output) { this.from = from; this.to = to; this.patternStr = patternStr; this.masterAttr = masterAttr; + this.output = output; this.pattern = Pattern.compile(patternStr); } @@ -113,5 +118,18 @@ // Test. return artifact.getDataAsString(parts[0]).equals(parts[1]); } + + + /** + * Returns true if no output condition exists, or the condition is met + * in parameter output. + */ + public boolean outputMatches(String output) { + if (this.output == null || this.output.equals("")) { + return true; + } + + return this.output.equals(output); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :