bjoern@3936: package de.intevation.flys.artifacts; bjoern@3936: bjoern@3936: import java.util.ArrayList; bjoern@3936: import java.util.List; bjoern@3936: bjoern@3936: import org.apache.log4j.Logger; bjoern@3936: bjoern@3936: import org.w3c.dom.Document; bjoern@3936: bjoern@3936: import de.intevation.artifactdatabase.state.DefaultOutput; bjoern@3936: import de.intevation.artifactdatabase.state.Facet; bjoern@4034: import de.intevation.artifactdatabase.data.DefaultStateData; bjoern@3936: bjoern@3936: import de.intevation.artifacts.ArtifactFactory; bjoern@3936: import de.intevation.artifacts.CallMeta; bjoern@3936: bjoern@3936: import de.intevation.artifacts.common.ArtifactNamespaceContext; bjoern@3936: import de.intevation.artifacts.common.utils.XMLUtils; bjoern@3936: bjoern@4032: import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet; bjoern@4032: import de.intevation.flys.artifacts.resources.Resources; bjoern@3936: import de.intevation.flys.artifacts.states.StaticState; bjoern@4032: bjoern@4032: import de.intevation.flys.model.Gauge; bjoern@4032: import de.intevation.flys.utils.FLYSUtils; bjoern@3936: bjoern@3936: bjoern@3936: /** bjoern@3936: * Artifact to calculate a discharge curve from a gauge overview info bjoern@3936: * bjoern@3936: * @author Björn Ricks bjoern@3936: */ bjoern@3936: public class GaugeDischargeCurveArtifact bjoern@3936: extends AbstractStaticStateArtifact bjoern@3936: { bjoern@3936: bjoern@3936: private static final Logger logger = bjoern@3936: Logger.getLogger(GaugeDischargeCurveArtifact.class); bjoern@3936: bjoern@4027: public static final String XPATH_RIVER = "/art:action/art:river/@art:name"; bjoern@4027: public static final String XPATH_GAUGE = "/art:action/art:gauge/@art:reference"; bjoern@3936: public static final String NAME = "gaugedischargecurve"; bjoern@3936: public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static"; bjoern@3936: bjoern@3936: /** bjoern@3936: * Setup initializes the data by extracting the river and gauge from bjoern@3936: * the XML Document. bjoern@3936: */ bjoern@3936: @Override bjoern@3936: public void setup( bjoern@3936: String identifier, bjoern@3936: ArtifactFactory factory, bjoern@3936: Object context, bjoern@3936: CallMeta callmeta, bjoern@3936: Document data) bjoern@3936: { bjoern@3936: logger.debug("GaugeDischargeCurveArtifact.setup"); bjoern@3936: bjoern@3936: if (logger.isDebugEnabled()) { bjoern@4028: logger.debug("GaugeDischargeCurveArtifact.setup" + XMLUtils.toString(data)); bjoern@3936: } bjoern@3936: String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE, bjoern@3936: ArtifactNamespaceContext.INSTANCE); bjoern@3936: String rivername = XMLUtils.xpathString(data, XPATH_RIVER, bjoern@3936: ArtifactNamespaceContext.INSTANCE); bjoern@3936: bjoern@4034: addData("river", new DefaultStateData("river", bjoern@4034: Resources.getMsg(callmeta, bjoern@4034: "facet.gauge_discharge_curve.river", bjoern@4034: "Name of the river"), bjoern@4034: "String", rivername)); bjoern@4034: addData("reference_gauge", new DefaultStateData("reference_gauge", bjoern@4034: Resources.getMsg(callmeta, bjoern@4034: "facet.gauge_discharge_curve.reference_gauge", bjoern@4034: "Gauge official number"), bjoern@4034: "Double", gaugeref)); bjoern@3936: bjoern@4032: Gauge gauge = FLYSUtils.getReferenceGauge(this); bjoern@4034: String gaugename = ""; bjoern@4034: if (gauge != null) { bjoern@4034: gaugename = gauge.getName(); bjoern@4034: } bjoern@4032: bjoern@4032: String description = Resources.format(callmeta, bjoern@4032: "facet.gauge_discharge_curve.description", bjoern@4032: "Discharge curve on gauge", bjoern@4032: rivername, bjoern@4034: gaugename); bjoern@4032: bjoern@4032: Facet gfacet = new GaugeDischargeCurveFacet(description); bjoern@3936: bjoern@3936: List fs = new ArrayList(1); bjoern@3936: fs.add(gfacet); bjoern@3936: bjoern@3936: addFacets(STATIC_STATE_NAME, fs); bjoern@3936: bjoern@3936: super.setup(identifier, factory, context, callmeta, data); bjoern@3936: } bjoern@3936: bjoern@3936: @Override bjoern@3936: public String getName() { bjoern@3936: return NAME; bjoern@3936: } bjoern@3936: bjoern@3936: @Override bjoern@3936: protected void initStaticState() { bjoern@3936: StaticState state = new StaticState(STATIC_STATE_NAME); bjoern@3936: List fs = facets.get(STATIC_STATE_NAME); bjoern@3936: DefaultOutput output = new DefaultOutput( bjoern@3936: "discharge_curve", bjoern@3936: "output.discharge_curve", "image/png", bjoern@3936: fs, bjoern@3936: "chart"); bjoern@3936: bjoern@3936: state.addOutput(output); bjoern@3936: setStaticState(state); bjoern@3936: } bjoern@3936: }