formatting
[jalview.git] / src / jalview / ws / rest / RestServiceDescription.java
index e0c56da..7e7e3fa 100644 (file)
@@ -52,8 +52,9 @@ public class RestServiceDescription
    */
   public RestServiceDescription()
   {
-    
+
   }
+
   /**
    * @param details
    * @param postUrl
@@ -379,11 +380,11 @@ public class RestServiceDescription
       return null;
     java.util.ArrayList<String> jv = new ArrayList<String>();
     int cp = 0, pos, escape;
-    boolean wasescaped = false,wasquoted=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 || wasquoted)
       {
@@ -402,12 +403,12 @@ public class RestServiceDescription
       if (!wasescaped)
       {
         // last separator may be in an unmatched quote
-        if (java.util.regex.Pattern.matches("('[^']*')*[^']*'",lstitem))
+        if (java.util.regex.Pattern.matches("('[^']*')*[^']*'", lstitem))
         {
-          wasquoted=true;
+          wasquoted = true;
         }
       }
-      
+
     }
     if (cp < list.length())
     {
@@ -605,8 +606,16 @@ public class RestServiceDescription
   private String getServiceIOProperties()
   {
     ArrayList<String> vls = new ArrayList<String>();
-    if (isHseparable()) { vls.add("hseparable");};
-    if (isVseparable()) { vls.add("vseparable");};
+    if (isHseparable())
+    {
+      vls.add("hseparable");
+    }
+    ;
+    if (isVseparable())
+    {
+      vls.add("vseparable");
+    }
+    ;
     vls.add(new String("gapCharacter='" + gapCharacter + "'"));
     vls.add(new String("returns='" + _genOutputFormatString() + "'"));
     return arrayToSeparatorList(vls.toArray(new String[0]), ",");
@@ -640,27 +649,35 @@ public class RestServiceDescription
   }
 
   /**
-   * processes a service encoded as a string (as generated by RestServiceDescription.toString())
-   * Note - this will only use the first service definition encountered in the string to configure the service.
+   * processes a service encoded as a string (as generated by
+   * RestServiceDescription.toString()) Note - this will only use the first
+   * service definition encountered in the string to configure the service.
+   * 
    * @param encoding
-   * @param warnings - where warning messages are reported.
-   * @return true if configuration was parsed successfully. 
+   * @param warnings
+   *          - where warning messages are reported.
+   * @return true if configuration was parsed successfully.
    */
   public boolean configureFromEncodedString(String encoding,
           StringBuffer warnings)
   {
     String[] list = separatorListToArray(encoding, "|");
-    
-    int nextpos=parseServiceList(list,warnings, 0);
-    if (nextpos>0)
+
+    int nextpos = parseServiceList(list, warnings, 0);
+    if (nextpos > 0)
     {
       return true;
     }
     return false;
   }
