Index: src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/EmlSAXHandler.java	(revision 2075)
+++ src/edu/ucsb/nceas/metacat/EmlSAXHandler.java	(revision 2076)
@@ -28,26 +28,24 @@
 
 package edu.ucsb.nceas.metacat;
 
-import java.sql.*;
 import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.IOException;
 import java.io.Reader;
-import java.io.StringReader;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.EmptyStackException;
+import java.util.Enumeration;
+import java.util.Hashtable;
 import java.util.Stack;
 import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Enumeration;
-import java.util.EmptyStackException;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.ext.DeclHandler;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * A database aware Class implementing callback bethods for the SAX parser to
@@ -1479,21 +1477,21 @@
    
      // Starting new thread for writing XML Index.
      // It calls the run method of the thread.
-     try 
-     {
-       xmlIndex.start();
-     } 
-     catch (NullPointerException e) 
-     {
-       xmlIndex = null;
-       throw new
-       SAXException("Problem with starting thread for writing XML Index. " +
-                    e.getMessage());
+     boolean useXMLIndex = 
+         (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
+     if (useXMLIndex) {
+            try {
+                xmlIndex.start();
+            } catch (NullPointerException e) {
+                xmlIndex = null;
+                throw new SAXException(
+                        "Problem with starting thread for writing XML Index. "
+                                + e.getMessage());
+            }
      }
-   
    }
    
-  /* The method to write all access rule intodb */
+  /* The method to write all access rule into db */
   private void writeAccessRuleToDB() throws SAXException
   {
     //Delete old permssion
Index: src/edu/ucsb/nceas/metacat/DBSAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 2075)
+++ src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 2076)
@@ -28,17 +28,19 @@
 
 package edu.ucsb.nceas.metacat;
 
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.EmptyStackException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Stack;
+import java.util.Vector;
+
 import edu.ucsb.nceas.morpho.datapackage.Triple;
 import edu.ucsb.nceas.morpho.datapackage.TripleCollection;
 
-import java.sql.*;
-import java.io.StringReader;
-import java.util.Stack;
-import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Enumeration;
-import java.util.EmptyStackException;
-
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
@@ -48,810 +50,840 @@
 
 /**
  * A database aware Class implementing callback bethods for the SAX parser to
- * call when processing the XML stream and generating events
+ * call when processing the XML stream and generating events.
  */
