Hi! I'm new to the orbeon environment and I've tried to write a processor quite similar to the xls-serializer. (1) Read an Excel template [ok] (2) Modify it using the POI library [ok] (3) return to the contenhandler a correct XML document which contain the base64Binary Data [problem] When I write the Excel Document on disk it is correctly modified but when I try to write it in base64 and pass it to an HTTP-serializer, the document is recognize as a text document (wrong MIME) and it is empty -_-' (I'm pretty sur that I'm loosing all data when trying to convert in base64 but I don't see my error...) I put here the fragment of the XPL pipeline that I'm using and the java code that is responsible for creating the base64 binary data <!-- the class XLSInsertion must return a binary document but... --> <p:processor name="oxf:java" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="config"> <config sourcepath="./java" class="org.cgcis.XLSInsertion"/> </p:input> <p:input name="data">...</p:input> <p:output name="data" id="xls-binary"/> </p:processor> <!-- Serialize --> <p:processor name="oxf:http-serializer"> <p:input name="data" href="#xls-binary"/> <p:input name="config"> <config> <header> <name>Content-Disposition</name> <value>attachment; filename=report.xls</value> </header> </config> </p:input> </p:processor> And here a fragment of the generate method of XLSInsertion public void generateData(final PipelineContext pipelineContext, ContentHandler contentHandler) { [...] wb.write(os); char[] cbuf = new char[0]; BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, Charset.forName("UTF-8"))); bw.write(cbuf); os.close(); /* Here I want to create a binary document looking like : * <document xsi:type="base64Binary" * content-type="application/vnd.ms-excel"> * /9j/3H4BLHERBFQ348IZU7 ... 34RFQ34F3Q43R3Q4== * </document> * * But it doesn't work :'( */ AttributesImpl atts = new AttributesImpl(); atts.addAttribute("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi:type", "String", "xs:base64Binary"); atts.addAttribute("", "content-type", "content-type", "String", "application/vnd.ms-excel"); contentHandler.startDocument(); contentHandler.startElement("", "document", "document", atts); contentHandler.characters(cbuf, 0, os.toString().length()); contentHandler.endElement("", "document", "document"); contentHandler.endDocument(); [...] } Thank you for your attention and have a nice day! ps. I'm using OF 3.5 milestone 1 (nightly release from 15 november 2006) ps2. Sorry for my poor english -_-' ps3. The problem of the empty document is more a java programming problem but if someone see quickly my error it would help me a lot ^^ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Youpii! All works now.
After looking at the "4.1 input Document Format" section the HTTP Serializer and the BinaryTextContentHandler.java, I found finally my errors (may it help someone...) : 1) My own processor is follow by an HTTPSerializer processor so I have to produce the binary content of the Workbook encoded with the base64 algo. (wb -> ByteArrayOutputStream -> byte [] -> String (base64) -> char[]) The library that give a method to convert a byte[] in a base64 encoded String is free : http://iharder.sourceforge.net/current/java/base64/ 2) The document that I had to produce was something like : <document xsi:type="xs:base64Binary" content-type="application/vnd.ms-excel"> ASGTRGHR4G5DAS3094=== </document> The problem was that I didn't bind the "xs" prefix of xs:base64binary with the uri "http://www.w3.org/2001/XMLSchema". Here is some lines of the code inside the method generateData(PipelineContext context, ContentHandler handler)... /* map the xs prefix with its respective URI */ contentHandler.startPrefixMapping("xs", "http://www.w3.org/2001/XMLSchema"); /* Prepare attributes of the document element () */ AttributesImpl atts = new AttributesImpl(); atts.addAttribute("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi:type", ContentHandlerHelper.CDATA, "xs:base64Binary"); atts.addAttribute("", "content-type", "content-type", ContentHandlerHelper.CDATA, CONTENT_TYPE); /* Write the correct xml input document to send to the HTTP-serializer */ contentHandler.startDocument(); contentHandler.startElement("", "document", "document", atts); contentHandler.characters(tab2, 0, tab2.length); contentHandler.endElement("", "document", "document"); contentHandler.endPrefixMapping("xs"); contentHandler.endDocument(); Have a nice day! -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Glad to hear that it's working now!
-Erik [hidden email] wrote: > Youpii! All works now. > > After looking at the "4.1 input Document Format" section the HTTP Serializer and the BinaryTextContentHandler.java, I found finally my errors (may it help someone...) : > > 1) My own processor is follow by an HTTPSerializer processor so I have to produce the binary content of the Workbook encoded with the base64 algo. (wb -> ByteArrayOutputStream -> byte [] -> String (base64) -> char[]) > The library that give a method to convert a byte[] in a base64 encoded String is free : http://iharder.sourceforge.net/current/java/base64/ > > 2) The document that I had to produce was something like : > <document xsi:type="xs:base64Binary" content-type="application/vnd.ms-excel"> > ASGTRGHR4G5DAS3094=== > </document> > > The problem was that I didn't bind the "xs" prefix of xs:base64binary with the uri "http://www.w3.org/2001/XMLSchema". Here is some lines of the code inside the method generateData(PipelineContext context, ContentHandler handler)... > > /* map the xs prefix with its respective URI */ > contentHandler.startPrefixMapping("xs", "http://www.w3.org/2001/XMLSchema"); > > /* Prepare attributes of the document element () */ > AttributesImpl atts = new AttributesImpl(); > atts.addAttribute("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi:type", ContentHandlerHelper.CDATA, "xs:base64Binary"); > atts.addAttribute("", "content-type", "content-type", ContentHandlerHelper.CDATA, CONTENT_TYPE); > > /* Write the correct xml input document to send to the HTTP-serializer */ > contentHandler.startDocument(); > contentHandler.startElement("", "document", "document", atts); > contentHandler.characters(tab2, 0, tab2.length); > contentHandler.endElement("", "document", "document"); > contentHandler.endPrefixMapping("xs"); > contentHandler.endDocument(); > > Have a nice day! Orbeon Forms - XForms Everywhere http://www.orbeon.com/blog/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |