Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 59523 invoked by uid 500); 12 Jun 2001 15:47:43 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 59497 invoked by uid 500); 12 Jun 2001 15:47:40 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 12 Jun 2001 15:47:39 -0000 Message-ID: <20010612154739.59475.qmail@apache.org> From: bloritsch@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/org/apache/cocoon/generation StreamGenerator.java bloritsch 01/06/12 08:47:39 Modified: src/org/apache/cocoon/generation Tag: cocoon_20_branch StreamGenerator.java Log: Reformat to find extra bracket. Is fixed now. Revision Changes Path No revision No revision 1.1.2.2 +42 -48 xml-cocoon2/src/org/apache/cocoon/generation/StreamGenerator.java Index: StreamGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/StreamGenerator.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- StreamGenerator.java 2001/06/12 15:00:13 1.1.2.1 +++ StreamGenerator.java 2001/06/12 15:47:37 1.1.2.2 @@ -5,12 +5,12 @@ * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ + package org.apache.cocoon.generation; import java.io.StringReader; import java.io.IOException; import java.util.Map; - import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; @@ -20,55 +20,53 @@ import org.apache.cocoon.environment.Source; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.util.PostInputStream; - import org.apache.avalon.excalibur.pool.Poolable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.parameters.Parameters; - import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** + * + * The StreamGenerator is a class that reads XML from a + * request InputStream and generates SAX Events. * - * The StreamGenerator is a class that reads XML from a request InputStream - * and generates SAX Events. - * For the POST requests with mimetype of application/x-www-form-urlencoded the xml data is - * expected to be associated with the name specified in the sitemap parameter. - * For the POST requests with mimetypes: text/plain, text/xml, application/xml the xml data is in the body of teh POST - * request and its length is specified by the value returned by getContentLength() method. - * The StreamGenerator uses helper org.apache.cocoon.util.PostInputStream class for InputStream reading operations. - * At the time that Parser is reading the data out of 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 - PostInputStream- and to return to - * the requestor -1 when the number of bytes read is equal to the getContentLength() value. + * For the POST requests with mimetype of + * application/x-www-form-urlencoded the xml data is expected to be + * associated with the name specified in the sitemap parameter. For + * the POST requests with mimetypes: text/plain, text/xml, + * application/xml the xml data is in the body of the POST request and + * its length is specified by the value returned by getContentLength() + * method. The StreamGenerator uses helper + * org.apache.cocoon.util.PostInputStream class for InputStream + * reading operations. At the time that Parser is reading the data + * out of 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- + * PostInputStream--and to return to the requestor '-1' when the + * number of bytes read is equal to the getContentLength() value. * * @author Kinga Dziembowski - * @version $Revision: 1.1.2.1 $ $Date: 2001/06/12 15:00:13 $ + * @version $Revision: 1.1.2.2 $ $Date: 2001/06/12 15:47:37 $ */ public class StreamGenerator extends ComposerGenerator { - public static final String CLASS = StreamGenerator.class.getName(); /** The parameter holding the name associated with the xml data **/ public static final String FORM_NAME = "form-name"; + /** The input source */ private InputSource inputSource; + /** The system ID of the input source */ - private String systemID; + private String systemID; /** - * Set the current ComponentManager instance used by this - * Composable. + * Recycle this component. + * All instance variables are set to null. */ - public void compose(ComponentManager manager) { - super.compose(manager); - } - - /** - * Recycle this component. - * All instance variables are set to null. - */ public void recycle() { super.recycle(); this.inputSource = null; @@ -76,41 +74,35 @@ } /** - * Setup the stream generator. - */ - public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) - throws ProcessingException, SAXException, IOException { - super.setup(resolver, objectModel, src, par); - } - - /** - * Generate XML data out of request InputStream. - */ - public void generate() throws IOException, SAXException, ProcessingException { + * Generate XML data out of request InputStream. + */ + public void generate() throws IOException, SAXException, ProcessingException { Parser parser = null; String parameter = parameters.getParameter(StreamGenerator.FORM_NAME, null); int len = 0; + try { - HttpRequest request = (HttpRequest) objectModel.get(Constants.REQUEST_OBJECT); + HttpRequest request = (HttpRequest)objectModel.get(Constants.REQUEST_OBJECT); if (request.getContentType().equals("application/x-www-form-urlencoded")) { String sXml = request.getParameter(parameter); inputSource = new InputSource(new StringReader(sXml)); - } else if (request.getContentType().equals("text/plain") - || request.getContentType().equals("text/xml") - || request.getContentType().equals("application/xml")) { + } else if (request.getContentType().equals("text/plain") || request.getContentType().equals("text/xml") || + request.getContentType().equals("application/xml")) { len = request.getContentLength(); + if (len > 0) { PostInputStream anStream = new PostInputStream(request.getInputStream(), len); inputSource = new InputSource(anStream); } else { throw new IOException("getContentLen() == 0"); } - } else { - throw new IOException("Unexpected getContentType(): " + request.getContentType()); - } + } else { + throw new IOException("Unexpected getContentType(): " + request.getContentType()); } - getLogger().debug("processing stream ContentType= " + request.getContentType() + "ContentLen= " + len); + if (getLogger().isDebugEnabled()) { + getLogger().debug("processing stream ContentType= " + request.getContentType() + "ContentLen= " + len); + } parser = (Parser)this.manager.lookup(Roles.PARSER); parser.setContentHandler(super.contentHandler); parser.setLexicalHandler(super.lexicalHandler); @@ -121,11 +113,13 @@ } catch (SAXException e) { getLogger().error("StreamGenerator.generate()", e); throw(e); - } catch (Exception e){ + } catch (Exception e) { getLogger().error("Could not get parser", e); - throw new ProcessingException("Exception in StreamGenerator.generate()",e); + throw new ProcessingException("Exception in StreamGenerator.generate()", e); } finally { - if (parser != null) this.manager.release((Component) parser); + if (parser != null) { + this.manager.release((Component)parser); + } } } } ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org