Index: src/edu/ucsb/nceas/metacat/DBWriter.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBWriter.java	(revision 54)
+++ src/edu/ucsb/nceas/metacat/DBWriter.java	(revision 55)
@@ -90,62 +90,81 @@
    * @param filename the filename to be loaded into the database
    * @param conn the database connection to which to write the XML file
    */
+  public DBSAXWriter( Reader xml, Connection conn)
+                  throws IOException, 
+                         SQLException, 
+                         ClassNotFoundException
+  {
+    this.conn = conn;
+
+    //try {
+
+      try {
+        SAXParser parser = initializeParser(conn);
+        parser.parse(xml);
+      } catch (SAXParseException e) {
+        System.err.println(e.getMessage());
+      } catch (SAXException e) {
+        System.err.println(e.getMessage());
+      }
+    //} catch (Exception e) {
+       //System.err.println(e.toString());
+    //}
+  }
+
   public DBSAXWriter( String filename, Connection conn)
                   throws IOException, 
                          SQLException, 
                          ClassNotFoundException
-   {
+  {
      this.conn = conn;
-    
-     //
-     // Set up the SAX document handlers for parsing
-     //
-
+     FileReader xmlfile = new FileReader(new File(filename).toString());
      try {
+       SAXParser parser = initializeParser(conn);
+       parser.parse(xmlfile);
+     } catch (SAXParseException e) {
+       System.err.println(e.getMessage());
+     } catch (SAXException e) {
+       System.err.println(e.getMessage());
+     }
+  }
+  
+  private SAXParser initializeParser(Connection conn) {
+    SAXParser parser = null;
+    //
+    // Set up the SAX document handlers for parsing
+    //
+    try {
+      // Use the XMLDocumentHandler interface for namespace support
+      // instead of org.xml.sax.DocumentHandler
+      XMLDocumentHandler xmlDocHandler = new DBSAXHandler(conn);
 
-        // Use the XMLDocumentHandler interface for namespace support
-        // instead of org.xml.sax.DocumentHandler
-        XMLDocumentHandler xmlDocHandler = new DBSAXHandler(conn);
+      // For all the other interface use the default provided by
+      // Handler base
+      HandlerBase defHandler = new HandlerBase();
 
-        // For all the other interface use the default provided by
-        // Handler base
-        HandlerBase defHandler = new HandlerBase();
+      // Get an instance of the parser
+      parser = new SAXParser();
 
-        // Get an instance of the parser
-        SAXParser parser = new SAXParser();
+      // Set Handlers in the parser
+      // Set the DocumentHandler to XMLDocumentHandler
+      parser.setDocumentHandler(xmlDocHandler);
 
-        // Set Handlers in the parser
-        // Set the DocumentHandler to XMLDocumentHandler
-        parser.setDocumentHandler(xmlDocHandler);
+      // Set the other Handler to the defHandler
+      parser.setErrorHandler(defHandler);
+      parser.setEntityResolver(defHandler);
+      parser.setDTDHandler(defHandler);
 
-        // Set the other Handler to the defHandler
-        parser.setErrorHandler(defHandler);
-        parser.setEntityResolver(defHandler);
-        parser.setDTDHandler(defHandler);
+    } catch (Exception e) {
+       System.err.println(e.toString());
+    }
 
-        try
-        {
-           parser.parse(fileToURL(new File(filename)).toString());
-        }
-        catch (SAXParseException e)
-        {
-           System.err.println(filename + ": " + e.getMessage());
-        }
-        catch (SAXException e)
-        {
-           System.err.println(filename + ": " + e.getMessage());
-        }
-     }
-     catch (Exception e)
-     {
-        System.err.println(e.toString());
-     }
+    return parser;
+  }
 
-   }
-  
-   /** Utility method to convert a file handle into a URL */
-   static public URL fileToURL(File file) 
-   {
+  /** Utility method to convert a file handle into a URL */
+  static public URL fileToURL(File file) 
+  {
      String path = file.getAbsolutePath();
      String fSep = System.getProperty("file.separator");
      if (fSep != null && fSep.length() == 1)
@@ -161,5 +180,4 @@
        throw new Error("unexpected MalformedURLException");
      }
   }
-
 }
Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 54)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 55)
@@ -19,6 +19,7 @@
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.sql.Connection;
+import java.sql.SQLException;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -50,6 +51,7 @@
 
   private ServletConfig		config = null;
   private ServletContext	context = null;
+  Connection 		conn = null;
   DBSimpleQuery		queryobj = null;
   DBReader		docreader = null;
   static  String 	user = MetaCatUtil.user;
@@ -68,12 +70,12 @@
     
       try {
         // Open a connection to the database
-        Connection dbconn = MetaCatUtil.openDBConnection(
+        conn = MetaCatUtil.openDBConnection(
                 "oracle.jdbc.driver.OracleDriver",
                 defaultDB, user, password);
 
-        queryobj = new DBSimpleQuery(dbconn);
-        docreader = new DBReader(dbconn);
+        queryobj = new DBSimpleQuery(conn);
+        docreader = new DBReader(conn);
       } catch (Exception e) {
       }
     } catch ( ServletException ex ) {
@@ -123,6 +125,8 @@
       handleQueryAction(out, params, response);
     } else if (action.equals("getdocument")) {
       handleGetDocumentAction(out, params, response);
+    } else if (action.equals("putdocument")) {
+      handlePutDocumentAction(out, params, response);
     } else {
       out.println("Error: action not registered.  Please report this error.");
     }
@@ -192,4 +196,30 @@
   
       out.println(doc);
   }
+
+  /** 
+   * Handle the database putdocument request and write an XML document 
+   * to the database connection
+   */
+  private void handlePutDocumentAction(PrintWriter out, Hashtable params, 
+               HttpServletResponse response) {
+      // Get the document indicated
+      String doctext = ((String[])params.get("doctext"))[0]; 
+      StringReader xml = new StringReader(doctext);
+      try {
+        DBSAXWriter dbw = new DBSAXWriter(doctext, conn);
+      } catch (SQLException e1) {
+          out.println("Error loading document:<p>\n" + e1.getMessage());
+      }catch (IOException e2) {
+          out.println("Error loading document:<p>\n" + e2.getMessage());
+      }catch (ClassNotFoundException e3) {
+          out.println("Error loading document:<p>\n" + e3.getMessage());
+      }
+      //String doc = docreader.readXMLDocument((new Long(docid)).longValue());
+
+      // set content type and other response header fields first
+      response.setContentType("text/html");
+  
+      out.println("Finished loading document.");
+  }
 }
Index: src/edu/ucsb/nceas/metacat/DBSAXWriter.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXWriter.java	(revision 54)
+++ src/edu/ucsb/nceas/metacat/DBSAXWriter.java	(revision 55)
@@ -90,62 +90,81 @@
    * @param filename the filename to be loaded into the database
    * @param conn the database connection to which to write the XML file
    */
+  public DBSAXWriter( Reader xml, Connection conn)
+                  throws IOException, 
+                         SQLException, 
+                         ClassNotFoundException
+  {
+    this.conn = conn;
+
+    //try {
+
+      try {
+        SAXParser parser = initializeParser(conn);
+        parser.parse(xml);
+      } catch (SAXParseException e) {
+        System.err.println(e.getMessage());
+      } catch (SAXException e) {
+        System.err.println(e.getMessage());
+      }
+    //} catch (Exception e) {
+       //System.err.println(e.toString());
+    //}
+  }
+
   public DBSAXWriter( String filename, Connection conn)
                   throws IOException, 
                          SQLException, 
                          ClassNotFoundException
-   {
+  {
      this.conn = conn;
-    
-     //
-     // Set up the SAX document handlers for parsing
-     //
-
+     FileReader xmlfile = new FileReader(new File(filename).toString());
      try {
+       SAXParser parser = initializeParser(conn);
+       parser.parse(xmlfile);
+     } catch (SAXParseException e) {
+       System.err.println(e.getMessage());
+     } catch (SAXException e) {
+       System.err.println(e.getMessage());
+     }
+  }
+  
+  private SAXParser initializeParser(Connection conn) {
+    SAXParser parser = null;
+    //
+    // Set up the SAX document handlers for parsing
+    //
+    try {
+      // Use the XMLDocumentHandler interface for namespace support
+      // instead of org.xml.sax.DocumentHandler
+      XMLDocumentHandler xmlDocHandler = new DBSAXHandler(conn);
 
-        // Use the XMLDocumentHandler interface for namespace support
-        // instead of org.xml.sax.DocumentHandler
-        XMLDocumentHandler xmlDocHandler = new DBSAXHandler(conn);
+      // For all the other interface use the default provided by
+      // Handler base
+      HandlerBase defHandler = new HandlerBase();
 
-        // For all the other interface use the default provided by
-        // Handler base
-        HandlerBase defHandler = new HandlerBase();
+      // Get an instance of the parser
+      parser = new SAXParser();
 
-        // Get an instance of the parser
-        SAXParser parser = new SAXParser();
+      // Set Handlers in the parser
+      // Set the DocumentHandler to XMLDocumentHandler
+      parser.setDocumentHandler(xmlDocHandler);
 
-        // Set Handlers in the parser
-        // Set the DocumentHandler to XMLDocumentHandler
-        parser.setDocumentHandler(xmlDocHandler);
+      // Set the other Handler to the defHandler
+      parser.setErrorHandler(defHandler);
+      parser.setEntityResolver(defHandler);
+      parser.setDTDHandler(defHandler);
 
-        // Set the other Handler to the defHandler
-        parser.setErrorHandler(defHandler);
-        parser.setEntityResolver(defHandler);
-        parser.setDTDHandler(defHandler);
+    } catch (Exception e) {
+       System.err.println(e.toString());
+    }
 
-        try
-        {
-           parser.parse(fileToURL(new File(filename)).toString());
-        }
-        catch (SAXParseException e)
-        {
-           System.err.println(filename + ": " + e.getMessage());
-        }
-        catch (SAXException e)
-        {
-           System.err.println(filename + ": " + e.getMessage());
-        }
-     }
-     catch (Exception e)
-     {
-        System.err.println(e.toString());
-     }
+    return parser;
+  }
 
-   }
-  
-   /** Utility method to convert a file handle into a URL */
-   static public URL fileToURL(File file) 
-   {
+  /** Utility method to convert a file handle into a URL */
+  static public URL fileToURL(File file) 
+  {
      String path = file.getAbsolutePath();
      String fSep = System.getProperty("file.separator");
      if (fSep != null && fSep.length() == 1)
@@ -161,5 +180,4 @@
        throw new Error("unexpected MalformedURLException");
      }
   }
-
 }
Index: contents.html
===================================================================
--- contents.html	(revision 54)
+++ contents.html	(revision 55)
@@ -33,6 +33,8 @@
 For the test database, some valid values for the search that produce document
 results include "Value1" and "lakename"
 </p>
+<p><a href="loadxml.html" target="right">Load an XML Document</a>
+</p>
 <p>
 To view results that are XML formatted in this demo, it is easiest to use 
 Internet Explorer 5. Although Netscape browsers will allow you to 
Index: MetaCatServlet.java
===================================================================
--- MetaCatServlet.java	(revision 54)
+++ MetaCatServlet.java	(revision 55)
@@ -19,6 +19,7 @@
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.sql.Connection;
+import java.sql.SQLException;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -50,6 +51,7 @@
 
   private ServletConfig		config = null;
   private ServletContext	context = null;
+  Connection 		conn = null;
   DBSimpleQuery		queryobj = null;
   DBReader		docreader = null;
   static  String 	user = MetaCatUtil.user;
@@ -68,12 +70,12 @@
     
       try {
         // Open a connection to the database
-        Connection dbconn = MetaCatUtil.openDBConnection(
+        conn = MetaCatUtil.openDBConnection(
                 "oracle.jdbc.driver.OracleDriver",
                 defaultDB, user, password);
 
-        queryobj = new DBSimpleQuery(dbconn);
-        docreader = new DBReader(dbconn);
+        queryobj = new DBSimpleQuery(conn);
+        docreader = new DBReader(conn);
       } catch (Exception e) {
       }
     } catch ( ServletException ex ) {
@@ -123,6 +125,8 @@
       handleQueryAction(out, params, response);
     } else if (action.equals("getdocument")) {
       handleGetDocumentAction(out, params, response);
+    } else if (action.equals("putdocument")) {
+      handlePutDocumentAction(out, params, response);
     } else {
       out.println("Error: action not registered.  Please report this error.");
     }
