You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Brian O'Kelley <co...@alumni.princeton.edu> on 2002/04/15 23:27:43 UTC

FOP and SAX

I'm trying to take an XML document, combine it with an XSL stylesheet,
and spit it to PDF using SAX events, and I'm having trouble finding an
example that works.

Here's my code (using Fop 0.20.3):

        TransformerHandler tHandler = XSLTranslateFactory.
                getHandler("FopInput.xsl") ; // gets TransformerHandler
from this file
        Driver fopDriver = new Driver() ;
        fopDriver.setRenderer(Driver.RENDER_PDF) ;
        fopDriver.setOutputStream(out) ;
        ContentHandler cHandler = driver.getContentHandler() ;

        XMLReader reader = XMLReaderFactory.createXMLReader() ;
        reader.setContentHandler(tHandler) ;
 
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
                tHandler) ;
        tHandler.setResult(new SAXResult(cHandler)) ;
        reader.parse(source) ;

Any ideas?

Thanks,
Brian


RE: Omitting content length

Posted by Arved Sandstrom <Ar...@chebucto.ns.ca>.
This code looks like it's on the right sheet of music. :-) I only read the
message, though.

Use of this approach is subject to my final comment, which boils down to, be
aware of what your servlet container is doing for you already.
Transfer-codings are properties of the message and not of the message
payload - they are things that the HTTP layer does to ensure safe
transmission of the message - and strictly speaking (IMO) servlets proper
shouldn't have to deal with them. However, if your servlet container doesn't
do this for you then the servlet pretty much must.

But I would also still be cognizant of the possibility that if the servlet
container is not HTTP 1.1 compliant in this regard, that if your servlet is
doing chunked transfer-coding don't necessarily assume that the container
will cooperate, recognise what you're up to, and keep the connection open
for you. When I say "container" in this sense I mean the server as a whole -
the thing which handles both the servlet spec and the HTTP spec.

And if the browser on the other end is HTTP 1.0 then don't even bother. :-)
You need to detect that first.

Regards,
AHS

> -----Original Message-----
> From: Jeremias Maerki [mailto:jeremias.maerki@outline.ch]
> Sent: April 16, 2002 3:12 AM
> To: fop-user@xml.apache.org
> Subject: Re: Omitting content length
>
>
> There was a recent post on chunked transfer. I haven't checked it out,
> but it might help you.
>
> http://marc.theaimsgroup.com/?l=fop-dev&m=101791907122593&w=2
>
> Cheers,
> Jeremias Märki
>
> mailto:jeremias.maerki@outline.ch
>
> OUTLINE AG
> Postfach 3954 - Rhynauerstr. 15 - CH-6002 Luzern
> Tel. +41 41 317 2020 - Fax +41 41 317 2029
> Internet http://www.outline.ch
>
>


Re: Omitting content length

Posted by Jeremias Maerki <je...@outline.ch>.
There was a recent post on chunked transfer. I haven't checked it out,
but it might help you.

http://marc.theaimsgroup.com/?l=fop-dev&m=101791907122593&w=2

Cheers,
Jeremias Märki

mailto:jeremias.maerki@outline.ch

OUTLINE AG
Postfach 3954 - Rhynauerstr. 15 - CH-6002 Luzern
Tel. +41 41 317 2020 - Fax +41 41 317 2029
Internet http://www.outline.ch


RE: Omitting content length

Posted by Arved Sandstrom <Ar...@chebucto.ns.ca>.
Well, the alternative is chunked transfer-coding (which can be used on
either the request or response payloads). This is completely defined by HTTP
1.1, and _must_ be accepted in both directions by HTTP 1.1 compliant apps,
so if you send it to a recent IE browser it should know what to do with it.
I assume. :-)

In the context of servlet engines it doesn't make sense for a servlet to be
aware that a _request_ was transfer-coded, whether chunked or anything else.
The HTTP layer should handle this transparently. If it doesn't then it will
probably choke before your servlet ever gets a chance at it (this is what
should happen anyway).

Going in the other direction one can only that the servlet engine/HTTP
server combo will pick up on the fact that, at the instant that it must
commit the response, it doesn't have a content-length, and will therefore
switch over to chunked transfer coding, thereby keeping the connection open
_and_ allowing you not to worry about calculating an overall content-length.

