All, XMLResource interface is seriously lacking and output stream method. As you know we have many tools XMLOutputter, DOMOutputter XMLSerializer helping to store documents in an output stream, but strangely enough XMLDB interface (XMLResource) does not accept output stream.
In an attempt to remedie this problem I would like to submit this patch for discussion. Couple of things first. 1) somebody has to lobby for the XMLResource interface to be extended with a method OutputStream setContentAsOutputStream() throws XMLDBException 2) I have attached a patch file [for sake of discussion]. I know that the implementation can be polished off with better OutputStream classes or even a PipedInputStream/OutputStream combinaison or even some other suggestions you may have. I have also left out the IOException handling. 3) If this patch does not PASS the discussion phase then others can use is as an example to get round output stream issue. Best Regards. JC. \\- - -// ( @ @ ) ===oOOo-(_)-oOOo================================================= [EMAIL PROTECTED] =================================================================
Index: XMLResourceImpl.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/resources/XMLResourceImpl.java,v retrieving revision 1.16 diff -u -r1.16 XMLResourceImpl.java --- XMLResourceImpl.java 9 Aug 2003 05:01:55 -0000 1.16 +++ XMLResourceImpl.java 12 Nov 2003 11:31:09 -0000 @@ -78,6 +78,11 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.StringReader; +import java.io.OutputStream; +import java.io.IOException; +import java.io.PipedOutputStream; +import java.io.BufferedOutputStream; + /** * XMLResourceImpl provides an implementation to handle XML resources @@ -100,6 +105,14 @@ protected String content = null; /** + * buffer size generously big + * + */ + public static final int BUFFER_SIZE = 8*1024; + + + + /** * This is a SAX feature that controls how namespaces are reported in SAX. * By default this feature is <em>on</em>. * @@ -313,6 +326,40 @@ */ public ContentHandler setContentAsSAX() throws XMLDBException { return new SetContentHandler(this); + } + + /** + * setContentAsOutputStream returns a OutputStream that can be used to set the + * content of the resource. + * + * @return The outputStream that is used to insert data into the database. + * @exception XMLDBException + */ + public OutputStream setContentAsOutputStream() throws XMLDBException { + + PipedOutputStream pipedOut = new PipedOutputStream() + { + public void write(byte b[], int off, int len) throws IOException + { + try + { + /** WARNING it's important to trim the string + * because when XMLOutputter, DOMOutputter, XMLSerializer + * is used to populate the outputstream; they append + * charaters unwanted by most XML parsers. + */ + content = new String(b).trim(); + bytes = null; + } catch (Exception e) { + //TODO log an exception here + //throw FaultCodes.createXMLDBException(e); + } + + } + + }; + + return new BufferedOutputStream(pipedOut, BUFFER_SIZE); } /**