-public class DBSAXHandler extends DefaultHandler
-                          implements LexicalHandler, DeclHandler, Runnable {
+public class DBSAXHandler extends DefaultHandler implements LexicalHandler,
+        DeclHandler, Runnable
+{
 
-   protected boolean	atFirstElement;
-   protected boolean	processingDTD;
-   protected String 	docname = null;
-   protected String 	doctype;
-   protected String 	systemid;
-   private boolean 	stackCreated = false;
-   protected Stack 	  nodeStack;
-   protected Vector   nodeIndex;
-   protected DBConnection	  connection = null;
-   protected DocumentImpl currentDocument;
-   protected DBSAXNode    rootNode;
-   protected String   action = null;
-   protected String   docid = null;
-   protected String   revision = null;
-   protected String   user = null;
-   protected String[] groups = null;
-   protected String   pub = null;
-   protected Thread   xmlIndex;
-   private boolean endDocument = false;
-   protected int serverCode = 1;
-   protected Hashtable namespaces = new Hashtable();
-   protected boolean hitTextNode = false; // a flag to hit text node
-   // a buffer to keep all text nodes for same element
-   // it is for element was splited
-   protected StringBuffer textBuffer = new StringBuffer();
-   protected Stack textBufferStack = new Stack();
+    protected boolean atFirstElement;
 
-   protected static final int MAXDATACHARS = 4000;
-   //protected static final int MAXDATACHARS = 50;
-   protected static final long INDEXDELAY = 10000;
-   // methods writeChildNodeToDB, setAttribute, setNamespace, 
-   // writeTextForDBSAXNode will increase endNodeId.
-   protected long  endNodeId = -1;    // The end node id for a substree
-// DOCTITLE attr cleared from the db
-//   private static final int MAXTITLELEN = 1000;
-   //HandlerTriple stuff
-   TripleCollection tripleList = new TripleCollection();
-   Triple currentTriple        = new Triple();
-   boolean startParseTriple    = false;
-   boolean hasTriple           = false;
+    protected boolean processingDTD;
 
-   /** Construct an instance of the handler class
-    *
-    * @param conn the JDBC connection to which information is written
-    */
-   public DBSAXHandler(DBConnection conn) {
-     this.connection = conn;
-     this.atFirstElement = true;
-     this.processingDTD = false;
+    protected String docname = null;
 
-     // Create the stack for keeping track of node context
-     // if it doesn't already exist
-     if (!stackCreated) {
-       nodeStack = new Stack();
-       nodeIndex = new Vector();
-       stackCreated = true;
-     }
-   }
+    protected String doctype;
 
-  /** Construct an instance of the handler class
-    *
-    * @param conn the JDBC connection to which information is written
-    * @param action - "INSERT" or "UPDATE"
-    * @param docid to be inserted or updated into JDBC connection
-    * @param user the user connected to MetaCat servlet and owns the document
-    * @param groups the groups to which user belongs
-    * @param pub flag for public "read" access on document
-    * @param serverCode the serverid from xml_replication on which this document
-    *        resides.
-    *
-    */
-   public DBSAXHandler(DBConnection conn, String action, String docid,
-                      String user, String[] groups, String pub, int serverCode)
-   {
-     this(conn);
-     this.action = action;
-     this.docid = docid;
-     this.user = user;
-     this.groups = groups;
-     this.pub = pub;
-     this.serverCode = serverCode;
-     this.xmlIndex = new Thread(this);
-   }
+    protected String systemid;
 
-  /** Construct an instance of the handler class
-    * In this constructor, user can specify the version need to upadate
-    *
-    * @param conn the JDBC connection to which information is written
-    * @param action - "INSERT" or "UPDATE"
-    * @param docid to be inserted or updated into JDBC connection
-    * @param revision, the user specified the revision need to be update
-    * @param user the user connected to MetaCat servlet and owns the document
-    * @param groups the groups to which user belongs
-    * @param pub flag for public "read" access on document
-    * @param serverCode the serverid from xml_replication on which this document
-    *        resides.
-    *
-    */
-   public DBSAXHandler(DBConnection conn, String action, String docid,
-     String revision, String user, String[] groups, String pub, int serverCode)
-   {
-     this(conn);
-     this.action = action;
-     this.docid = docid;
-     this.revision = revision;
-     this.user = user;
-     this.groups = groups;
-     this.pub = pub;
-     this.serverCode = serverCode;
-     this.xmlIndex = new Thread(this);
-   }
+    private boolean stackCreated = false;
 
-   /** SAX Handler that receives notification of beginning of the document */
-   public void startDocument() throws SAXException {
-     MetaCatUtil.debugMessage("start Document", 50);
+    protected Stack nodeStack;
 
-     // Create the document node representation as root
-     rootNode = new DBSAXNode(connection, this.docid);
-     // Add the node to the stack, so that any text data can be
-     // added as it is encountered
-     nodeStack.push(rootNode);
-   }
+    protected Vector nodeIndex;
 
-   /** SAX Handler that receives notification of end of the document */
-   public void endDocument() throws SAXException {
-     MetaCatUtil.debugMessage("end Document", 50);
-     // Starting new thread for writing XML Index.
-     // It calls the run method of the thread.
-     
-     //if it is data package insert triple into relationtion table;
-     if ( doctype != null && 
-         MetaCatUtil.getOptionList(MetaCatUtil.getOption("packagedoctype")).
-         contains(doctype) && hasTriple)
-      {
-        try
-        {
-          //initial handler and write into relationdb
-          RelationHandler handler = 
-                        new RelationHandler(docid,doctype, connection, tripleList);
+    protected DBConnection connection = null;
+
+    protected DocumentImpl currentDocument;
+
+    protected DBSAXNode rootNode;
+
+    protected String action = null;
+
+    protected String docid = null;
+
+    protected String revision = null;
+
+    protected String user = null;
+
+    protected String[] groups = null;
+
+    protected String pub = null;
+
+    protected Thread xmlIndex;
+
+    private boolean endDocument = false;
+
+    protected int serverCode = 1;
+
+    protected Hashtable namespaces = new Hashtable();
+
+    protected boolean hitTextNode = false; // a flag to hit text node
+
+    // a buffer to keep all text nodes for same element
+    // it is for element was splited
+    protected StringBuffer textBuffer = new StringBuffer();
+
+    protected Stack textBufferStack = new Stack();
+
+    protected static final int MAXDATACHARS = 4000;
+
+    //protected static final int MAXDATACHARS = 50;
+    protected static final long INDEXDELAY = 10000;
+
+    // methods writeChildNodeToDB, setAttribute, setNamespace,
+    // writeTextForDBSAXNode will increase endNodeId.
+    protected long endNodeId = -1; // The end node id for a substree
+    // DOCTITLE attr cleared from the db
+    //   private static final int MAXTITLELEN = 1000;
+
+    //HandlerTriple stuff
+    TripleCollection tripleList = new TripleCollection();
+
+    Triple currentTriple = new Triple();
+
+    boolean startParseTriple = false;
+
+    boolean hasTriple = false;
+
+    /**
+     * Construct an instance of the handler class
+     * 
+     * @param conn the JDBC connection to which information is written
+     */
+    private DBSAXHandler(DBConnection conn)
+    {
+        this.connection = conn;
+        this.atFirstElement = true;
+        this.processingDTD = false;
+
+        // Create the stack for keeping track of node context
+        // if it doesn't already exist
+        if (!stackCreated) {
+            nodeStack = new Stack();
+            nodeIndex = new Vector();
+            stackCreated = true;
         }
-        catch (Exception e)
-        {
-          MetaCatUtil.debugMessage
-                            ("Failed to write triples into relation table" + 
-                                                           e.getMessage(), 30);
-          throw new SAXException("Failed to write triples into relation table "+ e.getMessage());
+    }
+
+    /**
+     * Construct an instance of the handler class
+     * 
+     * @param conn the JDBC connection to which information is written
+     * @param action - "INSERT" or "UPDATE"
+     * @param docid to be inserted or updated into JDBC connection
+     * @param user the user connected to MetaCat servlet and owns the document
+     * @param groups the groups to which user belongs
+     * @param pub flag for public "read" access on document
+     * @param serverCode the serverid from xml_replication on which this
+     *            document resides.
+     *  
+     */
+/* TODO excise this constructor because not used anywhere in project 
+    public DBSAXHandler(DBConnection conn, String action, String docid,
+            String user, String[] groups, String pub, int serverCode)
+    {
+        this(conn);
+        this.action = action;
+        this.docid = docid;
+        this.user = user;
+        this.groups = groups;
+        this.pub = pub;
+        this.serverCode = serverCode;
+        this.xmlIndex = new Thread(this);
+    }
+*/
+    /**
+     * Construct an instance of the handler class In this constructor, user can
+     * specify the version need to upadate
+     * 
+     * @param conn the JDBC connection to which information is written
+     * @param action - "INSERT" or "UPDATE"
+     * @param docid to be inserted or updated into JDBC connection
+     * @param revision, the user specified the revision need to be update
+     * @param user the user connected to MetaCat servlet and owns the document
+     * @param groups the groups to which user belongs
+     * @param pub flag for public "read" access on document
+     * @param serverCode the serverid from xml_replication on which this
+     *            document resides.
+     *  
+     */
+    public DBSAXHandler(DBConnection conn, String action, String docid,
+            String revision, String user, String[] groups, String pub,
+            int serverCode)
+    {
+        this(conn);
+        this.action = action;
+        this.docid = docid;
+        this.revision = revision;
+        this.user = user;
+        this.groups = groups;
+        this.pub = pub;
+        this.serverCode = serverCode;
+        this.xmlIndex = new Thread(this);
+    }
+
+    /** SAX Handler that receives notification of beginning of the document */
+    public void startDocument() throws SAXException
+    {
+        MetaCatUtil.debugMessage("start Document", 50);
+
+        // Create the document node representation as root
+        rootNode = new DBSAXNode(connection, this.docid);
+        // Add the node to the stack, so that any text data can be
+        // added as it is encountered
+        nodeStack.push(rootNode);
+    }
+
+    /** SAX Handler that receives notification of end of the document */
+    public void endDocument() throws SAXException
+    {
+        MetaCatUtil.debugMessage("end Document", 50);
+        // Starting new thread for writing XML Index.
+        // It calls the run method of the thread.
+
+        //if it is data package insert triple into relationtion table;
+        if (doctype != null
+                && MetaCatUtil.getOptionList(
+                        MetaCatUtil.getOption("packagedoctype")).contains(
+                        doctype) && hasTriple) {
+            try {
+                //initial handler and write into relationdb
+                RelationHandler handler = new RelationHandler(docid, doctype,
+                        connection, tripleList);
+            } catch (Exception e) {
+                MetaCatUtil.debugMessage(
+                        "Failed to write triples into relation table"
+                                + e.getMessage(), 30);
+                throw new SAXException(
+                        "Failed to write triples into relation table "
+                                + e.getMessage());
+            }
         }
-      }
-     
-     
-     try {
-       xmlIndex.start();
-     } catch (NullPointerException e) {
-       xmlIndex = null;
-       throw new
-       SAXException("Problem with starting thread for writing XML Index. " +
-                    e.getMessage());
-     }
-   }
+        boolean useXMLIndex = 
+            (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
+        if (useXMLIndex) {
+            try {
+                xmlIndex.start();
+            } catch (NullPointerException e) {
+                xmlIndex = null;
+                throw new SAXException(
+                        "Problem with starting thread for writing XML Index. "
+                                + e.getMessage());
+            }   
+        }
+    }
 
-   /** SAX Handler that is called at the start of Namespace */
-   public void startPrefixMapping(String prefix, String uri)
-                                          throws SAXException
-   {
-    MetaCatUtil.debugMessage("NAMESPACE", 50);
+    /** SAX Handler that is called at the start of Namespace */
+    public void startPrefixMapping(String prefix, String uri)
+            throws SAXException
+    {
+        MetaCatUtil.debugMessage("NAMESPACE", 50);
 
-    namespaces.put(prefix, uri);
-   }
+        namespaces.put(prefix, uri);
+    }
 
-   /** SAX Handler that is called at the start of each XML element */
-   public void startElement(String uri, String localName,
-                            String qName, Attributes atts)
-               throws SAXException {
-     // for element <eml:eml...> qname is "eml:eml", local name is "eml"            
-     // for element <acl....> both qname and local name is "eml"
-     // uri is namesapce
-     MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
-     MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
-     MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
-     
-     DBSAXNode parentNode = null;
-     DBSAXNode currentNode = null;
+    /** SAX Handler that is called at the start of each XML element */
+    public void startElement(String uri, String localName, String qName,
+            Attributes atts) throws SAXException
+    {
+        // for element <eml:eml...> qname is "eml:eml", local name is "eml"
+        // for element <acl....> both qname and local name is "eml"
+        // uri is namesapce
+        MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
+        MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
+        MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
 
-     // Get a reference to the parent node for the id
-     try {
-       parentNode = (DBSAXNode)nodeStack.peek();
-     } catch (EmptyStackException e) {
-       parentNode = null;
-     }
-     
-     // If hit a text node, we need write this text for current's parent node
-     // This will happend if the element is mixted
-     if (hitTextNode && parentNode != null)
-     {
-       // write the textbuffer into db for parent node.
-        endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, parentNode);
-        // rest hitTextNode
-        hitTextNode =false;
-        // reset textbuffer
-        textBuffer = null;
-        textBuffer = new StringBuffer();
-       
-     }
+        DBSAXNode parentNode = null;
+        DBSAXNode currentNode = null;
 
-     // Document representation that points to the root document node
-     if (atFirstElement) 
-     {
-       atFirstElement = false;
-       // If no DOCTYPE declaration: docname = root element
-       // doctype = root element name or name space
-       if (docname == null) 
-       {
-         docname = localName;
-         // if uri isn't null doctype = uri(namespace)
-         // othewise root element
-         if (uri != null && !(uri.trim()).equals(""))
-         {
-           doctype = uri;
-         }
-         else
-         {
-           doctype = docname;
-         }
-         MetaCatUtil.debugMessage("DOCNAME-a: " + docname, 30);
-         MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype, 30);
-       } 
-       else if (doctype == null) 
-       {
-         // because docname is not null and it is declared in dtd
-         // so could not be in schema, no namespace
-         doctype = docname;
-         MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
-       }
-       rootNode.writeNodename(docname);
-       try {
-         // for validated XML Documents store a reference to XML DB Catalog
-         // Because this is select statement and it needn't to roll back if
-         // insert document action fialed.
-         // In order to decrease DBConnection usage count, we get a new
-         // dbconnection from pool
-         String catalogid = null;
-         DBConnection dbConn = null;
-         int serialNumber = -1;
+        // Get a reference to the parent node for the id
+        try {
+            parentNode = (DBSAXNode) nodeStack.peek();
+        } catch (EmptyStackException e) {
+            parentNode = null;
+        }
 
-         if ( systemid != null ) {
-           try
-           {
-            // Get dbconnection
-            dbConn=DBConnectionPool.getDBConnection
-                                          ("DBSAXHandler.startElement");
-            serialNumber=dbConn.getCheckOutSerialNumber();
+        // If hit a text node, we need write this text for current's parent
+        // node
+        // This will happend if the element is mixted
+        if (hitTextNode && parentNode != null) {
+            // write the textbuffer into db for parent node.
+            endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, parentNode);
+            // rest hitTextNode
+            hitTextNode = false;
+            // reset textbuffer
+            textBuffer = null;
+            textBuffer = new StringBuffer();
 
-            Statement stmt = dbConn.createStatement();
-            ResultSet rs = stmt.executeQuery(
-                          "SELECT catalog_id FROM xml_catalog " +
-                          "WHERE entry_type = 'DTD' " +
-                          "AND public_id = '" + doctype + "'");
-            boolean hasRow = rs.next();
-            if ( hasRow ) {
-              catalogid = rs.getString(1);
+        }
+
+        // Document representation that points to the root document node
+        if (atFirstElement) {
+            atFirstElement = false;
+            // If no DOCTYPE declaration: docname = root element
+            // doctype = root element name or name space
+            if (docname == null) {
+                docname = localName;
+                // if uri isn't null doctype = uri(namespace)
+                // othewise root element
+                if (uri != null && !(uri.trim()).equals("")) {
+                    doctype = uri;
+                } else {
+                    doctype = docname;
+                }
+                MetaCatUtil.debugMessage("DOCNAME-a: " + docname, 30);
+                MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype, 30);
+            } else if (doctype == null) {
+                // because docname is not null and it is declared in dtd
+                // so could not be in schema, no namespace
+                doctype = docname;
+                MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
             }
-            stmt.close();
-           }//try
-           finally
-           {
-             // Return dbconnection
-             DBConnectionPool.returnDBConnection(dbConn, serialNumber);
-           }//finally
-         }
+            rootNode.writeNodename(docname);
+            try {
+                // for validated XML Documents store a reference to XML DB
+                // Catalog
+                // Because this is select statement and it needn't to roll back
+                // if
+                // insert document action fialed.
+                // In order to decrease DBConnection usage count, we get a new
+                // dbconnection from pool
+                String catalogid = null;
+                DBConnection dbConn = null;
+                int serialNumber = -1;
 
-         //create documentImpl object by the constructor which can specify
-         //the revision
-         currentDocument = new DocumentImpl(connection, rootNode.getNodeID(),
-                               docname, doctype, docid, revision, action, user,
-                               this.pub, catalogid, this.serverCode);
+                if (systemid != null) {
+                    try {
+                        // Get dbconnection
+                        dbConn = DBConnectionPool
+                                .getDBConnection("DBSAXHandler.startElement");
+                        serialNumber = dbConn.getCheckOutSerialNumber();
 
+                        Statement stmt = dbConn.createStatement();
+                        ResultSet rs = stmt
+                                .executeQuery("SELECT catalog_id FROM xml_catalog "
+                                        + "WHERE entry_type = 'DTD' "
+                                        + "AND public_id = '" + doctype + "'");
+                        boolean hasRow = rs.next();
+                        if (hasRow) {
+                            catalogid = rs.getString(1);
+                        }
+                        stmt.close();
+                    }//try
+                    finally {
+                        // Return dbconnection
+                        DBConnectionPool.returnDBConnection(dbConn,
+                                serialNumber);
+                    }//finally
+                }
 
-       } catch (Exception ane) {
-         throw (new SAXException("Error in DBSaxHandler.startElement " +
-                                 action, ane));
-       }
-     }
+                //create documentImpl object by the constructor which can
+                // specify
+                //the revision
+                currentDocument = new DocumentImpl(connection, rootNode
+                        .getNodeID(), docname, doctype, docid, revision,
+                        action, user, this.pub, catalogid, this.serverCode);
 
-     // Create the current node representation
-     currentNode = new DBSAXNode(connection, qName, localName, parentNode,
-                                 currentDocument.getRootNodeID(),docid,
-                                 currentDocument.getDoctype());
+            } catch (Exception ane) {
+                throw (new SAXException("Error in DBSaxHandler.startElement "
+                        + action, ane));
+            }
+        }
 
-     // Add all of the namespaces
-     String prefix;
-     String nsuri;
-     Enumeration prefixes = namespaces.keys();
-     while ( prefixes.hasMoreElements() ) {
-       prefix = (String)prefixes.nextElement();
-       nsuri = (String)namespaces.get(prefix);
-       currentNode.setNamespace(prefix, nsuri, docid);
-     }
-     namespaces = null;
-     namespaces = new Hashtable();
+        // Create the current node representation
+        currentNode = new DBSAXNode(connection, qName, localName, parentNode,
+                currentDocument.getRootNodeID(), docid, currentDocument
+                        .getDoctype());
 
-     // Add all of the attributes
-     for (int i=0; i<atts.getLength(); i++) 
-     {
-       String attributeName = atts.getQName(i);
-       String attributeValue = atts.getValue(i);
-       endNodeId = 
-                currentNode.setAttribute(attributeName, attributeValue, docid);
-       
-       // To handle name space and schema location if the attribute name is
-       // xsi:schemaLocation. If the name space is in not in catalog table
-       // it will be regeistered.
-       if (attributeName != null && 
-           attributeName.indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1)
-       {
-         SchemaLocationResolver resolver = 
-                                  new SchemaLocationResolver(attributeValue);
-         resolver.resolveNameSpace();
-         
-       }
-     }
+        // Add all of the namespaces
+        String prefix;
+        String nsuri;
+        Enumeration prefixes = namespaces.keys();
+        while (prefixes.hasMoreElements()) {
+            prefix = (String) prefixes.nextElement();
+            nsuri = (String) namespaces.get(prefix);
+            currentNode.setNamespace(prefix, nsuri, docid);
+        }
+        namespaces = null;
+        namespaces = new Hashtable();
 
-     // Add the node to the stack, so that any text data can be
-     // added as it is encountered
-     nodeStack.push(currentNode);
-     // Add the node to the vector used by thread for writing XML Index
-     nodeIndex.addElement(currentNode);
-     // start parsing triple
-     if ( doctype != null && 
-         MetaCatUtil.getOptionList(MetaCatUtil.getOption("packagedoctype")).contains(doctype)
-         && localName.equals("triple"))
-      {
-        startParseTriple = true;
-        hasTriple = true;
-        currentTriple = new Triple();
-      }
-  }
+        // Add all of the attributes
+        for (int i = 0; i < atts.getLength(); i++) {
+            String attributeName = atts.getQName(i);
+            String attributeValue = atts.getValue(i);
+            endNodeId = currentNode.setAttribute(attributeName, attributeValue,
+                    docid);
 
-  /* The run method of xmlIndex thread. It writes XML Index for the document. */
-  public void run () {
-    DBSAXNode currNode = null;
-    DBSAXNode prevNode = null;
-    DBConnection dbConn = null;
-    int serialNumber = -1;
-    String doctype = currentDocument.getDoctype();
-    int step = 0;
-    int counter = 0;
+            // To handle name space and schema location if the attribute name
+            // is
+            // xsi:schemaLocation. If the name space is in not in catalog table
+            // it will be regeistered.
+            if (attributeName != null
+                    && attributeName
+                            .indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1) {
+                SchemaLocationResolver resolver = new SchemaLocationResolver(
+                        attributeValue);
+                resolver.resolveNameSpace();
 
-    try 
+            }
+        }
+
+        // Add the node to the stack, so that any text data can be
+        // added as it is encountered
+        nodeStack.push(currentNode);
+        // Add the node to the vector used by thread for writing XML Index
+        nodeIndex.addElement(currentNode);
+        // start parsing triple
+        if (doctype != null
+                && MetaCatUtil.getOptionList(
+                        MetaCatUtil.getOption("packagedoctype")).contains(
+                        doctype) && localName.equals("triple")) {
+            startParseTriple = true;
+            hasTriple = true;
+            currentTriple = new Triple();
+        }
+    }
+
+    /* The run method of xmlIndex thread. It writes XML Index for the document. */
+    public void run()
     {
-      // stop 5 second
-      Thread.sleep(5000);
-      // Opening separate db connection for writing XML Index
-      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.run");
-      serialNumber=dbConn.getCheckOutSerialNumber();
-      dbConn.setAutoCommit(false);
-      //make sure record is done
-      checkDocumentTable();   
-      // Going through the elements of the document and writing its Index
-      Enumeration nodes = nodeIndex.elements();
-      while ( nodes.hasMoreElements() ) {
-        currNode = (DBSAXNode)nodes.nextElement();
-        currNode.updateNodeIndex(dbConn, docid, doctype);
-      }
-      dbConn.commit();
+        DBSAXNode currNode = null;
+        DBSAXNode prevNode = null;
+        DBConnection dbConn = null;
+        int serialNumber = -1;
+        String doctype = currentDocument.getDoctype();
+        int step = 0;
+        int counter = 0;
 
-    } catch (Exception e) {
-      try {
-        dbConn.rollback();
-        //dbconn.close();
-      } catch (SQLException sqle) {}
-      MetaCatUtil.debugMessage("Error in DBSAXHandler.run " + 
-                                e.getMessage(), 30);
-      
+        try {
+            // stop 5 second
+            Thread.sleep(5000);
+            // Opening separate db connection for writing XML Index
+            dbConn = DBConnectionPool.getDBConnection("DBSAXHandler.run");
+            serialNumber = dbConn.getCheckOutSerialNumber();
+            dbConn.setAutoCommit(false);
+            //make sure record is done
+            checkDocumentTable();
+            // Going through the elements of the document and writing its Index
+            Enumeration nodes = nodeIndex.elements();
+            while (nodes.hasMoreElements()) {
+                currNode = (DBSAXNode) nodes.nextElement();
+                currNode.updateNodeIndex(dbConn, docid, doctype);
+            }
+            dbConn.commit();
+
+        } catch (Exception e) {
+            try {
+                dbConn.rollback();
+                //dbconn.close();
+            } catch (SQLException sqle) {
+            }
+            MetaCatUtil.debugMessage("Error in DBSAXHandler.run "
+                    + e.getMessage(), 30);
+
+        } finally {
+            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
+        }//finally
     }
-    finally
+
+    /*
+     * method to make sure insert is finished before create index table If new
+     * version of record is in xml_documents every thing will be fine
+     */
+    private void checkDocumentTable() throws Exception
     {
-      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
-    }//finally
-  }
 
-  /* method to make sure insert is finished before create index table
-   * If new version of record is in xml_documents every thing will be fine
-   */
-  private void checkDocumentTable() throws Exception
-  {
-    
-    DBConnection dbConn = null;
-    int serialNumber = -1;
-   
-    try 
+        DBConnection dbConn = null;
+        int serialNumber = -1;
+
+        try {
+            // Opening separate db connection for writing XML Index
+            dbConn = DBConnectionPool
+                    .getDBConnection("DBSAXHandler.checkDocumentTable");
+            serialNumber = dbConn.getCheckOutSerialNumber();
+
+            // the following while loop construct checks to make sure that 
+            // the docid of the document that we are trying to index is already 
+            // in the xml_documents table. if this is not the case, the foreign 
+            // key relationship between xml_documents and xml_index is 
+            // temporarily broken causing multiple problems.
+            boolean inxmldoc = false;
+            long startTime = System.currentTimeMillis();
+            while (!inxmldoc) {
+                String xmlDocumentsCheck = "select distinct docid from xml_documents"
+                        + " where docid ='"
+                        + docid
+                        + "' and "
+                        + " rev ='"
+                        + revision + "'";
+
+                PreparedStatement xmlDocCheck = dbConn
+                        .prepareStatement(xmlDocumentsCheck);
+                // Increase usage count
+                dbConn.increaseUsageCount(1);
+                xmlDocCheck.execute();
+                ResultSet doccheckRS = xmlDocCheck.getResultSet();
+                boolean tableHasRows = doccheckRS.next();
+                if (tableHasRows) {
+                    MetaCatUtil.debugMessage(
+                            "=========== find the correct document", 35);
+                    inxmldoc = true;
+                }
+                doccheckRS.close();
+                xmlDocCheck.close();
+                // make sure the while loop will be ended in reseaonable time
+                long stopTime = System.currentTimeMillis();
+                if ((stopTime - startTime) > INDEXDELAY) { throw new Exception(
+                        "Couldn't find the docid for index build in"
+                                + "reseaonable time!"); }
+            }//while
+        } catch (Exception e) {
+            try {
+                dbConn.rollback();
+                //dbconn.close();
+            } catch (SQLException sqle) {
+            }
+            MetaCatUtil.debugMessage("Error in DBSAXHandler.run "
+                    + e.getMessage(), 30);
+
+        } finally {
+            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
+        }//finally
+
+    }
+
+    /** SAX Handler that is called for each XML text node */
+    public void characters(char[] cbuf, int start, int len) throws SAXException
     {
-       // Opening separate db connection for writing XML Index
-      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.checkDocumentTable");
-      serialNumber=dbConn.getCheckOutSerialNumber();
-     
-      //the following while loop construct checks to make sure that the docid
-      //of the document that we are trying to index is already
-      //in the xml_documents table.  if this is not the case, the foreign
-      //key relationship between xml_documents and xml_index is temporarily
-      //broken causing multiple problems.
-      boolean inxmldoc = false;
-      long startTime = System.currentTimeMillis();
-      while(!inxmldoc)
-      {
-        String xmlDocumentsCheck = "select distinct docid from xml_documents" +
-                                   " where docid ='" + docid + "' and " +
-                                   " rev ='" + revision + "'";
-       
-        PreparedStatement xmlDocCheck =
-                                 dbConn.prepareStatement(xmlDocumentsCheck);
-        // Increase usage count
-        dbConn.increaseUsageCount(1);
-        xmlDocCheck.execute();
-        ResultSet doccheckRS = xmlDocCheck.getResultSet();
-        boolean tableHasRows = doccheckRS.next();
-        if (tableHasRows)
-        {
-           MetaCatUtil.debugMessage("=========== find the correct document", 35);
-           inxmldoc = true;
+        MetaCatUtil.debugMessage("CHARACTERS", 50);
+        // buffer all text nodes for same element. This is for text was splited
+        // into different nodes
+        textBuffer.append(new String(cbuf, start, len));
+        // set hittextnode true
+        hitTextNode = true;
+        // if text buffer .size is greater than max, write it to db.
+        // so we can save memory
+        if (textBuffer.length() > MAXDATACHARS) {
+            MetaCatUtil.debugMessage("Write text into DB in charaters"
+                    + " when text buffer size is greater than maxmum number",
+                    50);
+            DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
+            endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
+                    currentNode);
+            textBuffer = null;
+            textBuffer = new StringBuffer();
         }
-         doccheckRS.close();
-         xmlDocCheck.close();
-         // make sure the while loop will be ended in reseaonable time
-         long stopTime = System.currentTimeMillis();
-         if ((stopTime - startTime) > INDEXDELAY)
-         {
-           throw new Exception("Couldn't find the docid for index build in" +
-                              "reseaonable time!");
-         }
-       }//while
-    } 
-    catch (Exception e) 
+    }
+
+    /**
+     * SAX Handler that is called for each XML text node that is Ignorable
+     * white space
+     */
+    public void ignorableWhitespace(char[] cbuf, int start, int len)
+            throws SAXException
     {
-      try 
-      {
-        dbConn.rollback();
-        //dbconn.close();
-      } 
-      catch (SQLException sqle) 
-      {}
-      MetaCatUtil.debugMessage("Error in DBSAXHandler.run " + 
-                                e.getMessage(), 30);
-      
+        // When validation is turned "on", white spaces are reported here
+        // When validation is turned "off" white spaces are not reported here,
+        // but through characters() callback
+        MetaCatUtil.debugMessage("IGNORABLEWHITESPACE", 50);
+
+        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
+        String data = null;
+        int leftover = len;
+        int offset = start;
+        boolean moredata = true;
+
+        // This loop deals with the case where there are more characters
+        // than can fit in a single database text field (limit is
+        // MAXDATACHARS). If the text to be inserted exceeds MAXDATACHARS,
+        // write a series of nodes that are MAXDATACHARS long, and then the
+        // final node contains the remainder
+        while (moredata) {
+            if (leftover > MAXDATACHARS) {
+                data = new String(cbuf, offset, MAXDATACHARS);
+                leftover -= MAXDATACHARS;
+                offset += MAXDATACHARS;
+            } else {
+                data = new String(cbuf, offset, leftover);
+                moredata = false;
+            }
+
+            // Write the content of the node to the database
+            endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data,
+                    docid);
+        }
     }
