Index: lib/metacat.html
===================================================================
--- lib/metacat.html	(revision 742)
+++ lib/metacat.html	(revision 743)
@@ -36,7 +36,7 @@
     
     <FRAME SRC="contents.html" BORDER=0 NAME="left">
 
-    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&doctype=-//NCEAS//eml-dataset//EN" BORDER=0 NAME="right">
+    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&returndoctype=-//NCEAS//eml-dataset-2.0//EN" BORDER=0 NAME="right">
 
     </FRAMESET>
   </FRAMESET>
Index: lib/queform.html
===================================================================
--- lib/queform.html	(revision 742)
+++ lib/queform.html	(revision 743)
@@ -46,7 +46,8 @@
   <input type="radio" name="qformat" value="html" checked>HTML
   <br />
   Return: &nbsp;
-  <select name=doctype>
+  <select name="returndoctype">
+  <option value="-//NCEAS//eml-dataset-2.0//EN">eml-dataset-2.0
   <option value="-//NCEAS//eml-dataset//EN">eml-dataset
   <option value="any">Any
   </select>
Index: lib/filtertest.html
===================================================================
--- lib/filtertest.html	(nonexistent)
+++ lib/filtertest.html	(revision 743)
@@ -0,0 +1,69 @@
+<!--
+  *  '$RCSfile$'
+  *      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/
+  *
+  *   '$Author$'
+  *     '$Date$'
+  * '$Revision$'
+  * 
+  * This is an HTML document for displaying examples of the use of 
+  * Oracle XML tools for query only
+  *
+  * 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
+-->
+<html>
+<head>
+<title>MetaCat</title>
+<link rel="stylesheet" type="text/css" href="@html-path@/style/rowcol.css">
+</head>
+<body class="emlbody">
+<table width="100%">
+<tr><td colspan="2">
+<b>MetaCat Query</b> -- a simple database query against MetaCat
+</td></tr>
+<tr><td width="40%" valign="top">
+<form action="@servlet-path@" target="right" method="POST">
+  <input type="hidden" name="action" value="query">
+  <input type="text" name="anyfield" value="%" size="15">
+  <input type="submit" value="Run query"><br />
+  Format: 
+  <input type="radio" name="qformat" value="xml">XML
+  <input type="radio" name="qformat" value="html" checked>HTML
+  <br />
+  Search only (filter): &nbsp;
+  <select name="filterdoctype">
+  <option value="-//NCEAS//eml-dataset-2.0//EN">eml-dataset-2.0
+  <option value="-//NCEAS//eml-dataset//EN">eml-dataset
+  </select>
+</form>
+<a href="login.html" target="_top">Login</a>
+</td>
+<td valign="top">
+<font size="-1">
+For the test database, some valid values for the search that produce document
+results include "Value1" and "lakename" and maybe "122W"
+<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.
+</font>
+</td>
+</tr>
+</table>
+</body>
+</html>

Property changes on: lib/filtertest.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 742)
+++ lib/contents.html	(revision 743)
@@ -46,7 +46,8 @@
   <input type="radio" name="qformat" value="html" checked>HTML
   <br />
   Return: &nbsp;
-  <select name=doctype>
+  <select name=returndoctype>
+  <option value="-//NCEAS//eml-dataset-2.0//EN">eml-dataset-2.0
   <option value="-//NCEAS//eml-dataset//EN">eml-dataset
   <option value="any">Any
   </select>
Index: lib/marinenoredir.html
===================================================================
--- lib/marinenoredir.html	(revision 742)
+++ lib/marinenoredir.html	(revision 743)
@@ -38,7 +38,7 @@
 
 Please click 
 <a href="http://dev.nceas.ucsb.edu@html-path@/servlet/marine?
-action=query&anyfield=%&doctype=any&qformat=html&returnfield=surname&
+action=query&anyfield=%&returndoctype=any&qformat=html&returnfield=surname&
 returnfield=givenname&returnfield=organizationname">  
  here.</a> if you are not automatically redirected.
 
Index: lib/knbquery.html
===================================================================
--- lib/knbquery.html	(revision 742)
+++ lib/knbquery.html	(revision 743)
@@ -13,7 +13,7 @@
     <input type="hidden" name="operator" value="UNION" >
     <input type="hidden" name="returnfield" value="/download/date" >
     <input type="hidden" name="returnfield" value="/download/param" >
-    <input type="hidden" name="doctype" value="download">
+    <input type="hidden" name="filterdoctype" value="download">
     <input type="text" name="anyfield">
     <input type="submit">
   </form>
Index: lib/metacat.properties
===================================================================
--- lib/metacat.properties	(revision 742)
+++ lib/metacat.properties	(revision 743)
@@ -19,7 +19,7 @@
 saxparser=org.apache.xerces.parsers.SAXParser
 servletpath=@servlet-path@
 htmlpath=@html-path@
-packagedoctype=-//NCEAS//package//EN
+packagedoctype=-//NCEAS//eml-dataset-2.0//EN
 accessdoctype=-//NCEAS//eml-access//EN
 server=@server@
 authclass=edu.ucsb.nceas.metacat.AuthLdap
Index: lib/index.html
===================================================================
--- lib/index.html	(revision 742)
+++ lib/index.html	(revision 743)
@@ -36,7 +36,7 @@
     
     <FRAME SRC="queform.html" BORDER=0 NAME="left">
 
-    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&doctype=-//NCEAS//eml-dataset//EN" BORDER=0 NAME="right">
+    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&returndoctype=-//NCEAS//eml-dataset-2.0//EN" BORDER=0 NAME="right">
 
     </FRAMESET>
   </FRAMESET>
Index: lib/marine.html
===================================================================
--- lib/marine.html	(revision 742)
+++ lib/marine.html	(revision 743)
@@ -35,7 +35,7 @@
 
 <script language="JavaScript">
  window.location="http://@server@@servlet-path@?" +
-  "action=query&anyfield=%&doctype=any&qformat=html&" +
+  "action=query&anyfield=%&returndoctype=any&qformat=html&" +
   "returnfield=resource/dataset/originator/individualName/surName&" +
   "returnfield=resource/dataset/originator/individualName/givenName&" + 
   "returnfield=resource/dataset/originator/organizationName&" +
@@ -52,7 +52,7 @@
 <noscript>
 Please click 
 <a href="http://@server@@servlet-path@?
-action=query&anyfield=%&doctype=any&qformat=html&
+action=query&anyfield=%&returndoctype=any&qformat=html&
 returnfield=resource/dataset/originator/individualName/surName&
 returnfield=resource/dataset/originator/individualName/givenName&
 returnfield=resource/dataset/originator/organizationName&
@@ -65,7 +65,7 @@
 
 Please click 
 <a href="http://@server@@servlet-path@??
-action=query&anyfield=%&doctype=any&qformat=html&
+action=query&anyfield=%&returndoctype=any&qformat=html&
 returnfield=resource/dataset/originator/individualName/surName&
 returnfield=resource/dataset/originator/individualName/givenName&
 returnfield=resource/dataset/originator/organizationName&
Index: src/xmltables_postgres.sql
===================================================================
--- src/xmltables_postgres.sql	(revision 742)
+++ src/xmltables_postgres.sql	(revision 743)
@@ -214,6 +214,7 @@
 	relationid    INT8 default nextval('xml_relation_id_seq')  PRIMARY KEY, -- unique id
 	docid         VARCHAR(250) ,         -- the docid of the package file
 	                                      -- that this relation came from
+        packagetype   VARCHAR(250),          -- the type of the package
 	subject       VARCHAR(512) NOT NULL, -- the subject of the relation
 	subdoctype    VARCHAR(128),         	-- the doctype of the subject
 	relationship  VARCHAR(128)  NOT NULL,-- the relationship type
Index: src/loaddtd.sql
===================================================================
--- src/loaddtd.sql	(revision 742)
+++ src/loaddtd.sql	(revision 743)
@@ -28,3 +28,6 @@
 INSERT INTO xml_catalog (entry_type, public_id, system_id)
     VALUES ('DTD', '-//NCEAS//resource//EN',
             'http://dev.nceas.ucsb.edu/dtd/schemas/resource.dtd');
+INSERT INTO xml_catalog (entry_type, public_id, system_id)
+    VALUES ('DTD', '-//NCEAS//eml-dataset-2.0//EN',
+            'http://dev.nceas.ucsb.edu/metadata/dtd/eml-dataset-2.0.dtd');
Index: src/xmltables.sql
===================================================================
--- src/xmltables.sql	(revision 742)
+++ src/xmltables.sql	(revision 743)
@@ -235,10 +235,11 @@
 
 CREATE TABLE xml_relation (
 	relationid    NUMBER(20) PRIMARY KEY, -- unique id
-	docid         VARCHAR2(250) ,         -- the docid of the package file
+	docid         VARCHAR2(250),          -- the docid of the package file
 	                                      -- that this relation came from
+        packagetype   VARCHAR2(250),          -- the type of the package
 	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
-	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
+	subdoctype    VARCHAR2(128),          -- the doctype of the subject
 	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
 	object        VARCHAR2(512) NOT NULL, -- the object of the relation
 	objdoctype    VARCHAR2(128),          -- the doctype of the object
Index: src/edu/ucsb/nceas/metacat/QuerySpecification.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 742)
+++ src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 743)
@@ -54,9 +54,8 @@
  
   // Query data structures
   private String meta_file_id;
-// DOCTITLE attr cleared from the db
-//  private String querytitle;
-  private Vector doctypeList;
+  private Vector returnDocList;
+  private Vector filterDocList;
   private Vector returnFieldList;
   private Vector ownerList;
   private Vector siteList;
@@ -82,7 +81,8 @@
     super();
     
     // Initialize the class variables
-    doctypeList = new Vector();
+    returnDocList = new Vector();
+    filterDocList = new Vector();
     elementStack = new Stack();
     queryStack   = new Stack();
     returnFieldList = new Vector();
@@ -272,18 +272,17 @@
     String currentTag = currentNode.getTagName();
     if (currentTag.equals("meta_file_id")) {
       meta_file_id = inputString;
-// DOCTITLE attr cleared from the db
-//    } else if (currentTag.equals("querytitle")) {
-//      querytitle = inputString;
     } else if (currentTag.equals("value")) {
       currentValue = inputString;
     } else if (currentTag.equals("pathexpr")) {
       currentPathexpr = inputString;
     } else if (currentTag.equals("returndoctype")) {
-      doctypeList.add(inputString);
+      returnDocList.add(inputString);
     } else if (currentTag.equals("returnfield")) {
       returnFieldList.add(inputString);
       containsExtendedSQL = true;
+    } else if (currentTag.equals("filterdoctype")) {
+      filterDocList.add(inputString);
     } else if (currentTag.equals("owner")) {
       ownerList.add(inputString);
     } else if (currentTag.equals("site")) {
@@ -291,7 +290,6 @@
     }
   }
 
-
   /**
    * create a SQL serialization of the query that this instance represents
    */
@@ -308,11 +306,12 @@
     self.append(") ");
  
     // Add SQL to filter for doctypes requested in the query
-    // This is an implicit OR for the list of doctypes
-    if (!doctypeList.isEmpty()) {
+    // This is an implicit OR for the list of doctypes. Only doctypes in this
+    // list will be searched if the tag is present
+    if (!filterDocList.isEmpty()) {
       boolean firstdoctype = true;
       self.append(" AND ("); 
-      Enumeration en = doctypeList.elements();
+      Enumeration en = filterDocList.elements();
       while (en.hasMoreElements()) {
         String currentDoctype = (String)en.nextElement();
         if (firstdoctype) {
@@ -324,7 +323,7 @@
       }
       self.append(") ");
     }
-    
+
     // Add SQL to filter for owners requested in the query
     // This is an implicit OR for the list of owners
     if (!ownerList.isEmpty()) {
@@ -411,7 +410,7 @@
     StringBuffer self = new StringBuffer();
     self.append("select subject, relationship, object, subdoctype, ");
     self.append("objdoctype from xml_relation ");
-    self.append("where subject like '").append(docid).append("'");
+    self.append("where docid like '").append(docid).append("'");
     return self.toString();
   }
    
@@ -423,11 +422,11 @@
     StringBuffer self = new StringBuffer();
     self.append("select z.nodedata, x.nodedata, y.nodedata from ");
     self.append("(select nodeid, parentnodeid from xml_index where path like ");
-    self.append("'package/relation/subject') s, (select nodeid, parentnodeid ");
+    self.append("'triple/subject') s, (select nodeid, parentnodeid ");
     self.append("from xml_index where path like ");
-    self.append("'package/relation/relationship') rel, ");
+    self.append("'triple/relationship') rel, ");
     self.append("(select nodeid, parentnodeid from xml_index where path like ");
-    self.append("'package/relation/object') o, ");
+    self.append("'triple/object') o, ");
     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 ");
@@ -450,11 +449,11 @@
     StringBuffer self = new StringBuffer();
     self.append("select z.nodedata, x.nodedata, y.nodedata from ");
     self.append("(select nodeid, parentnodeid from xml_index where path like ");
-    self.append("'package/relation/subject') s, (select nodeid, parentnodeid ");
+    self.append("'triple/subject') s, (select nodeid, parentnodeid ");
     self.append("from xml_index where path like ");
-    self.append("'package/relation/relationship') rel, ");
+    self.append("'triple/relationship') rel, ");
     self.append("(select nodeid, parentnodeid from xml_index where path like ");
-    self.append("'package/relation/object') o, ");
+    self.append("'triple/object') o, ");
     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 ");
@@ -477,11 +476,11 @@
     StringBuffer self = new StringBuffer();
     self.append("select z.nodedata, x.nodedata, y.nodedata from ");
     self.append("(select nodeid, parentnodeid from xml_index where path like ");
-    self.append("'package/relation/subject') s, (select nodeid, parentnodeid ");
+    self.append("'triple/subject') s, (select nodeid, parentnodeid ");
     self.append("from xml_index where path like ");
-    self.append("'package/relation/relationship') rel, ");
+    self.append("'triple/relationship') rel, ");
     self.append("(select nodeid, parentnodeid from xml_index where path like ");
-    self.append("'package/relation/object') o, ");
+    self.append("'triple/object') o, ");
     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 ");
Index: src/edu/ucsb/nceas/metacat/DBQuery.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 742)
+++ src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 743)
@@ -112,7 +112,7 @@
           result.append("<resultset>\n"); 
   // following line removed by Dan Higgins to avoid insertion of query XML inside returned XML doc
   //        result.append("  <query>" + xmlfile + "</query>\n"); 
-          if(!showRuntime)
+          if (!showRuntime)
           {
             Enumeration doclist = nodelist.keys();
             while (doclist.hasMoreElements()) {
@@ -138,7 +138,7 @@
           }
           //System.out.println(result);
           //write into a file "result.txt"
-          if(!showRuntime)
+          if (!showRuntime)
           {
             File f = new File("./result.txt");
             FileWriter fw = new FileWriter(f);
@@ -199,14 +199,11 @@
   public Hashtable findDocuments(Reader xmlquery, String user, String group,
                                  String[] returndoc, boolean useXMLIndex)
   {
-    //System.out.println("in finddocuments");
       Hashtable   docListResult = new Hashtable();
       PreparedStatement pstmt = null;
       String docid = null;
       String docname = null;
       String doctype = null;
-// DOCTITLE attr cleared from the db
-//      String doctitle = null;
       String createDate = null;
       String updateDate = null;
       String fieldname = null;
@@ -217,8 +214,9 @@
       StringBuffer document = null; 
       Vector returndocVec = new Vector();
       
-      if(returndoc != null)
-      {//add the returndoc elements to a vector for easier manipulation
+      //add the returndoc elements to a vector for easier manipulation
+      if (returndoc != null)
+      {
         for(int i=0; i<returndoc.length; i++)
         {
           returndocVec.add(new String((String)returndoc[i]));
@@ -226,12 +224,9 @@
       }
       
       try {
-        if(conn == null || conn.isClosed())
-        {
+        if (conn == null || conn.isClosed()) {
           dbconn = util.openDBConnection();
-        }
-        else
-        {
+        } else {
           dbconn = conn;
         }
         // Get the XML query and covert it into a SQL statment
@@ -238,7 +233,6 @@
         QuerySpecification qspec = new QuerySpecification(xmlquery, 
                                    parserName, 
                                    util.getOption("accNumSeparator"));
-       // System.out.println(qspec.printSQL());
         pstmt = dbconn.prepareStatement( qspec.printSQL(useXMLIndex) );
 
         // Execute the SQL query using the JDBC connection
@@ -255,47 +249,49 @@
           }
           docname = rs.getString(2);
           doctype = rs.getString(3);
-// DOCTITLE attr cleared from the db
-//          doctitle = rs.getString(4);
           createDate = rs.getString(4);
           updateDate = rs.getString(5);
           rev = rs.getInt(6);
-          
-          //System.out.println("vec.size = " + returndocVec.size());
-          if(returndocVec.size() != 0 && !returndocVec.contains(doctype))
-          { //there are returndocs to match (backtracking can now be performed). 
-            //System.out.println("olddoctype: " + doctype);
+
+          //if there are returndocs to match, backtracking can be performed
+          // If no package exists, do not return the document
+          if (returndocVec.size() != 0 && !returndocVec.contains(doctype))
+          { 
+            String sep = util.getOption("accNumSeparator");
             StringBuffer btBuf = new StringBuffer();
-            btBuf.append("select object from xml_relation where ");
-            btBuf.append("objdoctype in (");
+            btBuf.append("select docid from xml_relation where ");
+
             //build the doctype list for the backtracking sql statement
+            btBuf.append("packagetype in (");
             for(int i=0; i<returndocVec.size(); i++)
             {
               btBuf.append("'").append((String)returndocVec.get(i)).append("'");
-              if(i != (returndocVec.size() - 1))
+              if (i != (returndocVec.size() - 1))
               {
                 btBuf.append(", ");
               } 
             }
             btBuf.append(") ");
-            btBuf.append("and subject like '");
-            //btBuf.append("metacat://").append(util.getOption("server"));
-            //btBuf.append("?docid=").append(docid).append("'");
-            btBuf.append("%docid=").append(docid).append("'");
-            //System.out.println("sql: " + btBuf.toString());
+
+            btBuf.append("and (subject like '");
+            btBuf.append(docid).append(sep).append(rev).append("'");
+            btBuf.append("or object like '");
+            btBuf.append(docid).append(sep).append(rev).append("')");
             
-            PreparedStatement npstmt = dbconn.prepareStatement(btBuf.toString());
+            PreparedStatement npstmt = dbconn.
+                                       prepareStatement(btBuf.toString());
             npstmt.execute();
             ResultSet btrs = npstmt.getResultSet();
             boolean hasBtRows = btrs.next();
-            if(hasBtRows)
+            while (hasBtRows)
             { //there was a backtrackable document found
               DocumentImpl xmldoc = null;
-              //System.out.println("document found is: " + btrs.getString(1));
-              MetacatURL objURL = new MetacatURL(btrs.getString(1));
+              String packageDocid = btrs.getString(1);
+              //MetacatURL objURL = new MetacatURL(packageDocid);
               try
               {
-                xmldoc = new DocumentImpl(dbconn, objURL.getParam(0)[1]);
+                //xmldoc = new DocumentImpl(dbconn, objURL.getParam(0)[1]);
+                xmldoc = new DocumentImpl(dbconn, packageDocid);
               }
               catch(Exception e)
               {
@@ -306,22 +302,40 @@
               docid   = xmldoc.getDocID();
               docname = xmldoc.getDocname();
               doctype = xmldoc.getDoctype();
-// DOCTITLE attr cleared from the db
-//              doctitle = xmldoc.getDocTitle();
               createDate = xmldoc.getCreateDate();
               updateDate = xmldoc.getUpdateDate();
-              //System.out.println("docname: " + docname + " doctype: " + doctype + 
-              //                   " doctitle: " + doctitle + " createdate: " +
-              //                   createDate + " updatedate: " + updateDate);
+              rev = xmldoc.getRev();
+
+              document = new StringBuffer();
+
+              String completeDocid = docid + util.getOption("accNumSeparator");
+              completeDocid += rev;
+              document.append("<docid>").append(completeDocid);
+              document.append("</docid>");
+              if (docname != null) {
+                document.append("<docname>" + docname + "</docname>");
+              }
+              if (doctype != null) {
+                document.append("<doctype>" + doctype + "</doctype>");
+              }
+              if (createDate != null) {
+                document.append("<createdate>" + createDate + "</createdate>");
+              }
+              if (updateDate != null) {
+                document.append("<updatedate>" + updateDate + "</updatedate>");
+              }
+              // Store the document id and the root node id
+              docListResult.put(docid,(String)document.toString());
+         
+              // Get the next package document linked to our hit
+              hasBtRows = btrs.next();
             }
             npstmt.close();
             btrs.close();
-          }
+          } else {
           
-          document = new StringBuffer();
-          //System.out.println("packagdoctype: " + util.getOption("packagedoctype"));
-          //if(!doctype.equals(util.getOption("packagedoctype")))
-          {
+            document = new StringBuffer();
+
             String completeDocid = docid + util.getOption("accNumSeparator");
             completeDocid += rev;
             document.append("<docid>").append(completeDocid).append("</docid>");
@@ -331,18 +345,15 @@
             if (doctype != null) {
               document.append("<doctype>" + doctype + "</doctype>");
             }
-// DOCTITLE attr cleared from the db
-//            if (doctitle != null) {
-//              document.append("<doctitle>" + doctitle + "</doctitle>");
-//            }
-            if(createDate != null) {
+            if (createDate != null) {
               document.append("<createdate>" + createDate + "</createdate>");
             }
-            if(updateDate != null) {
+            if (updateDate != null) {
               document.append("<updatedate>" + updateDate + "</updatedate>");
             }
             // Store the document id and the root node id
             docListResult.put(docid,(String)document.toString());
+  
           }
 
           // Advance to the next record in the cursor
@@ -351,7 +362,7 @@
         rs.close();
         //pstmt.close();
         
-        if(qspec.containsExtendedSQL())
+        if (qspec.containsExtendedSQL())
         {
           Vector extendedFields = new Vector(qspec.getReturnFieldList());
           Vector results = new Vector();
@@ -390,7 +401,7 @@
             document.append("</param>");
 
             tableHasRows = rs.next();
-            if(docListResult.containsKey(docid))
+            if (docListResult.containsKey(docid))
             {
               String removedelement = (String)docListResult.remove(docid);
               docListResult.put(docid, removedelement + document.toString());
@@ -411,11 +422,9 @@
           //String connstring = "metacat://"+util.getOption("server")+"?docid=";
           String connstring = "%docid=";
           String docidkey = (String)docidkeys.nextElement();
-          //System.out.println("relationsql: " + qspec.printRelationSQL(
-          //                                           connstring + docidkey));
+
           pstmt.close();
-          pstmt = dbconn.prepareStatement(
-                  qspec.printRelationSQL(connstring + docidkey));
+          pstmt = dbconn.prepareStatement(qspec.printRelationSQL(docidkey));
           pstmt.execute();
           rs = pstmt.getResultSet();
           tableHasRows = rs.next();
@@ -427,27 +436,36 @@
             String subDT = rs.getString(4);
             String objDT = rs.getString(5);
             
-            MetacatURL murl = new MetacatURL(sub);
-            if(murl.getProtocol().equals("metacat"))
-            {//we only want to process metacat urls here.
-              String[] tempparam = murl.getParam(0);
-              if(tempparam[0].equals("docid") && tempparam[1].equals(docidkey))
-              {
+            //MetacatURL murl = new MetacatURL(sub);
+            //we only want to process metacat urls here.
+            //if (murl.getProtocol().equals("metacat")) {
+              //String[] tempparam = murl.getParam(0);
+              //if (tempparam[0].equals("docid") && tempparam[1].equals(docidkey))
+              //{
                 document = new StringBuffer();
-                document.append("<relation>");
-                document.append("<relationtype>").append(rel);
-                document.append("</relationtype>");
-                document.append("<relationdoc>").append(obj);
-                document.append("</relationdoc>");
-                document.append("<relationdoctype>").append(objDT);
-                document.append("</relationdoctype>");
-                document.append("</relation>");
+                document.append("<triple>");
+                document.append("<subject>").append(sub);
+                document.append("</subject>");
+                if (!subDT.equals("null")) {
+                  document.append("<subjectdoctype>").append(subDT);
+                  document.append("</subjectdoctype>");
+                }
+                document.append("<relationship>").append(rel);
+                document.append("</relationship>");
+                document.append("<object>").append(obj);
+                document.append("</object>");
+                if (!objDT.equals("null")) {
+                  document.append("<objectdoctype>").append(objDT);
+                  document.append("</objectdoctype>");
+                }
+                document.append("</triple>");
                 
                 String removedelement = (String)docListResult.remove(docidkey);
-                docListResult.put(docidkey, removedelement + document.toString());
+                docListResult.put(docidkey, removedelement + 
+                                  document.toString());
                 
-              }
-            }
+              //}
+            //}
             tableHasRows = rs.next();
           }
           rs.close();
@@ -530,7 +548,7 @@
    * to the pathquery.dtd and is appropriate for submission to the DBQuery
    * structured query engine
    *
-   * @param params The list of parameters that  should be included in the query
+   * @param params The list of parameters that should be included in the query
    */
   public static String createSQuery(Hashtable params)
   { 
@@ -538,6 +556,7 @@
     Enumeration elements;
     Enumeration keys;
     String doctype = null;
+    String filterDoctype = null;
     String casesensitive = null;
     String searchmode = null;
     Object nextkey;
@@ -544,40 +563,35 @@
     Object nextelement;
     //add the xml headers
     query.append("<?xml version=\"1.0\"?>\n");
-    query.append("<pathquery version=\"1.0\"><meta_file_id>");
-    
-    if(params.containsKey("meta_file_id"))
+    query.append("<pathquery version=\"1.0\">\n");
+
+    if (params.containsKey("meta_file_id"))
     {
+      query.append("<meta_file_id>");
       query.append( ((String[])params.get("meta_file_id"))[0]);
       query.append("</meta_file_id>");
     }
-    else
-    {
-      query.append("unspecified</meta_file_id>");
-    }
     
-// DOCTITLE attr cleared from the db
-//    query.append("<querytitle>");
-//    if(params.containsKey("querytitle"))
-//    {
-//      query.append(((String[])params.get("querytitle"))[0]);
-//      query.append("</querytitle>");
-//    }
-//    else
-//    {
-//      query.append("unspecified</querytitle>");
-//    }
-    
-    if(params.containsKey("doctype"))
+    if (params.containsKey("returndoctype"))
     {
-      doctype = ((String[])params.get("doctype"))[0]; 
+      doctype = ((String[])params.get("returndoctype"))[0]; 
     }
     else
     {
       doctype = "ANY";  
     }
+
+    if (params.containsKey("filterdoctype"))
+    {
+      String[] filterDoctypes = ((String[])params.get("filterdoctype"));
+      for(int i=0; i<filterDoctypes.length; i++)
+      {
+        query.append("<filterdoctype>").append(filterDoctypes[i]);
+        query.append("</filterdoctype>");
+      }
+    }
     
-    if(params.containsKey("returnfield"))
+    if (params.containsKey("returnfield"))
     {
       String[] returnfield = ((String[])params.get("returnfield"));
       for(int i=0; i<returnfield.length; i++)
@@ -587,7 +601,7 @@
       }
     }
     
-    if(params.containsKey("owner"))
+    if (params.containsKey("owner"))
     {
       String[] owner = ((String[])params.get("owner"));
       for(int i=0; i<owner.length; i++)
@@ -597,7 +611,7 @@
       }
     }
     
-    if(params.containsKey("site"))
+    if (params.containsKey("site"))
     {
       String[] site = ((String[])params.get("site"));
       for(int i=0; i<site.length; i++)
@@ -607,8 +621,7 @@
       }
     }
     
-    //if you don't limit the query by doctype, then it just creates
-    //an empty returndoctype tag.
+    // back trace to doctype
     if (!doctype.equals("any") && 
         !doctype.equals("ANY") &&
         !doctype.equals("") ) 
@@ -616,13 +629,9 @@
        query.append("<returndoctype>");
        query.append(doctype).append("</returndoctype>");
     }
-    else
-    { 
-      query.append("<returndoctype></returndoctype>");
-    }
     
     //allows the dynamic switching of boolean operators
-    if(params.containsKey("operator"))
+    if (params.containsKey("operator"))
     {
       query.append("<querygroup operator=\"" + 
                 ((String[])params.get("operator"))[0] + "\">");
@@ -632,7 +641,7 @@
       query.append("<querygroup operator=\"UNION\">"); 
     }
         
-    if(params.containsKey("casesensitive"))
+    if (params.containsKey("casesensitive"))
     {
       casesensitive = ((String[])params.get("casesensitive"))[0]; 
     }
@@ -641,7 +650,7 @@
       casesensitive = "false"; 
     }
     
-    if(params.containsKey("searchmode"))
+    if (params.containsKey("searchmode"))
     {
       searchmode = ((String[])params.get("searchmode"))[0]; 
     }
@@ -654,13 +663,13 @@
     //free text search.  It does not have a <pathexpr>
     //tag.  This allows for a free text search within the structured
     //query.  This is useful if the INTERSECT operator is used.
-    if(params.containsKey("anyfield"))
+    if (params.containsKey("anyfield"))
     {
        String[] anyfield = ((String[])params.get("anyfield"));
        //allow for more than one value for anyfield
        for(int i=0; i<anyfield.length; i++)
        {
-         if(!anyfield[i].equals(""))
+         if (!anyfield[i].equals(""))
          {
            query.append("<queryterm casesensitive=\"" + casesensitive + 
                         "\" " + "searchmode=\"" + searchmode + "\"><value>" +
@@ -683,7 +692,8 @@
       //make sure we aren't querying for any of these
       //parameters since the are already in the query
       //in one form or another.
-      if(!nextkey.toString().equals("doctype") && 
+      if (!nextkey.toString().equals("returndoctype") && 
+         !nextkey.toString().equals("filterdoctype")  &&
          !nextkey.toString().equals("action")  &&
          !nextkey.toString().equals("qformat") && 
          !nextkey.toString().equals("anyfield") &&
@@ -695,7 +705,7 @@
         //allow for more than value per field name
         for(int i=0; i<((String[])nextelement).length; i++)
         {
-          if(!((String[])nextelement)[i].equals(""))
+          if (!((String[])nextelement)[i].equals(""))
           {
             query.append("<queryterm casesensitive=\"" + casesensitive +"\" " + 
                          "searchmode=\"" + searchmode + "\">" +
@@ -728,9 +738,6 @@
      StringBuffer xmlquery = new StringBuffer();
      xmlquery.append("<?xml version=\"1.0\"?>\n");
      xmlquery.append("<pathquery version=\"1.0\">");
-     xmlquery.append("<meta_file_id>Unspecified</meta_file_id>");
-// DOCTITLE attr cleared from the db
-//     xmlquery.append("<querytitle>Unspecified</querytitle>");
 
      if (!doctype.equals("any") && !doctype.equals("ANY")) {
        xmlquery.append("<returndoctype>");
@@ -741,7 +748,7 @@
      //chad added - 8/14
      //the if statement allows a query to gracefully handle a null 
      //query.  Without this if a nullpointerException is thrown.
-     if(!value.equals(""))
+     if (!value.equals(""))
      {
        xmlquery.append("<queryterm casesensitive=\"false\" ");
        xmlquery.append("searchmode=\"contains\">");
Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 742)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 743)
@@ -481,9 +481,9 @@
     String qformat = ((String[])params.get("qformat"))[0];
     String resultdoc = null;
     String[] returndoc = null;
-    if(params.contains("returndoc"))
+    if(params.contains("returndoctype"))
     {
-      returndoc = (String[])params.get("returndoc");
+      returndoc = (String[])params.get("returndoctype");
     }
     
     Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
@@ -515,9 +515,14 @@
   {
     //create the query and run it
     String[] returndoc = null;
-    if(params.containsKey("returndoc"))
+    if(params.containsKey("returndoctype"))
     {
-      returndoc = (String[])params.get("returndoc");
+      returndoc = (String[])params.get("returndoctype");
+      if (((String)returndoc[0]).equals("any") ||
+          ((String)returndoc[0]).equals("ANY") ||
+          ((String)returndoc[0]).equals("")) {
+        returndoc = null;
+      }
     }
     String xmlquery = DBQuery.createSQuery(params);
     Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
Index: src/edu/ucsb/nceas/metacat/RelationHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/RelationHandler.java	(revision 742)
+++ src/edu/ucsb/nceas/metacat/RelationHandler.java	(revision 743)
@@ -48,7 +48,7 @@
     }
     catch(Exception e)
     {
-      System.out.println("unable to get db connection in relationhandler." + 
+      MetaCatUtil.debugMessage("unable to get db connection in " + 
                          "relationhandler: " + e.getMessage());
     }
     this.xmldoc = xmldoc;
@@ -65,8 +65,10 @@
    */ 
   public void run()
   {
+    MetaCatUtil.debugMessage("Running relation handler!");
     Connection dbconn = null;
     String docid = xmldoc.getDocID();
+    String packagetype = xmldoc.getDoctype();
     // deletes all of the relations with a docid of @docid.
     deleteRelations(docid);
     //pseudo-code algorithm
@@ -79,6 +81,7 @@
     {
       dbconn = MetacatReplication.getDBConnection("RelationHandler." +
                                                   "run");
+
       PreparedStatement pstmt = dbconn.prepareStatement(
                                 QuerySpecification.printPackageSQL(docid));
       pstmt.execute();
@@ -89,81 +92,13 @@
       while(hasmorerows)
       {
         String subject = rs.getString(1);
+        String relationship = rs.getString(2);
+        String object = rs.getString(3);
+
         String subjectDoctype = null;
         String paramDocid = null;
         URL subjectMurl = null;
 
-        try
-        {
-          subjectMurl = new URL(subject);
-          subjectDoctype = null;
-          Hashtable murlParams = util.parseQuery(subjectMurl.getQuery());
-          paramDocid = (String)murlParams.get("docid"); 
-        }
-        catch(MalformedURLException murle)
-        { //assume this is just a docid not a url
-          paramDocid = subject;
-        }
-        
-        DocumentImpl subDoc = new DocumentImpl(dbconn, paramDocid);
-        subjectDoctype = subDoc.getDoctype();
-        String relationship = rs.getString(2);
-        String object = rs.getString(3);
-      
-        //compare r to each relation in xml_relation
-        
-        pstmt = dbconn.prepareStatement("select subject, subdoctype, " +
-                                      "relationship, object, objdoctype " +
-                                      "from xml_relation");
-        pstmt.execute();
-        //get each relation in xml_relation for comparison
-        ResultSet relations = pstmt.getResultSet();
-        boolean hasmorerelations = relations.next();
-        while(hasmorerelations)
-        {
-          String currentSub = relations.getString(1);
-          String currentSubDoctype = relations.getString(2);
-          String currentRelationship = relations.getString(3);
-          String currentObj = relations.getString(4);
-          String currentObjDoctype = relations.getString(5);
-         
-          if(object.equals(currentObj))
-          {//there is a transitive relation so add a new relation to the table
-            StringBuffer insertTransRelation = new StringBuffer();
-            insertTransRelation.append("insert into xml_relation (docid, ");
-            insertTransRelation.append(" subject, ");
-            insertTransRelation.append("subdoctype, relationship, object, ");
-            insertTransRelation.append("objdoctype) values ('");
-            insertTransRelation.append(docid).append("', '");
-            insertTransRelation.append(currentSub).append("', '");
-            insertTransRelation.append(currentSubDoctype).append("', ");
-            insertTransRelation.append("'hasTransitiveRelationTo', '");
-            insertTransRelation.append(subject).append("', '");
-            insertTransRelation.append(subjectDoctype).append("')");
-            //System.out.println("sql1: " + insertTransRelation.toString());
-            pstmt = dbconn.prepareStatement(insertTransRelation.toString());
-            pstmt.execute(); 
-            
-            insertTransRelation = new StringBuffer();
-            //put the same relation in with the subject and object switched
-            insertTransRelation.append("insert into xml_relation (docid, ");
-            insertTransRelation.append(" subject, ");
-            insertTransRelation.append("subdoctype, relationship, object, ");
-            insertTransRelation.append("objdoctype) values ('");
-            insertTransRelation.append(docid).append("', '");
-            insertTransRelation.append(subject).append("', '"); 
-            insertTransRelation.append(subjectDoctype).append("', ");
-            insertTransRelation.append("'hasTransitiveRelationTo', '");
-            insertTransRelation.append(currentSub).append("', '");
-            insertTransRelation.append(currentSubDoctype).append("')");
-            //System.out.println("sql2: " + insertTransRelation.toString());
-            pstmt = dbconn.prepareStatement(insertTransRelation.toString());
-            pstmt.execute();
-          }
-          
-          hasmorerelations = relations.next(); 
-        }
-        
         //get the current relations information
         String subDocid = null;
         String objDocid = null;
@@ -179,7 +114,7 @@
             subDocid = (String)subMurlParams.get("docid");
             if(subMurl.getProtocol().equals("metacat"))
             {
-              subDoc = new DocumentImpl(dbconn, subDocid);
+              DocumentImpl subDoc = new DocumentImpl(dbconn, subDocid);
               subDoctype = subDoc.getDoctype();
             }
           }
@@ -220,10 +155,11 @@
         //now that the comparisons are done, the new relation can be put
         //into xml_relation
         StringBuffer insertStmt = new StringBuffer();
-        insertStmt.append("insert into xml_relation (docid, subject, ");
-        insertStmt.append("subdoctype, ");
+        insertStmt.append("insert into xml_relation (docid, packagetype, ");
+        insertStmt.append("subject, subdoctype, ");
         insertStmt.append("relationship, object, objdoctype) values ('");
         insertStmt.append(docid).append("', '");
+        insertStmt.append(packagetype).append("', '");
         insertStmt.append(subject).append("', '");
         insertStmt.append(subDoctype).append("', '");
         insertStmt.append(relationship).append("', '");
@@ -244,9 +180,8 @@
     } 
     catch(Exception e) 
     { 
-      System.out.println("Error in relationHandler.run: " + e.getMessage());
-      util.debugMessage("Error in relationHandler.run: " + e.getMessage());
-      e.printStackTrace(System.out);
+      MetaCatUtil.debugMessage("Error in relationHandler.run: " + 
+                               e.getMessage());
       btThread = null;
       try 
       { 
@@ -270,7 +205,7 @@
     }
     catch(Exception ee)
     {
-      System.out.println("error in relationHandler.deleteRelations: " +
+      MetaCatUtil.debugMessage("error in relationHandler.deleteRelations: " +
                           ee.getMessage());
     }
     
@@ -284,9 +219,8 @@
     }
     catch(Exception e)
     {
-      System.out.println("error in RelationHandler.deleteRelations(): " + 
+      MetaCatUtil.debugMessage("error in RelationHandler.deleteRelations(): " + 
                           e.getMessage());
-      e.printStackTrace(System.out);
       try 
       { 
         dbconn.rollback();
@@ -294,6 +228,5 @@
       } 
       catch (SQLException sqle) {}
     }
-    
   }
 }
Index: src/xmltables-sqlserver.sql
===================================================================
--- src/xmltables-sqlserver.sql	(revision 742)
+++ src/xmltables-sqlserver.sql	(revision 743)
@@ -216,6 +216,7 @@
 	relationid    NUMBER(20) PRIMARY KEY, -- unique id
 	docid         VARCHAR2(250) ,         -- the docid of the package file
 	                                      -- that this relation came from
+        packagetype   VARCHAR2(250),          -- the type of the package
 	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
 	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
 	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
Index: bin/loadxml
===================================================================
--- bin/loadxml	(revision 742)
+++ bin/loadxml	(revision 743)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
-PDIR=/home/computer/jones/projects/pbi/development/xmltodb
+PDIR=/home/computer/$USER/development/xmltodb
 JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
 
 export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
Index: bin/xml2sql
===================================================================
--- bin/xml2sql	(revision 742)
+++ bin/xml2sql	(revision 743)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
-PDIR=/home/computer/jones/projects/pbi/development/xmltodb
+PDIR=/home/computer/$USER/development/xmltodb
 JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
 
 export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
Index: bin/valxml
===================================================================
--- bin/valxml	(revision 742)
+++ bin/valxml	(revision 743)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
-PDIR=/home/computer/jones/projects/pbi/development/xmltodb
+PDIR=/home/computer/$USER/development/xmltodb
 JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
 
 export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
Index: bin/queryxml
===================================================================
--- bin/queryxml	(revision 742)
+++ bin/queryxml	(revision 743)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
-PDIR=/home/computer/jones/projects/pbi/development/xmltodb
+PDIR=/home/computer/$USER/development/xmltodb
 JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
 
 export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
Index: bin/squeryxml
===================================================================
--- bin/squeryxml	(revision 742)
+++ bin/squeryxml	(revision 743)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
-PDIR=/home/computer/jones/projects/pbi/development/xmltodb
+PDIR=/home/computer/$USER/development/xmltodb
 JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
 
 export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
Index: bin/readxml
===================================================================
--- bin/readxml	(revision 742)
+++ bin/readxml	(revision 743)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
-PDIR=/home/computer/jones/projects/pbi/development/xmltodb
+PDIR=/home/computer/$USER/development/xmltodb
 JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
 
 export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