@@ -192,4 +196,30 @@
   
       out.println(doc);
   }
+
+  /** 
+   * Handle the database putdocument request and write an XML document 
+   * to the database connection
+   */
+  private void handlePutDocumentAction(PrintWriter out, Hashtable params, 
+               HttpServletResponse response) {
+      // Get the document indicated
+      String doctext = ((String[])params.get("doctext"))[0]; 
+      StringReader xml = new StringReader(doctext);
+      try {
+        DBSAXWriter dbw = new DBSAXWriter(doctext, conn);
+      } catch (SQLException e1) {
+          out.println("Error loading document:<p>\n" + e1.getMessage());
+      }catch (IOException e2) {
+          out.println("Error loading document:<p>\n" + e2.getMessage());
+      }catch (ClassNotFoundException e3) {
+          out.println("Error loading document:<p>\n" + e3.getMessage());
+      }
+      //String doc = docreader.readXMLDocument((new Long(docid)).longValue());
+
+      // set content type and other response header fields first
+      response.setContentType("text/html");
+  
+      out.println("Finished loading document.");
+  }
 }
Index: loadxml.html
===================================================================
--- loadxml.html	(nonexistent)
+++ loadxml.html	(revision 55)
@@ -0,0 +1,33 @@
+<!--
+  * loadxml.html
+  *
+  *      Authors: Matt Jones
+  *    Copyright: 2000 Regents of the University of California and the
+  *               National Center for Ecological Analysis and Synthesis
+  *  For Details: http://www.nceas.ucsb.edu/
+  *      Created: 2000 April 5
+  *    File Info: '$Id$'
+  * 
+  * This is an HTML document for loading an xml document into Oracle
+-->
+<html>
+<head>
+<title>MetaCat</title>
+</head>
+<body bgcolor="white">
+<b>MetaCat XML Loader</b>
+<p>
+Load an XML document into MetaCat<br>
+by pasting the XML into this box.<br>
+<form action="/servlets/MetaCatServlet" target="right" method="POST">
+  <input type="hidden" name="action" value="putdocument">
+  <textarea name="doctext" size="50"></textarea>
+  <input type="submit" value="Load XML">
+</form>
+<p>
+To view results that are XML formatted in this demo, it is easiest to use 
+Internet Explorer 5. Although Netscape browsers will allow you to 
+download XML documents, only IE5 will display XML at this time.
+<p>
+</body>
+</html>

Property changes on: loadxml.html
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: lib/contents.html
===================================================================
--- lib/contents.html	(revision 54)
+++ lib/contents.html	(revision 55)
@@ -33,6 +33,8 @@
 For the test database, some valid values for the search that produce document
 results include "Value1" and "lakename"
 </p>
+<p><a href="loadxml.html" target="right">Load an XML Document</a>
+</p>
 <p>
 To view results that are XML formatted in this demo, it is easiest to use 
 Internet Explorer 5. Although Netscape browsers will allow you to 
Index: lib/loadxml.html
===================================================================
--- lib/loadxml.html	(nonexistent)
+++ lib/loadxml.html	(revision 55)
@@ -0,0 +1,33 @@
+<!--
+  * loadxml.html
+  *
+  *      Authors: Matt Jones
+  *    Copyright: 2000 Regents of the University of California and the
+  *               National Center for Ecological Analysis and Synthesis
+  *  For Details: http://www.nceas.ucsb.edu/
+  *      Created: 2000 April 5
+  *    File Info: '$Id$'
+  * 
+  * This is an HTML document for loading an xml document into Oracle
+-->
+<html>
+<head>
+<title>MetaCat</title>
+</head>
+<body bgcolor="white">
+<b>MetaCat XML Loader</b>
+<p>
+Load an XML document into MetaCat<br>
+by pasting the XML into this box.<br>
+<form action="/servlets/MetaCatServlet" target="right" method="POST">
+  <input type="hidden" name="action" value="putdocument">
+  <textarea name="doctext" size="50"></textarea>
+  <input type="submit" value="Load XML">
+</form>
+<p>
+To view results that are XML formatted in this demo, it is easiest to use 
+Internet Explorer 5. Although Netscape browsers will allow you to 
+download XML documents, only IE5 will display XML at this time.
+<p>
+</body>
+</html>

