Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 5194)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 5195)
@@ -2335,7 +2335,7 @@
             }
             
             logMetacat.debug("MetaCatServlet.handleInsertOrUpdateAction - the xml document in metacat servlet (before parsing):\n" + doctext[0]);
-            StringReader xml = new StringReader(doctext[0]);
+            StringReader xmlReader = new StringReader(doctext[0]);
             boolean validate = false;
             DocumentImplWrapper documentWrapper = null;
             try {
@@ -2342,7 +2342,7 @@
                 // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ...
                 // >
                 // in order to decide whether to use validation parser
-                validate = needDTDValidation(xml);
+                validate = needDTDValidation(xmlReader);
                 if (validate) {
                     // set a dtd base validation parser
                     String rule = DocumentImpl.DTD;
@@ -2349,7 +2349,7 @@
                     documentWrapper = new DocumentImplWrapper(rule, validate);
                 } else {
                     
-                    String namespace = XMLSchemaService.findDocumentNamespace(xml);
+                    String namespace = XMLSchemaService.findDocumentNamespace(xmlReader);
                     
                     if (namespace != null) {
                         if (namespace.compareTo(DocumentImpl.EML2_0_0NAMESPACE) == 0
@@ -2405,7 +2405,7 @@
                             accNumber = null;
                         }
 
-                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
+                        newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
                                 doAction, accNumber, user, groups);
                                 
                         EventLog.getInstance().log(request.getRemoteAddr(),
@@ -2413,7 +2413,7 @@
                     } catch (NullPointerException npe) {
                       // MCD this seems a bit dubious, since many things can throw npe
                       logMetacat.warn("MetaCatServlet.handleInsertOrUpdateAction - writing with null acnumber");
-                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
+                        newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
                                 doAction, null, user, groups);
                         EventLog.getInstance().log(request.getRemoteAddr(),
                                 user, "", action[0]);
Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 5194)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 5195)
@@ -63,7 +63,7 @@
 import edu.ucsb.nceas.metacat.replication.ReplicationService;
 import edu.ucsb.nceas.metacat.service.XMLSchema;
 import edu.ucsb.nceas.metacat.service.XMLSchemaService;
-import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
+import edu.ucsb.nceas.metacat.shared.AccessException;
 import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
 import edu.ucsb.nceas.metacat.util.AuthUtil;
 import edu.ucsb.nceas.metacat.util.DocumentUtil;
@@ -71,7 +71,6 @@
 import edu.ucsb.nceas.metacat.util.SystemUtil;
 import edu.ucsb.nceas.utilities.FileUtil;
 import edu.ucsb.nceas.utilities.PropertyNotFoundException;
-import edu.ucsb.nceas.utilities.StringUtil;
 import edu.ucsb.nceas.utilities.UtilException;
 
 import org.apache.log4j.Logger;
@@ -166,6 +165,8 @@
     protected long rootnodeid;
     private ElementNode rootNode = null;
     private TreeSet<NodeRecord> nodeRecordList = null;
+    
+    private Vector<String> pathsForIndexing = null;
   
     private static Logger logMetacat = Logger.getLogger(DocumentImpl.class);
     private static Logger logReplication = Logger.getLogger("ReplicationLogging");
@@ -199,6 +200,8 @@
             //this.conn = conn;
             this.docid = DocumentUtil.getDocIdFromAccessionNumber(accNum);
             this.rev   = DocumentUtil.getRevisionFromAccessionNumber(accNum);
+            
+            pathsForIndexing = SystemUtil.getPathsForIndexing();
 
             // Look up the document information
             getDocumentInfo(docid, rev);
@@ -284,6 +287,9 @@
         this.doctype = docType;
         this.docid = docId;
         this.rev = (new Integer(newRevision)).intValue();
+        
+        pathsForIndexing = SystemUtil.getPathsForIndexing();
+        
         //this.updatedVersion = newRevision;
         writeDocumentToDB(action, user, pub, catalogId, serverCode, createDate, updateDate);
     }
