From cocoon-cvs-return-11482-apmail-xml-cocoon-cvs-archive=xml.apache.org@xml.apache.org Tue Apr 01 08:27:31 2003 Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 19146 invoked by uid 500); 1 Apr 2003 08:27:30 -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 19135 invoked by uid 500); 1 Apr 2003 08:27:30 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 19130 invoked from network); 1 Apr 2003 08:27:30 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 1 Apr 2003 08:27:30 -0000 Received: (qmail 1354 invoked by uid 1638); 1 Apr 2003 08:27:28 -0000 Date: 1 Apr 2003 08:27:28 -0000 Message-ID: <20030401082728.1352.qmail@icarus.apache.org> From: bruno@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/blocks/html/java/org/apache/cocoon/generation HTMLGenerator.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bruno 2003/04/01 00:27:28 Modified: src/blocks/html/java/org/apache/cocoon/generation HTMLGenerator.java Log: - fix double endDocument call when using xpath expressions, by using the normal DOMStreamer instead of a TRAX transform (reported on cocoon-users by Tonny Collen). - removed setNormalizeNamespaces(false) call on DOMStreamer, so that correct SAX events are generated (a startPrefixMapping for the xhtml namespace was called, but the uri's of the individual start- and endElement calls were empty) - IDEA has been trimming some whitespace-only lines Revision Changes Path 1.4 +27 -29 cocoon-2.1/src/blocks/html/java/org/apache/cocoon/generation/HTMLGenerator.java Index: HTMLGenerator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/html/java/org/apache/cocoon/generation/HTMLGenerator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HTMLGenerator.java 19 Mar 2003 15:42:17 -0000 1.3 +++ HTMLGenerator.java 1 Apr 2003 08:27:28 -0000 1.4 @@ -101,16 +101,16 @@ */ public class HTMLGenerator extends ComposerGenerator implements Configurable, CacheableProcessingComponent, Disposable { - + /** The parameter that specifies what request attribute to use, if any */ public static final String FORM_NAME = "form-name"; - + /** The source, if coming from a file */ private Source inputSource; - + /** The source, if coming from the request */ private InputStream requestStream; - + /** XPATH expression */ private String xpath = null; @@ -125,7 +125,7 @@ super.compose( manager ); this.processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE); } - + public void configure(Configuration config) throws ConfigurationException { String configUrl = config.getChild("jtidy-config").getValue(null); @@ -139,10 +139,10 @@ if (getLogger().isDebugEnabled()) { getLogger().debug("Loading configuration from " + configSource.getURI()); } - + this.properties = new Properties(); this.properties.load(configSource.getInputStream()); - + } catch (Exception e) { getLogger().warn("Cannot load configuration from " + configUrl); throw new ConfigurationException("Cannot load configuration from " + configUrl, e); @@ -178,14 +178,14 @@ super.setup(resolver, objectModel, src, par); HttpServletRequest request = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT); - + if (src == null) { // Handle this request as the StreamGenerator does (from the POST // request or from a request parameter), but try to make sure // that the output will be well-formed - + String contentType = request.getContentType(); - + if (contentType == null ) { throw new IOException("Content-type was not specified for this request"); } else if (contentType.startsWith("application/x-www-form-urlencoded") || @@ -197,11 +197,11 @@ FORM_NAME + "' for handling form data" ); } - + String sXml = request.getParameter(requested); - + requestStream = new ByteArrayInputStream(sXml.getBytes()); - + } else if (contentType.startsWith("text/plain") || contentType.startsWith("text/xml") || contentType.startsWith("application/xml")) { @@ -214,9 +214,9 @@ } } else { throw new IOException("Unexpected getContentType(): " + request.getContentType()); - } - - + } + + } xpath = request.getParameter("xpath"); @@ -251,7 +251,7 @@ public java.io.Serializable getKey() { if (this.inputSource == null) return null; - + if (this.xpath != null) { StringBuffer buffer = new StringBuffer(this.inputSource.getURI()); buffer.append(':').append(this.xpath); @@ -285,7 +285,7 @@ // Setup an instance of Tidy. Tidy tidy = new Tidy(); tidy.setXmlOut(true); - + if (this.properties == null) { tidy.setXHTML(true); } else { @@ -302,10 +302,10 @@ tidy.setErrout(errorWriter); // Extract the document using JTidy and stream it. - + if (inputSource != null) requestStream = this.inputSource.getInputStream(); - + org.w3c.dom.Document doc = tidy.parseDOM(new BufferedInputStream(requestStream), null); // FIXME: Jtidy doesn't warn or strip duplicate attributes in same @@ -318,23 +318,21 @@ getLogger().warn(stringWriter.toString()); } - + if(xpath != null) { - Transformer serializer = TransformerFactory.newInstance().newTransformer(); - serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + DOMStreamer domStreamer = new DOMStreamer(this.contentHandler,this.lexicalHandler); + contentHandler.startDocument(); NodeList nl = processor.selectNodeList(doc, xpath); int length = nl.getLength(); for(int i=0;i