-    finally
+
+    /**
+     * SAX Handler called once for each processing instruction found: node that
+     * PI may occur before or after the root element.
+     */
+    public void processingInstruction(String target, String data)
+            throws SAXException
     {
-      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
-    }//finally
-  
-  }
-  
-  /** SAX Handler that is called for each XML text node */
-  public void characters(char[] cbuf, int start, int len) throws SAXException 
-  {
-     MetaCatUtil.debugMessage("CHARACTERS", 50);
-     // buffer all text nodes for same element. This is for text was splited
-     // into different nodes
-     textBuffer.append(new String(cbuf, start,len));
-     // set hittextnode true
-     hitTextNode = true;
-     // if text buffer .size is greater than max, write it to db. 
-     // so we can save memory
-     if (textBuffer.length() > MAXDATACHARS)
-     {
-       MetaCatUtil.debugMessage("Write text into DB in charaters" + 
-                   " when text buffer size is greater than maxmum number", 50);
-       DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-       endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode);
-       textBuffer = null;
-       textBuffer = new StringBuffer();
-     }
-  }
+        MetaCatUtil.debugMessage("PI", 50);
+        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
+        endNodeId = currentNode.writeChildNodeToDB("PI", target, data, docid);
+    }
 
-   /**
-    * SAX Handler that is called for each XML text node that is
-    * Ignorable white space
-    */
-   public void ignorableWhitespace(char[] cbuf, int start, int len)
-               throws SAXException {
-     // When validation is turned "on", white spaces are reported here
-     // When validation is turned "off" white spaces are not reported here,
-     // but through characters() callback
-     MetaCatUtil.debugMessage("IGNORABLEWHITESPACE", 50);
+    /** SAX Handler that is called at the end of each XML element */
+    public void endElement(String uri, String localName, String qName)
+            throws SAXException
+    {
+        MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
 
+        // write buffered text nodes into db (so no splited)
+        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
 
-     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-     String data = null;
-     int leftover = len;
-     int offset = start;
-     boolean moredata = true;
+        // If before the end element, the parser hit text nodes and store them
+        // into the buffer, write the buffer to data base. The reason we put
+        // write database here is for xerces some time split text node
+        if (hitTextNode) {
+            MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
+            endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
+                    currentNode);
 
-     // This loop deals with the case where there are more characters
-     // than can fit in a single database text field (limit is
-     // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
-     // write a series of nodes that are MAXDATACHARS long, and then the
-     // final node contains the remainder
-     while (moredata) {
-       if (leftover > MAXDATACHARS) {
-         data = new String(cbuf, offset, MAXDATACHARS);
-         leftover -= MAXDATACHARS;
-         offset += MAXDATACHARS;
-       } else {
-         data = new String(cbuf, offset, leftover);
-         moredata = false;
-       }
+            //if it is triple parsing process
+            if (startParseTriple) {
 
-       // Write the content of the node to the database
-       endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data, docid);
-     }
-   }
+                String content = textBuffer.toString().trim();
+                if (localName.equals("subject")) { //get the subject content
+                    currentTriple.setSubject(content);
+                } else if (localName.equals("relationship")) { //get the
+                                                               // relationship
+                                                               // content
+                    currentTriple.setRelationship(content);
+                } else if (localName.equals("object")) { //get the object
+                                                         // content
+                    currentTriple.setObject(content);
+                }
+            }
 
-   /**
-    * SAX Handler called once for each processing instruction found:
-    * node that PI may occur before or after the root element.
-    */
-   public void processingInstruction(String target, String data)
-          throws SAXException {
-     MetaCatUtil.debugMessage("PI", 50);
-     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-     endNodeId = currentNode.writeChildNodeToDB("PI", target, data, docid);
-   }
+        }//if
 
-   /** SAX Handler that is called at the end of each XML element */
-   public void endElement(String uri, String localName,
-                          String qName) throws SAXException {
-     MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
-     
-     // write buffered text nodes into db (so no splited)
-     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-      
-     // If before the end element, the parser hit text nodes and store them
-     // into the buffer, write the buffer to data base. The reason we put
-     // write database here is for xerces some time split text node
-     if (hitTextNode)
-     {
-       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
-       endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode);
-       
-       //if it is triple parsing process
-       if (startParseTriple)
-       {
-         
-          String content = textBuffer.toString().trim();
-          if(localName.equals("subject"))
-          { //get the subject content
-            currentTriple.setSubject(content);
-          }
-          else if(localName.equals("relationship"))
-          { //get the relationship content
-            currentTriple.setRelationship(content);
-          }
-          else if(localName.equals("object"))
-          { //get the object content
-            currentTriple.setObject(content);
-          }
-       }
-       
-     }//if
-     
-     //set hitText false
-     hitTextNode = false;
-     // reset textbuff
-     textBuffer = null;
-     textBuffer = new StringBuffer();
+        //set hitText false
+        hitTextNode = false;
+        // reset textbuff
+        textBuffer = null;
+        textBuffer = new StringBuffer();
 
