# HG changeset patch # User Ingo Weinzierl # Date 1333610518 0 # Node ID 27cc95e65f18faadbd036f37d7da233b00eb1ec7 # Parent b0597a63fe705b57a6e23488cb95888b4a7284da Defined a style for WSPLGEN layers which are now modifiable. flys-artifacts/trunk@4200 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b0597a63fe70 -r 27cc95e65f18 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Apr 05 07:21:58 2012 +0000 @@ -1,3 +1,19 @@ +2012-04-05 Ingo Weinzierl + + * doc/conf/themes.xml: Defined a theme for WSPLGEN layers. + + * src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java: + Made style creation more robust against nullpointers and added an + Expression class. + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: Added a static + method createWSPLGENStyle() and some helpers to create a WSPLGEN style. + + * src/main/java/de/intevation/flys/exports/MapGenerator.java, + src/main/java/de/intevation/flys/utils/MapfileGenerator.java: Methods + for creating the WSPLGEN layer now take a style document. + + 2012-04-04 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java: diff -r b0597a63fe70 -r 27cc95e65f18 flys-artifacts/doc/conf/themes.xml --- a/flys-artifacts/doc/conf/themes.xml Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/doc/conf/themes.xml Thu Apr 05 07:21:58 2012 +0000 @@ -840,6 +840,16 @@ + + + + + + + + + + @@ -1002,6 +1012,7 @@ + diff -r b0597a63fe70 -r 27cc95e65f18 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java Thu Apr 05 07:21:58 2012 +0000 @@ -31,7 +31,7 @@ item.toString(sb); } - sb.append("END"); + sb.append("END\n"); return sb.toString(); } @@ -68,7 +68,10 @@ public void toString(StringBuilder sb) { sb.append("STYLE\n"); sb.append("WIDTH " + String.valueOf(size) + "\n"); - sb.append("OUTLINECOLOR " + outlinecolor + "\n"); + + if (outlinecolor != null) { + sb.append("OUTLINECOLOR " + outlinecolor + "\n"); + } if (color != null) { sb.append("COLOR " + color + "\n"); @@ -108,6 +111,20 @@ } } + public static class Expression implements ClazzItem { + protected String value; + + public Expression(String value) { + this.value = value; + } + + @Override + public void toString(StringBuilder sb) { + sb.append("EXPRESSION " + value); + sb.append("\n"); + } + } + protected List classes; diff -r b0597a63fe70 -r 27cc95e65f18 flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Thu Apr 05 07:21:58 2012 +0000 @@ -104,7 +104,7 @@ if (FLOODMAP_WSPLGEN.equals(name)) { setInitialExtent(extent); - createWSPLGENLayer(flys, wms); + createWSPLGENLayer(flys, wms, attr); } else if (FLOODMAP_BARRIERS.equals(name)) { createBarriersLayer(flys, wms); @@ -119,10 +119,17 @@ } - protected void createWSPLGENLayer(FLYSArtifact flys, WMSLayerFacet wms) { + protected void createWSPLGENLayer( + FLYSArtifact flys, + WMSLayerFacet wms, + Document attr + ) { try { MapfileGenerator mfg = MapfileGenerator.getInstance(); - mfg.createUeskLayer(flys, wms); + mfg.createUeskLayer( + flys, + wms, + ThemeUtil.createWSPLGENStyle(attr)); } catch (IOException ioe) { logger.error(ioe, ioe); diff -r b0597a63fe70 -r 27cc95e65f18 flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Thu Apr 05 07:21:58 2012 +0000 @@ -364,8 +364,11 @@ * @param flys The FLYSArtifact that owns wms. * @param wms The WMSLayerFacet that contains information for the layer. */ - public void createUeskLayer(FLYSArtifact flys, WMSLayerFacet wms) - throws FileNotFoundException, IOException + public void createUeskLayer( + FLYSArtifact flys, + WMSLayerFacet wms, + String style + ) throws FileNotFoundException, IOException { logger.debug("createUeskLayer"); @@ -375,6 +378,7 @@ layerinfo.setDirectory(flys.identifier()); layerinfo.setData(WSPLGEN_RESULT_SHAPE); layerinfo.setTitle("I18N_WSPLGEN_RESULT"); + layerinfo.setStyle(style); String name = MS_LAYER_PREFIX + wms.getName(); diff -r b0597a63fe70 -r 27cc95e65f18 flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Thu Apr 05 07:21:58 2012 +0000 @@ -5,12 +5,17 @@ import java.awt.Color; import java.awt.Font; +import javax.xml.xpath.XPathConstants; + import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.model.MapserverStyle; import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; +import de.intevation.flys.artifacts.model.MapserverStyle.Expression; import de.intevation.flys.artifacts.model.MapserverStyle.Style; import de.intevation.flys.artifacts.model.MapserverStyle.Label; @@ -80,6 +85,9 @@ public final static String XPATH_SHOW_MAXIMUM = "/theme/field[@name='showmaximum']/@default"; + public final static String XPATH_WSPLGEN_FIELDS = + "/theme[@name='WSPLGEN']/field"; + /** Parse string to be boolean with default if empty or unrecognized. */ public static boolean parseBoolean(String value, boolean defaultsTo) { @@ -404,6 +412,62 @@ } + public static String createWSPLGENStyle(Document theme) { + NodeList categories = (NodeList) XMLUtils.xpath( + theme, + XPATH_WSPLGEN_FIELDS, + XPathConstants.NODESET); + + return createWSPLGENStyle(categories).toString(); + } + + protected static MapserverStyle createWSPLGENStyle(NodeList categories) { + MapserverStyle ms = new MapserverStyle(); + + for (int i = 0, n = categories.getLength(); i < n; i++) { + Element cat = (Element) categories.item(i); + String color = cat.getAttribute("default"); + String name = cat.getAttribute("name"); + + String expr; + + try { + int length = name.length(); + int idx = Integer.valueOf(name.substring(length-1, length)); + + expr = createWSPLGENExpression(idx); + } + catch (NumberFormatException nfe) { + logger.warn("Error while parsing WSPLGEN category.", nfe); + continue; + } + + Clazz c = new Clazz(expr); + Style s = new Style(); + s.setColor(color.replace(",", "")); + s.setSize(5); + + c.addItem(new Expression("(" + expr + ")")); + c.addItem(s); + + ms.addClazz(c); + } + + return ms; + } + + + protected static String createWSPLGENExpression(int idx) { + if (idx < 5) { + int lower = idx - 1; + return "[DIFF] >= " + lower + " AND [DIFF] < " + idx; + } + else { + return "[DIFF] >= 4"; + } + } + + public static String createMapserverStyle(Document theme) { String symbol = getSymbol(theme); String backcolor = getBackgroundColorString(theme);