Property changes on: lib/loadxml.html
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: DBSAXWriter.java
===================================================================
--- DBSAXWriter.java	(revision 54)
+++ DBSAXWriter.java	(revision 55)
@@ -90,62 +90,81 @@
    * @param filename the filename to be loaded into the database
    * @param conn the database connection to which to write the XML file
    */
+  public DBSAXWriter( Reader xml, Connection conn)
+                  throws IOException, 
+                         SQLException, 
+                         ClassNotFoundException
+  {
+    this.conn = conn;
+
+    //try {
+
+      try {
+        SAXParser parser = initializeParser(conn);
+        parser.parse(xml);
+      } catch (SAXParseException e) {
+        System.err.println(e.getMessage());
+      } catch (SAXException e) {
+        System.err.println(e.getMessage());
+      }
+    //} catch (Exception e) {
+       //System.err.println(e.toString());
+    //}
+  }
+
   public DBSAXWriter( String filename, Connection conn)
                   throws IOException, 
                          SQLException, 
                          ClassNotFoundException
-   {
+  {
      this.conn = conn;
-    
-     //
-     // Set up the SAX document handlers for parsing
-     //
-
+     FileReader xmlfile = new FileReader(new File(filename).toString());
      try {
+       SAXParser parser = initializeParser(conn);
+       parser.parse(xmlfile);
+     } catch (SAXParseException e) {
+       System.err.println(e.getMessage());
+     } catch (SAXException e) {
+       System.err.println(e.getMessage());
+     }
+  }
+  
+  private SAXParser initializeParser(Connection conn) {
+    SAXParser parser = null;
+    //
+    // Set up the SAX document handlers for parsing
+    //
+    try {
+      // Use the XMLDocumentHandler interface for namespace support
+      // instead of org.xml.sax.DocumentHandler
+      XMLDocumentHandler xmlDocHandler = new DBSAXHandler(conn);
 
-        // Use the XMLDocumentHandler interface for namespace support
-        // instead of org.xml.sax.DocumentHandler
-        XMLDocumentHandler xmlDocHandler = new DBSAXHandler(conn);
+      // For all the other interface use the default provided by
+      // Handler base
+      HandlerBase defHandler = new HandlerBase();
 
-        // For all the other interface use the default provided by
-        // Handler base
-        HandlerBase defHandler = new HandlerBase();
+      // Get an instance of the parser
+      parser = new SAXParser();
 
-        // Get an instance of the parser
-        SAXParser parser = new SAXParser();
+      // Set Handlers in the parser
+      // Set the DocumentHandler to XMLDocumentHandler
+      parser.setDocumentHandler(xmlDocHandler);
 
-        // Set Handlers in the parser
-        // Set the DocumentHandler to XMLDocumentHandler
-        parser.setDocumentHandler(xmlDocHandler);
+      // Set the other Handler to the defHandler
+      parser.setErrorHandler(defHandler);
+      parser.setEntityResolver(defHandler);
+      parser.setDTDHandler(defHandler);
 
-        // Set the other Handler to the defHandler
-        parser.setErrorHandler(defHandler);
-        parser.setEntityResolver(defHandler);
-        parser.setDTDHandler(defHandler);
+    } catch (Exception e) {
+       System.err.println(e.toString());
+    }
 
-        try
-        {
-           parser.parse(fileToURL(new File(filename)).toString());
-        }
-        catch (SAXParseException e)
-        {
-           System.err.println(filename + ": " + e.getMessage());
-        }
-        catch (SAXException e)
-        {
-           System.err.println(filename + ": " + e.getMessage());
-        }
-     }
-     catch (Exception e)
-     {
-        System.err.println(e.toString());
-     }
+    return parser;
+  }
 
-   }
-  
-   /** Utility method to convert a file handle into a URL */
-   static public URL fileToURL(File file) 
-   {
+  /** Utility method to convert a file handle into a URL */
+  static public URL fileToURL(File file) 
+  {
      String path = file.getAbsolutePath();
      String fSep = System.getProperty("file.separator");
      if (fSep != null && fSep.length() == 1)
@@ -161,5 +180,4 @@
        throw new Error("unexpected MalformedURLException");
      }
   }
-
 }
