cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r430738 - in /cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources: SourceHttpServletRequestWrapper.java WebappSource.java WebappSourceInfo.java
Date Fri, 11 Aug 2006 09:21:21 GMT
Author: cziegeler
Date: Fri Aug 11 02:21:20 2006
New Revision: 430738

URL: http://svn.apache.org/viewvc?rev=430738&view=rev
Log:
Update new cocoon protocol impl

Added:
    cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java
  (with props)
Modified:
    cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSource.java
    cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSourceInfo.java

Added: cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java?rev=430738&view=auto
==============================================================================
--- cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java
(added)
+++ cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java
Fri Aug 11 02:21:20 2006
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.cocoon.resources;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cocoon.environment.wrapper.RequestParameters;
+import org.apache.cocoon.servlet.UriHttpServletRequestWrapper;
+import org.apache.commons.collections.iterators.IteratorEnumeration;
+
+/**
+ * 
+ * @version $Id$
+ * @since 2.2
+ */
+public class SourceHttpServletRequestWrapper extends UriHttpServletRequestWrapper {
+
+    /** The query string */
+    private String queryString;
+
+    /** The request parameters */
+    private final RequestParameters parameters;
+
+    /** raw mode? **/
+    private final boolean rawMode;
+
+    public SourceHttpServletRequestWrapper(HttpServletRequest request,
+                                           String             servletPath,
+                                           String             pathInfo,
+                                           boolean            rawMode,
+                                           String             additionalQueryString) {
+        super(request, servletPath, pathInfo);
+        this.queryString = additionalQueryString;
+        this.parameters = new RequestParameters(additionalQueryString);
+        this.rawMode = rawMode;
+        if (this.getQueryString() != null && !this.rawMode) {
+            if (this.queryString == null) {
+                this.queryString = this.getQueryString();
+            } else {
+                this.queryString += '&' + this.getQueryString();
+            }
+        }
+    }
+
+    /**
+     * @see javax.servlet.ServletRequestWrapper#getParameter(java.lang.String)
+     */
+    public String getParameter(String name) {
+        String value = this.parameters.getParameter(name);
+        if (value == null && !this.rawMode) {
+            return super.getParameter(name);
+        }
+        return value;
+    }
+
+    /**
+     * @see javax.servlet.ServletRequestWrapper#getParameterNames()
+     */
+    public Enumeration getParameterNames() {
+        if ( !this.rawMode ) {
+            // put all parameter names into a set
+            Set parameterNames = new HashSet();
+            Enumeration names = this.parameters.getParameterNames();
+            while (names.hasMoreElements()) {
+                parameterNames.add(names.nextElement());
+            }
+            names = this.getParameterNames();
+            while (names.hasMoreElements()) {
+                parameterNames.add(names.nextElement());
+            }
+            return new IteratorEnumeration(parameterNames.iterator());
+        }
+        return this.parameters.getParameterNames();
+    }
+
+    /**
+     * @see javax.servlet.ServletRequestWrapper#getParameterValues(java.lang.String)
+     */
+    public String[] getParameterValues(String name) {
+        if ( !this.rawMode ) {
+            String[] values = this.parameters.getParameterValues(name);
+            String[] inherited = this.getParameterValues(name);
+            if (inherited == null) return values;
+            if (values == null) return inherited;
+            String[] allValues = new String[values.length + inherited.length];
+            System.arraycopy(values, 0, allValues, 0, values.length);
+            System.arraycopy(inherited, 0, allValues, values.length, inherited.length);
+            return allValues;
+        }
+        return this.parameters.getParameterValues(name);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#getQueryString()
+     */
+    public String getQueryString() {
+        return this.queryString;
+    }
+
+    /**
+     * @see javax.servlet.ServletRequestWrapper#getParameterMap()
+     */
+    public Map getParameterMap() {
+        final Map paramMap = new HashMap();
+        if ( !this.rawMode ) {
+            paramMap.putAll(super.getParameterMap());
+        }
+        final Enumeration e = this.parameters.getParameterNames();
+        while ( e.hasMoreElements() ) {
+            final String name = (String)e.nextElement();
+            final String[] values = this.parameters.getParameterValues(name);
+            paramMap.put(name, values);
+        }
+        return paramMap;
+    }
+}
+

Propchange: cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/SourceHttpServletRequestWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSource.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSource.java?rev=430738&r1=430737&r2=430738&view=diff
==============================================================================
--- cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSource.java
(original)
+++ cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSource.java
Fri Aug 11 02:21:20 2006
@@ -32,7 +32,6 @@
 import org.apache.cocoon.environment.http.HttpEnvironment;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 import org.apache.cocoon.processing.SAXAwareHttpServletResponseWrapper;
-import org.apache.cocoon.servlet.RequestUtil;
 import org.apache.cocoon.xml.SaxBuffer;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
@@ -45,6 +44,7 @@
  * Implementation of a {@link Source} that gets its content
  * by using the request dispatcher.
  *
+ * TODO: Caching
  * @version $Id$
  */
 public final class WebappSource
@@ -84,18 +84,20 @@
     throws MalformedURLException {
         this.servletContext = servletContext;
 
+        // TODO - we need a standard way to get the environment information from the current
request!
+        // Like prefix, view etc.
         Environment env = EnvironmentHelper.getCurrentEnvironment();
         if ( env == null ) {
             throw new MalformedURLException("The cocoon protocol can not be used outside
an environment.");
         }
         this.enableLogging(logger);
 
-        WebappSourceInfo info = WebappSourceInfo.parseURI(env, uri);
+        WebappSourceInfo info = WebappSourceInfo.parseURI(env.getURIPrefix(), uri, env.getView());
         this.protocol = info.protocol;
 
         final HttpServletRequest oldRequest = (HttpServletRequest) env.getObjectModel().get(HttpEnvironment.HTTP_REQUEST_OBJECT);
         final HttpServletResponse oldResponse = (HttpServletResponse) env.getObjectModel().get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
-        this.request = RequestUtil.createRequestForUri(oldRequest, info.requestURI, null);
+        this.request = new SourceHttpServletRequestWrapper(oldRequest, info.requestURI, null,
info.rawMode, info.queryString);
         this.response = new SAXAwareHttpServletResponseWrapper(oldResponse);
 
         this.systemId = info.systemId;

Modified: cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSourceInfo.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSourceInfo.java?rev=430738&r1=430737&r2=430738&view=diff
==============================================================================
--- cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSourceInfo.java
(original)
+++ cocoon/whiteboard/processor/src/main/java/org/apache/cocoon/resources/WebappSourceInfo.java
Fri Aug 11 02:21:20 2006
@@ -18,7 +18,6 @@
 import java.net.MalformedURLException;
 
 import org.apache.cocoon.Constants;
-import org.apache.cocoon.environment.Environment;
 
 /**
  * This is a helper class for the cocoon protocol.
@@ -69,7 +68,7 @@
      */
     public boolean processFromRoot;
 
-    public static WebappSourceInfo parseURI(Environment env, String sitemapURI) 
+    public static WebappSourceInfo parseURI(String currentPrefix, String sitemapURI, String
currentView) 
     throws MalformedURLException {
         WebappSourceInfo info = new WebappSourceInfo();
         info.rawMode = false;
@@ -94,7 +93,7 @@
             info.processFromRoot = true;
         } else if (sitemapURI.startsWith("/", position)) {
             position ++;
-            info.prefix = env.getURIPrefix();
+            info.prefix = currentPrefix;
             info.processFromRoot = false;
         } else {
             throw new MalformedURLException("Malformed cocoon URI: " + sitemapURI);
@@ -111,7 +110,7 @@
 
         
         // determine if the queryString specifies a cocoon-view
-        info.view = getView(info.queryString, env);
+        info.view = getView(info.queryString, currentView);
 
         // build the request uri which is relative to the context
         info.requestURI = info.prefix + info.uri;
@@ -127,7 +126,7 @@
         return info;
     }
 
-    public static String getView(String query, Environment env) {
+    public static String getView(String query, String currentView) {
         if (query != null) {
             int index = query.indexOf(Constants.VIEW_PARAM);
             if (index != -1 
@@ -143,10 +142,10 @@
                     return tmp;
                 }
             } else {
-                return env.getView();
+                return currentView;
             }
         } else {
-            return env.getView();
+            return currentView;
         }
     }
 }



Mime
View raw message