(no commit message)
[utils] / support / src / org / wamblee / xml / XSLT.java
index e7c5fc7643c76c046e06c69c401f67a435df5618..ae603976b6de126e8a1ac22a3880fb76d1599f7c 100644 (file)
@@ -17,6 +17,7 @@
 package org.wamblee.xml;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -28,6 +29,7 @@ import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.w3c.dom.Document;
@@ -88,6 +90,21 @@ public class XSLT {
         transform(source, result, aXslt);
         return (Document) result.getNode();
     }
+    
+    /**
+     * Transforms a document to a text output. This supports XSLT transformations
+     * that result in text documents. 
+     * @param aDocument Document to transform.
+     * @param aXslt XSL transformation. 
+     * @return Transformed document.  
+     */
+    public String textTransform(byte[] aDocument, InputResource aXslt) throws IOException, TransformerException { 
+        Source source = new StreamSource(new ByteArrayInputStream(aDocument));
+        ByteArrayOutputStream os = new ByteArrayOutputStream(); 
+        StreamResult result = new StreamResult(os);
+        transform(source, result, aXslt);
+        return new String(os.toByteArray());
+    }
 
     /**
      * Transforms a document using XSLT.