Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxDateState.java @ 756:1614b27dcbfa
Added Support of Layers which are Joined from two Tables.
gnv-artifacts/trunk@804 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 19 Mar 2010 12:12:10 +0000 |
parents | dde7f51dbe1e |
children | 9a828e5a2390 |
line wrap: on
line source
package de.intevation.gnv.state; import de.intevation.artifactdatabase.XMLUtils; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.ressource.RessourceFactory; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.util.DateUtils; import de.intevation.gnv.state.describedata.DefaultMinMaxDescribeData; import de.intevation.gnv.state.describedata.DescribeData; import de.intevation.gnv.state.describedata.MinMaxDescribeData; import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.utils.InputValidator; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.Locale; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; /** * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) */ public class MinMaxDateState extends MinMaxState { public static final String EXCEPTION_DATE_REQUIRED = "input.is.not.valid.date.required"; public static final String EXCEPTION_START_AFTER_END = "start.date.after.end.date"; private static Logger logger = Logger.getLogger(MinMaxDateState.class); public MinMaxDateState() { super(); } /** * @see de.intevation.gnv.state.StateBase#feed(java.util.Collection, * java.lang.String) */ @Override public Document feed( CallContext context, Collection<InputData> inputData, String uuid) throws StateException { RessourceFactory resFactory = RessourceFactory.getInstance(); Locale[] serverLocales = resFactory.getLocales(); Locale locale = context.getMeta().getPreferredLocale( serverLocales); if (inputData == null) { String msg = "No input data given."; logger.warn(msg); return feedFailure(msg); } InputValidator iv = new InputValidator(); Iterator iter = inputData.iterator(); Object min = null; Object max = null; while (iter.hasNext()) { InputData tmp = (InputData) iter.next(); InputValue meta = inputValues.get(tmp.getName()); String type = meta.getType(); String value = tmp.getValue(); String name = tmp.getName(); if (meta == null) { String msg = "Input data not expected here. Data will be ignored."; logger.warn(msg); return feedFailure(msg); } boolean valid = iv.isInputValid(value, type); if (!valid) { String msg = resFactory.getRessource( locale, EXCEPTION_DATE_REQUIRED, EXCEPTION_DATE_REQUIRED); logger.error(msg); return feedFailure(msg); } if (name.equals(MINVALUEFIELDNAME)) { min = value; } if (name.equals(MAXVALUEFIELDNAME)) { max = value; } if (min != null && max != null) { if (!iv.isInputValid((String) min, (String) max, type)) { String msg = resFactory.getRessource( locale, EXCEPTION_START_AFTER_END, EXCEPTION_START_AFTER_END); logger.error(msg); return feedFailure(msg); } } } DescribeData values = new DefaultMinMaxDescribeData( dataName, min, max, getID()); this.inputData.put(dataName, new DefaultInputData(dataName, values)); return feedSuccess(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: