Index: src/edu/ucsb/nceas/metacat/DBTransform.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBTransform.java	(revision 2087)
+++ src/edu/ucsb/nceas/metacat/DBTransform.java	(revision 2088)
@@ -110,6 +110,18 @@
     transformXMLDocument(doc, sourceType, targetType, qformat, pw, param, null);
   }
 
+   /**
+   * @see transformXMLDocument(String doc, String sourceType,
+   *            String targetType, String qFormat, StringWriter pw
+   *            String sessionid)
+   */
+  public void transformXMLDocument(String doc, String sourceType,
+                String targetType, String qFormat, StringWriter pw)
+  {
+    transformXMLDocument(doc, sourceType, targetType, qFormat, pw, null);
+  }
+
+
   /**
    * Transform an XML document using the stylesheet reference from the db
    *
@@ -128,46 +140,26 @@
 
     // Look up the stylesheet for this type combination
     String xslSystemId = getStyleSystemId(qformat, sourceType, targetType);
+    if (xslSystemId != null)
+    {
+      try
+      {// Create a stylesheet from the system id that was found
+        doc = removeDOCTYPE(doc);
+        StringReader xml = new StringReader(doc);
+        StreamResult result = new StreamResult(pw);
+        doTransform(xml, result, xslSystemId, param, qformat, sessionid);
 
-    if (xslSystemId != null) {
-      // Create a stylesheet from the system id that was found
-      try {
-        TransformerFactory tFactory = TransformerFactory.newInstance();
-        Transformer transformer = tFactory.newTransformer(
-                                  new StreamSource(xslSystemId));
-        transformer.setParameter("qformat", qformat);
-        MetaCatUtil.debugMessage("qformat: "+qformat, 30);
-
-        if(sessionid != null)
-        {
-          transformer.setParameter("sessid", sessionid);
-        }
-
-        // Set up parameter for transformation
-        if ( param != null)
-        {
-          Enumeration en = param.keys();
-          while (en.hasMoreElements())
-          {
-            String key =(String)en.nextElement();
-            String value = ((String[])(param.get(key)))[0];
-            MetaCatUtil.debugMessage(key+" : "+value, 30);
-            transformer.setParameter(key, value);
-          }
-        }
-        
-        doc = removeDOCTYPE(doc);
-        StreamSource xml = new StreamSource(new StringReader(doc));
-        //modify the system id for dtd
-        //modifiedXmlStreamSource(xml, sourceType);
-        transformer.transform(xml, new StreamResult(pw));
-      } catch (Exception e) {
+      }
+      catch (Exception e)
+      {
         pw.println(xslSystemId + "Error transforming document in " +
                    "DBTransform.transformXMLDocument: " +
                    e.getMessage());
 
       }
-    } else {
+    }
+    else
+    {
       // No stylesheet registered form this document type, so just return the
       // XML stream we were passed
       pw.print(doc);
@@ -185,34 +177,31 @@
    */
   public void transformXMLDocument(String doc, String sourceType,
                 String targetType, String qFormat, StringWriter pw,
-                String sessionid) {
+                String sessionid)
+  {
 
     // Look up the stylesheet for this type combination
     String xslSystemId = getStyleSystemId(qFormat, sourceType, targetType);
-
-    if (xslSystemId != null) {
+    if (xslSystemId != null)
+    {
       // Create a stylesheet from the system id that was found
-      try {
-        TransformerFactory tFactory = TransformerFactory.newInstance();
-        Transformer transformer = tFactory.newTransformer(
-                                  new StreamSource(xslSystemId));
-        if(sessionid != null)
-        {
-          transformer.setParameter("sessid", sessionid);
-        }
-        transformer.setParameter("qFormat", qFormat);
+      try
+      {
         doc = removeDOCTYPE(doc);
-        StreamSource xml = new StreamSource(new StringReader(doc));
-        //modify the system id for dtd
-        //modifiedXmlStreamSource(xml, sourceType);
-        transformer.transform(xml, new StreamResult(pw));
-      } catch (Exception e) {
+        StringReader xml = new StringReader(doc);
+        StreamResult result = new StreamResult(pw);
+        doTransform(xml, result, xslSystemId, null, qFormat, sessionid);
+      }
+      catch (Exception e)
+      {
         util.debugMessage(xslSystemId + "Error transforming document in " +
                    "DBTransform.transformXMLDocument: " +
                    e.getMessage(), 30);
 
       }
-    } else {
+    }
+    else
+    {
       // No stylesheet registered form this document type, so just return the
       // XML stream we were passed
       pw.write(doc);
@@ -220,16 +209,83 @@
   }
 
   /**
-   * @see transformXMLDocument(String doc, String sourceType,
-   *            String targetType, String qFormat, StringWriter pw
-   *            String sessionid)
+   * Method to do transform for a string reader
+   * @param doc the document to be transformed
+   * @param sourcetype the document type of the source
+   * @param targettype the target document type
+   * @param qformat the name of the style set to use
+   * @param pw the PrintWriter to which output is printed
+   * @param params some parameters for eml2 transformation
    */
-  public void transformXMLDocument(String doc, String sourceType,
-                String targetType, String qFormat, StringWriter pw)
+   public void transformXMLDocument(StringReader docContent, String sourceType,
+                                   String targetType, String qformat,
+                                   PrintWriter pw, Hashtable param,
+                                   String sessionid)
+   {
+     // Look up the stylesheet for this type combination
+    String xslSystemId = getStyleSystemId(qformat, sourceType, targetType);
+    if (xslSystemId != null)
+    {
+      try
+      {// Create a stylesheet from the system id that was found
+        StreamResult result = new StreamResult(pw);
+        doTransform(docContent, result, xslSystemId, param, qformat, sessionid);
+
+      }
+      catch (Exception e)
+      {
+        pw.println(xslSystemId + "Error transforming document in " +
+                   "DBTransform.transformXMLDocument: " +
+                   e.getMessage());
+
+      }
+    }
+    else
+    {
+      // No stylesheet registered form this document type, so just return the
+      // XML stream we were passed
+      pw.print(docContent);
+    }
+   }
+
+  /*
+   * Method to do transfer
+   */
+  private void doTransform(StringReader docContent, StreamResult resultOutput,
+                           String xslSystemId, Hashtable param,
+                           String qformat, String sessionid)
+                          throws Exception
   {
-    transformXMLDocument(doc, sourceType, targetType, qFormat, pw, null);
-  }
+    if (xslSystemId != null)
+    {
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        Transformer transformer = tFactory.newTransformer(
+                                  new StreamSource(xslSystemId));
+        transformer.setParameter("qformat", qformat);
+        MetaCatUtil.debugMessage("qformat: "+qformat, 30);
 
+        if(sessionid != null)
+        {
+          transformer.setParameter("sessid", sessionid);
+        }
+        // Set up parameter for transformation
+        if ( param != null)
+        {
+          Enumeration en = param.keys();
+          while (en.hasMoreElements())
+          {
+            String key =(String)en.nextElement();
+            String value = ((String[])(param.get(key)))[0];
+            MetaCatUtil.debugMessage(key+" : "+value, 30);
+            transformer.setParameter(key, value);
+          }
+        }
+        StreamSource xml = new StreamSource(docContent);
+        transformer.transform(xml,resultOutput);
+    }
+  }//doTransform
+
+
   /**
    * gets the content of a tag in a given xml file with the given path
    * @param f the file to parse
@@ -371,7 +427,7 @@
  /* Method to modified the system id of xml input -- make sure it
     points to system id in xml_catalog table
   */
-  private void modifiedXmlStreamSource(StreamSource xml, String publicId)   
+  private void modifiedXmlStreamSource(StreamSource xml, String publicId)
                                        throws Exception
   {
     // make sure the xml is not null
@@ -387,21 +443,21 @@
     //set system id to input stream
     xml.setSystemId(systemId);
   }
-  
+
   /*
    * removes the DOCTYPE element and its contents from a Sting
-   * used to avoid problems with incorrect SystemIDs 
+   * used to avoid problems with incorrect SystemIDs
    */
-  private String removeDOCTYPE(String in) {  
+  private String removeDOCTYPE(String in) {
     String ret = "";
     int startpos = in.indexOf("<!DOCTYPE");
     if (startpos>-1) {
-      int stoppos = in.indexOf(">", startpos + 8);   
+      int stoppos = in.indexOf(">", startpos + 8);
       ret = in.substring(0,startpos) + in.substring(stoppos+1,in.length());
     } else {
       return in;
     }
-    return ret;  
+    return ret;
   }
 
   /**
