Index: lib/metacat.properties
===================================================================
--- lib/metacat.properties	(revision 898)
+++ lib/metacat.properties	(revision 899)
@@ -7,7 +7,7 @@
 password=@password@
 defaultDB=@jdbc-connect@
 dbDriver=@dbDriver@
-dbAdapter=edu.ucsb.nceas.dbadapter.OracleAdapter
+dbAdapter=edu.ucsb.nceas.dbadapter.PostgresqlAdapter
 initialConnections=5
 incrementConnections=5
 maximumConnections=10
Index: src/xmltables_postgres.sql
===================================================================
--- src/xmltables_postgres.sql	(revision 898)
+++ src/xmltables_postgres.sql	(revision 899)
@@ -119,7 +119,7 @@
 	user_owner VARCHAR(100),	-- the user owned the document
 	user_updated VARCHAR(100),	-- the user updated the document
 	server_location INT8,	-- the server on which this document resides
-	rev INT8,   -- the revision number of the document
+	rev INT8 default 1,   -- the revision number of the document
 	date_created DATE,
 	date_updated DATE,
 	public_access INT8,	-- flag for public access
Index: src/edu/ucsb/nceas/dbadapter/PostgresqlAdapter.java
===================================================================
--- src/edu/ucsb/nceas/dbadapter/PostgresqlAdapter.java	(revision 898)
+++ src/edu/ucsb/nceas/dbadapter/PostgresqlAdapter.java	(revision 899)
@@ -95,7 +95,7 @@
    */
   public String getStringDelimiter() {
 
-    return "'";
+    return "\"";
   }
   
 }
Index: src/edu/ucsb/nceas/metacat/QuerySpecification.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 898)
+++ src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 899)
@@ -30,6 +30,8 @@
 
 package edu.ucsb.nceas.metacat;
 
+import edu.ucsb.nceas.dbadapter.*;
+
 import java.io.*;
 import java.util.Stack;
 import java.util.Vector;
@@ -76,7 +78,9 @@
   private String currentPathexpr;
   private String parserName = null;
   private String accNumberSeparator = null;
+  private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
 
