You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/08/11 10:58:55 UTC

svn commit: r430727 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet: RequestUtil.java UriHttpServletRequestWrapper.java

Author: cziegeler
Date: Fri Aug 11 01:58:54 2006
New Revision: 430727

URL: http://svn.apache.org/viewvc?rev=430727&view=rev
Log:
Factor out class

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java   (with props)
Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java?rev=430727&r1=430726&r2=430727&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java Fri Aug 11 01:58:54 2006
@@ -18,7 +18,6 @@
 import java.io.IOException;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
 /**
@@ -75,7 +74,7 @@
     }
 
     public static HttpServletRequest createRequestForUri(HttpServletRequest request, String servletPath, String pathInfo) {
-        return new HttpServletRequestImpl(request, servletPath, pathInfo);
+        return new UriHttpServletRequestWrapper(request, servletPath, pathInfo);
     }
 
     public static HttpServletRequest createRequestByRemovingPrefixFromUri(HttpServletRequest request, String prefix) {
@@ -88,83 +87,6 @@
         } else {
             newServletPath = servletPath + pathInfo.substring(0, prefix.length()+1);
         }
-        return new HttpServletRequestImpl(request, newServletPath, newPathInfo);
-    }
-
-    protected static final class HttpServletRequestImpl extends HttpServletRequestWrapper {
-
-        final private String servletPath;
-
-        final private String pathInfo;
-
-        final private String uri;
-
-        public HttpServletRequestImpl(HttpServletRequest request, String servletPath, String pathInfo) {
-            super(request);
-            this.servletPath = servletPath;
-            this.pathInfo = pathInfo;
-            final StringBuffer buffer = new StringBuffer();
-            if ( request.getContextPath() != null ) {
-                buffer.append(request.getContextPath());
-            }
-            if ( buffer.length() == 1 && buffer.charAt(0) == '/' ) {
-                buffer.deleteCharAt(0);
-            }
-            if ( servletPath != null ) {
-                buffer.append(servletPath);
-            }
-            if ( pathInfo != null ) {
-                buffer.append(pathInfo);
-            }
-            if ( buffer.charAt(0) != '/' ) {
-                buffer.insert(0, '/');
-            }
-            this.uri = buffer.toString();
-            
-        }
-
-        /**
-         * @see javax.servlet.http.HttpServletRequestWrapper#getPathInfo()
-         */
-        public String getPathInfo() {
-            return this.pathInfo;
-        }
-
-        /**
-         * @see javax.servlet.http.HttpServletRequestWrapper#getRequestURI()
-         */
-        public String getRequestURI() {
-            return this.uri;
-        }
-
-        /**
-         * @see javax.servlet.http.HttpServletRequestWrapper#getRequestURL()
-         */
-        public StringBuffer getRequestURL() {
-            final StringBuffer buffer = new StringBuffer();
-            buffer.append(this.getProtocol());
-            buffer.append("://");
-            buffer.append(this.getServerName());
-            boolean appendPort = true;
-            if ( this.getScheme().equals("http") && this.getServerPort() == 80 ) {
-                appendPort = false;
-            }
-            if ( this.getScheme().equals("https") && this.getServerPort() == 443) {
-                appendPort = false;
-            }
-            if ( appendPort ) {
-                buffer.append(':');
-                buffer.append(this.getServerPort());
-            }
-            buffer.append(this.uri);
-            return buffer;
-        }
-
-        /**
-         * @see javax.servlet.http.HttpServletRequestWrapper#getServletPath()
-         */
-        public String getServletPath() {
-            return this.servletPath;
-        }
+        return new UriHttpServletRequestWrapper(request, newServletPath, newPathInfo);
     }
 }

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java?rev=430727&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java Fri Aug 11 01:58:54 2006
@@ -0,0 +1,102 @@
+/*
+ * 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.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+/**
+ * 
+ * @version $Id$
+ * @since 2.2
+ */
+public class UriHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+    final private String servletPath;
+
+    final private String pathInfo;
+
+    final private String uri;
+
+    public UriHttpServletRequestWrapper(HttpServletRequest request, String servletPath, String pathInfo) {
+        super(request);
+        this.servletPath = servletPath;
+        this.pathInfo = pathInfo;
+        final StringBuffer buffer = new StringBuffer();
+        if ( request.getContextPath() != null ) {
+            buffer.append(request.getContextPath());
+        }
+        if ( buffer.length() == 1 && buffer.charAt(0) == '/' ) {
+            buffer.deleteCharAt(0);
+        }
+        if ( servletPath != null ) {
+            buffer.append(servletPath);
+        }
+        if ( pathInfo != null ) {
+            buffer.append(pathInfo);
+        }
+        if ( buffer.charAt(0) != '/' ) {
+            buffer.insert(0, '/');
+        }
+        this.uri = buffer.toString();
+        
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#getPathInfo()
+     */
+    public String getPathInfo() {
+        return this.pathInfo;
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#getRequestURI()
+     */
+    public String getRequestURI() {
+        return this.uri;
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#getRequestURL()
+     */
+    public StringBuffer getRequestURL() {
+        final StringBuffer buffer = new StringBuffer();
+        buffer.append(this.getProtocol());
+        buffer.append("://");
+        buffer.append(this.getServerName());
+        boolean appendPort = true;
+        if ( this.getScheme().equals("http") && this.getServerPort() == 80 ) {
+            appendPort = false;
+        }
+        if ( this.getScheme().equals("https") && this.getServerPort() == 443) {
+            appendPort = false;
+        }
+        if ( appendPort ) {
+            buffer.append(':');
+            buffer.append(this.getServerPort());
+        }
+        buffer.append(this.uri);
+        return buffer;
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#getServletPath()
+     */
+    public String getServletPath() {
+        return this.servletPath;
+    }
+}
+

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/UriHttpServletRequestWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Id