-     // Get the node from the stack
-     currentNode = (DBSAXNode)nodeStack.pop();
-     //finishing parsing single triple
-     if (startParseTriple && localName.equals("triple"))
-      {
-        // add trip to triple collection
-        tripleList.addTriple(currentTriple);
-        //rest variable
-        currentTriple = null;
-        startParseTriple = false;   
-      }
-   }
+        // Get the node from the stack
+        currentNode = (DBSAXNode) nodeStack.pop();
+        //finishing parsing single triple
+        if (startParseTriple && localName.equals("triple")) {
+            // add trip to triple collection
+            tripleList.addTriple(currentTriple);
+            //rest variable
+            currentTriple = null;
+            startParseTriple = false;
+        }
+    }
 
-   //
-   // the next section implements the LexicalHandler interface
-   //
+    //
+    // the next section implements the LexicalHandler interface
+    //
 
-   /** SAX Handler that receives notification of DOCTYPE. Sets the DTD */
-   public void startDTD(String name, String publicId, String systemId)
-               throws SAXException {
-     docname = name;
-     doctype = publicId;
-     systemid = systemId;
+    /** SAX Handler that receives notification of DOCTYPE. Sets the DTD */
+    public void startDTD(String name, String publicId, String systemId)
+            throws SAXException
+    {
+        docname = name;
+        doctype = publicId;
+        systemid = systemId;
 
-     processingDTD = true;
-     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-     //create a DTD node and write docname,publicid and system id into db
-     // we don't put the dtd node into node stack
-     DBSAXNode dtdNode = new DBSAXNode (connection, name, publicId, systemId, 
-                               currentNode, currentNode.getRootNodeID(), docid);
-     MetaCatUtil.debugMessage("Start DTD", 50);
-     MetaCatUtil.debugMessage("Setting processingDTD to true", 50);
-     MetaCatUtil.debugMessage("DOCNAME: " + docname, 50);
-     MetaCatUtil.debugMessage("DOCTYPE: " + doctype, 50);
-     MetaCatUtil.debugMessage("  SYSID: " + systemid, 50);
-   }
+        processingDTD = true;
+        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
+        //create a DTD node and write docname,publicid and system id into db
+        // we don't put the dtd node into node stack
+        DBSAXNode dtdNode = new DBSAXNode(connection, name, publicId, systemId,
+                currentNode, currentNode.getRootNodeID(), docid);
+        MetaCatUtil.debugMessage("Start DTD", 50);
+        MetaCatUtil.debugMessage("Setting processingDTD to true", 50);
+        MetaCatUtil.debugMessage("DOCNAME: " + docname, 50);
+        MetaCatUtil.debugMessage("DOCTYPE: " + doctype, 50);
+        MetaCatUtil.debugMessage("  SYSID: " + systemid, 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of end of DTD
-    */
-   public void endDTD() throws SAXException {
+    /**
+     * SAX Handler that receives notification of end of DTD
+     */
+    public void endDTD() throws SAXException
+    {
 
-     processingDTD = false;
-     MetaCatUtil.debugMessage("Setting processingDTD to false", 50);
-     MetaCatUtil.debugMessage("end DTD", 50);
-   }
+        processingDTD = false;
+        MetaCatUtil.debugMessage("Setting processingDTD to false", 50);
+        MetaCatUtil.debugMessage("end DTD", 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of comments in the DTD
-    */
-   public void comment(char[] ch, int start, int length) throws SAXException {
-     MetaCatUtil.debugMessage("COMMENT", 50);
-     if ( !processingDTD ) {
-       DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-       endNodeId = 
-        currentNode.writeChildNodeToDB("COMMENT", null, 
-                                       new String(ch, start, length), docid);
-     }
-   }
+    /**
+     * SAX Handler that receives notification of comments in the DTD
+     */
+    public void comment(char[] ch, int start, int length) throws SAXException
+    {
+        MetaCatUtil.debugMessage("COMMENT", 50);
+        if (!processingDTD) {
+            DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
+            endNodeId = currentNode.writeChildNodeToDB("COMMENT", null,
+                    new String(ch, start, length), docid);
+        }
+    }
 
-   /**
-    * SAX Handler that receives notification of the start of CDATA sections
-    */
-   public void startCDATA() throws SAXException {
-     MetaCatUtil.debugMessage("start CDATA", 50);
-   }
+    /**
+     * SAX Handler that receives notification of the start of CDATA sections
+     */
+    public void startCDATA() throws SAXException
+    {
+        MetaCatUtil.debugMessage("start CDATA", 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of the end of CDATA sections
-    */
-   public void endCDATA() throws SAXException {
-     MetaCatUtil.debugMessage("end CDATA", 50);
-   }
+    /**
+     * SAX Handler that receives notification of the end of CDATA sections
+     */
+    public void endCDATA() throws SAXException
+    {
+        MetaCatUtil.debugMessage("end CDATA", 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of the start of entities
-    */
-   public void startEntity(String name) throws SAXException {
-     MetaCatUtil.debugMessage("start ENTITY: " + name, 50);
-//System.out.println("start ENTITY: " + name);
-     if (name.equals("[dtd]")) {
-       processingDTD = true;
-     }
-   }
+    /**
+     * SAX Handler that receives notification of the start of entities
+     */
+    public void startEntity(String name) throws SAXException
+    {
+        MetaCatUtil.debugMessage("start ENTITY: " + name, 50);
+        //System.out.println("start ENTITY: " + name);
+        if (name.equals("[dtd]")) {
+            processingDTD = true;
+        }
+    }
 
-   /**
-    * SAX Handler that receives notification of the end of entities
-    */
-   public void endEntity(String name) throws SAXException {
-     MetaCatUtil.debugMessage("end ENTITY: " + name, 50);
-//System.out.println("end ENTITY: " + name);
-     if (name.equals("[dtd]")) {
-       processingDTD = false;
-     }
-   }
+    /**
+     * SAX Handler that receives notification of the end of entities
+     */
+    public void endEntity(String name) throws SAXException
+    {
+        MetaCatUtil.debugMessage("end ENTITY: " + name, 50);
+        //System.out.println("end ENTITY: " + name);
+        if (name.equals("[dtd]")) {
+            processingDTD = false;
+        }
+    }
 
-   /**
-    * SAX Handler that receives notification of element declarations
-    */
-   public void elementDecl(String name, String model)
-                        throws org.xml.sax.SAXException {
-//System.out.println("ELEMENTDECL: " + name + " " + model);
-     MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model, 50);
-   }
+    /**
+     * SAX Handler that receives notification of element declarations
+     */
+    public void elementDecl(String name, String model)
+            throws org.xml.sax.SAXException
+    {
+        //System.out.println("ELEMENTDECL: " + name + " " + model);
+        MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model, 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of attribute declarations
-    */
-   public void attributeDecl(String eName, String aName,
-                        String type, String valueDefault, String value)
-                        throws org.xml.sax.SAXException {
+    /**
+     * SAX Handler that receives notification of attribute declarations
+     */
+    public void attributeDecl(String eName, String aName, String type,
+            String valueDefault, String value) throws org.xml.sax.SAXException
+    {
 
-//System.out.println("ATTRIBUTEDECL: " + eName + " "
-//                        + aName + " " + type + " " + valueDefault + " "
-//                        + value);
-     MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " "
-                        + aName + " " + type + " " + valueDefault + " "
-                        + value, 50);
-   }
+        //System.out.println("ATTRIBUTEDECL: " + eName + " "
+        //                        + aName + " " + type + " " + valueDefault + " "
+        //                        + value);
+        MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " " + aName + " "
+                + type + " " + valueDefault + " " + value, 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of internal entity declarations
-    */
-   public void internalEntityDecl(String name, String value)
-                        throws org.xml.sax.SAXException {
-//System.out.println("INTERNENTITYDECL: " + name + " " + value);
-     MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value, 50);
-   }
+    /**
+     * SAX Handler that receives notification of internal entity declarations
+     */
+    public void internalEntityDecl(String name, String value)
+            throws org.xml.sax.SAXException
+    {
+        //System.out.println("INTERNENTITYDECL: " + name + " " + value);
+        MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value, 50);
+    }
 
-   /**
-    * SAX Handler that receives notification of external entity declarations
-    */
-   public void externalEntityDecl(String name, String publicId,
-                        String systemId)
-                        throws org.xml.sax.SAXException {
-//System.out.println("EXTERNENTITYDECL: " + name + " " + publicId
-//                              + " " + systemId);
-     MetaCatUtil.debugMessage("EXTERNENTITYDECL: " + name + " " + publicId
-                              + " " + systemId, 50);
-     // it processes other external entity, not the DTD;
-     // it doesn't signal for the DTD here
-     processingDTD = false;
-   }
+    /**
+     * SAX Handler that receives notification of external entity declarations
+     */
+    public void externalEntityDecl(String name, String publicId, String systemId)
+            throws org.xml.sax.SAXException
+    {
+        //System.out.println("EXTERNENTITYDECL: " + name + " " + publicId
+        //                              + " " + systemId);
+        MetaCatUtil.debugMessage("EXTERNENTITYDECL: " + name + " " + publicId
+                + " " + systemId, 50);
+        // it processes other external entity, not the DTD;
+        // it doesn't signal for the DTD here
+        processingDTD = false;
+    }
 
-   //
-   // the next section implements the ErrorHandler interface
-   //
+    //
+    // the next section implements the ErrorHandler interface
+    //
 
-   /**
-    * SAX Handler that receives notification of fatal parsing errors
-    */
-   public void fatalError(SAXParseException exception) throws SAXException {
-     MetaCatUtil.debugMessage("FATALERROR: "+exception.getMessage(), 50);
-     throw (new SAXException("Fatal processing error.", exception));
-   }
+    /**
+     * SAX Handler that receives notification of fatal parsing errors
+     */
+    public void fatalError(SAXParseException exception) throws SAXException
+    {
+        MetaCatUtil.debugMessage("FATALERROR: " + exception.getMessage(), 50);
+        throw (new SAXException("Fatal processing error.", exception));
+    }
 
-   /**
-    * SAX Handler that receives notification of recoverable parsing errors
-    */
-   public void error(SAXParseException exception) throws SAXException {
-     MetaCatUtil.debugMessage("ERROR: "+exception.getMessage(), 50);
-     throw (new SAXException("Processing error.", exception));
-   }
+    /**
+     * SAX Handler that receives notification of recoverable parsing errors
+     */
+    public void error(SAXParseException exception) throws SAXException
+    {
+        MetaCatUtil.debugMessage("ERROR: " + exception.getMessage(), 50);
+        throw (new SAXException("Processing error.", exception));
+    }
 
-   /**
-    * SAX Handler that receives notification of warnings
-    */
-   public void warning(SAXParseException exception) throws SAXException {
-     MetaCatUtil.debugMessage("WARNING: "+exception.getMessage(), 50);
-     throw (new SAXException("Warning.", exception));
-   }
+    /**
+     * SAX Handler that receives notification of warnings
+     */
+    public void warning(SAXParseException exception) throws SAXException
+    {
+        MetaCatUtil.debugMessage("WARNING: " + exception.getMessage(), 50);
+        throw (new SAXException("Warning.", exception));
+    }
 
-   //
-   // Helper, getter and setter methods
-   //
+    //
+    // Helper, getter and setter methods
+    //
 
-   /**
-    * get the document name
-    */
-   public String getDocname() {
-     return docname;
-   }
+    /**
+     * get the document name
+     */
+    public String getDocname()
+    {
+        return docname;
+    }
 
-   /**
-    * get the document processing state
-    */
-   public boolean processingDTD() {
-     return processingDTD;
-   }
-   
-   /* Method to write a text buffer for DBSAXNode*/
-   protected long writeTextForDBSAXNode(long previousEndNodeId, 
-                                        StringBuffer strBuffer, DBSAXNode node)
-                                        throws SAXException
-   {
-     long nodeId = previousEndNodeId;
-     // Check parameter
-     if ( strBuffer == null || node == null)
-     {
-       return nodeId;
-     }
-     boolean moredata = true;
-     String data = null;
-     int bufferSize = strBuffer.length();
-     int start = 0;
-    
-     // if there are some cotent in buffer, write it
-     if (bufferSize > 0)
-     {
-       MetaCatUtil.debugMessage("Write text into DB", 50);
-       // This loop deals with the case where there are more characters
-       // than can fit in a single database text field (limit is
-       // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
-       // write a series of nodes that are MAXDATACHARS long, and then the
-       // final node contains the remainder
-       while (moredata) 
-       {
-          bufferSize = strBuffer.length();
-          if (bufferSize > MAXDATACHARS) 
-         {
-            data = strBuffer.substring(start, MAXDATACHARS);
-            // cut the stringbuffer part that already written into db
-            strBuffer = strBuffer.delete(start, MAXDATACHARS);
-          } 
-          else 
-          {
-            data = strBuffer.substring(start, bufferSize);
-            moredata = false;
-          }
-       
-          // Write the content of the node to the database
-          nodeId = node.writeChildNodeToDB("TEXT", null, data, docid);
-        }//while
-     }//if
-     return nodeId;
-   }
+    /**
+     * get the document processing state
+     */
+    public boolean processingDTD()
+    {
+        return processingDTD;
+    }
+
+    /* Method to write a text buffer for DBSAXNode */
+    protected long writeTextForDBSAXNode(long previousEndNodeId,
+            StringBuffer strBuffer, DBSAXNode node) throws SAXException
+    {
+        long nodeId = previousEndNodeId;
+        // Check parameter
+        if (strBuffer == null || node == null) { return nodeId; }
+        boolean moredata = true;
+        String data = null;
+        int bufferSize = strBuffer.length();
+        int start = 0;
+
+        // if there are some cotent in buffer, write it
+        if (bufferSize > 0) {
+            MetaCatUtil.debugMessage("Write text into DB", 50);
+            // This loop deals with the case where there are more characters
+            // than can fit in a single database text field (limit is
+            // MAXDATACHARS). If the text to be inserted exceeds MAXDATACHARS,
+            // write a series of nodes that are MAXDATACHARS long, and then the
+            // final node contains the remainder
+            while (moredata) {
+                bufferSize = strBuffer.length();
+                if (bufferSize > MAXDATACHARS) {
+                    data = strBuffer.substring(start, MAXDATACHARS);
+                    // cut the stringbuffer part that already written into db
+                    strBuffer = strBuffer.delete(start, MAXDATACHARS);
+                } else {
+                    data = strBuffer.substring(start, bufferSize);
+                    moredata = false;
+                }
+
+                // Write the content of the node to the database
+                nodeId = node.writeChildNodeToDB("TEXT", null, data, docid);
+            }//while
+        }//if
+        return nodeId;
+    }
 }
Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 2075)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 2076)
@@ -27,27 +27,29 @@
 
 package edu.ucsb.nceas.metacat;
 
-import java.sql.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.io.InputStreamReader;
-import java.io.*;
-import java.text.SimpleDateFormat;
-
-import java.util.Date;
+import java.net.URL;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Stack;
 import java.util.TreeSet;
 import java.util.Vector;
-import java.util.Enumeration;
 
-import org.xml.sax.AttributeList;
+import edu.ucsb.nceas.dbadapter.AbstractDatabase;
+
 import org.xml.sax.ContentHandler;
 import org.xml.sax.DTDHandler;
 import org.xml.sax.EntityResolver;
@@ -54,14 +56,8 @@
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
 import org.xml.sax.helpers.XMLReaderFactory;
 
-import java.net.URL;
-
-import edu.ucsb.nceas.dbadapter.AbstractDatabase;
-
 /**
  * A class that represents an XML document. It can be created with a simple
  * document identifier from a database connection.  It also will write an
@@ -1607,18 +1603,22 @@
           thisrev=Integer.parseInt(updatedVersion);
         }
         MetaCatUtil.debugMessage("final revsion is: "+thisrev, 40);
-        MetaCatUtil.debugMessage("before delete", 40);
-        // Delete index for the old version of docid
-        // The new index is inserting on the next calls to DBSAXNode
-        pstmt = connection.prepareStatement(
-                "DELETE FROM xml_index WHERE docid='" + this.docid + "'");
-        MetaCatUtil.debugMessage("after delete", 40);
-        // Increase dbconnection usage count
-        connection.increaseUsageCount(1);
+        boolean useXMLIndex = 
+            (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
+        if (useXMLIndex) {
+            MetaCatUtil.debugMessage("before delete", 40);
+            // Delete index for the old version of docid
+            // The new index is inserting on the next calls to DBSAXNode
+            pstmt = connection.prepareStatement(
+                    "DELETE FROM xml_index WHERE docid='" + this.docid + "'");
+            MetaCatUtil.debugMessage("after delete", 40);
+            // Increase dbconnection usage count
+            connection.increaseUsageCount(1);
+            
+            pstmt.execute();
+            pstmt.close();    
+        }
         
-        pstmt.execute();
-        pstmt.close();
-
         // Update the new document to reflect the new node tree
         pstmt = connection.prepareStatement(
             "UPDATE xml_documents " +
@@ -1972,7 +1972,7 @@
                                +" metacat with servercode: "+ serverCode, 10);
                         
   
-    // insert into xml_nodes and xml_index table
+    // insert into xml_nodes table
     XMLReader parser = null;
     try 
     { 
@@ -2199,11 +2199,15 @@
       DocumentImpl.archiveDocRevision(conn, docid, user );
 
       // Now delete it from the xml_index table
-      pstmt = conn.prepareStatement("DELETE FROM xml_index WHERE docid = ?");
-      pstmt.setString(1,docid);
-      pstmt.execute();
-      pstmt.close();
-      conn.increaseUsageCount(1);
+      boolean useXMLIndex = 
+          (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
+      if (useXMLIndex) {
+          pstmt = conn.prepareStatement("DELETE FROM xml_index WHERE docid = ?");
+          pstmt.setString(1,docid);
+          pstmt.execute();
+          pstmt.close();
+          conn.increaseUsageCount(1);
+      }
       
       //stmt.execute("DELETE FROM xml_access WHERE docid = '" + docid + "'");
       // Now delete it from xml_access table
