Mercurial > dive4elements > river
changeset 1994:3e703d134bbe
Parse the Settings of each Output during Collection's describe() operation.
flys-artifacts/trunk@3431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 09:56:32 +0000 |
parents | 85132c9edd64 |
children | f114c0d55d19 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java |
diffstat | 3 files changed, 148 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Dec 16 09:19:11 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Dec 16 09:56:32 2011 +0000 @@ -1,3 +1,11 @@ +2011-12-16 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/ChartSettings.java: Added new + functions that allow parsing a ChartSettings object from DOM Node. + + * src/main/java/de/intevation/flys/collections/AttributeParser.java: Parse + the Settings of each Output. + 2011-12-16 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/collections/CollectionAttribute.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java Fri Dec 16 09:19:11 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java Fri Dec 16 09:56:32 2011 +0000 @@ -17,10 +17,12 @@ import de.intevation.artifactdatabase.state.DefaultOutput; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.Output; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.model.ManagedDomFacet; +import de.intevation.flys.exports.ChartSettings; /** * Access parts of the Attribute parts of a FLYSCollections description @@ -115,10 +117,27 @@ attribute.addOutput(name, o); } + parseSettings(out, name); parseItems(out, name); } + protected void parseSettings(Node out, String outname) { + Node settingsNode = (Node) XMLUtils.xpath( + out, "settings", + XPathConstants.NODE, + null); + + if (settingsNode == null) { + logger.debug("No Settings found for Output '" + outname + "'"); + return; + } + + Settings settings = ChartSettings.parse(settingsNode); + attribute.setSettings(outname, settings); + } + + protected void parseItems(Node out, String outname) { NodeList themes = (NodeList) XMLUtils.xpath( out, "art:facet",
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Fri Dec 16 09:19:11 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Fri Dec 16 09:56:32 2011 +0000 @@ -1,5 +1,14 @@ package de.intevation.flys.exports; +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.XMLUtils; + import de.intevation.artifactdatabase.state.DefaultSection; import de.intevation.artifactdatabase.state.DefaultSettings; import de.intevation.artifactdatabase.state.Section; @@ -10,6 +19,8 @@ */ public class ChartSettings extends DefaultSettings { + private static final Logger logger = Logger.getLogger(ChartSettings.class); + protected Section chartSection; protected Section legendSection; protected Section axesSection; @@ -88,5 +99,115 @@ axesSection.addSubsection(axisSection); } } + + + /** + * Parses the settings from <i>settings</i>. The result is a new + * ChartSettings instance. + * + * @param settings A <i>settings</i> node. + * + * @return a new <i>ChartSettings</i> instance. + */ + public static ChartSettings parse(Node settings) { + if (settings == null) { + logger.warn("Tried to parse ChartSettings from empty Node!"); + return null; + } + + ChartSettings chartSettings = new ChartSettings(); + + parseAxes(chartSettings, settings); + parseChart(chartSettings, settings); + parseLegend(chartSettings, settings); + + return chartSettings; + } + + + protected static void parseAxes(ChartSettings target, Node settings) { + NodeList axesList = (NodeList) XMLUtils.xpath( + settings, "axes/axis", XPathConstants.NODESET, null); + + int num = axesList != null ? axesList.getLength() : 0; + + if (num <= 0) { + logger.debug("No axis sections found."); + return; + } + + for (int i = 0; i < num; i++) { + parseAxis(target, axesList.item(i)); + } + } + + + protected static void parseAxis(ChartSettings target, Node axis) { + AxisSection section = new AxisSection(); + + String id = XMLUtils.xpathString(axis, "id", null); + String label = XMLUtils.xpathString(axis, "label", null); + String fSize = XMLUtils.xpathString(axis, "font-size", null); + String fixation = XMLUtils.xpathString(axis, "fixation", null); + String low = XMLUtils.xpathString(axis, "lower", null); + String up = XMLUtils.xpathString(axis, "upper", null); + + if (logger.isDebugEnabled()) { + logger.debug("Fount axis id: '" + id + "'"); + logger.debug("Fount axis label: '" + label + "'"); + logger.debug("Fount axis font size: '" + fSize + "'"); + logger.debug("Fount axis fixation: '" + fixation + "'"); + logger.debug("Fount axis lower: '" + low + "'"); + logger.debug("Fount axis upper: '" + up + "'"); + } + + section.setIdentifier(id); + section.setLabel(label); + section.setFontSize(Integer.valueOf(fSize.length() > 0 ? fSize : "-1")); + section.setFixed(Boolean.valueOf(fixation)); + section.setLowerRange(Double.valueOf(low.length() > 0 ? low : "0")); + section.setUpperRange(Double.valueOf(up.length() > 0 ? up : "0")); + + target.addAxisSection(section); + } + + + protected static void parseChart(ChartSettings target, Node chart) { + ChartSection chartSection = new ChartSection(); + + String title = XMLUtils.xpathString(chart, "chart/title", null); + String sub = XMLUtils.xpathString(chart, "chart/subtitle", null); + String grid = XMLUtils.xpathString(chart, "chart/display-grid", null); + + if (logger.isDebugEnabled()) { + logger.debug("Found chart title: '" + title + "'"); + logger.debug("Found chart subtitle: '" + sub + "'"); + logger.debug("Found chart grid: '" + grid + "'"); + } + + chartSection.setTitle(title); + chartSection.setSubtitle(sub); + chartSection.setDisplayGird(Boolean.valueOf(grid)); + + target.setChartSection(chartSection); + } + + + protected static void parseLegend(ChartSettings target, Node legend) { + LegendSection section = new LegendSection(); + + String vis = XMLUtils.xpathString(legend, "legend/visibility", null); + String fSize = XMLUtils.xpathString(legend, "legend/font-size", null); + + if (logger.isDebugEnabled()) { + logger.debug("Found legend visibility: '" + vis + "'"); + logger.debug("Found legend font size : '" + fSize + "'"); + } + + section.setVisibility(Boolean.valueOf(vis)); + section.setFontSize(Integer.valueOf(fSize.length() > 0 ? fSize : "-1")); + + target.setLegendSection(section); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :