Mercurial > dive4elements > gnv-client
changeset 860:f94a95009423
Improved the input validator: empty strings are invalid (issue251).
gnv-artifacts/trunk@989 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 26 Apr 2010 13:31:11 +0000 |
parents | 3fbabd4803d7 |
children | 2ab49a1e29ca |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java |
diffstat | 3 files changed, 81 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Apr 26 09:09:20 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Apr 26 13:31:11 2010 +0000 @@ -1,3 +1,13 @@ +2010-04-26 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue251 + + * src/main/java/de/intevation/gnv/state/SingleInputState.java: Override feed + method for input validation. + + * src/main/java/de/intevation/gnv/utils/InputValidator.java: New case: an + empty string is invalid. + 2010-04-26 Tim Englich <tim.englich@intevation.de> ISSUE252
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java Mon Apr 26 09:09:20 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java Mon Apr 26 13:31:11 2010 +0000 @@ -1,15 +1,23 @@ package de.intevation.gnv.state; +import de.intevation.artifacts.CallContext; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; import de.intevation.gnv.geobackend.base.Result; - import de.intevation.gnv.state.describedata.DefaultSingleValueDescribeData; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.utils.InputValidator; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; +import java.util.Locale; import org.apache.log4j.Logger; +import org.w3c.dom.Document; + /** * This state handles single user input. The user is allowed to select just one * value. @@ -51,5 +59,63 @@ return describeData; } + + /** + * This feed method needs a collection of two InputData objects. These + * objects' values need to be a datetime string which is turned into a Date + * object. Afterwards, the given dates are validated. Min and max date need + * to be in range of the min and max date retrieved by + * {@link #getDescibeData(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."; + log.warn(msg); + return feedFailure(msg); + } + + Iterator<InputData> it = inputData.iterator(); + InputData tmpItem = it.next(); + InputValue inputValue = inputValues.get(tmpItem.getName()); + + if (inputValue == null) { + String msg = resFactory.getRessource( + locale, + EXCEPTION_INVALID_INPUT, + EXCEPTION_INVALID_INPUT); + log.warn(msg); + return feedFailure(msg); + } + + boolean valid = InputValidator.isInputValid( + tmpItem.getValue(), inputValue.getType()); + + if (valid) { + String[] desc = getDescriptionForInputData(tmpItem, uuid); + tmpItem.setDescription(desc); + + this.inputData.put(tmpItem.getName(), tmpItem); + return feedSuccess(); + } + + else { + String msg = resFactory.getRessource( + locale, + EXCEPTION_INVALID_INPUT, + EXCEPTION_INVALID_INPUT); + log.warn(msg); + return feedFailure(msg); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java Mon Apr 26 09:09:20 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java Mon Apr 26 13:31:11 2010 +0000 @@ -81,6 +81,10 @@ * @return true if the input is valid, otherwise false. */ public static boolean isInputValid(String input, String type) { + if (input.length() == 0 || input.equals("")) { + return false; + } + log.debug("InputValidator.isInputValid " + input + " " + type); // Let's check polygons and linestrings first, because they might