@@ -1404,7 +1410,7 @@
 	 * @param accNumber
 	 *            the document id which is used to name the output file
 	 */
-    private static void writeToFileSystem(String xml, String accNumber) throws McdbException {
+    private static void writeToFileSystem(Reader xml, String accNumber) throws McdbException {
 
 		// write the document to disk
 //		FileWriter fileWriter = null;
@@ -1748,18 +1754,13 @@
                       currentName, docid, doctype, parentId));
                   }
                 }
-                try {
-					if (SystemUtil.getPathsForIndexing().contains(currentName)
-							&& leafData.trim().length() != 0) {
-						logMetacat.debug("paths found for indexing: " + currentName);
-						pathsFoundForIndexing.put(currentName, new PathIndexEntry(
-								leafNodeId, currentName, docid, leafParentId, leafData,
-								leafDataNumerical));
-					}
-				} catch (MetacatUtilException ue) {
-					logMetacat.warn("Could not get index paths: " + ue.getMessage());
+				if (pathsForIndexing.contains(currentName)
+						&& leafData.trim().length() != 0) {
+					logMetacat.debug("paths found for indexing: " + currentName);
+					pathsFoundForIndexing.put(currentName, new PathIndexEntry(
+							leafNodeId, currentName, docid, leafParentId, leafData,
+							leafDataNumerical));
 				}
-                
             }
             
             // process relative xpaths
@@ -1777,15 +1778,11 @@
                 logMetacat.debug("B: " + path +"\n");
                 pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
                     doctype, parentId));
-            	try {
-					if (SystemUtil.getPathsForIndexing().contains(path)
-							&& leafData.trim().length() != 0) {
-						logMetacat.debug("paths found for indexing: " + currentName);
-						pathsFoundForIndexing.put(path, new PathIndexEntry(leafNodeId,
-								path, docid, leafParentId, leafData, leafDataNumerical));
-					}
-				} catch (MetacatUtilException ue) {
-					logMetacat.warn("Could not get index paths: " + ue.getMessage());
+				if (pathsForIndexing.contains(path)
+						&& leafData.trim().length() != 0) {
+					logMetacat.debug("paths found for indexing: " + currentName);
+					pathsFoundForIndexing.put(path, new PathIndexEntry(leafNodeId,
+							path, docid, leafParentId, leafData, leafDataNumerical));
 				}
             }
             // process absolute xpaths
@@ -1797,16 +1794,13 @@
                 logMetacat.debug("C: " + fullPath +"\n");
                 pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath,
                     docid, doctype, parentId));
-                try {
-					if (SystemUtil.getPathsForIndexing().contains(fullPath)
-							&& leafData.trim().length() != 0) {
-						logMetacat.debug("paths found for indexing: " + currentName);
-						pathsFoundForIndexing.put(fullPath, new PathIndexEntry(
-								leafNodeId, fullPath, docid, leafParentId, leafData,
-								leafDataNumerical));
-					}
-				} catch (MetacatUtilException ue) {
-					logMetacat.warn("Could not get index paths: " + ue.getMessage());
+
+				if (pathsForIndexing.contains(fullPath)
+						&& leafData.trim().length() != 0) {
+					logMetacat.debug("paths found for indexing: " + currentName);
+					pathsFoundForIndexing.put(fullPath, new PathIndexEntry(
+							leafNodeId, fullPath, docid, leafParentId, leafData,
+							leafDataNumerical));
 				}
             }
         } 
@@ -1843,12 +1837,20 @@
         double afterDeleteIndex = System.currentTimeMillis()/1000;
         logMetacat.debug("DocumentImpl.deleteNodeIndex - The delete index time is "+(afterDeleteIndex - start));
         // Delete all the entries in xml_queryresult
-        pstmt = conn.prepareStatement(
-                "DELETE FROM xml_queryresult WHERE docid = ?");
-        pstmt.setString(1, docid);
-        rows = pstmt.executeUpdate();
-        conn.increaseUsageCount(1);
-        pstmt.close();
+        
+//        pstmt = conn.prepareStatement(
+//                "DELETE FROM xml_queryresult WHERE docid = ?");
+//        pstmt.setString(1, docid);
+//        rows = pstmt.executeUpdate();
+//        conn.increaseUsageCount(1);
+//        pstmt.close();
+        try {
+            XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
+            xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
+        } catch (AccessException ae) {
+        	throw new SQLException("Problem deleting xml query result for docid " + 
+        			docid + " : " + ae.getMessage());
+        }
         logMetacat.debug("DocumentImpl.deleteNodeIndex - Deleted " + rows + " rows from xml_queryresult " +
                 "for document " + docid);
         double afterDeleteQueryResult = System.currentTimeMillis()/1000;
@@ -2496,7 +2498,7 @@
      * false); }
      */
 
-    public static String write(DBConnection conn, Reader xml, String pub,
+    public static String write(DBConnection conn, String xmlString, String pub,
             Reader dtd, String action, String docid, String user,
             String[] groups, String ruleBase, boolean needValidation)
             throws Exception
@@ -2505,7 +2507,7 @@
         //in MetacatServlet class and now is wrapper into documentImple
         // get server location for this doc
         int serverLocation = getServerLocationNumber(docid);
-        return write(conn, xml, pub, dtd, action, docid, user, groups,
+        return write(conn, xmlString, pub, dtd, action, docid, user, groups,
                 serverLocation, false, ruleBase, needValidation);
     }
 
@@ -2539,7 +2541,7 @@
      *            and version checked.
      */
 
-    public static String write(DBConnection conn, Reader xml, String pub,
+    public static String write(DBConnection conn, String xmlString, String pub,
             Reader dtd, String action, String accnum, String user,
             String[] groups, int serverCode, boolean override, String ruleBase,
             boolean needValidation) throws Exception
@@ -2547,7 +2549,7 @@
         // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
     	
     	// Get the xml as a string so we can write to file later
-    	String xmlString = StringUtil.readerToString(xml);
+    	StringReader xmlReader = new StringReader(xmlString);
     	
         logMetacat.debug("DocumentImpl.write - conn usage count before writting: "
                 + conn.getUsageCount());
@@ -2598,7 +2600,7 @@
                      * updaterev, validate, user, groups, pub, serverCode, dtd);
                      */
                     logMetacat.debug("DocumentImpl.write - initializing parser");
-                    parser = initializeParser(conn, action, docid, xml, updaterev,
+                    parser = initializeParser(conn, action, docid, xmlReader, updaterev,
                             user, groups, pub, serverCode, dtd, ruleBase,
                             needValidation, false, null, null);// false means it is not a revision doc
                                    //null, null are createdate and updatedate
@@ -2605,13 +2607,14 @@
                                    //null will use current time as create date time
                     conn.setAutoCommit(false);
                     logMetacat.debug("DocumentImpl.write - parsing xml");
-                    parser.parse(new InputSource(xml));
+                    parser.parse(new InputSource(xmlReader));
                     conn.commit();
                     conn.setAutoCommit(true);
                     
                     //write the file to disk
                     logMetacat.debug("DocumentImpl.write - Writing xml to file system");
-                	writeToFileSystem(xmlString, accnum);
+                    StringReader xmlReaderForFile = new StringReader(xmlString);
+                	writeToFileSystem(xmlReaderForFile, accnum);
 
                     // write to xml_node complete. start the indexing thread.
                     addDocidToIndexingQueue(docid, rev);
@@ -2676,7 +2679,7 @@
         }
         XMLReader parser = null;
         try {
-            parser = initializeParser(conn, action, docid, xml, rev, user, groups,
+            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
                     pub, serverCode, dtd, ruleBase, needValidation, false, null, null);
                     // null and null are createtime and updatetime
                     // null will create current time
@@ -2683,14 +2686,15 @@
                     //false means it is not a revision doc
 
             conn.setAutoCommit(false);
-            logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xml);
-            parser.parse(new InputSource(xml));
+            logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xmlString);
+            parser.parse(new InputSource(xmlReader));
 
             conn.commit();
             conn.setAutoCommit(true);
             
             //write the file to disk
