Class StreamGenerator

  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.generation.AbstractGenerator
              extended byorg.apache.cocoon.generation.ServiceableGenerator
                  extended byorg.apache.cocoon.generation.StreamGenerator
All Implemented Interfaces:
Disposable, org.apache.cocoon.generation.Generator, Poolable, Recyclable, Serviceable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.xml.XMLProducer

public class StreamGenerator
extends org.apache.cocoon.generation.ServiceableGenerator

The StreamGenerator is a class that reads XML from a request InputStream and generates SAX Events.

For the POST requests with a mimetype of application/x-www-form-urlencoded or multipart/form-data the xml data is expected to be associated with the sitemap parameter form-name.

For the POST requests with mimetypes text/plain, text/xml, application/xhtml+xml, application/xml the xml data is expected to be in the body of the POST request and its length is specified by the value returned by Request.getContentLength() method.

The StreamGenerator uses helper PostInputStream class for InputStream reading operations. At the time when Parser is reading the data out of the InputStream, Parser has no knowledge about the length of data to be read. The only way to signal to the Parser that all data was read from the InputStream is to control reading operation - by the means of PostInputStream - and to return to the requestor '-1' when the number of bytes read is equal to the content length value.

$Id: StreamGenerator.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
static String FORM_NAME
          The parameter holding the name associated with the xml data
Fields inherited from class org.apache.cocoon.generation.ServiceableGenerator
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
Fields inherited from interface org.apache.cocoon.generation.Generator
Constructor Summary
Method Summary
 void generate()
          Generate XML data out of request InputStream.
 String getCharacterEncoding(org.apache.cocoon.environment.Request req, String contentType)
          Content type HTTP header can contain character encoding information, for example: Content-Type: text/xml; charset=UTF-8.
Methods inherited from class org.apache.cocoon.generation.ServiceableGenerator
dispose, service
Methods inherited from class org.apache.cocoon.generation.AbstractGenerator
recycle, setup
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.cocoon.xml.XMLProducer

Field Detail


public static final String FORM_NAME
The parameter holding the name associated with the xml data

See Also:
Constant Field Values
Constructor Detail


public StreamGenerator()
Method Detail


public void generate()
              throws IOException,
Generate XML data out of request InputStream.



public String getCharacterEncoding(org.apache.cocoon.environment.Request req,
                                   String contentType)
Content type HTTP header can contain character encoding information, for example: Content-Type: text/xml; charset=UTF-8.

If the servlet is following spec 2.3 and higher, the servlet API can be used to retrieve character encoding part of Content-Type header. Some containers can choose to not unpack charset info - the spec is not strong about it. In any case, this method can be used as a last resort to retrieve the passed charset value.

It is very common mistake to send : Content-Type: text/xml; charset="UTF-8". Some containers are not filtering this mistake and the processing results in exception. This method compensates for the above mistake.

If contentType is null or has no charset part, null is returned.

contentType - value associated with Content-Type HTTP header.

Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.