[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Wed Feb 6 16:00:58 UTC 2008
gordonp
Wed Feb 6 11:00:57 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util
In directory dev.open-bio.org:/tmp/cvs-serv5178/src/main/ca/ucalgary/services/util
Modified Files:
XHTMLForm.java
Log Message:
Commit of XHTML form parsing that passes a the parsing test (logic test not done yet)
moby-live/Java/src/main/ca/ucalgary/services/util XHTMLForm.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util/XHTMLForm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util/XHTMLForm.java 2008/01/29 19:11:10 1.1
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util/XHTMLForm.java 2008/02/06 16:00:57 1.2
@@ -289,6 +289,9 @@
for(int i = 0; i < formParams.getLength(); i++){
Element input = (Element) formParams.item(i);
String mobySpec = parseMobySpec(input, mobyPrefix);
+ if(mobySpec != null && mobySpec.length() > mobyPrefix.length()+1){
+ mobySpec = mobySpec.substring(mobyPrefix.length()+1);
+ }
parseFormField(input, serviceName, mobySpec, inputSpecs, secondarySpecs, fixed, submits, images);
}
Map<String,String> inputSpecsAsStrings = new HashMap<String,String>();
@@ -327,14 +330,6 @@
Map<String,String> images)
throws Exception{
- // if no spec or type is hidden, interpret as a secondary parameter to auto-configure
- if(mobySpec == null || mobySpec.length() == 0){
- parseFormFieldDefault(inputElement, serviceName, secondarySpecs, fixed);
- return; // next param, nothing else to config here...
- }
-
- // If we get this far, there is a moby spec (we're not just using HTML defaults)
- String[] specFields = mobySpec.split(":");
String[] defaultSpec = createDefaultSecondarySpec(inputElement, serviceName);
if(defaultSpec == null){
return; // e.g. reset buttons ignored
@@ -343,6 +338,18 @@
// See if a default value needs to be filled in anywhere
boolean isRadioDefault = RADIO_DEFAULT_SENTINEL.equals(defaultSpec[3]);
boolean isRadio = isRadioDefault || RADIO_SENTINEL.equals(defaultSpec[3]);
+
+ // if no spec or type is hidden, interpret as a secondary parameter to auto-configure
+ // radios without sopecs are a special case, as they may have real specs
+ // in other input fields.
+ if(!isRadio && (mobySpec == null || mobySpec.length() == 0)){
+ parseFormFieldDefault(inputElement, serviceName, secondarySpecs, fixed, submits, images);
+ return; // next param, nothing else to config here...
+ }
+
+ // If we get this far, there is a moby spec (we're not just using HTML defaults)
+ // -1 means keep trailing blank values in split()
+ String[] specFields = mobySpec == null ? new String[4] : mobySpec.split(":", -1);
for(int j = 0; j < defaultSpec.length && j < specFields.length; j++){
if(specFields[j] == null || specFields[j].length() == 0){
specFields[j] = defaultSpec[j];
@@ -356,11 +363,12 @@
// don't send this value, nor make it part of the moby params
return;
}
- else if(specFields.length != 4){
+ else if(specFields.length != 3 && specFields.length != 4){
throw new Exception("The moby parameter specification for form field \""+
- specFields[0]+"\" did not have any of the expected formats: " +
- "moby:paramName:secondaryType:[value_range] " +
- "moby:paramName:mobyDataType:textformat or moby:null");
+ specFields[0]+"\" (" + mobySpec +
+ ") did not have any of the expected formats: " +
+ "moby:paramName:secondaryType:defaultValue:[value_range], " +
+ "moby:paramName:mobyDataType:textformat or moby:null");
}
// submit buttons aren't like other params, handle them separately
else if(defaultSpec[1].equals(SUBMIT_DATATYPE) ||
@@ -432,10 +440,8 @@
submits.put(specFields[0], specFields[2]);
}
}
- // if spec says this is a primary param (i.e. last arg in spec
- // isn't a range or enum of the form [...])
- else if(specFields[3] != null && specFields[3].length() > 0 &&
- !specFields[3].matches("\\[.*\\]")){
+ // if spec says this is a primary param (i.e. only three args in spec)
+ else if(specFields.length == 3){
if(inputSpecs.containsKey(defaultSpec[0]) ||
secondarySpecs.containsKey(defaultSpec[0])){
throw new Exception("The parameter name \""+defaultSpec[0]+
@@ -469,7 +475,9 @@
}
// else: ignore any other radio value, we're sticking with the fixed value
}
- else if(specFields[2] != null && specFields[2].length() > 0){
+ // Did the user manually set a fixed value for the readio button?
+ else if(specFields[2] != null && specFields[2].length() > 0 &&
+ !specFields[2].equals(defaultSpec[2])){
// first time we're fixing the radio param value to send
fixed.put(defaultSpec[0], specFields[2]);
secondarySpecs.remove(defaultSpec[0]); //in case we've encountered the radio earlier
@@ -535,14 +543,31 @@
*/
protected void parseFormFieldDefault(Element inputElement, String serviceName,
Map<String,String[]> secondarySpecs,
- Map<String,String> fixed)
+ Map<String,String> fixed,
+ Map<String,String> submits,
+ Map<String,String> images)
throws Exception{
String[] defaultSpec = createDefaultSecondarySpec(inputElement, serviceName);
if(defaultSpec == null){
return; // e.g. reset button
}
- if(secondarySpecs.containsKey(defaultSpec[0])){
+
+ // The if/elses below direct the params accordingly depending on if
+ // the param is an image, a submit, a hidden, or other
+ if(SUBMIT_DATATYPE.equals(defaultSpec[1])){
+ if(defaultSpec[2].equals(submits.get(defaultSpec[0]))){
+ // TODO: how do we handle multiple submits with the same name but different values??
+ }
+ submits.put(defaultSpec[0], defaultSpec[2]);
+ }
+ else if(IMAGE_DATATYPE.equals(defaultSpec[1])){
+ if(defaultSpec[2].equals(images.get(defaultSpec[0]))){
+ // TODO: how do we handle multiple submits with the same name but different values??
+ }
+ images.put(defaultSpec[0], defaultSpec[2]);
+ }
+ else if(secondarySpecs.containsKey(defaultSpec[0])){
// Radio buttons are a funny case where the spec is
// spread over multiple input elements.
if(RADIO_SENTINEL.equals(defaultSpec[3]) ||
@@ -551,7 +576,7 @@
// append the value to the existing radio param value enumeration
existingSpec[3] += ","+defaultSpec[2];
if(RADIO_DEFAULT_SENTINEL.equals(defaultSpec[3])){
- // we've been told this item os the default value for the radio
+ // we've been told this item is the default value for the radio
existingSpec[2] = defaultSpec[2];
}
}
@@ -768,7 +793,7 @@
// use a special sentinel to denote this
nameAttr = SUBMIT_ANONYMOUS_NAME;
}
- // submits with names will need to be handled specialluy by the caller
+ // submits with names will need to be handled specially by the caller
dataType = SUBMIT_DATATYPE;
}
else if("hidden".equals(fieldType)){
More information about the MOBY-guts
mailing list