cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r654418 - in /cocoon/branches/BRANCH_2_1_X: src/blocks/html/java/org/apache/cocoon/generation/NekoHTMLGenerator.java status.xml
Date Thu, 08 May 2008 05:24:42 GMT
Author: joerg
Date: Wed May  7 22:24:42 2008
New Revision: 654418

URL: http://svn.apache.org/viewvc?rev=654418&view=rev
Log:
COCOON-2063: Fix encoding issue in NekoHTMLGenerator when reading a request parameter value.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/html/java/org/apache/cocoon/generation/NekoHTMLGenerator.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/html/java/org/apache/cocoon/generation/NekoHTMLGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/html/java/org/apache/cocoon/generation/NekoHTMLGenerator.java?rev=654418&r1=654417&r2=654418&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/html/java/org/apache/cocoon/generation/NekoHTMLGenerator.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/html/java/org/apache/cocoon/generation/NekoHTMLGenerator.java
Wed May  7 22:24:42 2008
@@ -16,9 +16,9 @@
  */
 package org.apache.cocoon.generation;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringReader;
 import java.util.Map;
 import java.util.Properties;
 
@@ -75,10 +75,13 @@
 public class NekoHTMLGenerator extends ServiceableGenerator
                                implements Configurable, CacheableProcessingComponent, Disposable
{
 
-    /** The parameter that specifies what request attribute to use, if any */
+    /** The parameter that specifies what request parameter to use, if any */
     public static final String FORM_NAME = "form-name";
 
-    /** The  source, if coming from a file */
+    /** The request parameter value, if coming from a request parameter */
+    private String requestParameterValue;
+
+    /** The source, if coming from a file */
     private Source inputSource;
 
     /** The source, if coming from the request */
@@ -132,11 +135,19 @@
      * All instance variables are set to <code>null</code>.
      */
     public void recycle() {
+        if (this.requestStream != null) {
+            try {
+                this.requestStream.close();
+            } catch (IOException e) {
+                // ignore
+            }
+            this.requestStream = null;
+        }
         if (this.inputSource != null) {
             this.resolver.release(this.inputSource);
             this.inputSource = null;
-            this.requestStream = null;
         }
+        this.requestParameterValue = null;
         this.xpath = null;
         super.recycle();
     }
@@ -151,7 +162,7 @@
 
         Request request = ObjectModelHelper.getRequest(objectModel);
         
-        if (src == null) {
+        if (this.source == 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
@@ -160,8 +171,8 @@
 
             if (contentType == null ) {
                 throw new IOException("Content-type was not specified for this request");
-            } else if (contentType.startsWith("application/x-www-form-urlencoded") ||
-                contentType.startsWith("multipart/form-data")) {
+            } else if (contentType.startsWith("application/x-www-form-urlencoded")
+                       || contentType.startsWith("multipart/form-data")) {
                 String requested = parameters.getParameter(FORM_NAME, null);
                 if (requested == null) {
                     throw new ProcessingException(
@@ -170,13 +181,10 @@
                     );
                 }
 
-                String sXml = request.getParameter(requested);
-
-                requestStream = new ByteArrayInputStream(sXml.getBytes());
-
-            } else if (contentType.startsWith("text/plain") ||
-                contentType.startsWith("text/xml") ||
-                contentType.startsWith("application/xml")) {
+                requestParameterValue = request.getParameter(requested);
+            } else if (contentType.startsWith("text/plain")
+                       || contentType.startsWith("text/xml")
+                       || contentType.startsWith("application/xml")) {
 
                 HttpServletRequest httpRequest = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
                 if ( httpRequest == null ) {
@@ -191,28 +199,26 @@
             } else {
                 throw new IOException("Unexpected getContentType(): " + request.getContentType());
             }
+        } else {
+            // append the request parameter to the URL if necessary
+            if (parameters.getParameterAsBoolean("copy-parameters", false)
+                    && request.getQueryString() != null) {
+                StringBuffer query = new StringBuffer(this.source);
+                query.append(this.source.indexOf("?") == -1 ? '?' : '&');
+                query.append(request.getQueryString());
+                this.source = query.toString();
+            }
 
-
+            try {
+                this.inputSource = resolver.resolveURI(this.source);
+            } catch (SourceException se) {
+                throw SourceUtil.handle("Unable to resolve " + this.source, se);
+            }
         }
 
         xpath = request.getParameter("xpath");
-        if(xpath == null)
+        if (xpath == null) {
             xpath = par.getParameter("xpath",null);
-
-        // append the request parameter to the URL if necessary
-        if (par.getParameterAsBoolean("copy-parameters", false)
-                && request.getQueryString() != null) {
-            StringBuffer query = new StringBuffer(super.source);
-            query.append(super.source.indexOf("?") == -1 ? '?' : '&');
-            query.append(request.getQueryString());
-            super.source = query.toString();
-        }
-
-        try {
-            if (source != null)
-                this.inputSource = resolver.resolveURI(super.source);
-        } catch (SourceException se) {
-            throw SourceUtil.handle("Unable to resolve " + super.source, se);
         }
     }
 
@@ -259,13 +265,21 @@
         try {
             NekoHtmlSaxParser parser = new NekoHtmlSaxParser(this.properties);
             
-            if (inputSource != null)
-                requestStream = this.inputSource.getInputStream();
-
+            InputSource saxSource;
+            if (this.requestParameterValue != null) {
+                saxSource = new InputSource(new StringReader(this.requestParameterValue));
+            }
+            else {
+                if (inputSource != null) {
+                    requestStream = this.inputSource.getInputStream();
+                }
+                saxSource = new InputSource(requestStream);
+            }
+            
             if (xpath != null) {
                 DOMBuilder builder = new DOMBuilder();
                 parser.setContentHandler(builder);
-                parser.parse(new InputSource(requestStream));
+                parser.parse(saxSource);
                 Document doc = builder.getDocument();
 
                 DOMStreamer domStreamer = new DOMStreamer(this.contentHandler,
@@ -279,9 +293,8 @@
                 this.contentHandler.endDocument();
             } else {
                 parser.setContentHandler(this.contentHandler);
-                parser.parse(new InputSource(requestStream));
+                parser.parse(saxSource);
             }
-            requestStream.close();
         } catch (IOException e){
             throw new ResourceNotFoundException("Could not get resource "
                 + this.inputSource.getURI(), e);

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=654418&r1=654417&r2=654418&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Wed May  7 22:24:42 2008
@@ -182,8 +182,9 @@
 
   <changes>
   <release version="2.1.12" date="TBD">
-    <action dev="VG" type="fix" fixes-bug="COCOON-2063">
-      HTML: Fix encoding issue in NekoHTMLTransformer.
+    <action dev="VG, JH" type="fix" fixes-bug="COCOON-2063">
+      HTML: Fix encoding issue in NekoHTMLTransformer. Fix similar issue in NekoHTMLGenerator
when reading a request
+      parameter value.
     </action>
     <action dev="JH" type="fix" fixes-bug="COCOON-1825" due-to="Vincent Demay" due-to-email="vincent@demay-fr.net">
       Forms: Fix @id handling on fi:group/fi:struct element in conjunction with AJAX requests.



Mime
View raw message