I see from mailing lists that the Tomcat people were talking about chunked
transfer coding for Tomcat 3.2/3.3 a year or more ago - do they have it
properly implemented in 4.0 - I don't know. Worth checking out.

If all else fails I'd suggest that your servlet do all the work itself, but
my gut feeling is that if the servlet engine doesn't do chunked transfer
coding anyway, it's hardly going to properly react to the fact that your
servlet is doing it itself - it'll probably close the connection on you
anyway after committing the first buffer.

Hope that helps.

Regards,
AHS

> -----Original Message-----
> From: Brian O'Kelley [mailto:cokelley@alumni.princeton.edu]
> Sent: April 15, 2002 7:25 PM
> To: fop-user@xml.apache.org
> Subject: Omitting content length
>
>
> Ignore the question below - it works (if anyone needs SAX example, this
> is decent).
>
> It looks like what is happening is that I was writing this directly to a
> servlet's outputstream, so I never set the content length header. This
> made IE puke, although Lynx caught it ok. I've read through the threads
> about how IE handles content length header and requests the document
> twice.
>
> Is there any alternative to writing to a byte array to calculate the
> length before rewriting to the servlet's output stream? I'd like to
> avoid the memory consequences.
>
> Thanks,
> Brian
>
>
>
> -----Original Message-----
> From: Brian O'Kelley [mailto:cokelley@alumni.princeton.edu]
> Sent: Monday, April 15, 2002 5:28 PM
> To: fop-user@xml.apache.org
> Subject: FOP and SAX
>
>
> I'm trying to take an XML document, combine it with an XSL stylesheet,
> and spit it to PDF using SAX events, and I'm having trouble finding an
> example that works.
>
> Here's my code (using Fop 0.20.3):
>
>         TransformerHandler tHandler = XSLTranslateFactory.
>                 getHandler("FopInput.xsl") ; // gets TransformerHandler
> from this file
>         Driver fopDriver = new Driver() ;
>         fopDriver.setRenderer(Driver.RENDER_PDF) ;
>         fopDriver.setOutputStream(out) ;
>         ContentHandler cHandler = driver.getContentHandler() ;
>
>         XMLReader reader = XMLReaderFactory.createXMLReader() ;
>         reader.setContentHandler(tHandler) ;
>
> reader.setProperty("http://xml.org/sax/properties/lexical-handler",
>                 tHandler) ;
>         tHandler.setResult(new SAXResult(cHandler)) ;
>         reader.parse(source) ;
>
> Any ideas?
>
> Thanks,
> Brian
>
>


Omitting content length

Posted by Brian O'Kelley <co...@alumni.princeton.edu>.
Ignore the question below - it works (if anyone needs SAX example, this
is decent).

It looks like what is happening is that I was writing this directly to a
servlet's outputstream, so I never set the content length header. This
made IE puke, although Lynx caught it ok. I've read through the threads
about how IE handles content length header and requests the document
twice.

Is there any alternative to writing to a byte array to calculate the
length before rewriting to the servlet's output stream? I'd like to
avoid the memory consequences.

Thanks,
Brian



-----Original Message-----
From: Brian O'Kelley [mailto:cokelley@alumni.princeton.edu] 
Sent: Monday, April 15, 2002 5:28 PM
To: fop-user@xml.apache.org
Subject: FOP and SAX


I'm trying to take an XML document, combine it with an XSL stylesheet,
and spit it to PDF using SAX events, and I'm having trouble finding an
example that works.

Here's my code (using Fop 0.20.3):

        TransformerHandler tHandler = XSLTranslateFactory.
                getHandler("FopInput.xsl") ; // gets TransformerHandler
from this file
        Driver fopDriver = new Driver() ;
        fopDriver.setRenderer(Driver.RENDER_PDF) ;
        fopDriver.setOutputStream(out) ;
        ContentHandler cHandler = driver.getContentHandler() ;

        XMLReader reader = XMLReaderFactory.createXMLReader() ;
        reader.setContentHandler(tHandler) ;
 
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
                tHandler) ;
        tHandler.setResult(new SAXResult(cHandler)) ;
        reader.parse(source) ;

Any ideas?

Thanks,
Brian