Index: src/edu/ucsb/nceas/metacat/DBReader.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBReader.java	(revision 102)
+++ src/edu/ucsb/nceas/metacat/DBReader.java	(revision 103)
@@ -144,11 +144,115 @@
    */
   public String readXMLDocument(long docid) {
     StringBuffer doc = new StringBuffer();
+    DoctypeInfo dti = getDoctypeInfo(docid);
+    String docname = dti.getDocname();
+    String doctype = dti.getDoctype();
+    String sysid = dti.getSystemID();
 
     ReaderElement element = new ReaderElement(conn, getRootNode(docid));
     doc.append("<?xml version=\"1.0\"?>\n");
+    
+    if (docname != null) {
+      if ((doctype != null) && (sysid != null)) {
+        doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
+                   "\" \"" + sysid + "\">\n");
+      } else {
+        doc.append("<!DOCTYPE " + docname + ">\n");
+      }
+    }
     doc.append(element.toString());
 
     return (doc.toString());
   }
+
+  /**
+   * Look up the document type information from the database
+   *
+   * @param docid the id of the document to look up
+   */
+  public DoctypeInfo getDoctypeInfo(long docid) {
+    PreparedStatement pstmt;
+    String doctype = null;
+    String docname = null;
+    String sysid   = null;
+    DoctypeInfo dti = null;
+
+    try {
+      pstmt =
+        conn.prepareStatement("SELECT docname,doctype " +
+                                "FROM xml_documents " +
+                               "WHERE docid = ?");
+      // Bind the values to the query
+      pstmt.setLong(1, new Long(docid).longValue());
+
+      pstmt.execute();
+      ResultSet rs = pstmt.getResultSet();
+      boolean tableHasRows = rs.next();
+      if (tableHasRows) {
+        docname  = rs.getString(1);
+        doctype  = rs.getString(2);
+      } 
+      pstmt.close();
+
+      pstmt =
+        conn.prepareStatement("SELECT system_id " +
+                                "FROM xml_catalog " +
+                               "WHERE public_id = ?");
+      // Bind the values to the query
+      pstmt.setString(1, doctype);
+
+      pstmt.execute();
+      rs = pstmt.getResultSet();
+      tableHasRows = rs.next();
+      if (tableHasRows) {
+        sysid  = rs.getString(1);
+      } 
+      pstmt.close();
+    } catch (SQLException e) {
+      System.out.println("Error getting id: " + e.getMessage());
+    }
+
+    dti = new DoctypeInfo(docname, doctype, sysid);
+    return dti;
+  }
+
+  /**
+   * A utility class that encapsulates document type information
+   */
+  public class DoctypeInfo {
+    private String docname = null;
+    private String doctype = null;
+    private String system_id = null;
+
+    /**
+     * Constructor
+     */
+    public DoctypeInfo(String docname, String doctype, String system_id) {
+      this.docname = docname;
+      this.doctype = doctype;
+      this.system_id = system_id;
+    }
+
+    /**
+     * get the document name
+     */
+    public String getDocname() {
+      return docname;
+    }
+
+    /**
+     * get the document type
+     */
+    public String getDoctype() {
+      return doctype;
+    }
+
+    /**
+     * get the system identifier
+     */
+    public String getSystemID() {
+      return system_id;
+    }
+  }
+
 }
Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 102)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 103)
@@ -163,16 +163,48 @@
   
     String name = null;
     String[] value = null;
+    String[] docid = new String[3];
     Hashtable params = new Hashtable();
     Enumeration paramlist = request.getParameterNames();
     while (paramlist.hasMoreElements()) {
       name = (String)paramlist.nextElement();
       value = request.getParameterValues(name);
+
+      // Decode the docid and mouse click information
+      if (name.endsWith(".y")) {
+        docid[0] = name.substring(0,name.length()-2);
+        //out.println("docid => " + docid[0]);
+        params.put("docid", docid);
+        name = "ypos";
+      }
+      if (name.endsWith(".x")) {
+        name = "xpos";
+      }
+
       //out.println(name + " => " + value[0]);
       params.put(name,value);
     }
 
+    // Determine what type of request the user made
+    // if the action parameter is set, use it as a default
+    // but if the ypos param is set, calculate the action needed
     String action = ((String[])params.get("action"))[0];
+    long ypos = 0;
+    try {
+      ypos = (new Long(((String[])params.get("ypos"))[0]).longValue());
+      //out.println("<P>YPOS IS " + ypos);
+      if (ypos <= 13) {
+        action = "getdocument";
+      } else if (ypos > 13 && ypos <= 27) {
+        action = "validate";
+      } else if (ypos > 27) {
+        action = "transform";
+      } else {
+        action = "";
+      }
+    } catch (Exception npe) {
+      //out.println("<P>Caught exception looking for Y value.");
+    }
 
     if (action.equals("query")) {
       handleQueryAction(out, params, response);
@@ -180,9 +212,9 @@
       try {
         handleGetDocumentAction(out, params, response);
       } catch (ClassNotFoundException e) {
-        System.out.println(e.getMessage());
+        out.println(e.getMessage());
       } catch (SQLException se) {
-        System.out.println(se.getMessage());
+        out.println(se.getMessage());
       }
     } else if (action.equals("putdocument")) {
       handlePutDocumentAction(out, params, response);
@@ -292,7 +324,7 @@
         response.setContentType("text/html");
 
         // Look up the document type
-        String sourcetype = getDoctype(docid);
+        String sourcetype = docreader.getDoctypeInfo(docid).getDoctype();
 
         // Transform the document to the new doctype
         dbt.transformXMLDocument(doc, sourcetype, "-//W3C//HTML//EN", out);
@@ -333,14 +365,33 @@
    */
   private void handleValidateAction(PrintWriter out, Hashtable params, HttpServletResponse response) {
 
-      // Get the document indicated
-      String[] valtext = (String[])params.get("valtext");
+    // Get the document indicated
+    String valtext = null;
+    try {
+      valtext = ((String[])params.get("valtext"))[0];
+    } catch (Exception nullpe) {
 
+      String docidstr = null;
+      long docid = 0;
+      try {
+        // Find the document id number
+        docidstr = ((String[])params.get("docid"))[0]; 
+        docid = (new Long(docidstr)).longValue();
+  
+        // Get the document indicated fromthe db
+        valtext = docreader.readXMLDocument(docid);
+      } catch (NullPointerException npe) {
+        response.setContentType("text/html");
+        out.println("Error getting document ID: " + 
+                     docidstr +" (" + docid + ")");
+      }
+    }
 
-      SAXParser parser = new SAXParser();           // works for both Xerces and Oracle
-      parser.setValidationMode(true);               // Oracle
+    SAXParser parser = new SAXParser();  // works for both Xerces and Oracle
+    parser.setValidationMode(true);      // Oracle
+    try {
       GenericXMLValidate gxv = new GenericXMLValidate(parser, xmlcatalogfile);
-      boolean valid = gxv.validateString(valtext[0]);
+      boolean valid = gxv.validateString(valtext);
 
       // set content type and other response header fields first
       response.setContentType("text/plain");
@@ -347,18 +398,25 @@
   
       if (valid) {
         out.println("The input XML is VALID!");
-      }
-      else {
+      } else {
         out.println("The input XML is NOT VALID\n" + gxv.returnErrors());
+        //response.setContentType("text/xml");
+        //out.println(valtext);
       } 
+    } catch (NullPointerException npe2) {
+      // set content type and other response header fields first
+      response.setContentType("text/html");
+      //out.println(valtext); 
+      out.println("Error validating document."); 
     }
+  }
 
   /** 
    * Look up the document type from the database
    *
+   * @param docid the id of the document to look up
    */
-  private String getDoctype(long docid) {
-    // Look up the System ID of the XSL sheet
+  private String OldgetDoctype(long docid) {
     PreparedStatement pstmt;
     String doctype = null;
  
Index: DBReader.java
===================================================================
--- DBReader.java	(revision 102)
+++ DBReader.java	(revision 103)
@@ -144,11 +144,115 @@
    */
   public String readXMLDocument(long docid) {
     StringBuffer doc = new StringBuffer();
+    DoctypeInfo dti = getDoctypeInfo(docid);
+    String docname = dti.getDocname();
+    String doctype = dti.getDoctype();
+    String sysid = dti.getSystemID();
 
     ReaderElement element = new ReaderElement(conn, getRootNode(docid));
     doc.append("<?xml version=\"1.0\"?>\n");
+    
+    if (docname != null) {
+      if ((doctype != null) && (sysid != null)) {
+        doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
+                   "\" \"" + sysid + "\">\n");
+      } else {
+        doc.append("<!DOCTYPE " + docname + ">\n");
+      }
+    }
     doc.append(element.toString());
 
     return (doc.toString());
   }
+
+  /**
+   * Look up the document type information from the database
+   *
+   * @param docid the id of the document to look up
+   */
+  public DoctypeInfo getDoctypeInfo(long docid) {
+    PreparedStatement pstmt;
+    String doctype = null;
+    String docname = null;
+    String sysid   = null;
+    DoctypeInfo dti = null;
+
+    try {
+      pstmt =
+        conn.prepareStatement("SELECT docname,doctype " +
+                                "FROM xml_documents " +
+                               "WHERE docid = ?");
+      // Bind the values to the query
+      pstmt.setLong(1, new Long(docid).longValue());
+
+      pstmt.execute();
+      ResultSet rs = pstmt.getResultSet();
+      boolean tableHasRows = rs.next();
+      if (tableHasRows) {
+        docname  = rs.getString(1);
+        doctype  = rs.getString(2);
+      } 
+      pstmt.close();
+
+      pstmt =
+        conn.prepareStatement("SELECT system_id " +
+                                "FROM xml_catalog " +
+                               "WHERE public_id = ?");
+      // Bind the values to the query
+      pstmt.setString(1, doctype);
+
+      pstmt.execute();
+      rs = pstmt.getResultSet();
+      tableHasRows = rs.next();
+      if (tableHasRows) {
+        sysid  = rs.getString(1);
+      } 
+      pstmt.close();
+    } catch (SQLException e) {
+      System.out.println("Error getting id: " + e.getMessage());
+    }
+
+    dti = new DoctypeInfo(docname, doctype, sysid);
+    return dti;
+  }
+
+  /**
+   * A utility class that encapsulates document type information
+   */
+  public class DoctypeInfo {
+    private String docname = null;
+    private String doctype = null;
+    private String system_id = null;
+
+    /**
+     * Constructor
+     */
+    public DoctypeInfo(String docname, String doctype, String system_id) {
+      this.docname = docname;
+      this.doctype = doctype;
+      this.system_id = system_id;
+    }
+
+    /**
+     * get the document name
+     */
+    public String getDocname() {
+      return docname;
+    }
+
+    /**
+     * get the document type
+     */
+    public String getDoctype() {
+      return doctype;
+    }
+
+    /**
+     * get the system identifier
+     */
+    public String getSystemID() {
+      return system_id;
+    }
+  }
+
 }
Index: MetaCatServlet.java
===================================================================
--- MetaCatServlet.java	(revision 102)
+++ MetaCatServlet.java	(revision 103)
@@ -163,16 +163,48 @@
   
     String name = null;
     String[] value = null;
+    String[] docid = new String[3];
     Hashtable params = new Hashtable();
     Enumeration paramlist = request.getParameterNames();
     while (paramlist.hasMoreElements()) {
       name = (String)paramlist.nextElement();
       value = request.getParameterValues(name);
+
+      // Decode the docid and mouse click information
+      if (name.endsWith(".y")) {
+        docid[0] = name.substring(0,name.length()-2);
+        //out.println("docid => " + docid[0]);
+        params.put("docid", docid);
+        name = "ypos";
+      }
+      if (name.endsWith(".x")) {
+        name = "xpos";
+      }
+
       //out.println(name + " => " + value[0]);
       params.put(name,value);
     }
 
+    // Determine what type of request the user made
+    // if the action parameter is set, use it as a default
+    // but if the ypos param is set, calculate the action needed
     String action = ((String[])params.get("action"))[0];
+    long ypos = 0;
+    try {
+      ypos = (new Long(((String[])params.get("ypos"))[0]).longValue());
+      //out.println("<P>YPOS IS " + ypos);
+      if (ypos <= 13) {
+        action = "getdocument";
+      } else if (ypos > 13 && ypos <= 27) {
+        action = "validate";
+      } else if (ypos > 27) {
+        action = "transform";
+      } else {
+        action = "";
+      }
+    } catch (Exception npe) {
+      //out.println("<P>Caught exception looking for Y value.");
+    }
 
     if (action.equals("query")) {
       handleQueryAction(out, params, response);
@@ -180,9 +212,9 @@
       try {
         handleGetDocumentAction(out, params, response);
       } catch (ClassNotFoundException e) {
-        System.out.println(e.getMessage());
+        out.println(e.getMessage());
       } catch (SQLException se) {
-        System.out.println(se.getMessage());
+        out.println(se.getMessage());
       }
     } else if (action.equals("putdocument")) {
       handlePutDocumentAction(out, params, response);
@@ -292,7 +324,7 @@
         response.setContentType("text/html");
 
         // Look up the document type
-        String sourcetype = getDoctype(docid);
+        String sourcetype = docreader.getDoctypeInfo(docid).getDoctype();
 
         // Transform the document to the new doctype
         dbt.transformXMLDocument(doc, sourcetype, "-//W3C//HTML//EN", out);
@@ -333,14 +365,33 @@
    */
   private void handleValidateAction(PrintWriter out, Hashtable params, HttpServletResponse response) {
 
-      // Get the document indicated
-      String[] valtext = (String[])params.get("valtext");
+    // Get the document indicated
+    String valtext = null;
+    try {
+      valtext = ((String[])params.get("valtext"))[0];
+    } catch (Exception nullpe) {
 
+      String docidstr = null;
+      long docid = 0;
+      try {
+        // Find the document id number
+        docidstr = ((String[])params.get("docid"))[0]; 
+        docid = (new Long(docidstr)).longValue();
+  
+        // Get the document indicated fromthe db
+        valtext = docreader.readXMLDocument(docid);
+      } catch (NullPointerException npe) {
+        response.setContentType("text/html");
+        out.println("Error getting document ID: " + 
+                     docidstr +" (" + docid + ")");
+      }
+    }
 
-      SAXParser parser = new SAXParser();           // works for both Xerces and Oracle
-      parser.setValidationMode(true);               // Oracle
+    SAXParser parser = new SAXParser();  // works for both Xerces and Oracle
+    parser.setValidationMode(true);      // Oracle
+    try {
       GenericXMLValidate gxv = new GenericXMLValidate(parser, xmlcatalogfile);
-      boolean valid = gxv.validateString(valtext[0]);
+      boolean valid = gxv.validateString(valtext);
 
       // set content type and other response header fields first
       response.setContentType("text/plain");
@@ -347,18 +398,25 @@
   
       if (valid) {
         out.println("The input XML is VALID!");
-      }
-      else {
+      } else {
         out.println("The input XML is NOT VALID\n" + gxv.returnErrors());
+        //response.setContentType("text/xml");
+        //out.println(valtext);
       } 
+    } catch (NullPointerException npe2) {
+      // set content type and other response header fields first
+      response.setContentType("text/html");
+      //out.println(valtext); 
+      out.println("Error validating document."); 
     }
+  }
 
   /** 
    * Look up the document type from the database
    *
+   * @param docid the id of the document to look up
    */
-  private String getDoctype(long docid) {
-    // Look up the System ID of the XSL sheet
+  private String OldgetDoctype(long docid) {
     PreparedStatement pstmt;
     String doctype = null;
  
Index: lib/resultset.xsl
===================================================================
--- lib/resultset.xsl	(revision 102)
+++ lib/resultset.xsl	(revision 103)
@@ -56,6 +56,7 @@
             </xsl:attribute>
 
           <td>
+<!--
               <input type="radio" name="docid">
                 <xsl:attribute name="value">
                   <xsl:value-of select="./docid"/>
@@ -62,14 +63,20 @@
                 </xsl:attribute>
               </input>
               <input type="submit" value="Display"/>
-<!--
-              <input border="0" type="image" name="docid" 
-                     src="/xmltodb/images/details.png">
-                <xsl:attribute name="value">
+-->
+              <input border="0" type="image">
+                <xsl:attribute name="src">
+                  <xsl:choose>
+                    <xsl:when test="position() 
+                         mod 2 = 1">/xmltodb/images/bttns-white.png</xsl:when>
+                    <xsl:when test="position() 
+                         mod 2 = 0">/xmltodb/images/bttns-blue.jpg</xsl:when>
+                  </xsl:choose>
+                </xsl:attribute>
+                <xsl:attribute name="name">
                   <xsl:value-of select="./docid"/>
                 </xsl:attribute>
               </input>
--->
           </td>
           <td><xsl:value-of select="./doctitle"/>
               <xsl:text>&nbsp;</xsl:text>
Index: lib/style/resultset.xsl
===================================================================
--- lib/style/resultset.xsl	(revision 102)
+++ lib/style/resultset.xsl	(revision 103)
@@ -56,6 +56,7 @@
             </xsl:attribute>
 
           <td>
+<!--
               <input type="radio" name="docid">
                 <xsl:attribute name="value">
                   <xsl:value-of select="./docid"/>
@@ -62,14 +63,20 @@
                 </xsl:attribute>
               </input>
               <input type="submit" value="Display"/>
-<!--
-              <input border="0" type="image" name="docid" 
-                     src="/xmltodb/images/details.png">
-                <xsl:attribute name="value">
+-->
+              <input border="0" type="image">
+                <xsl:attribute name="src">
+                  <xsl:choose>
+                    <xsl:when test="position() 
+                         mod 2 = 1">/xmltodb/images/bttns-white.png</xsl:when>
+                    <xsl:when test="position() 
+                         mod 2 = 0">/xmltodb/images/bttns-blue.jpg</xsl:when>
+                  </xsl:choose>
+                </xsl:attribute>
+                <xsl:attribute name="name">
                   <xsl:value-of select="./docid"/>
                 </xsl:attribute>
               </input>
--->
           </td>
           <td><xsl:value-of select="./doctitle"/>
               <xsl:text>&nbsp;</xsl:text>
Index: resultset.xsl
===================================================================
--- resultset.xsl	(revision 102)
+++ resultset.xsl	(revision 103)
@@ -56,6 +56,7 @@
             </xsl:attribute>
 
           <td>
+<!--
               <input type="radio" name="docid">
                 <xsl:attribute name="value">
                   <xsl:value-of select="./docid"/>
@@ -62,14 +63,20 @@
                 </xsl:attribute>
               </input>
               <input type="submit" value="Display"/>
-<!--
-              <input border="0" type="image" name="docid" 
-                     src="/xmltodb/images/details.png">
-                <xsl:attribute name="value">
+-->
+              <input border="0" type="image">
+                <xsl:attribute name="src">
+                  <xsl:choose>
+                    <xsl:when test="position() 
+                         mod 2 = 1">/xmltodb/images/bttns-white.png</xsl:when>
+                    <xsl:when test="position() 
+                         mod 2 = 0">/xmltodb/images/bttns-blue.jpg</xsl:when>
+                  </xsl:choose>
+                </xsl:attribute>
+                <xsl:attribute name="name">
                   <xsl:value-of select="./docid"/>
                 </xsl:attribute>
               </input>
--->
           </td>
           <td><xsl:value-of select="./doctitle"/>
               <xsl:text>&nbsp;</xsl:text>
