From be893de63f21e1ac9a4a13429820e7483deaed48 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 25 Aug 2011 10:52:05 +0100 Subject: [PATCH] JAL-715 - better validation logic --- src/jalview/ws/rest/RestServiceDescription.java | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/jalview/ws/rest/RestServiceDescription.java b/src/jalview/ws/rest/RestServiceDescription.java index db35a2b..20895a2 100644 --- a/src/jalview/ws/rest/RestServiceDescription.java +++ b/src/jalview/ws/rest/RestServiceDescription.java @@ -487,15 +487,16 @@ public class RestServiceDescription * param warnings a StringBuffer that any warnings about invalid * content will be appended to. */ - private void configureFromServiceInputProperties(String propList, + private boolean configureFromServiceInputProperties(String propList, StringBuffer warnings) { String[] props = separatorListToArray(propList, ","); if (props == null) { - return; + return true; } ; + boolean valid=true; String val = null; int i; for (String prop : props) @@ -520,8 +521,9 @@ public class RestServiceDescription } if (prop.equals("gapCharacter")) { - if (val == null || val.length() > 1) + if (val == null || val.length()==0 || val.length() > 1) { + valid=false; warnings.append((warnings.length() > 0 ? "\n" : "") + ("Invalid service property: gapCharacter=' ' (single character) - was given '" + val + "'")); @@ -533,9 +535,12 @@ public class RestServiceDescription } if (prop.equals("returns")) { + int l=warnings.length(); _configureOutputFormatFrom(val, warnings); + valid = (l!=warnings.length()); } } + return valid; } private String _genOutputFormatString() @@ -627,23 +632,23 @@ public class RestServiceDescription public boolean configureFromEncodedString(String encoding, StringBuffer warnings) { - boolean valid = false; + boolean invalid = false; String[] list = separatorListToArray(encoding, "|"); details.Name = list[0]; details.Action = list[1]; details.description = list[2]; - configureFromServiceInputProperties(list[3], warnings); + invalid|=!configureFromServiceInputProperties(list[3], warnings); if (list.length > 5) { urlSuffix = list[4]; - valid |= configureFromInputParamEncodedUrl(list[5], warnings); + invalid |= !configureFromInputParamEncodedUrl(list[5], warnings); } else { urlSuffix = null; - valid |= configureFromInputParamEncodedUrl(list[4], warnings); + invalid |= !configureFromInputParamEncodedUrl(list[4], warnings); } - return valid; + return !invalid; } /** @@ -966,7 +971,7 @@ public class RestServiceDescription return jobId + urlSuffix; } - private List resultData; + private List resultData=new ArrayList(); /** * -- 1.7.10.2