{
super();
this.details = new UIinfo();
- details.Action = action;
- details.description = description;
- details.Name = name;
- this.postUrl = postUrl;
- this.urlSuffix = urlSuffix;
- this.inputParams = inputParams;
+ details.Action = action == null ? "" : action;
+ details.description = description == null ? "" : description;
+ details.Name = name == null ? "" : name;
+ this.postUrl = postUrl == null ? "" : postUrl;
+ this.urlSuffix = urlSuffix == null ? "" : urlSuffix;
+ if (inputParams != null)
+ {
+ this.inputParams = inputParams;
+ }
this.hseparable = hseparable;
this.vseparable = vseparable;
this.gapCharacter = gapCharacter;
/**
* input info given as key/value pairs - mapped to post arguments
*/
- Map<String, InputType> inputParams = new HashMap<String,InputType>();
+ Map<String, InputType> inputParams = new HashMap<String, InputType>();
/**
* assigns the given inputType it to its corresponding input parameter token
public RestServiceDescription(RestServiceDescription toedit)
{
- // Rather then do the above, we cheat and use our human readable serialization code to clone everything
+ // Rather then do the above, we cheat and use our human readable
+ // serialization code to clone everything
this(toedit.toString());
/**
- if (toedit == null)
- {
- return;
- }
- /**
- urlSuffix = toedit.urlSuffix;
- postUrl = toedit.postUrl;
- hseparable = toedit.hseparable;
- vseparable = toedit.vseparable;
- gapCharacter = toedit.gapCharacter;
- details = new RestServiceDescription.UIinfo();
- details.Action = toedit.details.Action;
- details.description = toedit.details.description;
- details.Name = toedit.details.Name;
- for (InputType itype: toedit.inputParams.values())
- {
- inputParams.put(itype.token, itype.clone());
-
- }
-
- */
+ * if (toedit == null) { return; } /** urlSuffix = toedit.urlSuffix; postUrl
+ * = toedit.postUrl; hseparable = toedit.hseparable; vseparable =
+ * toedit.vseparable; gapCharacter = toedit.gapCharacter; details = new
+ * RestServiceDescription.UIinfo(); details.Action = toedit.details.Action;
+ * details.description = toedit.details.description; details.Name =
+ * toedit.details.Name; for (InputType itype: toedit.inputParams.values()) {
+ * inputParams.put(itype.token, itype.clone());
+ *
+ * }
+ */
// TODO Implement copy constructor NOW*/
}
return null;
java.util.ArrayList<String> jv = new ArrayList<String>();
int cp = 0, pos, escape;
- boolean wasescaped = false;
+ boolean wasescaped = false,wasquoted=false;
String lstitem = null;
while ((pos = list.indexOf(separator, cp)) >= cp)
{
- escape = (pos>0 && list.charAt(pos - 1) == '\\') ? -1 : 0;
- if (wasescaped)
+
+ escape = (pos > 0 && list.charAt(pos - 1) == '\\') ? -1 : 0;
+ if (wasescaped || wasquoted)
{
// append to previous pos
jv.set(jv.size() - 1,
}
cp = pos + seplen;
wasescaped = escape == -1;
+ if (!wasescaped)
+ {
+ // last separator may be in an unmatched quote
+ if (java.util.regex.Pattern.matches("('[^']*')*[^']*'",lstitem))
+ {
+ wasquoted=true;
+ }
+ }
+
}
if (cp < list.length())
{
String c = list.substring(cp);
- if (wasescaped)
+ if (wasescaped || wasquoted)
{
// append final separator
jv.set(jv.size() - 1, lstitem + separator + c);
{
if (list[i] != null)
{
- if (v.length()>0)
+ if (v.length() > 0)
{
v.append(separator);
}
return true;
}
;
- boolean valid=true;
+ boolean valid = true;
String val = null;
int i;
for (String prop : props)
}
if (prop.equals("gapCharacter"))
{
- if (val == null || val.length()==0 || val.length() > 1)
+ if (val == null || val.length() == 0 || val.length() > 1)
{
- valid=false;
+ valid = false;
warnings.append((warnings.length() > 0 ? "\n" : "")
+ ("Invalid service property: gapCharacter=' ' (single character) - was given '"
+ val + "'"));
}
if (prop.equals("returns"))
{
- int l=warnings.length();
+ int l = warnings.length();
_configureOutputFormatFrom(val, warnings);
- valid = (l!=warnings.length());
+ valid = (l != warnings.length());
}
}
return valid;
private String _genOutputFormatString()
{
String buff = "";
- if (resultData==null)
+ if (resultData == null)
{
return "";
}
private void _configureOutputFormatFrom(String outstring,
StringBuffer warnings)
{
- if (outstring.indexOf(";")==-1) {
+ if (outstring.indexOf(";") == -1)
+ {
// we add a token, for simplicity
- outstring = outstring+";";
+ outstring = outstring + ";";
}
StringTokenizer st = new StringTokenizer(outstring, ";");
String tok = "";
details.Name = list[0];
details.Action = list[1];
details.description = list[2];
- invalid|=!configureFromServiceInputProperties(list[3], warnings);
+ invalid |= !configureFromServiceInputProperties(list[3], warnings);
if (list.length > 5)
{
urlSuffix = list[4];
}
else
{
- urlSuffix = null;
- invalid |= !configureFromInputParamEncodedUrl(list[4], warnings);
+ if (list.length > 4)
+ {
+ urlSuffix = null;
+ invalid |= !configureFromInputParamEncodedUrl(list[4], warnings);
+ }
}
return !invalid;
}
iprmparams = iprm.substring(colon + 1);
iprm = iprm.substring(0, colon);
}
- valid = parseTypeString(prms.group(0), tok, iprm, iprmparams, iparams, warnings);
+ valid = parseTypeString(prms.group(0), tok, iprm, iprmparams,
+ iparams, warnings);
}
if (valid)
{
return valid;
}
- public static boolean parseTypeString(String fullstring, String tok, String iprm, String iprmparams,
- Map<String, InputType> iparams, StringBuffer warnings)
+ public static Class[] getInputTypes()
{
- boolean valid=true;
- InputType jinput;
// TODO - find a better way of maintaining this classlist
- for (Class type : new Class[]
+ return new Class[]
{ jalview.ws.rest.params.Alignment.class,
jalview.ws.rest.params.AnnotationFile.class,
SeqGroupIndexVector.class,
jalview.ws.rest.params.SeqIdVector.class,
jalview.ws.rest.params.SeqVector.class,
- jalview.ws.rest.params.Tree.class })
+ jalview.ws.rest.params.Tree.class };
+ }
+
+ public static boolean parseTypeString(String fullstring, String tok,
+ String iprm, String iprmparams, Map<String, InputType> iparams,
+ StringBuffer warnings)
+ {
+ boolean valid = true;
+ InputType jinput;
+ for (Class type : getInputTypes())
{
try
{
ArrayList<String> al = new ArrayList<String>();
for (String prprm : separatorListToArray(iprmparams, ","))
{
+ // hack to ensure that strings like "sep=','" containing unescaped commas as values are concatenated
al.add(prprm.trim());
}
if (!jinput.configureFromURLtokenString(al, warnings))
{
valid = false;
- warnings.append("Failed to parse '" + fullstring
- + "' as a " + jinput.getURLtokenPrefix()
- + " input tag.\n");
+ warnings.append("Failed to parse '" + fullstring + "' as a "
+ + jinput.getURLtokenPrefix() + " input tag.\n");
}
else
{
jinput.token = tok;
iparams.put(tok, jinput);
- valid=true;
+ valid = true;
}
break;
}
return valid;
}
-
public static void main(String argv[])
{
+ // test separator list
+ try {
+ assert(separatorListToArray("foo=',',min='foo',max='1,2,3',fa=','", ",").length==4);
+ if (separatorListToArray("minsize='2', sep=','", ",").length==2)
+ {
+ assert(false);
+ }
+
+ } catch (AssertionError x)
+ {
+ System.err.println("separatorListToArray is faulty.");
+ }
if (argv.length == 0)
{
if (!testRsdExchange("Test using default Shmmr service",
return jobId + urlSuffix;
}
- private List<JvDataType> resultData=new ArrayList<JvDataType>();
+ private List<JvDataType> resultData = new ArrayList<JvDataType>();
/**
*
{
return resultData;
}
-
+
}