+
   /**
-   * processes the given list from position p, attempting to configure the service from it.
-   * Service lists are formed by concatenating individual stringified services. The first character of a stringified service is '|', enabling this, and the parser will ignore empty fields in a '|' separated list when they fall outside a service definition.
+   * processes the given list from position p, attempting to configure the
+   * service from it. Service lists are formed by concatenating individual
+   * stringified services. The first character of a stringified service is '|',
+   * enabling this, and the parser will ignore empty fields in a '|' separated
+   * list when they fall outside a service definition.
+   * 
    * @param list
    * @param warnings
    * @param p
@@ -670,32 +687,34 @@ public class RestServiceDescription
   {
     boolean invalid = false;
     // look for the first non-empty position - expect it to be service name
-    while (list[p]!=null && list[p].trim().length()==0)
+    while (list[p] != null && list[p].trim().length() == 0)
     {
       p++;
     }
     details.Name = list[p];
-    details.Action = list[p+1];
-    details.description = list[p+2];
-    invalid |= !configureFromServiceInputProperties(list[p+3], warnings);
-    if (list.length-p > 5 && list[p+5]!=null && list[p+5].trim().length()>5)
+    details.Action = list[p + 1];
+    details.description = list[p + 2];
+    invalid |= !configureFromServiceInputProperties(list[p + 3], warnings);
+    if (list.length - p > 5 && list[p + 5] != null
+            && list[p + 5].trim().length() > 5)
     {
-      urlSuffix = list[p+4];
-      invalid |= !configureFromInputParamEncodedUrl(list[p+5], warnings);
-      p+=6;
+      urlSuffix = list[p + 4];
+      invalid |= !configureFromInputParamEncodedUrl(list[p + 5], warnings);
+      p += 6;
     }
     else
     {
-      if (list.length-p > 4 && list[p+4]!=null && list[p+4].trim().length()>5)
+      if (list.length - p > 4 && list[p + 4] != null
+              && list[p + 4].trim().length() > 5)
       {
         urlSuffix = null;
-        invalid |= !configureFromInputParamEncodedUrl(list[p+4], warnings);
-        p+=5;
+        invalid |= !configureFromInputParamEncodedUrl(list[p + 4], warnings);
+        p += 5;
       }
     }
     return invalid ? -1 : p;
   }
-  
+
   /**
    * @return string representation of the input parameters, their type and
    *         constraints, appended to the service's base submission URL
@@ -838,7 +857,8 @@ public class RestServiceDescription
           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
+            // hack to ensure that strings like "sep=','" containing unescaped
+            // commas as values are concatenated
             al.add(prprm.trim());
           }
           if (!jinput.configureFromURLtokenString(al, warnings))
@@ -867,13 +887,15 @@ public class RestServiceDescription
   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)
+    try
+    {
+      assert (separatorListToArray("foo=',',min='foo',max='1,2,3',fa=','",
+              ",").length == 4);
+      if (separatorListToArray("minsize='2', sep=','", ",").length == 2)
       {
-        assert(false);
+        assert (false);
       }
-      
+
     } catch (AssertionError x)
     {
       System.err.println("separatorListToArray is faulty.");
@@ -1069,26 +1091,37 @@ public class RestServiceDescription
 
   /**
    * parse a concatenated list of rest service descriptions into an array
+   * 
    * @param services
    * @return zero or more services.
-   * @throws exceptions if the services are improperly encoded.
+   * @throws exceptions
+   *           if the services are improperly encoded.
    */
-  public static List<RestServiceDescription> parseDescriptions(String services) throws Exception
+  public static List<RestServiceDescription> parseDescriptions(
+          String services) throws Exception
   {
     String[] list = separatorListToArray(services, "|");
     List<RestServiceDescription> svcparsed = new ArrayList<RestServiceDescription>();
-    int p=0,lastp=0;
-    StringBuffer warnings=new StringBuffer();
-    do {
+    int p = 0, lastp = 0;
+    StringBuffer warnings = new StringBuffer();
+    do
+    {
       RestServiceDescription rsd = new RestServiceDescription();
-      p=rsd.parseServiceList(list, warnings, lastp=p);
-      if (p>lastp && rsd.isValid())
+      p = rsd.parseServiceList(list, warnings, lastp = p);
+      if (p > lastp && rsd.isValid())
       {
         svcparsed.add(rsd);
-      } else {
-        throw new Exception("Failed to parse user defined RSBS services from :"+services+"\nFirst error was encountered at token "+lastp+" starting "+list[lastp]+":\n"+rsd.getInvalidMessage());
       }
-    } while (p<lastp && p<list.length-1);
+      else
+      {
+        throw new Exception(
+                "Failed to parse user defined RSBS services from :"
+                        + services
+                        + "\nFirst error was encountered at token " + lastp
+                        + " starting " + list[lastp] + ":\n"
+                        + rsd.getInvalidMessage());
+      }
+    } while (p < lastp && p < list.length - 1);
     return svcparsed;
   }