+
   /**
    * construct an instance of the QuerySpecification class 
    *
@@ -558,9 +562,9 @@
     self.append("xml_nodes x, xml_nodes y, xml_nodes z ");
     self.append("where s.parentnodeid = rel.parentnodeid ");
     self.append("and rel.parentnodeid = o.parentnodeid ");
-    self.append("and x.parentnodeid in rel.nodeid ");
-    self.append("and y.parentnodeid in o.nodeid ");
-    self.append("and z.parentnodeid in s.nodeid ");
+    self.append("and x.parentnodeid in (rel.nodeid) ");
+    self.append("and y.parentnodeid in (o.nodeid) ");
+    self.append("and z.parentnodeid in (s.nodeid) ");
     //self.append("and z.nodedata like '%");
     //self.append(docid);
     //self.append("%'");
@@ -585,9 +589,9 @@
     self.append("xml_nodes x, xml_nodes y, xml_nodes z ");
     self.append("where s.parentnodeid = rel.parentnodeid ");
     self.append("and rel.parentnodeid = o.parentnodeid ");
-    self.append("and x.parentnodeid in rel.nodeid ");
-    self.append("and y.parentnodeid in o.nodeid ");
-    self.append("and z.parentnodeid in s.nodeid ");
+    self.append("and x.parentnodeid in (rel.nodeid) ");
+    self.append("and y.parentnodeid in (o.nodeid) ");
+    self.append("and z.parentnodeid in (s.nodeid) ");
     self.append("and z.docid like '").append(docid).append("'");
     
     return self.toString();
@@ -612,9 +616,9 @@
     self.append("xml_nodes x, xml_nodes y, xml_nodes z ");
     self.append("where s.parentnodeid = rel.parentnodeid ");
     self.append("and rel.parentnodeid = o.parentnodeid ");
-    self.append("and x.parentnodeid in rel.nodeid ");
-    self.append("and y.parentnodeid in o.nodeid ");
-    self.append("and z.parentnodeid in s.nodeid ");
+    self.append("and x.parentnodeid in (rel.nodeid) ");
+    self.append("and y.parentnodeid in (o.nodeid) ");
+    self.append("and z.parentnodeid in (s.nodeid) ");
     self.append("and (z.nodedata like '");
     self.append(subDocidURL);
     self.append("' or y.nodedata like '");
Index: src/edu/ucsb/nceas/metacat/DBSAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 898)
+++ src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 899)
@@ -251,7 +251,38 @@
       MetaCatUtil util = new MetaCatUtil();
       dbconn = util.openDBConnection();
       dbconn.setAutoCommit(false);
-
+      
+      //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;
+      while(!inxmldoc)
+      {
+        String xmlDocumentsCheck = "select distinct docid from xml_documents";
+        PreparedStatement xmlDocCheck = dbconn.prepareStatement(xmlDocumentsCheck);
+        xmlDocCheck.execute();
+        ResultSet doccheckRS = xmlDocCheck.getResultSet();
+        boolean tableHasRows = doccheckRS.next();
+        Vector docids = new Vector();
+        while(tableHasRows) 
+        {
+          docids.add(doccheckRS.getString(1).trim());
+          tableHasRows = doccheckRS.next();
+        }
+        
+        for(int i=0; i<docids.size(); i++)
+        {
+          String d = ((String)docids.elementAt(i)).trim();
+          if(docid.trim().equals(d))
+          {
+            inxmldoc = true;
+          }
+        }
+        xmlDocCheck.close();
+      }
+      
       // Going through the elements of the document and writing its Index
       Enumeration nodes = nodeIndex.elements();
       while ( nodes.hasMoreElements() ) {
Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 898)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 899)
@@ -692,16 +692,20 @@
     String nodename = null;
     String nodeprefix = null;
     String nodedata = null;
+    String quotechar = dbAdapter.getStringDelimiter();
 
     try {
       pstmt =
       conn.prepareStatement("SELECT nodeid,parentnodeid,nodeindex, " +
-           "nodetype,nodename,nodeprefix,"+               
+           "nodetype,nodename,nodeprefix,nodedata " +               
+           /*"replace(" +
            "replace(" +
-           "replace(" +
-           "replace(nodedata,'&','&amp;') " +
-           ",'<','&lt;') " +
-           ",'>','&gt;') " +
+           "replace(nodedata," + quotechar + "&" + quotechar + "," + quotechar + "&amp;" +
+           quotechar + ") " +
+           "," + quotechar + "<" + quotechar + "," + quotechar + "&lt;" + 
+           quotechar + ") " +
+           "," + quotechar + ">" + quotechar + "," + quotechar + "&gt;" + 
+           quotechar + ") " +*/
            "FROM xml_nodes WHERE rootnodeid = ?");
 
       // Bind the values to the query
@@ -718,7 +722,7 @@
         nodename = rs.getString(5);
         nodeprefix = rs.getString(6);
         nodedata = rs.getString(7);
-
+        nodedata = MetaCatUtil.normalize(nodedata);
         // add the data to the node record list hashtable
         NodeRecord currentRecord = new NodeRecord(nodeid,parentnodeid,nodeindex,
                                        nodetype, nodename, nodeprefix, nodedata);
Index: src/edu/ucsb/nceas/metacat/DBSAXNode.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXNode.java	(revision 898)
+++ src/edu/ucsb/nceas/metacat/DBSAXNode.java	(revision 899)
@@ -389,7 +389,6 @@
               "INSERT INTO xml_index (nodeid, path, docid, doctype, " + 
                "parentnodeid) " + 
               "VALUES (?, ?, ?, ?, ?)");
-      //((OraclePreparedStatement)pstmt).setExecuteBatch(counter);
   
       pstmt.setString(3, docid);
       pstmt.setString(4, doctype);
@@ -402,16 +401,14 @@
         Long nodeid = (Long)pathlist.get(path);
         pstmt.setLong(1, nodeid.longValue());
         pstmt.setString(2, path);
+        
         pstmt.executeUpdate();
-  
-        //System.out.println(nodeid + " ==> " + path);
       }
-
       // Close the database statement
       pstmt.close();
     } catch (SQLException sqe) {
       System.err.println("SQL Exception while inserting path to index in " +
-                         "DBSAXNode.updateNodeIndex");
+                         "DBSAXNode.updateNodeIndex for document " + docid);
       System.err.println(sqe.getMessage());
       throw new SAXException(sqe.getMessage());
     }
