cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r348420 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ src/blocks/portal/java/org/apache/cocoon/portal/serialization/ src/blocks/portal/java/org/apache/cocoon/portal/transformation/
Date Wed, 23 Nov 2005 12:19:46 GMT
Author: cziegeler
Date: Wed Nov 23 04:19:37 2005
New Revision: 348420

URL: http://svn.apache.org/viewcvs?rev=348420&view=rev
Log:
 Portal block: Fix possible encoding problems with portlets and support external form actions
in HTML transformation

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletResponseImpl.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/serialization/IncludingHTMLSerializer.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletResponseImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletResponseImpl.java?rev=348420&r1=348419&r2=348420&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletResponseImpl.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletResponseImpl.java
Wed Nov 23 04:19:37 2005
@@ -17,7 +17,9 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.Locale;
 
 import javax.servlet.ServletOutputStream;
@@ -40,25 +42,33 @@
 
     protected String redirectURL;
 
+    protected String encoding = "ISO-8859-1";
+
     public ServletResponseImpl(HttpServletResponse response) {
         super(response);
         this.stream = new MyOutputStream();
-        this.writer = new PrintWriter(this.stream);
     }
 
     /**
      * Return the content of the portlet
      */
     public String getContent() {
-        this.writer.flush();
+        if ( this.writer != null ) {
+            this.writer.flush();
+        }
         try {
             this.stream.flush();
         } catch (IOException ignore) {
             // just ignore it
         }
-        final String value = new String(this.stream.stream.toByteArray());
+        String value;
+        try {
+            value = this.stream.stream.toString(this.encoding);
+        } catch (UnsupportedEncodingException uee) {
+            value = new String(this.stream.stream.toByteArray());
+        }
         this.stream = new MyOutputStream();
-        this.writer = new PrintWriter(this.stream);
+        this.writer = null;
         return value;
     }
 
@@ -69,108 +79,87 @@
         return this.redirectURL;
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.lang.Object#toString()
      */
     public String toString() {
         return this.getContent();
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see javax.servlet.http.HttpServletResponse#sendError(int,
-     *      java.lang.String)
+    /**
+     * @see javax.servlet.http.HttpServletResponse#sendError(int, String)
      */
     public void sendError(int arg0, String arg1) throws IOException {
         //this.response.sendError(arg0, arg1);
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.http.HttpServletResponse#sendError(int)
      */
     public void sendError(int arg0) throws IOException {
         //this.response.sendError(arg0);
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.http.HttpServletResponse#redirect(java.lang.String)
      */
     public void sendRedirect(String arg0) throws IOException {
         this.redirectURL = arg0;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see javax.servlet.http.HttpServletResponse#setStatus(int,
-     *      java.lang.String)
+    /**
+     * @see javax.servlet.http.HttpServletResponse#setStatus(int, String)
      */
     public void setStatus(int arg0, String arg1) {
         //this.response.setStatus(arg0, arg1);
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.http.HttpServletResponse#setStatus(int)
      */
     public void setStatus(int arg0) {
         //this.response.setStatus(arg0);
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#flushBuffer()
      */
     public void flushBuffer() throws IOException {
         this.committed = true;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#getBufferSize()
      */
     public int getBufferSize() {
         return this.bufferSize = 1024;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#getOutputStream()
      */
     public ServletOutputStream getOutputStream() throws IOException {
         return this.stream;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#getWriter()
      */
     public PrintWriter getWriter() throws IOException {
+        if ( this.writer == null ) {
+            this.writer = new PrintWriter(new OutputStreamWriter(this.stream, this.encoding));
+        }
         return this.writer;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#isCommitted()
      */
     public boolean isCommitted() {
         return this.committed;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#reset()
      */
     public void reset() {
@@ -179,78 +168,71 @@
         }
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#setBufferSize(int)
      */
     public void setBufferSize(int arg0) {
         this.bufferSize = arg0;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#setContentLength(int)
      */
     public void setContentLength(int arg0) {
         // nothing to do 
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#setContentType(java.lang.String)
      */
-    public void setContentType(String arg0) {
-        // nothing to do 
+    public void setContentType(String typeInfo) {
+        if ( typeInfo != null ) {
+            int pos = typeInfo.indexOf("charset=");
+            if ( pos != -1 ) {
+                this.encoding = typeInfo.substring(pos + 8);
+            }
+        }
+    }
+
+    public void setCharacterEncoding(String enc) {
+        this.encoding = enc;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#setLocale(java.util.Locale)
      */
-    public void setLocale(Locale arg0) {
+    public void setLocale(Locale locale) {
         // nothing to do 
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see javax.servlet.ServletResponse#resetBuffer()
      */
     public void resetBuffer() {
         // nothing to do 
     }
 
-}
+    protected final static class MyOutputStream extends ServletOutputStream {
 
-class MyOutputStream extends ServletOutputStream {
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
 
-    ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        public MyOutputStream() {
+            // nothing to do 
+        }
 
-    public MyOutputStream() {
-        // nothing to do 
-    }
+        /**
+         * @see java.io.OutputStream#write(int)
+         */
+        public void write(int b) throws IOException {
+            this.stream.write(b);
+        }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see java.io.OutputStream#write(int)
-     */
-    public void write(int b) throws IOException {
-        this.stream.write(b);
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see java.io.OutputStream#flush()
-     */
-    public void flush() throws IOException {
-        super.flush();
-        this.stream.flush();
+        /**
+         * @see java.io.OutputStream#flush()
+         */
+        public void flush() throws IOException {
+            super.flush();
+            this.stream.flush();
+        }
     }
-
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/serialization/IncludingHTMLSerializer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/serialization/IncludingHTMLSerializer.java?rev=348420&r1=348419&r2=348420&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/serialization/IncludingHTMLSerializer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/serialization/IncludingHTMLSerializer.java
Wed Nov 23 04:19:37 2005
@@ -21,6 +21,8 @@
 import java.util.LinkedList;
 import java.util.Map;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.serialization.HTMLSerializer;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -36,7 +38,7 @@
  *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  * 
- * @version CVS $Id: IncludingHTMLSerializer.java,v 1.3 2004/03/15 10:14:39 cziegeler Exp
$
+ * @version CVS $Id$
  */
 public class IncludingHTMLSerializer 
     extends HTMLSerializer {
@@ -50,8 +52,20 @@
     protected static final char token = '~';
     
     protected static final char[] tokens = new char[] {token, token};
-    
-    /* (non-Javadoc)
+
+    /** The encoding. */
+    protected String encoding = "utf-8";
+ 
+    /**
+     * @see org.apache.cocoon.serialization.HTMLSerializer#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration conf)
+    throws ConfigurationException {
+        super.configure(conf);
+        this.encoding = conf.getChild("encoding").getValue(this.encoding);
+    }
+
+    /**
      * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
      */
     public void recycle() {
@@ -75,7 +89,7 @@
         map.put(name, content);
     }
     
-    /* (non-Javadoc)
+    /**
      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
      */
     public void endElement(String uri, String loc, String raw)
@@ -85,7 +99,7 @@
         }
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
org.xml.sax.Attributes)
      */
     public void startElement(String uri, String loc, String raw, Attributes a)
@@ -107,47 +121,55 @@
         }
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.cocoon.sitemap.SitemapOutputComponent#setOutputStream(java.io.OutputStream)
      */
     public void setOutputStream(OutputStream stream) throws IOException {
-        super.setOutputStream(new ReplacingOutputStream(stream, this.orderedPortletList));
+        super.setOutputStream(new ReplacingOutputStream(stream,
+                                                        this.orderedPortletList,
+                                                        this.encoding));
     }
 
 }
-class ReplacingOutputStream extends OutputStream {
+final class ReplacingOutputStream extends OutputStream {
     
-    /** Stream */
+    /** Stream. */
     protected final OutputStream stream;
-    
+
     protected boolean inKey;
-    
+
     protected final LinkedList orderedValues;
-    
+
+    /** Encoding. */
+    protected final String encoding;
+
     /**
-     * Constructor
+     * Constructor.
      */
-    public ReplacingOutputStream(OutputStream stream, LinkedList values) {
+    public ReplacingOutputStream(OutputStream stream,
+                                 LinkedList   values,
+                                 String       enc) {
         this.stream = stream;    
         this.orderedValues = values;
         this.inKey = false;
+        this.encoding = enc;
     }
-    
-    /* (non-Javadoc)
+
+    /**
      * @see java.io.OutputStream#close()
      */
     public void close() throws IOException {
         this.stream.close();
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.io.OutputStream#flush()
      */
     public void flush() throws IOException {
         this.stream.flush();
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.io.OutputStream#write(byte[], int, int)
      */
     public void write(byte[] b, int off, int len) throws IOException {
@@ -198,14 +220,14 @@
         } while (!end);
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.io.OutputStream#write(byte[])
      */
     public void write(byte[] b) throws IOException {
         this.write(b, 0, b.length);
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.io.OutputStream#write(int)
      */
     public void write(int b) throws IOException {
@@ -229,7 +251,7 @@
     protected void writeNextValue() throws IOException {
         final String value = (String)this.orderedValues.removeLast();
         if ( value != null ) {
-            this.stream.write(value.getBytes(), 0, value.length());
+            this.stream.write(value.getBytes(this.encoding), 0, value.length());
         }        
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java?rev=348420&r1=348419&r2=348420&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
Wed Nov 23 04:19:37 2005
@@ -33,9 +33,9 @@
  * that only contain an anchor are ignored.
  * In addition if a link has the attribute "external" with the value
  * "true", the link is also ignored.
- * 
+ *
  * TODO: Support target attribute
- * 
+ *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  * @version CVS $Id$
  */
@@ -48,7 +48,7 @@
     /** The jxpath for the attribute */
     protected String jxPath;
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
      */
     public void setup(SourceResolver resolver,
@@ -61,7 +61,7 @@
         this.jxPath = "temporaryAttributes/" + this.attributeName;
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
org.xml.sax.Attributes)
      */
     public void startElement(String uri, String name, String raw, Attributes attr)
@@ -79,15 +79,19 @@
                 processed = true;
             }
         } else if ("form".equals(name) ) {
-            this.createFormEvent(attr);
-            processed = true;
+            boolean convert = this.isExternalForm(attr);
+            this.stack.push(convert ? Boolean.TRUE: Boolean.FALSE);
+            if ( convert ) {
+                this.createFormEvent(attr);
+                processed = true;
+            }
         }
         if ( !processed ) {
             super.startElement(uri, name, raw, attr);
         }
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
      */
     public void endElement(String uri, String name, String raw)
@@ -103,11 +107,14 @@
                 processed = true;
             }
         } else if ( "form".equals(name) ) {
-            this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
-                    CopletTransformer.LINK_ELEM,
-                    "coplet:" + CopletTransformer.LINK_ELEM);
-            this.xmlConsumer.endPrefixMapping("coplet");
-            processed = true;
+            final Boolean converted = (Boolean)this.stack.pop();
+            if ( converted.booleanValue() ) {
+                this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
+                        CopletTransformer.LINK_ELEM,
+                        "coplet:" + CopletTransformer.LINK_ELEM);
+                this.xmlConsumer.endPrefixMapping("coplet");
+                processed = true;
+            }
         }
         if ( !processed ) {
             super.endElement(uri, name, raw);
@@ -157,7 +164,6 @@
                 CopletTransformer.LINK_ELEM,
                 "coplet:" + CopletTransformer.LINK_ELEM,
                 newAttributes);
-
     }
 
     protected String getLink(String base, String link) {
@@ -187,9 +193,10 @@
     }
 
     /**
-     * a link in an external application is not transformed
+     * Is this link an external link?
+     * A link in an external application is not transformed
      * if there is an attribute external="true" in the link-element
-     * or if the link starts with "mailto:".
+     * or if the link starts with "mailto:" or "javascript:".
      * 
      * @param attributes attributes of the node
      * @return true if the attribute 'external' is 'true'
@@ -208,5 +215,28 @@
         }
         return false;
     }
-    
+
+    /**
+     * Does this form contain an external action?
+     * A form is not transformed if there is an attribute
+     * external="true" in the form action or if the action
+     * starts with "javascript:".
+     * 
+     * @param attributes attributes of the node
+     * @return True if the action is external.
+     */
+    private boolean isExternalForm(Attributes attributes) {        
+        final String external = attributes.getValue("external");
+        // links to external documents will be not transformed to portal links
+        if (external != null && external.trim().length() > 0 
+            && external.trim().toLowerCase().equals ("true") ) {            
+            return true;
+        }
+        final String link = attributes.getValue("action");
+        if ( link != null 
+             && link.startsWith("javascript:") ) {
+            return true;
+        }
+        return false;
+    }
 }

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=348420&r1=348419&r2=348420&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Wed Nov 23 04:19:37 2005
@@ -179,6 +179,12 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.9" date="TBD">
+    <action dev="CZ" type="fix">
+      Portal block: Fix possible encoding problems with JSR 168 portlets.
+    </action>
+    <action dev="CZ" type="add">
+      Portal block: Support external form actions in HTML transformation.
+    </action>
     <action dev="AN" type="fix" fixes-bug="COCOON-1691" due-to="Feliciano Borrego" due-to-email="felibv@gmail.com">
       Database block: Renaming AttributeImpl xspAttr to _xspAttr was not applied to ESQL
logicsheet.
       That caused compliation errors in all XSPs using it.



Mime
View raw message