Index: test/JDBCTest.java
===================================================================
--- test/JDBCTest.java	(revision 2067)
+++ test/JDBCTest.java	(revision 2068)
@@ -100,7 +100,7 @@
         select(conn);
         index++;
       }//for
-      System.out.prinln("End");
+      System.out.println("End");
      
     }//try
     catch (SQLException e)
Index: test/query.xml
===================================================================
--- test/query.xml	(revision 2067)
+++ test/query.xml	(revision 2068)
@@ -17,4 +17,4 @@
       </querygroup>
     </querygroup>
   </querygroup>
-<pathquery>
+</pathquery>
Index: test/edu/ucsb/nceas/metacattest/QuerySpecificationTest.java
===================================================================
--- test/edu/ucsb/nceas/metacattest/QuerySpecificationTest.java	(nonexistent)
+++ test/edu/ucsb/nceas/metacattest/QuerySpecificationTest.java	(revision 2068)
@@ -0,0 +1,124 @@
+/**
+ *  '$RCSfile$'
+ *  Copyright: 2004 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *
+ *   '$Author$'
+ *     '$Date$'
+ * '$Revision$'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+package edu.ucsb.nceas.metacattest;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import edu.ucsb.nceas.metacat.MetaCatUtil;
+import edu.ucsb.nceas.metacat.QuerySpecification;
+import edu.ucsb.nceas.utilities.Options;
+
+/**
+ * @author jones
+ * 
+ * Test the output of the QuerySpecification class
+ */
+public class QuerySpecificationTest extends TestCase
+{
+    /** A test query document in xml format */
+    private FileReader xml;
+    
+    /** The utilities object for accessing property values */
+    private MetaCatUtil util;
+    
+    /**
+     * Constructor to build the test
+     * 
+     * @param name the name of the test method
+     */
+    public QuerySpecificationTest(String name)
+    {
+        super(name);
+    }
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        try {
+            File propertyFile = new File("./lib/metacat.properties");
+            Options options = Options.initialize(propertyFile);
+            util = new MetaCatUtil();
+            String xmlfile = "./test/query.xml";
+            xml = new FileReader(new File(xmlfile));
+        } catch (FileNotFoundException e) {
+            fail(e.getMessage());
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    /**
+     * Create a suite of tests to be run together
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+        suite.addTest(new QuerySpecificationTest("testPrintSQL"));
+        suite.addTest(new QuerySpecificationTest("testPrintExtendedSQL"));
+        return suite;
+    }
+
+    /**
+     * Print the sql generated from this specification
+     */
+    public void testPrintSQL()
+    {
+        try {
+            QuerySpecification qspec = new QuerySpecification(xml, 
+                    MetaCatUtil.getOption("saxparser"), 
+                    MetaCatUtil.getOption("accNumberSeparator"));
+            System.out.println(qspec.printSQL(true));
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    /**
+     * Print the extended SQL for a result set.
+     */
+    public void testPrintExtendedSQL()
+    {
+        try {
+            Hashtable controlPairs = new Hashtable();
+            QuerySpecification qspec = new QuerySpecification(xml, 
+                    MetaCatUtil.getOption("saxparser"), 
+                    MetaCatUtil.getOption("accNumberSeparator"));
+            System.out.println(qspec.printExtendedSQL("n.1.1, n.2.2", controlPairs));
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+    }
+
+}

Property changes on: test/edu/ucsb/nceas/metacattest/QuerySpecificationTest.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: src/edu/ucsb/nceas/metacat/QuerySpecification.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 2067)
+++ src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 2068)
@@ -30,8 +30,6 @@
 
 package edu.ucsb.nceas.metacat;
 
-import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
@@ -357,38 +355,6 @@
         return accessQuery;
     }
 
-    /** Main routine for testing */
-    static public void main(String[] args)
-    {
-
-        if (args.length < 1) {
-            System.err.println("Wrong number of arguments!!!");
-            System.err.println("USAGE: java QuerySpecification <xmlfile>");
-            return;
-        } else {
-            int i = 0;
-            boolean useXMLIndex = true;
-            if (args[i].equals("-noindex")) {
-                useXMLIndex = false;
-                i++;
-            }
-            String xmlfile = args[i];
-
-            try {
-                MetaCatUtil util = new MetaCatUtil();
-                FileReader xml = new FileReader(new File(xmlfile));
-                QuerySpecification qspec = new QuerySpecification(xml, util
-                        .getOption("saxparser"), util
-                        .getOption("accNumberSeparator"));
-                System.out.println(qspec.printSQL(useXMLIndex));
-
-            } catch (IOException e) {
-                System.err.println(e.getMessage());
-            }
-
-        }
-    }
-
     /**
      * Returns true if the parsed query contains and extended xml query (i.e.
      * there is at least one &lt;returnfield&gt; in the pathquery document)
@@ -814,7 +780,8 @@
         sql.append(") AND startnodeid IS NOT NULL AND ");
         sql.append("(");
         sql.append("(");
-        sql.append("startnodeid NOT IN (SELECT startnodeid from xml_access, xml_documents ");
+        sql
+                .append("startnodeid NOT IN (SELECT startnodeid from xml_access, xml_documents ");
         sql.append(" WHERE xml_access.docid = xml_documents.docid");
         sql.append(" AND lower(xml_documents.user_owner) ='");
         sql.append(userName);
@@ -822,11 +789,13 @@
         sql.append(")");
         sql.append(" AND ");
         sql.append("(");
-        sql.append("(startnodeid NOT IN (SELECT startnodeid from xml_access where( ");
+        sql
+                .append("(startnodeid NOT IN (SELECT startnodeid from xml_access where( ");
         sql.append(allowString);
         sql.append(") AND (startnodeid IS NOT NULL))");
         sql.append(")");
-        sql.append(" OR (startnodeid IN (SELECT startnodeid from xml_access where( ");
+        sql
+                .append(" OR (startnodeid IN (SELECT startnodeid from xml_access where( ");
         sql.append(denyString);
         sql.append(") AND (startnodeid IS NOT NULL))");
         sql.append(")");
@@ -851,8 +820,7 @@
             Hashtable unaccessableNodePair)
     {
         StringBuffer self = new StringBuffer();
-        self
-                .append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, ");
+        self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, ");
         self.append("xml_nodes.parentnodeid ");
         self.append("from xml_index, xml_nodes where xml_index.nodeid=");
         self.append("xml_nodes.parentnodeid and (xml_index.path like '");
Index: src/edu/ucsb/nceas/metacat/MetaCatUtil.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatUtil.java	(revision 2067)
+++ src/edu/ucsb/nceas/metacat/MetaCatUtil.java	(revision 2068)
@@ -28,14 +28,9 @@
 package edu.ucsb.nceas.metacat;
 
 import java.io.File;
+import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.MalformedURLException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.PropertyResourceBundle;
 import java.util.Hashtable;
-import java.util.Enumeration;
 import java.util.Stack;
 import java.util.Vector;
 
@@ -45,649 +40,604 @@
 /**
  * A suite of utility classes for the metadata catalog server
  */
-public class MetaCatUtil {
+public class MetaCatUtil
+{
 
-  public static AbstractDatabase dbAdapter;
-  private static Options options = null;
-  private static boolean debug = true;
+    public static AbstractDatabase dbAdapter;
 
-  //private Hashtable connectionPool = new Hashtable();
+    private static Options options = null;
 
-  /**
-   * Determine our db adapter class and create an instance of that class
-   */
-  static {
-    try {
-      dbAdapter = (AbstractDatabase)createObject(getOption("dbAdapter"));
-    } catch (Exception e) {
-      System.err.println("Error in MetaCatUtil static block:" + e.getMessage());
+    private static boolean debug = true;
+
+    /**
+     * Determine our db adapter class and create an instance of that class
+     */
+    static {
+        try {
+            dbAdapter = (AbstractDatabase) createObject(getOption("dbAdapter"));
+        } catch (Exception e) {
+            System.err.println("Error in MetaCatUtil static block:"
+                    + e.getMessage());
+        }
     }
-  }
 
+    /**
+     * Instantiate a class using the name of the class at runtime
+     * 
+     * @param className the fully qualified name of the class to instantiate
+     */
+    public static Object createObject(String className) throws Exception
+    {
 
+        Object object = null;
+        try {
+            Class classDefinition = Class.forName(className);
+            object = classDefinition.newInstance();
+        } catch (InstantiationException e) {
+            throw e;
+        } catch (IllegalAccessException e) {
+            throw e;
+        } catch (ClassNotFoundException e) {
+            throw e;
+        }
+        return object;
+    }
 
-  /**
-   * Instantiate a class using the name of the class at runtime
-   *
-   * @param className the fully qualified name of the class to instantiate
-   */
-  public static Object createObject(String className) throws Exception {
+    /**
+     * Utility method to get an option value from the properties file
+     * 
+     * @param optionName the name of the option requested
+     * @return the String value for the option, or null if not set
+     */
+    public static String getOption(String optionName)
+    {
+        if (options == null) {
+            options = Options.getInstance();
+        }
+        String value = options.getOption(optionName);
+        return value;
+    }
 
-    Object object = null;
-    try {
-      Class classDefinition = Class.forName(className);
-      object = classDefinition.newInstance();
-    } catch (InstantiationException e) {
-      throw e;
-    } catch (IllegalAccessException e) {
-      throw e;
-    } catch (ClassNotFoundException e) {
-      throw e;
+    /** Utility method to convert a file handle into a URL */
+    public static URL fileToURL(File file)
+    {
+        String path = file.getAbsolutePath();
+        String fSep = System.getProperty("file.separator");
+        if (fSep != null && fSep.length() == 1)
+                path = path.replace(fSep.charAt(0), '/');
+        if (path.length() > 0 && path.charAt(0) != '/') path = '/' + path;
+        try {
+            return new URL("file", null, path);
+        } catch (java.net.MalformedURLException e) {
+            /*
+             * According to the spec this could only happen if the file
+             */
+            throw new Error("unexpected MalformedURLException");
+        }
     }
-    return object;
-  }
 
-  /**
-   * Utility method to get an option value from the properties file
-   *
-   * @param optionName the name of the option requested
-   * @return the String value for the option, or null if not set
-   */
-  public static String getOption(String optionName) {
-      if (options == null) {
-        options = Options.getInstance();
-      }
-      String value = options.getOption(optionName);
-      return value;
-  }
+    /**
+     * Utility method to parse the query part of a URL into parameters. This
+     * method assumes the format of the query par tof the url is an ampersand
+     * separated list of name/value pairs, with equal signs separating the name
+     * from the value (e.g., name=tom&zip=99801 ). Returns a has of the name
+     * value pairs, hashed on name.
+     */
+    public static Hashtable parseQuery(String query)
+            throws MalformedURLException
+    {
+        String[][] params = new String[200][2];
+        Hashtable parameters = new Hashtable();
 
-  /** Utility method to convert a file handle into a URL */
-  public static URL fileToURL(File file)
-  {
-     String path = file.getAbsolutePath();
-     String fSep = System.getProperty("file.separator");
-     if (fSep != null && fSep.length() == 1)
-       path = path.replace(fSep.charAt(0), '/');
-     if (path.length() > 0 && path.charAt(0) != '/')
-       path = '/' + path;
-     try {
-       return new URL("file", null, path);
-     }
-     catch (java.net.MalformedURLException e) {
-       /* According to the spec this could only happen if the file
-          protocol were not recognized. */
-       throw new Error("unexpected MalformedURLException");
-     }
-  }
+        String temp = "";
+        boolean ampflag = true;
+        boolean poundflag = false;
+        int arrcount = 0;
 
-  /**
-   * Utility method to parse the query part of a URL into parameters. This
-   * method assumes the format of the query par tof the url is an
-   * ampersand separated list of name/value pairs, with equal signs separating
-   * the name from the value (e.g., name=tom&zip=99801 ). Returns a
-   * has of the name value pairs, hashed on name.
-   */
-  public static Hashtable parseQuery(String query) throws MalformedURLException
-  {
-    String[][] params = new String[200][2];
-    Hashtable parameters = new Hashtable();
+        if (query != null) {
+            for (int i = 0; i < query.length(); i++) {
 
-    String temp = "";
-    boolean ampflag = true;
-    boolean poundflag = false;
-    int arrcount = 0;
+                // go throught the remainder of the query one character at a
+                // time.
+                if (query.charAt(i) == '=') {
+                    // if the current char is a # then the preceding should be
+                    // a name
+                    if (!poundflag && ampflag) {
+                        params[arrcount][0] = temp.trim();
+                        temp = "";
+                    } else {
+                        //if there are two #s or &s in a row throw an
+                        // exception.
+                        throw new MalformedURLException(
+                                "metacatURL: Two parameter names "
+                                        + "not allowed in sequence");
+                    }
+                    poundflag = true;
+                    ampflag = false;
+                } else if (query.charAt(i) == '&' || i == query.length() - 1) {
+                    //the text preceding the & should be the param value.
+                    if (i == query.length() - 1) {
+                        //if at the end of the string grab the last value and
+                        // append it.
+                        if (query.charAt(i) != '=') {
+                            //ignore an extra & on the end of the string
+                            temp += query.charAt(i);
+                        }
+                    }
 
-    if ( query != null ) {
-      for (int i=0; i < query.length(); i++) {
-
-        // go throught the remainder of the query one character at a time.
-        if (query.charAt(i) == '=') {
-          // if the current char is a # then the preceding should be a name
-          if (!poundflag && ampflag) {
-            params[arrcount][0] = temp.trim();
-            temp = "";
-          } else {
-            //if there are two #s or &s in a row throw an exception.
-            throw new MalformedURLException("metacatURL: Two parameter names "+
-                                            "not allowed in sequence");
-          }
-          poundflag = true;
-          ampflag = false;
-        } else if (query.charAt(i) == '&' || i == query.length()-1) {
-          //the text preceding the & should be the param value.
-          if (i == query.length() - 1) {
-            //if at the end of the string grab the last value and append it.
-            if (query.charAt(i) != '=') {
-            //ignore an extra & on the end of the string
-              temp += query.charAt(i);
+                    if (!ampflag && poundflag) {
+                        params[arrcount][1] = temp.trim();
+                        parameters
+                                .put(params[arrcount][0], params[arrcount][1]);
+                        temp = "";
+                        arrcount++; //increment the array to the next row.
+                    } else {
+                        //if there are two =s or &s in a row through an
+                        // exception
+                        throw new MalformedURLException(
+                                "metacatURL: Two parameter values "
+                                        + "not allowed in sequence");
+                    }
+                    poundflag = false;
+                    ampflag = true;
+                } else {
+                    //get the next character in the string
+                    temp += query.charAt(i);
+                }
             }
-          }
-
-          if (!ampflag && poundflag) {
-            params[arrcount][1] = temp.trim();
-            parameters.put(params[arrcount][0], params[arrcount][1]);
-            temp = "";
-            arrcount++; //increment the array to the next row.
-          } else {
-            //if there are two =s or &s in a row through an exception
-            throw new MalformedURLException("metacatURL: Two parameter values "+
-                                            "not allowed in sequence");
-          }
-          poundflag = false;
-          ampflag = true;
-        } else {
-          //get the next character in the string
-          temp += query.charAt(i);
         }
-      }
+        return parameters;
     }
-    return parameters;
-  }
 
-   /**
-   * Utility method to print debugging messages. User can set debug level
-   * for this message. The number is fewer, the message is more important
-   * @param msg, the content of the message
-   * @param debugLevel, an integer indicating the message debug leve
-   */
-  public static void debugMessage(String msg, int debugLevel)
-  {
-    if (debug)
+    /**
+     * Utility method to print debugging messages. User can set debug level for
+     * this message. The number is fewer, the message is more important
+     * 
+     * @param msg, the content of the message
+     * @param debugLevel, an integer indicating the message debug leve
+     */
+    public static void debugMessage(String msg, int debugLevel)
     {
-      int limit = 1;
-      try
-      {
-        limit=Integer.parseInt(getOption("debuglevel"));
+        if (debug) {
+            int limit = 1;
+            try {
+                limit = Integer.parseInt(getOption("debuglevel"));
 
-      }
-      catch (Exception e)
-      {
-        System.out.println(e.getMessage());
-      }
-      //don't allow the user set debugLevel less than or equals 0
-      if (debugLevel<=0)
-      {
-        debugLevel=1;
-      }
+            } catch (Exception e) {
+                System.out.println(e.getMessage());
+            }
+            //don't allow the user set debugLevel less than or equals 0
+            if (debugLevel <= 0) {
+                debugLevel = 1;
+            }
 
-      if (debugLevel < limit)
-      {
-        System.err.println("@debugprefix@ " +msg);
-      }
+            if (debugLevel < limit) {
+                System.err.println("@debugprefix@ " + msg);
+            }
+        }
     }
-  }
 
+    public static Vector getOptionList(String optiontext)
+    {
+        Vector optionsVector = new Vector();
+        if (optiontext.indexOf(",") == -1) {
+            optionsVector.addElement(optiontext);
+            return optionsVector;
+        }
 
-  public static Vector getOptionList(String optiontext)
-  {
-    Vector optionsVector = new Vector();
-    if(optiontext.indexOf(",") == -1)
-    {
-      optionsVector.addElement(optiontext);
-      return optionsVector;
+        while (optiontext.indexOf(",") != -1) {
+            String s = optiontext.substring(0, optiontext.indexOf(","));
+            optionsVector.addElement(s.trim());
+            optiontext = optiontext.substring(optiontext.indexOf(",") + 1,
+                    optiontext.length());
+            if (optiontext.indexOf(",") == -1) { //catch the last list entry
+                optionsVector.addElement(optiontext.trim());
+            }
+        }
+        return optionsVector;
     }
 
-    while(optiontext.indexOf(",") != -1)
+    /** Normalizes the given string. Taken from configXML.java */
+    public static String normalize(String s)
     {
-      String s = optiontext.substring(0, optiontext.indexOf(","));
-      optionsVector.addElement(s.trim());
-      optiontext = optiontext.substring(optiontext.indexOf(",") + 1,
-                                        optiontext.length());
-      if(optiontext.indexOf(",") == -1)
-      { //catch the last list entry
-        optionsVector.addElement(optiontext.trim());
-      }
+        StringBuffer str = new StringBuffer();
+
+        int len = (s != null) ? s.length() : 0;
+        for (int i = 0; i < len; i++) {
+            char ch = s.charAt(i);
+            switch (ch) {
+            case '<':
+                {
+                    str.append("&lt;");
+                    break;
+                }
+            case '>':
+                {
+                    str.append("&gt;");
+                    break;
+                }
+            case '&':
+                {
+                    str.append("&amp;");
+                    break;
+                }
+            case '"':
+                {
+                    str.append("&quot;");
+                    break;
+                }
+            case '\r':
+            case '\n':
+                {
+                    // else, default append char
+                }
+            default:
+                {
+                    str.append(ch);
+                }
+            }
+        }
+        return (str.toString());
     }
-    return optionsVector;
-  }
 
-  /** Normalizes the given string. Taken from configXML.java*/
-  public static String normalize(String s)
-  {
-    StringBuffer str = new StringBuffer();
-
-    int len = (s != null) ? s.length() : 0;
-    for (int i = 0; i < len; i++)
+    /**
+     * Get docid from online/url string
+     */
+    public static String getDocIdWithRevFromOnlineURL(String url)
     {
-      char ch = s.charAt(i);
-      switch (ch)
-      {
-      case '<':
-      {
-        str.append("&lt;");
-        break;
-      }
-        case '>':
-      {
-        str.append("&gt;");
-        break;
-      }
-      case '&':
-      {
-        str.append("&amp;");
-        break;
-      }
-      case '"':
-      {
-        str.append("&quot;");
-        break;
-      }
-      case '\r':
-      case '\n':
-      {
-        // else, default append char
-      }
-      default:
-      {
-        str.append(ch);
-      }
-      }
+        String docid = null;
+        String DOCID = "docid";
+        boolean find = false;
+        char limited = '&';
+        int count = 0; //keep track how many & was found
+        Vector list = new Vector();// keep index number for &
+        if (url == null) {
+            MetaCatUtil.debugMessage("url is null and null will be returned",
+                    30);
+            return docid;
+        }
+        // the first element in list is 0
+        list.add(new Integer(0));
+        for (int i = 0; i < url.length(); i++) {
+            if (url.charAt(i) == limited) {
+                // count plus 1
+                count++;
+                list.add(new Integer(i));
+                // get substring beween two &
+                String str = url.substring(
+                        ((Integer) list.elementAt(count - 1)).intValue(), i);
+                MetaCatUtil.debugMessage("substring between two & is: " + str,
+                        30);
+                //if the subString contains docid, we got it
+                if (str.indexOf(DOCID) != -1) {
+                    //get index of '="
+                    int start = getIndexForGivenChar(str, '=') + 1;
+                    int end = str.length();
+                    docid = str.substring(start, end);
+                    find = true;
+                }//if
+            }//if
+        }//for
+        //if not find, we need check the subtring between the index of last &
+        // and
+        // the end of string
+        if (!find) {
+            MetaCatUtil.debugMessage("Checking the last substring", 35);
+            String str = url.substring(((Integer) list.elementAt(count))
+                    .intValue() + 1, url.length());
+            MetaCatUtil.debugMessage("Last substring is: " + str, 30);
+            if (str.indexOf(DOCID) != -1) {
+                //get index of '="
+                int start = getIndexForGivenChar(str, '=') + 1;
+                int end = str.length();
+                docid = str.substring(start, end);
+                find = true;
+            }//if
+        }//if
+        MetaCatUtil.debugMessage("The docid from online url is:" + docid, 30);
+        return docid.trim();
     }
-    return (str.toString());
-  }
-  
-  /** 
-   * Get docid from online/url string
-   */
-  public static String getDocIdWithRevFromOnlineURL(String url)
-  {
-    String docid = null;
-    String DOCID = "docid";
-    boolean find = false;
-    char limited = '&';
-    int  count = 0; //keep track how many & was found
-    Vector list = new Vector();// keep index number for &
-    if (url == null)
+
+    private static int getIndexForGivenChar(String str, char character)
     {
-      MetaCatUtil.debugMessage("url is null and null will be returned", 30);
-      return docid;
+        int index = -1;
+        // make sure str is not null
+        if (str == null) {
+            MetaCatUtil.debugMessage(
+                    "The given str is null and -1 will be returned", 30);
+            return index;
+        }
+        // got though the string
+        for (int i = 0; i < str.length(); i++) {
+            // find the first one then break the loop
+            if (str.charAt(i) == character) {
+                index = i;
+                break;
+            }//if
+        }//for
+        MetaCatUtil.debugMessage("the index for char " + character + " is: "
+                + index, 30);
+        return index;
     }
-    // the first element in list is 0
-    list.add(new Integer(0));
-    for (int i=0; i< url.length(); i++)
+
+    /**
+     * Utility method to get docid from a given string
+     * 
+     * @param string, the given string should be these two format: 1) str1.str2
+     *            in this case docid= str1.str2 2) str1.str2.str3, in this case
+     *            docid =str1.str2
+     * @param the sperator char
+     */
+    public static String getDocIdFromString(String str)
     {
-      if (url.charAt(i) == limited)
-      {
-        // count plus 1
-        count++;
-        list.add(new Integer(i));
-        // get substring beween two &
-        String str = url.substring(((Integer)list.elementAt(count-1)).intValue(), i);
-        MetaCatUtil.debugMessage("substring between two & is: " + str, 30);
-        //if the subString contains docid, we got it
-        if (str.indexOf(DOCID) != -1)
-        { 
-          //get index of '="
-          int start = getIndexForGivenChar(str, '=')+1;
-          int end   = str.length();
-          docid = str.substring(start, end);
-          find = true;
-        }//if
-      }//if
-    }//for
-    //if not find, we need check the subtring between the index of last & and 
-    // the end of string
-    if (!find)
-    {
-      MetaCatUtil.debugMessage("Checking the last substring", 35);
-      String str = url.substring(((Integer)list.elementAt(count)).intValue() +1, 
-                                 url.length());
-      MetaCatUtil.debugMessage("Last substring is: " + str, 30);
-      if (str.indexOf(DOCID) != -1)
-      { 
-          //get index of '="
-          int start = getIndexForGivenChar(str, '=')+1;
-          int end   = str.length();
-          docid = str.substring(start, end);
-          find = true;
-      }//if
-    }//if
-    MetaCatUtil.debugMessage("The docid from online url is:"+ docid, 30);
-    return docid.trim();
-  }
-  
-  private static int getIndexForGivenChar(String str, char character)
-  {
-    int index = -1;
-    // make sure str is not null
-    if(str == null)
-    {
-      MetaCatUtil.debugMessage("The given str is null and -1 will be returned",
-                                30);
-      return index;
-    }
-    // got though the string
-    for (int i=0; i<str.length(); i++)
-    {
-      // find the first one then break the loop
-      if (str.charAt(i) == character)
-      {
-        index = i;
-        break;
-      }//if
-    }//for
-    MetaCatUtil.debugMessage("the index for char "+ character +
-                             " is: "+index, 30);
-    return index;
-  }
-  
-  /**
-   * Utility method to get docid from a given string
-   * @param string, the given string should be these two format:
-   *              1) str1.str2  in this case docid= str1.str2
-   *              2) str1.str2.str3, in this case docid =str1.str2
-   * @param the sperator char
-   */
-  public static String getDocIdFromString(String str)
-  {
-    String docId = null;
-    if (str == null)
-    {
-      MetaCatUtil.debugMessage("The given str is null and null will be returned"
-                                +" in getDocIdfromString", 30);
-      return docId;
-    } //make sure docid is not null
-    int dotNumber = 0;//count how many dots in given string
-    int indexOfLastDot = 0;
+        String docId = null;
+        if (str == null) {
+            MetaCatUtil.debugMessage(
+                    "The given str is null and null will be returned"
+                            + " in getDocIdfromString", 30);
+            return docId;
+        } //make sure docid is not null
+        int dotNumber = 0;//count how many dots in given string
+        int indexOfLastDot = 0;
 
-    //assume that seperator is one charactor string
-    char seperator=getOption("accNumSeparator").charAt(0);
+        //assume that seperator is one charactor string
+        char seperator = getOption("accNumSeparator").charAt(0);
 
-    for (int i=0; i<str.length(); i++)
-    {
-      if ( str.charAt(i)==seperator)
-      {
-        dotNumber++;//count how many dots
-        indexOfLastDot=i;//keep the last dot postion
-      }
-    }//for
+        for (int i = 0; i < str.length(); i++) {
+            if (str.charAt(i) == seperator) {
+                dotNumber++;//count how many dots
+                indexOfLastDot = i;//keep the last dot postion
+            }
+        }//for
 
-    //The string formatt is wrong, because it has more than two or less than
-    //one seperator
-    if ( dotNumber>2 || dotNumber < 1)
+        //The string formatt is wrong, because it has more than two or less
+        // than
+        //one seperator
+        if (dotNumber > 2 || dotNumber < 1) {
+            docId = null;
+        } else if (dotNumber == 2) //the case for str1.str2.str3
+        {
+            docId = str.substring(0, indexOfLastDot);
+        } else if (dotNumber == 1) //the case for str1.str2
+        {
+            docId = str;
+        }
+
+        return docId;
+    }//getDocIdFromString
+
+    /**
+     * Utility method to get version number from a given string
+     * 
+     * @param string, the given string should be these two format: 1)
+     *            str1.str2(no version) version =-1; 2) str1.str2.str3, in this
+     *            case version = str3; 3) other, vresion =-2
+     */
+    public static int getVersionFromString(String str)
+            throws NumberFormatException
     {
-      docId=null;
-    }
-    else if (dotNumber == 2) //the case for str1.str2.str3
-    {
-       docId=str.substring(0, indexOfLastDot);
-    }
-    else if (dotNumber == 1) //the case for str1.str2
-    {
-      docId=str;
-    }
+        int version = -1;
+        String versionString = null;
+        int dotNumber = 0;//count how many dots in given string
+        int indexOfLastDot = 0;
 
-    return docId;
-  }//getDocIdFromString
-  
+        //assume that seperator is one charactor string
+        char seperator = getOption("accNumSeparator").charAt(0);
 
+        for (int i = 0; i < str.length(); i++) {
+            if (str.charAt(i) == seperator) {
+                dotNumber++;//count how many dots
+                indexOfLastDot = i;//keep the last dot postion
+            }
+        }//for
 
-  /**
-   * Utility method to get version number from a given string
-   * @param string, the given string should be these two format:
-   *              1) str1.str2(no version)  version =-1;
-   *              2) str1.str2.str3, in this case version = str3;
-   *              3) other, vresion =-2
-   */
-  public static int getVersionFromString(String str)
-                                throws NumberFormatException
-  {
-    int version=-1;
-    String versionString=null;
-    int dotNumber = 0;//count how many dots in given string
-    int indexOfLastDot = 0;
+        //The string formatt is wrong, because it has more than two or less
+        // than
+        //one seperator
+        if (dotNumber > 2 || dotNumber < 1) {
+            version = -2;
+        } else if (dotNumber == 2 && (indexOfLastDot != (str.length() - 1)))
+        //the case for str1.str2.str3
+        {
+            versionString = str.substring((indexOfLastDot + 1), str.length());
+            version = Integer.parseInt(versionString);
+        } else if (dotNumber == 1) //the case for str1.str2
+        {
+            version = -1;
+        }
 
-    //assume that seperator is one charactor string
-    char seperator=getOption("accNumSeparator").charAt(0);
+        return version;
+    }//getVersionFromString
 
-    for (int i=0; i<str.length(); i++)
+    /**
+     * Utility method to get version string from a given string
+     * 
+     * @param string, the given string should be these two format: 1)
+     *            str1.str2(no version) version=null; 2) str1.str2.str3, in
+     *            this case version = str3; 3) other, vresion =null;
+     */
+    public static String getRevisionStringFromString(String str)
+            throws NumberFormatException
     {
-      if ( str.charAt(i)==seperator)
-      {
-        dotNumber++;//count how many dots
-        indexOfLastDot=i;//keep the last dot postion
-      }
-    }//for
+        // String to store the version
+        String versionString = null;
+        int dotNumber = 0;//count how many dots in given string
+        int indexOfLastDot = 0;
 
-    //The string formatt is wrong, because it has more than two or less than
-    //one seperator
-    if ( dotNumber>2 || dotNumber < 1)
-    {
-      version=-2;
-    }
-    else if (dotNumber == 2 && (indexOfLastDot != (str.length() -1)))
-     //the case for str1.str2.str3
-    {
-       versionString=str.substring((indexOfLastDot+1), str.length());
-       version=Integer.parseInt(versionString);
-    }
-    else if (dotNumber == 1) //the case for str1.str2
-    {
-      version=-1;
-    }
+        //assume that seperator is one charactor string
+        char seperator = getOption("accNumSeparator").charAt(0);
 
-    return version;
-  }//getVersionFromString
+        for (int i = 0; i < str.length(); i++) {
+            if (str.charAt(i) == seperator) {
+                dotNumber++;//count how many dots
+                indexOfLastDot = i;//keep the last dot postion
+            }
+        }//for
 
+        //The string formatt is wrong, because it has more than two or less
+        // than
+        //one seperator
+        if (dotNumber > 2 || dotNumber < 1) {
+            versionString = null;
+        } else if (dotNumber == 2 && (indexOfLastDot != (str.length() - 1))) {
+            //the case for str1.str2.str3
+            // indexOfLastDot != (str.length() -1) means get rid of str1.str2.
+            versionString = str.substring((indexOfLastDot + 1), str.length());
+        } else if (dotNumber == 1) //the case for str1.str2 or str1.str2.
+        {
+            versionString = null;
+        }
 
-  /**
-   * Utility method to get version string from a given string
-   * @param string, the given string should be these two format:
-   *              1) str1.str2(no version)  version=null;
-   *              2) str1.str2.str3, in this case version = str3;
-   *              3) other, vresion =null;
-   */
-  public static String getRevisionStringFromString(String str)
-                                throws NumberFormatException
-  {
-    // String to store the version
-    String versionString=null;
-    int dotNumber = 0;//count how many dots in given string
-    int indexOfLastDot = 0;
+        return versionString;
+    }//getVersionFromString
 
-    //assume that seperator is one charactor string
-    char seperator=getOption("accNumSeparator").charAt(0);
-
-    for (int i=0; i<str.length(); i++)
+    /**
+     * This method will get docid from an AccessionNumber. There is no
+     * assumption the accessnumber will be str1.str2.str3. It can be more. So
+     * we think the docid will be get rid of last part
+     */
+    public static String getDocIdFromAccessionNumber(String accessionNumber)
     {
-      if ( str.charAt(i)==seperator)
-      {
-        dotNumber++;//count how many dots
-        indexOfLastDot=i;//keep the last dot postion
-      }
-    }//for
+        String docid = null;
+        if (accessionNumber == null) { return docid; }
+        String seperator = getOption("accNumSeparator");
+        int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
+        docid = accessionNumber.substring(0, indexOfLastSeperator);
+        MetaCatUtil.debugMessage("after parsing accessionnumber, docid is "
+                + docid, 30);
+        return docid;
+    }
 
-    //The string formatt is wrong, because it has more than two or less than
-    //one seperator
-    if ( dotNumber>2 || dotNumber < 1)
+    /**
+     * This method will call both getDocIdFromString and
+     * getDocIdFromAccessionNumber. So first, if the string looks str1.str2,
+     * the docid will be str1.str2. If the string is str1.str2.str3, the docid
+     * will be str1.str2. If the string is str1.str2.str3.str4 or more, the
+     * docid will be str1.str2.str3. If the string look like str1, null will be
+     * returned
+     *  
+     */
+    public static String getSmartDocId(String str)
     {
-      versionString = null;
+        String docid = null;
+        //call geDocIdFromString first.
+        docid = getDocIdFromString(str);
+        // If docid is null, try to call getDocIdFromAccessionNumber
+        // it will handle the seperator more than2
+        if (docid == null) {
+            docid = getDocIdFromAccessionNumber(str);
+        }
+        MetaCatUtil.debugMessage("The docid get from smart docid getor is "
+                + docid, 30);
+        return docid;
     }
-    else if (dotNumber == 2 && (indexOfLastDot != (str.length() -1)))
+
+    /**
+     * This method will get revision from an AccessionNumber. There is no
+     * assumption the accessnumber will be str1.str2.str3. It can be more. So
+     * we think the docid will be get rid of last part
+     */
+    public static int getRevisionFromAccessionNumber(String accessionNumber)
+            throws NumberFormatException
     {
-      //the case for str1.str2.str3
-      // indexOfLastDot != (str.length() -1) means get rid of str1.str2.
-      versionString=str.substring((indexOfLastDot+1), str.length());
+        String rev = null;
+        int revNumber = -1;
+        if (accessionNumber == null) { return revNumber; }
+        String seperator = getOption("accNumSeparator");
+        int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
+        rev = accessionNumber.substring(indexOfLastSeperator + 1,
+                accessionNumber.length());
+        revNumber = Integer.parseInt(rev);
+        MetaCatUtil.debugMessage("after parsing accessionnumber, rev is "
+                + revNumber, 30);
+        return revNumber;
     }
-    else if (dotNumber == 1) //the case for str1.str2 or str1.str2.
+
+    /**
+     * Method to get the name of local replication server
+     */
+    public static String getLocalReplicationServerName()
     {
-      versionString=null;
+        String replicationServerName = null;
+        String serverHost = null;
+        serverHost = getOption("server");
+        // append "context/servelet/replication" to the host name
+        replicationServerName = serverHost + getOption("replicationpath");
+        return replicationServerName;
+
     }
 
-    return versionString;
-  }//getVersionFromString
-
-  /**
-   * This method will get docid from an AccessionNumber. There is no assumption
-   * the accessnumber will be str1.str2.str3. It can be more. So we think
-   * the docid will be get rid of last part
-   */
-   public static String getDocIdFromAccessionNumber(String accessionNumber)
-   {
-     String docid = null;
-     if (accessionNumber == null)
-     {
-       return docid;
-     }
-     String seperator=getOption("accNumSeparator");
-     int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
-     docid=accessionNumber.substring(0, indexOfLastSeperator);
-     MetaCatUtil.debugMessage("after parsing accessionnumber, docid is " + 
-                              docid, 30);
-     return docid;
-   }
-   
-   /**
-    * This method will call both getDocIdFromString and
-    * getDocIdFromAccessionNumber. So first, if the string looks
-    * str1.str2, the docid will be str1.str2.
-    * If the string is str1.str2.str3, the docid will be str1.str2.
-    * If the string is str1.str2.str3.str4 or more, the docid will be
-    * str1.str2.str3.
-    * If the string look like str1, null will be returned
-    *
-    */
-    public static String getSmartDocId(String str)
+    /**
+     * Method to get docidwithrev from eml2 inline data id The eml inline data
+     * id would look like eml.200.2.3
+     */
+    public static String getDocIdWithoutRevFromInlineDataID(String inlineDataID)
     {
-      String docid = null;
-      //call geDocIdFromString first. 
-      docid = getDocIdFromString(str);
-      // If docid is null, try to call getDocIdFromAccessionNumber
-      // it will handle the seperator more than2
-      if (docid == null)
-      {
-         docid = getDocIdFromAccessionNumber(str);        
-      }
-      MetaCatUtil.debugMessage("The docid get from smart docid getor is " +
-                                docid, 30);
-      return docid;
-    }
-   
-    /**
-   * This method will get revision from an AccessionNumber. There is no assumption
-   * the accessnumber will be str1.str2.str3. It can be more. So we think
-   * the docid will be get rid of last part
-   */
-   public static int getRevisionFromAccessionNumber(String accessionNumber)
-                                        throws NumberFormatException
-   {
-     String rev = null;
-     int revNumber =-1;
-     if (accessionNumber == null)
-     {
-       return revNumber;
-     }
-     String seperator=getOption("accNumSeparator");
-     int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
-     rev =accessionNumber.substring(indexOfLastSeperator+1, 
-                                    accessionNumber.length());
-     revNumber = Integer.parseInt(rev);
-     MetaCatUtil.debugMessage("after parsing accessionnumber, rev is " + 
-                               revNumber, 30);
-     return revNumber;
-   }
-   
-  
-  /**
-   * Method to get the name of local replication server
-   */
-   public static String getLocalReplicationServerName()
-   {
-     String replicationServerName=null;
-     String serverHost=null;
-     serverHost=getOption("server");
-     // append "context/servelet/replication" to the host name
-     replicationServerName=serverHost+getOption("replicationpath");
-     return replicationServerName;
+        String docidWithoutRev = null;
+        if (inlineDataID == null) { return docidWithoutRev; }
+        String seperator = MetaCatUtil.getOption("accNumSeparator");
+        char charSeperator = seperator.charAt(0);
+        int targetNumberOfSeperator = 2;// we want to know his index
+        int numberOfSeperator = 0;
+        for (int i = 0; i < inlineDataID.length(); i++) {
+            // meet seperator, increase number of seperator
+            if (inlineDataID.charAt(i) == charSeperator) {
+                numberOfSeperator++;
+            }
+            // if number of seperator reach the target one, record the index(i)
+            // and get substring and terminate the loop
+            if (numberOfSeperator == targetNumberOfSeperator) {
+                docidWithoutRev = inlineDataID.substring(0, i);
+                break;
+            }
+        }
 
-   }
+        MetaCatUtil.debugMessage("Docid without rev from inlinedata id: "
+                + docidWithoutRev, 35);
+        return docidWithoutRev;
 
-   /**
-    * Method to get docidwithrev from eml2 inline data id
-    * The eml inline data id would look like eml.200.2.3
-    */
-   public static String getDocIdWithoutRevFromInlineDataID(String inlineDataID)
-   {
-     String docidWithoutRev = null;
-     if ( inlineDataID == null)
-     {
-       return docidWithoutRev;
-     }
-     String seperator = MetaCatUtil.getOption("accNumSeparator");
-     char charSeperator = seperator.charAt(0);
-     int targetNumberOfSeperator = 2;// we  want to know his index
-     int numberOfSeperator = 0;
-     for (int i = 0; i< inlineDataID.length(); i++)
-     {
-       // meet seperator, increase number of seperator
-       if (inlineDataID.charAt(i) == charSeperator)
-       {
-         numberOfSeperator++;
-       }
-       // if number of seperator reach the target one, record the index(i)
-       // and get substring and terminate the loop
-       if ( numberOfSeperator == targetNumberOfSeperator)
-       {
-         docidWithoutRev = inlineDataID.substring(0, i);
-         break;
-       }
-     }
+    }
 
-     MetaCatUtil.debugMessage("Docid without rev from inlinedata id: " +
-                               docidWithoutRev, 35);
-     return docidWithoutRev;
+    /**
+     * Revise stack change a stack to opposite order
+     */
+    public static Stack reviseStack(Stack stack)
+    {
+        Stack result = new Stack();
+        // make sure the parameter is correct
+        if (stack == null || stack.isEmpty()) {
+            result = stack;
+            return result;
+        }
 
-   }
-   
-   /**
-    * Revise stack change a stack to opposite order 
-    */
-   public static Stack reviseStack(Stack stack)
-   {
-     Stack result = new Stack();
-     // make sure the parameter is correct
-     if (stack == null || stack.isEmpty())
-     {
-       result = stack;
-       return result;
-     }
-     
-     while (!stack.isEmpty())
-     {
-       Object obj = stack.pop();
-       result.push(obj);
-     }
-     return result;
-   }
-  
-  /** A method to replace whitespace in url*/
-  public static String replaceWhiteSpaceForURL(String urlHasWhiteSpace)
-  {
-    StringBuffer newUrl = new StringBuffer();
-    String whiteSpaceReplace ="%20";
-    if (urlHasWhiteSpace == null || urlHasWhiteSpace.trim().equals(""))
-    {
-      return null;
+        while (!stack.isEmpty()) {
+            Object obj = stack.pop();
+            result.push(obj);
+        }
+        return result;
     }
 
-    for (int i=0; i<urlHasWhiteSpace.length(); i++)
+    /** A method to replace whitespace in url */
+    public static String replaceWhiteSpaceForURL(String urlHasWhiteSpace)
     {
-       char ch = urlHasWhiteSpace.charAt(i);
-       if ( !Character.isWhitespace(ch))
-       {
-          newUrl.append(ch);
-       }
-       else
-       {
-         //it is white sapce, replace it by %20
-         newUrl = newUrl.append(whiteSpaceReplace);
-       }
+        StringBuffer newUrl = new StringBuffer();
+        String whiteSpaceReplace = "%20";
+        if (urlHasWhiteSpace == null || urlHasWhiteSpace.trim().equals("")) { return null; }
 
-   }//for
-   MetaCatUtil.debugMessage("The new string without space is:"+ 
-                             newUrl.toString(), 35);
-   return newUrl.toString();
+        for (int i = 0; i < urlHasWhiteSpace.length(); i++) {
+            char ch = urlHasWhiteSpace.charAt(i);
+            if (!Character.isWhitespace(ch)) {
+                newUrl.append(ch);
+            } else {
+                //it is white sapce, replace it by %20
+                newUrl = newUrl.append(whiteSpaceReplace);
+            }
 
-  }// replaceWhiteSpaceForUR
+        }//for
+        MetaCatUtil.debugMessage("The new string without space is:"
+                + newUrl.toString(), 35);
+        return newUrl.toString();
 
+    }// replaceWhiteSpaceForUR
+
 }
Index: src/edu/ucsb/nceas/metacat/QueryTerm.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QueryTerm.java	(revision 2067)
+++ src/edu/ucsb/nceas/metacat/QueryTerm.java	(revision 2068)
@@ -30,263 +30,250 @@
 
 package edu.ucsb.nceas.metacat;
 
-import edu.ucsb.nceas.dbadapter.*;
-
-import java.io.*;
-import java.util.Hashtable;
-import java.util.Stack;
 import java.util.Vector;
-import java.util.Enumeration;
 
 /** a utility class that represents a single term in a query */
-public class QueryTerm {
+public class QueryTerm
+{
+
     private boolean casesensitive = false;
+
     private String searchmode = null;
+
     private String value = null;
+
     private String pathexpr = null;
+
     private boolean percentageSymbol = false;
+
     private int countPercentageSearchItem = 0;
-   
 
     /**
-     * Construct a new instance of a query term for a free text search
-     * (using the value only)
-     *
-     * @param casesensitive flag indicating whether case is used to match
-     * @param searchmode determines what kind of substring match is performed
-     *        (one of starts-with|ends-with|contains|matches-exactly)
-     * @param value the text value to match
+     * Construct a new instance of a query term for a free text search (using
+     * the value only)
+     * 
+     * @param casesensitive
+     *            flag indicating whether case is used to match
+     * @param searchmode
+     *            determines what kind of substring match is performed (one of
+     *            starts-with|ends-with|contains|matches-exactly)
+     * @param value
+     *            the text value to match
      */
-    public QueryTerm(boolean casesensitive, String searchmode, 
-                     String value) {
-      this.casesensitive = casesensitive;
-      this.searchmode = searchmode;
-      this.value = value;
+    public QueryTerm(boolean casesensitive, String searchmode, String value)
+    {
+        this.casesensitive = casesensitive;
+        this.searchmode = searchmode;
+        this.value = value;
     }
 
     /**
      * Construct a new instance of a query term for a structured search
      * (matching the value only for those nodes in the pathexpr)
-     *
-     * @param casesensitive flag indicating whether case is used to match
-     * @param searchmode determines what kind of substring match is performed
-     *        (one of starts-with|ends-with|contains|matches-exactly)
-     * @param value the text value to match
-     * @param pathexpr the hierarchical path to the nodes to be searched
+     * 
+     * @param casesensitive
+     *            flag indicating whether case is used to match
+     * @param searchmode
+     *            determines what kind of substring match is performed (one of
+     *            starts-with|ends-with|contains|matches-exactly)
+     * @param value
+     *            the text value to match
+     * @param pathexpr
+     *            the hierarchical path to the nodes to be searched
      */
-    public QueryTerm(boolean casesensitive, String searchmode, 
-                     String value, String pathexpr) {
-      this(casesensitive, searchmode, value);
-      this.pathexpr = pathexpr;
+    public QueryTerm(boolean casesensitive, String searchmode, String value,
+            String pathexpr)
+    {
+        this(casesensitive, searchmode, value);
+        this.pathexpr = pathexpr;
     }
 
     /** determine if the QueryTerm is case sensitive */
-    public boolean isCaseSensitive() {
-      return casesensitive;
+    public boolean isCaseSensitive()
+    {
+        return casesensitive;
     }
 
     /** get the searchmode parameter */
-    public String getSearchMode() {
-      return searchmode;
+    public String getSearchMode()
+    {
+        return searchmode;
     }
- 
+
     /** get the Value parameter */
-    public String getValue() {
-      return value;
+    public String getValue()
+    {
+        return value;
     }
 
     /** get the path expression parameter */
-    public String getPathExpression() {
-      return pathexpr;
+    public String getPathExpression()
+    {
+        return pathexpr;
     }
-    
-    /** get the percentage count for one query term*/
+
+    /** get the percentage count for one query term */
     public int getPercentageSymbolCount()
     {
-      return countPercentageSearchItem;
+        return countPercentageSearchItem;
     }
 
     /**
      * create a SQL serialization of the query that this instance represents
      */
-    public String printSQL(boolean useXMLIndex) {
-      StringBuffer self = new StringBuffer();
+    public String printSQL(boolean useXMLIndex)
+    {
+        StringBuffer self = new StringBuffer();
 
-      // Uppercase the search string if case match is not important
-      String casevalue = null;
-      String nodedataterm = null;
+        // Uppercase the search string if case match is not important
+        String casevalue = null;
+        String nodedataterm = null;
 
-      if (casesensitive) {
-        nodedataterm = "nodedata";
-        casevalue = value;
-      } else {
-        nodedataterm = "UPPER(nodedata)";
-        casevalue = value.toUpperCase();
-      }
+        if (casesensitive) {
+            nodedataterm = "nodedata";
+            casevalue = value;
+        } else {
+            nodedataterm = "UPPER(nodedata)";
+            casevalue = value.toUpperCase();
+        }
 
-      // Add appropriate wildcards to search string
-      //String searchvalue = null;
-      String searchexpr = null;
-      if (searchmode.equals("starts-with")) {
-        //searchvalue = casevalue + "%";
-        searchexpr = nodedataterm + " LIKE '" + casevalue + "%' ";
-      } else if (searchmode.equals("ends-with")) {
-        //searchvalue = "%" + casevalue;
-        searchexpr = nodedataterm + " LIKE '%" + casevalue + "' ";
-      } else if (searchmode.equals("contains")) {
-        //searchvalue = "%" + casevalue + "%";
-        if (!casevalue.equals("%"))
-        {
-          searchexpr = nodedataterm + " LIKE '%" + casevalue + "%' ";
-        }
-        else
-        {
-          searchexpr = nodedataterm + " LIKE '" + casevalue + "' ";
-          // find percentage symbol
-          percentageSymbol = true;
-        }
-      } else if (searchmode.equals("not-contains")) {
-        //searchvalue = "%" + casevalue;
-        searchexpr = nodedataterm + " NOT LIKE '%" + casevalue + "%' ";
-      } else if (searchmode.equals("equals")) {
-        //searchvalue = casevalue;
-        searchexpr = nodedataterm + " = '" + casevalue + "' ";
-      } else if (searchmode.equals("isnot-equal")) {
-        //searchvalue = casevalue;
-        searchexpr = nodedataterm + " != '" + casevalue + "' ";
-      } else { 
-        //searchvalue = casevalue;
-        String oper = null;
-        if (searchmode.equals("greater-than")) {
-          oper = ">";
-          nodedataterm = "nodedata";
-        } else if (searchmode.equals("greater-than-equals")) {
-          oper = ">=";
-          nodedataterm = "nodedata";
-        } else if (searchmode.equals("less-than")) {
-          oper = "<";
-          nodedataterm = "nodedata";
-        } else if (searchmode.equals("less-than-equals")) {
-          oper = "<=";
-          nodedataterm = "nodedata";
+        // Add appropriate wildcards to search string
+        String searchexpr = null;
+        if (searchmode.equals("starts-with")) {
+            searchexpr = nodedataterm + " LIKE '" + casevalue + "%' ";
+        } else if (searchmode.equals("ends-with")) {
+            searchexpr = nodedataterm + " LIKE '%" + casevalue + "' ";
+        } else if (searchmode.equals("contains")) {
+            if (!casevalue.equals("%")) {
+                searchexpr = nodedataterm + " LIKE '%" + casevalue + "%' ";
+            } else {
+                searchexpr = nodedataterm + " LIKE '" + casevalue + "' ";
+                // find percentage symbol
+                percentageSymbol = true;
+            }
+        } else if (searchmode.equals("not-contains")) {
+            searchexpr = nodedataterm + " NOT LIKE '%" + casevalue + "%' ";
+        } else if (searchmode.equals("equals")) {
+            searchexpr = nodedataterm + " = '" + casevalue + "' ";
+        } else if (searchmode.equals("isnot-equal")) {
+            searchexpr = nodedataterm + " != '" + casevalue + "' ";
         } else {
-          System.out.println("NOT expected case. NOT recognized operator: " +
-                             searchmode);
-          return null;
+            String oper = null;
+            if (searchmode.equals("greater-than")) {
+                oper = ">";
+                nodedataterm = "nodedata";
+            } else if (searchmode.equals("greater-than-equals")) {
+                oper = ">=";
+                nodedataterm = "nodedata";
+            } else if (searchmode.equals("less-than")) {
+                oper = "<";
+                nodedataterm = "nodedata";
+            } else if (searchmode.equals("less-than-equals")) {
+                oper = "<=";
+                nodedataterm = "nodedata";
+            } else {
+                System.out
+                        .println("NOT expected case. NOT recognized operator: "
+                                + searchmode);
+                return null;
+            }
+            try {
+                // it is number; numeric comparison
+                // but we need to make sure there is no string in node data
+                String getRidOfString = " AND UPPER(nodedata) = LOWER(nodedata)"
+                        + " AND LTRIM(nodedata) != ' ' "
+                        + " AND nodedata IS NOT NULL ";
+                searchexpr = nodedataterm + " " + oper + " "
+                        + new Double(casevalue) + " " + getRidOfString;
+            } catch (NumberFormatException nfe) {
+                // these are characters; character comparison
+                searchexpr = nodedataterm + " " + oper + " '" + casevalue
+                        + "' ";
+            }
         }
-        try {
-          // it is number; numeric comparison
-          // but we need to make sure there is no string in node data
-          String getRidOfString = " AND UPPER(nodedata) = LOWER(nodedata)" +
-                                  " AND LTRIM(nodedata) != ' ' " +
-                                  " AND nodedata IS NOT NULL ";
-          searchexpr = nodedataterm + " " + oper + " " +
-                       new Double(casevalue) + " "+getRidOfString;          
-        } catch (NumberFormatException nfe) {
-          // these are characters; character comparison
-          searchexpr = nodedataterm + " " + oper + " '" + casevalue + "' ";
-        }
-      }
 
-      self.append("SELECT DISTINCT docid FROM xml_nodes WHERE \n");
-      //self.append(nodedataterm + " LIKE " + "'" + searchvalue + "' ");
-      self.append(searchexpr);
-      if (pathexpr != null) 
-      {
-        
-        // use XML Index
-        if ( useXMLIndex ) 
-        {
-          if (!hasAttributeInPath(pathexpr))
-          {
-            // without attributes in path
-            self.append("AND parentnodeid IN ");
-          }
-          else
-          {
-            // has a attribute in path
-            String attributeName = QuerySpecification.getAttributeName(pathexpr);
-            self.append("AND nodetype LIKE 'ATTRIBUTE' AND nodename LIKE '"+
-                        attributeName + "' ");
-            self.append("AND parentnodeid IN ");
-            pathexpr = 
-                 QuerySpecification.newPathExpressionWithOutAttribute(pathexpr);
-            
-          } 
-          self.append("(SELECT nodeid FROM xml_index WHERE path LIKE " + 
-                      "'" +  pathexpr + "') " );
-        } 
-        else 
-        {
-          // without using XML Index; using nested statements instead
-          self.append("AND parentnodeid IN ");
-          self.append(useNestedStatements(pathexpr));
+        self.append("SELECT DISTINCT docid FROM xml_nodes WHERE \n");
+        self.append(searchexpr);
+        if (pathexpr != null) {
+
+            // use XML Index
+            if (useXMLIndex) {
+                if (!hasAttributeInPath(pathexpr)) {
+                    // without attributes in path
+                    self.append("AND parentnodeid IN ");
+                } else {
+                    // has a attribute in path
+                    String attributeName = QuerySpecification
+                            .getAttributeName(pathexpr);
+                    self.append("AND nodetype LIKE 'ATTRIBUTE' AND nodename LIKE '"
+                                    + attributeName + "' ");
+                    self.append("AND parentnodeid IN ");
+                    pathexpr = QuerySpecification
+                            .newPathExpressionWithOutAttribute(pathexpr);
+
+                }
+                self.append("(SELECT nodeid FROM xml_index WHERE path LIKE "
+                        + "'" + pathexpr + "') ");
+            } else {
+                // without using XML Index; using nested statements instead
+                self.append("AND parentnodeid IN ");
+                self.append(useNestedStatements(pathexpr));
+            }
+        } else if ((value.trim()).equals("%")) {
+            //if pathexpr is null and search value is %, is a
+            // percentageSearchItem
+            // the count number will be increase one
+            countPercentageSearchItem++;
+
         }
-      }
-      else if ((value.trim()).equals("%"))
-      {
-        //if pathexpr is null and search value is %, is a percentageSearchItem
-        // the count number will be increase one
-        countPercentageSearchItem++;
-        
-       }
 
-      return self.toString();
+        return self.toString();
     }
-    
-    /* A method to judge if a path have attribute */
+
+    /** A method to judge if a path have attribute */
     private boolean hasAttributeInPath(String path)
     {
-      if (path.indexOf(QuerySpecification.ATTRIBUTESYMBOL)!=-1)
-      {
-        return true;
-      }
-      else
-      {
-        return false;
-      }
+        if (path.indexOf(QuerySpecification.ATTRIBUTESYMBOL) != -1) {
+            return true;
+        } else {
+            return false;
+        }
     }
-    
-   
-    
-    /* 
-     * Constraint the query with @pathexp without using the XML Index,
-     * but nested SQL statements instead. The query migth be slower.
+
+    /*
+     * Constraint the query with @pathexp without using the XML Index, but
+     * nested SQL statements instead. The query migth be slower.
      */
     private String useNestedStatements(String pathexpr)
     {
-      StringBuffer nestedStmts = new StringBuffer();
-      Vector nodes = new Vector();
-      String path = pathexpr;
-      int inx = 0;
+        StringBuffer nestedStmts = new StringBuffer();
+        Vector nodes = new Vector();
+        String path = pathexpr;
+        int inx = 0;
 
-      do {
-        inx = path.lastIndexOf("/");
+        do {
+            inx = path.lastIndexOf("/");
 
-        nodes.addElement(path.substring(inx+1));
-        path = path.substring(0, Math.abs(inx));
-      } while ( inx > 0 );
-      
-      // nested statements
-      int i = 0;
-      for (i = 0; i < nodes.size()-1; i++) {
-        nestedStmts.append("(SELECT nodeid FROM xml_nodes" + 
-                           " WHERE nodename LIKE '" +
-                             (String)nodes.elementAt(i) + "'" +
-                           " AND parentnodeid IN ");
-      }
-      // for the last statement: it is without " AND parentnodeid IN "
-      nestedStmts.append("(SELECT nodeid FROM xml_nodes" + 
-                         " WHERE nodename LIKE '" +
-                         (String)nodes.elementAt(i) + "'" );
-      // node.size() number of closing brackets
-      for (i = 0; i < nodes.size(); i++) {
-        nestedStmts.append(")");
-      }
+            nodes.addElement(path.substring(inx + 1));
+            path = path.substring(0, Math.abs(inx));
+        } while (inx > 0);
 
+        // nested statements
+        int i = 0;
+        for (i = 0; i < nodes.size() - 1; i++) {
+            nestedStmts.append("(SELECT nodeid FROM xml_nodes"
+                    + " WHERE nodename LIKE '" + (String) nodes.elementAt(i)
+                    + "'" + " AND parentnodeid IN ");
+        }
+        // for the last statement: it is without " AND parentnodeid IN "
+        nestedStmts.append("(SELECT nodeid FROM xml_nodes"
+                + " WHERE nodename LIKE '" + (String) nodes.elementAt(i) + "'");
+        // node.size() number of closing brackets
+        for (i = 0; i < nodes.size(); i++) {
+            nestedStmts.append(")");
+        }
 
-
-      return nestedStmts.toString();
+        return nestedStmts.toString();
     }
 
     /**
@@ -293,8 +280,9 @@
      * create a String description of the query that this instance represents.
      * This should become a way to get the XML serialization of the query.
      */
-    public String toString() {
+    public String toString()
+    {
 
-      return this.printSQL(true);
+        return this.printSQL(true);
     }
-  }
+}
