incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r960453 - /sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java
Date Mon, 05 Jul 2010 06:09:50 GMT
Author: cziegeler
Date: Mon Jul  5 06:09:49 2010
New Revision: 960453

URL: http://svn.apache.org/viewvc?rev=960453&view=rev
Log:
Don't split url if it is a post and action contains request parameters - just add additional
params.

Modified:
    sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java

Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java?rev=960453&r1=960452&r2=960453&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java
(original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java
Mon Jul  5 06:09:49 2010
@@ -17,9 +17,6 @@
 package org.apache.sling.portal.container.internal.request;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.StringTokenizer;
 
 import org.apache.cocoon.xml.sax.AbstractSAXPipe;
 import org.apache.cocoon.xml.sax.AttributesImpl;
@@ -35,9 +32,6 @@ import org.xml.sax.SAXException;
  * The link transformer factory for the portal link rewriter.
  * This link rewriter rewrites all links on the page to contain
  * the current state of the portlets on that page.
- * In addition it splits up an action url into the path and
- * hidden parameters.
- *
  * @scr.component metatype="no"
  * @scr.service
  * @scr.property name="pipeline.mode" value="global"
@@ -86,8 +80,6 @@ public class LinkTransformerFactory impl
         public void startElement(String uri, String loc, String raw,
                 Attributes a)
         throws SAXException {
-            String queryString = null;
-
             // this is a link
             if ( "a".equalsIgnoreCase(loc) ) {
                 this.checkPortletQueryString();
@@ -102,42 +94,19 @@ public class LinkTransformerFactory impl
                     }
                 }
             } else if ( "form".equalsIgnoreCase(loc) ) {
-                if ( "post".equalsIgnoreCase(a.getValue("method")) ) {
-                    final String url = a.getValue("action");
-                    final int queryPos = (url == null ? -1 : url.indexOf('?'));
-                    if ( queryPos != -1 ) {
-                        queryString = url.substring(queryPos + 1);
+                this.checkPortletQueryString();
+                if ( this.portletQueryString != null ) {
+                    final String href = a.getValue("action");
+                    if ( needsRewrite(href) ) {
+                        char sep = (href.indexOf('?') == -1 ? '?' : '&');
                         final AttributesImpl ai = new AttributesImpl(a);
                         ai.removeAttribute("action");
-                        ai.addCDATAAttribute("action", url.substring(0, queryPos));
+                        ai.addCDATAAttribute("action", href + sep + portletQueryString);
                         a = ai;
                     }
                 }
             }
             super.startElement(uri, loc, raw, a);
-            if ( queryString != null ) {
-                // parse it and create hidden fields
-                final StringTokenizer st = new StringTokenizer(queryString, "&");
-                while ( st.hasMoreTokens() ) {
-                    final String token = st.nextToken();
-                    final int pos = token.indexOf('=');
-                    final String name;
-                    final String value;
-                    if ( pos == -1 ) {
-                        name = token;
-                        value = "";
-                    } else {
-                        name = token.substring(0, pos);
-                        value = decodeValue(token.substring(pos + 1));
-                    }
-                    final AttributesImpl ai = new AttributesImpl();
-                    ai.addCDATAAttribute("type", "hidden");
-                    ai.addCDATAAttribute("name", name);
-                    ai.addCDATAAttribute("value", value);
-                    this.startElement(uri, "input", "input", ai);
-                    this.endElement(uri, "input", "input");
-                }
-            }
         }
 
         private boolean needsRewrite(String url) {
@@ -157,15 +126,6 @@ public class LinkTransformerFactory impl
             return true;
         }
 
-        private String decodeValue(final String value) {
-            try {
-                return URLDecoder.decode(value, "UTF-8");
-            } catch (UnsupportedEncodingException e) {
-                // this should never happen, but we gracefully return just the value
-                return value;
-            }
-        }
-
         /**
          * @see org.apache.sling.rewriter.Transformer#dispose()
          */



Mime
View raw message