-        	writeToFileSystem(xmlString, accnum);
+            StringReader xmlReaderForFile = new StringReader(xmlString);
+        	writeToFileSystem(xmlReaderForFile, accnum);
 
             addDocidToIndexingQueue(docid, rev);
         } catch (Exception e) {
@@ -2719,13 +2723,20 @@
         // result next time
         if (action.equals("UPDATE")) {
           try {
-              PreparedStatement pstmt = null;
-              pstmt = conn.prepareStatement(
-                      "DELETE FROM xml_queryresult WHERE docid = ?");
-              pstmt.setString(1, docid);
-              pstmt.execute();
-              pstmt.close();
-              conn.increaseUsageCount(1);
+//              PreparedStatement pstmt = null;
+//              pstmt = conn.prepareStatement(
+//                      "DELETE FROM xml_queryresult WHERE docid = ?");
+//              pstmt.setString(1, docid);
+//              pstmt.execute();
+//              pstmt.close();
+//              conn.increaseUsageCount(1);
+              try {
+                  XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
+                  xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
+              } catch (AccessException ae) {
+              	throw new SQLException("Problem deleting xml query result for docid " + 
+              			docid + " : " + ae.getMessage());
+              }
           } catch (Exception e){
               logMetacat.error("DocumentImpl.write - Error in deleting enteries from "
                                        + "xml_queryresult where docid is "
@@ -2790,7 +2801,7 @@
      *            the server which notify local server the force replication
      *            command
      */
-    public static String writeReplication(DBConnection conn, Reader xml,
+    public static String writeReplication(DBConnection conn, String xmlString,
             String pub, Reader dtd, String action, String accnum, String user,
             String[] groups, String homeServer, String notifyServer,
             String ruleBase, boolean needValidation, String tableName, 
@@ -2797,7 +2808,7 @@
             boolean timedReplication, String createDate, String updateDate) throws Exception
     {
     	// Get the xml as a string so we can write to file later
-    	String xmlString = StringUtil.readerToString(xml);
+    	StringReader xmlReader = new StringReader(xmlString);
     	
         long rootId;
         String docType = null;
@@ -2851,17 +2862,18 @@
             {
                 isRevision = true;
             }
-            parser = initializeParser(conn, action, docid, xml, rev, user, groups,
+            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
                     pub, serverCode, dtd, ruleBase, needValidation, 
                     isRevision, createDate, updateDate);
          
             conn.setAutoCommit(false);
-            parser.parse(new InputSource(xml));
+            parser.parse(new InputSource(xmlReader));
             conn.commit();
             conn.setAutoCommit(true);
             
             // Write the file to disk
-        	writeToFileSystem(xmlString, accnum);
+            StringReader xmlReaderForFile = new StringReader(xmlString);
+        	writeToFileSystem(xmlReaderForFile, accnum);
             
             // write to xml_node complete. start the indexing thread.
             // this only for xml_documents
@@ -3173,13 +3185,20 @@
             double afterDeleteXmlAccess2 = System.currentTimeMillis()/1000;
             logMetacat.info("DocumentImpl.delete - The deleting xml_access base on docid time is "+(afterDeleteXmlAccess2 - afterDeleteXmlAccess1 ));
             // Delete enteries from xml_queryresult
-            pstmt = conn.prepareStatement(
-                    "DELETE FROM xml_queryresult WHERE docid = ?");
-            pstmt.setString(1, docid);
-            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
-            pstmt.execute();
-            pstmt.close();
-            conn.increaseUsageCount(1);
+//            pstmt = conn.prepareStatement(
+//                    "DELETE FROM xml_queryresult WHERE docid = ?");
+//            pstmt.setString(1, docid);
+//            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
+//            pstmt.execute();
+//            pstmt.close();
+//            conn.increaseUsageCount(1);
+            try {
+                XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
+                xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
+            } catch (AccessException ae) {
+            	throw new SQLException("Problem deleting xml query result for docid " + 
+            			docid + " : " + ae.getMessage());
+            }
             double afterDeleteQueryResult = System.currentTimeMillis()/1000;
             logMetacat.info("DocumentImpl.delete - The deleting xml_queryresult time is "+(afterDeleteQueryResult - afterDeleteXmlAccess2));
             // Delete it from relation table
Index: src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java	(revision 5194)
+++ src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java	(revision 5195)
@@ -58,7 +58,7 @@
        
   }//Constructor
 
-  public String write(DBConnection conn,Reader xml,String pub,Reader dtd,
+  public String write(DBConnection conn, String xml, String pub, Reader dtd,
                       String action, String docid, String user, String[] groups)
                       throws Exception
   {
@@ -66,7 +66,7 @@
                               groups, ruleBase, needValidation);
   }
   
-  public String writeReplication(DBConnection conn, Reader xml, 
+  public String writeReplication(DBConnection conn, String xml, 
                                         String pub, Reader dtd, String action, 
                                         String accnum, String user,
                                         String[] groups,String homeServer, 
@@ -104,7 +104,7 @@
    * @return
    * @throws Exception
    */
-  public String writeReplication(DBConnection conn, Reader xml, 
+  public String writeReplication(DBConnection conn, String xml, 
           String pub, Reader dtd, String action, 
           String accnum, String user,
           String[] groups,String homeServer, 
Index: src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java
===================================================================
--- src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java	(revision 5194)
+++ src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java	(revision 5195)
@@ -152,7 +152,7 @@
              // using emlparser to check id validation
              EMLParser parser = new EMLParser(eml210Content);
              DocumentImplWrapper documentWrapper = new DocumentImplWrapper(rule, true);
-             StringReader xml = new StringReader(eml210Content);
+//             StringReader xml = new StringReader(eml210Content);
              String  doAction = "UPDATE";
              String pub = null;
              String []groups = null;
@@ -164,7 +164,7 @@
             	 dbconn = DBConnectionPool
                  .getDBConnection("EMLVersionsTransformer.handleSingleEML200Document");
                   serialNumber = dbconn.getCheckOutSerialNumber();
-                  documentWrapper.write(dbconn, xml, pub, dtd,
+                  documentWrapper.write(dbconn, eml210Content, pub, dtd,
                           doAction, newId, owner, groups);
                   logMetacat.warn("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
                   transformLog("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
Index: src/edu/ucsb/nceas/metacat/XMLQueryresultAccess.java
===================================================================
--- src/edu/ucsb/nceas/metacat/XMLQueryresultAccess.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/XMLQueryresultAccess.java	(revision 5195)
@@ -0,0 +1,115 @@
+/**
+ *  '$RCSfile$'
+ *    Purpose: A Class that manages database access of xml access  
+ *             information.
+ *  Copyright: 2009 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *    Authors: Michael Daigle
+ * 
+ *   '$Author: daigle $'
+ *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
+ * '$Revision: 4854 $'
+ *
+ * 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.metacat;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.log4j.Logger;
+
+import edu.ucsb.nceas.metacat.database.DBConnection;
+import edu.ucsb.nceas.metacat.database.DBConnectionPool;
+import edu.ucsb.nceas.metacat.shared.AccessException;
+import edu.ucsb.nceas.metacat.shared.BaseAccess;
+import edu.ucsb.nceas.metacat.shared.BaseDAO;
+
+public class XMLQueryresultAccess extends BaseAccess {
+	
+	private Logger logMetacat = Logger.getLogger(XMLQueryresultAccess.class);
+	
+	// Constructor
+	public XMLQueryresultAccess() throws AccessException {}
+	
+	/**
+	 * Delete xml access.  This removes all access records from the database for a given document
+	 * 
+	 * @param docId
+	 *            document id
+	 */
+	public void deleteXMLQueryresulForDoc(String docId) throws AccessException {
+		if (docId == null) {
+			throw new AccessException("XMLQueryresultAccess.deleteXMLQueryresulForDoc - docid is required when " + 
+					"deleting XML access record");
+		}
+		
+	    PreparedStatement pstmt = null;
+		DBConnection conn = null;
+		int serialNumber = -1;
+		try {
+			// check out DBConnection
+			conn = DBConnectionPool.getDBConnection("XMLQueryresultAccess.deleteXMLQueryresulForDoc");
+    		serialNumber = conn.getCheckOutSerialNumber();
+    		
+			String sql = "DELETE FROM xml_queryresult WHERE docid = ?";
+			pstmt = conn.prepareStatement(sql);
+
+			// Bind the values to the query
+			pstmt.setString(1, docId);
+
+			String sqlReport = "XMLQueryresultAccess.deleteXMLQueryresulForDoc - SQL: " + sql;
+			sqlReport += " [" + docId + "]";
+			
+			logMetacat.info(sqlReport);
+
+			pstmt.execute();
+		} catch (SQLException sqle) {
+			throw new AccessException("XMLQueryresultAccess.deleteXMLQueryresulForDoc - SQL error when deleting"
+					+ "xml query result for doc id: " + docId + ":" + sqle.getMessage());
+		} finally {
+			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
+		}	   
+	}
+	
+	/**
+	 * Populate a job data object with the current row in a resultset
+	 * 
+	 * @param resultSet
+	 *            the result set which is already pointing to the desired row.
+	 * @return a scheduled job data object
+	 */
+	protected BaseDAO populateDAO(ResultSet resultSet) throws SQLException {
+
+//		XMLAccessDAO xmlAccessDAO = new XMLAccessDAO();
+//		xmlAccessDAO.setDocId(resultSet.getString("docid"));
+//		xmlAccessDAO.setAccessFileId(resultSet.getString("accessfileid"));
+//		xmlAccessDAO.setPrincipalName(resultSet.getString("principal_name"));
+//		xmlAccessDAO.setPermission(resultSet.getLong("permission"));
+//		xmlAccessDAO.setPermType(resultSet.getString("perm_type"));
+//		xmlAccessDAO.setPermOrder(resultSet.getString("perm_order"));
+//		xmlAccessDAO.setBeginTime(resultSet.getDate("begin_time"));
+//		xmlAccessDAO.setEndTime(resultSet.getDate("end_time"));
+//		xmlAccessDAO.setTicketCount(resultSet.getLong("ticket_count"));
+//		xmlAccessDAO.setSubTreeId(resultSet.getString("subtreeid"));
+//		xmlAccessDAO.setStartNodeId(resultSet.getString("startnodeid"));
+//		xmlAccessDAO.setEndNodeId(resultSet.getString("endnodeid"));
+
+		return null;
+	}
+	
+}
\ No newline at end of file
Index: src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java	(revision 5194)
+++ src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java	(revision 5195)
@@ -382,7 +382,7 @@
       // Write the document into local host
       DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
       String newDocid = wrapper.writeReplication(dbConn,
-                              new StringReader(newxmldoc),
+                              newxmldoc,
                               docinfoHash.get("public_access"),
                               null,  /* the dtd text */
                               actions,
Index: src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
===================================================================
--- src/edu/ucsb/nceas/metacat/replication/ReplicationService.java	(revision 5194)
+++ src/edu/ucsb/nceas/metacat/replication/ReplicationService.java	(revision 5195)
@@ -40,7 +40,9 @@
 import edu.ucsb.nceas.metacat.DocumentImplWrapper;
 import edu.ucsb.nceas.metacat.EventLog;
 import edu.ucsb.nceas.metacat.McdbException;
+import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
+import edu.ucsb.nceas.metacat.accesscontrol.PermOrderException;
 import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
 import edu.ucsb.nceas.metacat.database.DBConnection;
 import edu.ucsb.nceas.metacat.database.DBConnectionPool;
@@ -554,61 +556,80 @@
 			// write the document to local database
 			DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
 			//try this independently so we can set
-			Exception writeException = null;
+//			Exception writeException = null;
 			try {
-				wrapper.writeReplication(dbConn, new StringReader(xmldoc), null, null,
+				wrapper.writeReplication(dbConn, xmldoc, null, null,
 						dbaction, docid, user, null, homeServer, server, createdDate,
 						updatedDate);
-			} catch (Exception e) {
-				writeException = e;
-			}
+			} finally {
+//				writeException = e;
 
-			//process extra access rules before dealing with the write exception (doc exist already)
-//			Vector<AccessControlForSingleFile> accessControlList = dih
-//					.getAccessControlList();
-			
-	        Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList();
-	        if (accessControlList != null) {
-	        	AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid);
-	        	for (XMLAccessDAO xmlAccessDAO : accessControlList) {
-	        		if (!acfsf.accessControlExists(xmlAccessDAO)) {
-	        			acfsf.insertPermissions(xmlAccessDAO);
-						logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
-								+ " permissions added to DB");
-	        		}
-	            }
-	        }
-//			if (accessControlList != null) {
-//				for (int i = 0; i < accessControlList.size(); i++) {
-//					AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList
-//							.get(i);
-//					if (!acfsf.accessControlExists()) {
-//						acfsf.insertPermissions();
-//						logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
-//								+ " permissions added to DB");
+				//process extra access rules before dealing with the write exception (doc exist already)			
+		        Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList();
+		        if (accessControlList != null) {
+		        	AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid);
+		        	for (XMLAccessDAO xmlAccessDAO : accessControlList) {
+		        		if (!acfsf.accessControlExists(xmlAccessDAO)) {
+		        			acfsf.insertPermissions(xmlAccessDAO);
+							logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
+									+ " permissions added to DB");
+		        		}
+		            }
+		        }
+//				if (accessControlList != null) {
+//					for (int i = 0; i < accessControlList.size(); i++) {
+//						AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList
+//								.get(i);
+//						if (!acfsf.accessControlExists()) {
+//							acfsf.insertPermissions();
+//							logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
+//									+ " permissions added to DB");
+//						}
 //					}
 //				}
-//			}
 
-			if (writeException != null) {
-				throw writeException;
+//				if (writeException != null) {
+//					throw writeException;
+//				}
+
+				logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid + " added to DB with "
+						+ "action " + dbaction);
+				EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid,
+						dbaction);
 			}
-
-			logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid + " added to DB with "
-					+ "action " + dbaction);
-			EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid,
-					dbaction);
-		}//try
-		catch (Exception e) {
+		} catch (SQLException sqle) {
 			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
-			logReplication.error("document " + docid
-					+ " failed to added to DB with " + "action " + dbaction + " because "
-					+ e.getMessage());
-			logReplication.error("ReplicationService.handleForceReplicateRequest - "
-					+ "error: " + e.getMessage());
-
-		}//catch
-		finally {
+			logReplication.error("ReplicationService.handleForceReplicateRequest - SQL error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + sqle.getMessage());
+		} catch (MalformedURLException mue) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - URL error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + mue.getMessage());
+		} catch (SAXException se) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - SAX parsing error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + se.getMessage());
+		} catch (HandlerException he) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - Handler error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + he.getMessage());
+		} catch (IOException ioe) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - I/O error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + ioe.getMessage());
+		} catch (PermOrderException poe) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - Permissions order error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + poe.getMessage());
+		} catch (AccessControlException ace) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - Permissions order error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + ace.getMessage());
+		} catch (Exception e) {
+			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
+			logReplication.error("ReplicationService.handleForceReplicateRequest - General error when adding doc " + docid + 
+					" to DB with action " + dbaction + ": " + e.getMessage());
+		} finally {
 			// Return the checked out DBConnection
 			DBConnectionPool.returnDBConnection(dbConn, serialNumber);
 		}//finally
