incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r812354 - in /sling/whiteboard/portal/container/src/main: java/org/apache/sling/portal/container/internal/request/ resources/OSGI-INF/ resources/OSGI-INF/metatype/
Date Tue, 08 Sep 2009 07:22:34 GMT
Author: cziegeler
Date: Tue Sep  8 07:22:34 2009
New Revision: 812354

URL: http://svn.apache.org/viewvc?rev=812354&view=rev
Log:
Add a switch to disable the portlet link rewriting.

Added:
    sling/whiteboard/portal/container/src/main/resources/OSGI-INF/
    sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/
    sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
  (with props)
Modified:
    sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/LinkTransformerFactory.java
    sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/PortalFilter.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=812354&r1=812353&r2=812354&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
Tue Sep  8 07:22:34 2009
@@ -64,20 +64,25 @@
 
         private ContentHandler handler;
 
+        private boolean enabled = true;
         /**
          * @see org.apache.sling.rewriter.Transformer#init(org.apache.sling.rewriter.ProcessingContext,
org.apache.sling.rewriter.ProcessingComponentConfiguration)
          */
         public void init(ProcessingContext context,
                          ProcessingComponentConfiguration config)
         throws IOException {
-            // nothing to do
+            this.enabled = PortalRequestContext.getContext() != null;
         }
 
         @Override
         public void setContentHandler(ContentHandler ch) {
             this.handler = ch;
-            this.buffer = new SAXBuffer();
-            super.setContentHandler(this.buffer);
+            if ( this.enabled ) {
+                this.buffer = new SAXBuffer();
+                super.setContentHandler(this.buffer);
+            } else {
+                super.setContentHandler(ch);
+            }
         }
 
         @Override
@@ -103,27 +108,30 @@
                 Attributes a)
         throws SAXException {
             String queryString = null;
-            // this is a link
-            if ( portletQueryString != null && "a".equals(loc) ) {
-                final String href = a.getValue("href");
-                if ( needsRewrite(href) ) {
-                    char sep = (href.indexOf('?') == -1 ? '?' : '&');
-                    final AttributesImpl ai = new AttributesImpl(a);
-                    ai.removeAttribute("href");
-                    ai.addCDATAAttribute("href", href + sep + portletQueryString);
-                    a = ai;
-                }
-            } else if ( "form".equals(loc) ) {
-                if ( "post".equalsIgnoreCase(a.getValue("method")) ) {
-                    final String url = a.getValue("action");
-                    final int queryPos = url.indexOf('?');
-                    if ( queryPos != -1 ) {
-                        queryString = url.substring(queryPos + 1);
+
+            if ( this.enabled ) {
+                // this is a link
+                if ( portletQueryString != null && "a".equals(loc) ) {
+                    final String href = a.getValue("href");
+                    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.removeAttribute("href");
+                        ai.addCDATAAttribute("href", href + sep + portletQueryString);
                         a = ai;
                     }
+                } else if ( "form".equals(loc) ) {
+                    if ( "post".equalsIgnoreCase(a.getValue("method")) ) {
+                        final String url = a.getValue("action");
+                        final int queryPos = url.indexOf('?');
+                        if ( queryPos != -1 ) {
+                            queryString = url.substring(queryPos + 1);
+                            final AttributesImpl ai = new AttributesImpl(a);
+                            ai.removeAttribute("action");
+                            ai.addCDATAAttribute("action", url.substring(0, queryPos));
+                            a = ai;
+                        }
+                    }
                 }
             }
             super.startElement(uri, loc, raw, a);

Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/PortalFilter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/PortalFilter.java?rev=812354&r1=812353&r2=812354&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/PortalFilter.java
(original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/request/PortalFilter.java
Tue Sep  8 07:22:34 2009
@@ -30,14 +30,16 @@
 
 import org.apache.pluto.container.PortletContainerException;
 import org.apache.pluto.container.PortletWindow;
+import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.portal.container.SlingPortletContainer;
 import org.apache.sling.portal.container.internal.impl.DefaultPortalURLFactory;
+import org.osgi.service.component.ComponentContext;
 
 /**
  * This filter checks the url for special portal container parameters
  * and sets up the environment for portlet processing
  *
- * @scr.component metatype="false"
+ * @scr.component label="%filter.name" description="%filter.description"
  * @scr.service interface="javax.servlet.Filter"
  *
  * @scr.property name="filter.scope" value="request" private="true"
@@ -51,12 +53,28 @@
     /** @scr.reference */
     private SlingPortletContainer portletContainer;
 
+    /** @scr.property valueRef="DEFAULT_ENABLE" */
+    private static final String PROPERTY_ENABLE = "filter.enable";
+
+    /** Default value for enable. */
+    private static final boolean DEFAULT_ENABLE = false;
+
+    private boolean enabled;
+
+    protected void activate(final ComponentContext ctx) {
+        this.enabled = OsgiUtil.toBoolean(ctx.getProperties().get(PROPERTY_ENABLE), DEFAULT_ENABLE);
+    }
+
     /**
      * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
javax.servlet.FilterChain)
      */
     public void doFilter(ServletRequest request, ServletResponse response,
                          FilterChain chain)
     throws IOException, ServletException {
+        if ( !enabled ) {
+            chain.doFilter(request, response);
+            return;
+        }
         final HttpServletRequest req = (HttpServletRequest)request;
         // we just instantiate a portal request context which might be used by the
         // portal

Added: sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=812354&view=auto
==============================================================================
--- sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
(added)
+++ sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
Tue Sep  8 07:22:34 2009
@@ -0,0 +1,34 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+#
+# This file contains localization strings for configuration labels and
+# descriptions as used in the metatype.xml descriptor generated by the
+# the SCR plugin
+
+#
+# Filter
+filter.name = Apache Sling Portal Container Filter 
+filter.description = The portal container uses this filter for rewriting \
+ all links on a page to contain relevant portlet information. \
+ By default this filter is enabled, if you want to embed portlets \
+ in your page, you should activate this filter.
+
+filter.enable.name = Enabled
+filter.enable.descrition = Enable this filter.

Propchange: sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: sling/whiteboard/portal/container/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message