Index: src/edu/ucsb/nceas/metacat/AccessControlList.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AccessControlList.java	(revision 898)
+++ src/edu/ucsb/nceas/metacat/AccessControlList.java	(revision 899)
@@ -319,7 +319,6 @@
 
         // insert into db calculated permission for the list of principals
         try {
-// System.out.println("before insertPermission " +leavingTagName);
           // go through the objects in xml_relation about this acl doc
           for (int i=0; i < aclObjects.size(); i++) {
             // docid of the current object
@@ -326,7 +325,6 @@
             String docid = (String)aclObjects.elementAt(i); 
             DocumentIdentifier docID = new DocumentIdentifier(docid);
             docid = docID.getIdentifier();
-// System.out.println(docid);
             insertPermissions(docid,leavingTagName);
           }
 
@@ -433,7 +431,6 @@
           throws SQLException 
   {
     PreparedStatement pstmt;
- 
     try {
       pstmt = conn.prepareStatement(
               "INSERT INTO xml_access " + 
@@ -451,7 +448,7 @@
       if ( ticketCount > 0 ) {
         pstmt.setString(8, "" + ticketCount);
       } else {
-        pstmt.setString(8, "");
+        pstmt.setString(8, null);
       }
 
       String prName;
Index: build.xml
===================================================================
--- build.xml	(revision 898)
+++ build.xml	(revision 899)
@@ -32,14 +32,14 @@
 <project name="metacat" default="jar" basedir=".">
    <target name="init">
       <property name="jdbc-connect" 
-                value="jdbc:oracle:thin:@dev.nceas.ucsb.edu:1521:exp"/>
-      <property name="installdir" value="/opt/tomcat/webapps/metacat" />
-      <property name="dbDriver" value="oracle.jdbc.driver.OracleDriver"/>
+                value="jdbc:postgresql://localhost/berkley"/>
+      <property name="installdir" value="/home/berkley/tomcat/webapps/metacat" />
+      <property name="dbDriver" value="org.postgresql.Driver"/>
       <property name="name" value="metacat"/>
       <property name="Name" value="MetaCat"/>
       <property name="release" value="1.0.3"/>
       <property name="web-base-url" 
-                value="http://knb.ecoinformatics.org"/>
+                value="http://alpha.nceas.ucsb.edu:8080/"/>
 
       <property name="replication-path" value="/servlet/replication"/>
       <property name="servlet-path" value="/metacat/servlet/metacat"/>
@@ -46,10 +46,10 @@
       <property name="html-path" value="/metacat"/>
       <property name="image-path" value="/img/metacat" />
       <property name="style-path" value="/metacat/style"/>
-      <property name="server" value="dev.nceas.ucsb.edu"/>
-      <property name="replication-log" value="/tmp/metacatreplication.log"/>
-      <property name="user" value="metacat_username"/>
-      <property name="password" value="your_pw_here"/>
+      <property name="server" value="alpha.nceas.ucsb.edu:8080"/>
+      <property name="replication-log" value="/home/berkley/tomcat/webapps/metacat/metacatreplication.log"/>
+      <property name="user" value="berkley"/>
+      <property name="password" value=""/>
       <property name="config-dir" value="${installdir}" />
       <property name="default-style" value="knb" />
       <property name="eml-module" value="mdstandards/eml" />
@@ -99,15 +99,15 @@
       <property name="toolsdir" 
                 value="/usr/local/devtools" />
       <property name="xmlp" 
-                value="${toolsdir}/OracleXSU111/lib/xmlparserv2.jar" />
+                value="./lib/xmlparserv2.jar" />
       <property name="xmlp2" 
-                value="${toolsdir}/xerces-1_1_3/xerces.jar" />
+                value="./lib/xerces.jar" />
       <property name="jdbc" 
-                value="${oracle_home}/jdbc/lib/classes111.zip" />
+                value="/home/berkley/xmltodb/lib/jdbc7.1-1.2.jar" />
       <property name="jserv" 
                 value="/usr/lib/apache/ApacheJServ.jar" />
       <property name="jsdk" 
-                value="${toolsdir}/jakarta-tomcat/lib/servlet.jar" />
+                value="/home/berkley/tomcat/lib/common/servlet.jar" />
       <property name="srb" 
                 value="lib/srbrmi" />
       <property name="cos" 
