velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1855537 - in /velocity/tools/trunk/velocity-tools-view/src: main/java/org/apache/velocity/tools/view/ test/java/org/apache/velocity/tools/test/blackbox/
Date Thu, 14 Mar 2019 16:12:37 GMT
Author: cbrisson
Date: Thu Mar 14 16:12:36 2019
New Revision: 1855537

URL: http://svn.apache.org/viewvc?rev=1855537&view=rev
Log:
[tools/view] New BreadcrumbTool tool; factorize some code in blackbox tools tests

Added:
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BaseToolTests.java
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BreadcrumbToolTests.java
Modified:
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/CookieToolTests.java
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java

Added: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java?rev=1855537&view=auto
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
(added)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
Thu Mar 14 16:12:36 2019
@@ -0,0 +1,260 @@
+package org.apache.velocity.tools.view;
+
+/*
+ * 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.
+ */
+
+import org.apache.velocity.tools.Scope;
+import org.apache.velocity.tools.config.DefaultKey;
+import org.apache.velocity.tools.config.ValidScope;
+import org.apache.velocity.tools.generic.LocaleConfig;
+import org.apache.velocity.tools.generic.ValueParser;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * <p>Helper tool to display a navigation breadcrumb to the end user.</p>
+ * <p>It relies on the asumption that your URI hierarchy corresponds to the navigation
hierarchy you want to present
+ * to your users, each level having its landing index page. Please note that this asumption
is considered a *good practice*.</p>
+ * <p>Each intermediate path element becomes a navigation element, and there is an
additional ending navigation element
+ * when the page is not an index page.</p>
+ * <p>For instance, if the URI is `/colors/red/nuances.html`, the provided path elements
will be:</p>
+ * <ul>
+ *     <li>'colors', pointing towards '/colors/index.html'</li>
+ *     <li>'red', pointing towards '/colors/red/index.html'</li>
+ *     <li>'nuances', pointing towards '/colors/red/nuances.html'</li>
+ * </ul>
+ * <p>The filename extension (`html` in the above example) is inferred from found URIs.</p>
+ * <p>By default, the displayed name of a navigation element is the name of its corresponding
path element with all
+ * '<code>_</code>' replaced by spaces, transformed to lowercase.</p>
+ * <p>You can customize this displayed name and the URL of every path element using
tools properties:</p>
+ * <pre><code>
+ *     <tool key="breadcrumb" colors.name="My Colors" colors.url="/colors/all.vhtml"/>
+ * </code></pre>
+ * <p>where '<code>colors</code>' refers to the <code>/colors/</code>
path element. The name and destination of the
+ * root path element can be changed with '<code>home.name</code>' and '<code>home.url</code>'.</p>
+ * <p>Inside a template, you would either render directly the default resulting HTML
fragment with:</p>
+ * <pre><code>$breadcrumb</code></pre>
+ * <p>which would produce simething like:</p>
+ * <pre><code>&lt;a href="/index.vhtml"&gt;home&lt;/a&gt;&amp;nbsp;&amp;gt;&amp;nbsp;&lt;a
href="/colors/all.vhtml"&gt;My Colors&lt;/a&gt;&amp;nbsp;&amp;gt;&amp;nbsp;nuances</code></pre>
+ * <p>or you would iterate through navigation elements for a better control of the
output with:</p>
+ * <pre><code>
+ * <div id="breadcrumb">
+ * #foreach($element in $breadcrumb)
+ *  #if(!$foreach.first)
+ *   <span class="divider">&gt;</span>
+ *  #end
+ *  #if(!$foreach.last)<a href="$element.url">#end
+ *   $element.name
+ *  #if(!$foreach.last)</a>#end
+ * #end
+ *</div></code></pre>
+ * <p>And of course, you would supply the necessary CSS, for instance:</p>
+ * <pre><code>
+ * #breadcrumb { font-size: smaller; }
+ * #breadcrumb a { color: #4183c4; text-decoration: none; }
+ * #breadcrumb .divider { color: rgba(0, 0, 0, 0.4); vertical-align: baseline; margin: 0
0.2rem; }
+ * </code></pre>
+ *
+ * @version $$
+ * @author Claude Brisson
+ * @since 3.1
+ *
+ */
+
+@DefaultKey("breadcrumb")
+@ValidScope(Scope.REQUEST)
+public class BreadcrumbTool extends LocaleConfig implements Iterable<BreadcrumbTool.NavigationElement>
+{
+    /**
+     * Navigation elements for the current URI
+     */
+    protected List<NavigationElement> navigationElements = null;
+
+    /**
+     * Class representing a navigation element
+     */
+    public static class NavigationElement
+    {
+        /**
+         * destination URL
+         */
+        private String url;
+
+        /**
+         * Displayed name
+         */
+        private String name;
+
+        /**
+         * Constructor
+         * @param url destination URL
+         * @param name displayed name
+         */
+        public NavigationElement(String url, String name)
+        {
+            this.url = url;
+            if (name.endsWith(".vhtml")) name = name.substring(0, name.indexOf(".vhtml"));
+            this.name = name;
+        }
+
+        /**
+         * Destination URL getter
+         * @return destination URL
+         */
+        public String getUrl() { return url; }
+
+        /**
+         * Displayed name getter
+         * @return displayed name
+         */
+        public String getName() { return name; }
+
+        /**
+         * Displayed name setter
+         * @param name displayed name
+         */
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        /**
+         * Destination URL setter
+         * @param url destination url
+         */
+        public void setUrl(String url)
+        {
+            this.url = url;
+        }
+    }
+
+    /**
+     * Current request setter
+     * @param request
+     */
+    public void setRequest(HttpServletRequest request)
+    {
+        String uri = request.getRequestURI();
+        // infer extension
+        String ext = getExtension(uri);
+        String index = "index." + ext;
+        if ("/".equals(uri)) uri = "/" + index;
+        String elements[] = uri.split("/");
+        navigationElements = new ArrayList<NavigationElement>();
+        StringBuilder builder = new StringBuilder();
+        for (String elem : elements)
+        {
+            builder.append(elem);
+            String currentPath = builder.toString();
+            if (index.equals(elem)) continue;
+            if (!elem.endsWith('.' + ext)) currentPath = currentPath + '/' + index;
+            String name = builder.length() == 0 ? "home" : elem.replace('_', ' ').toLowerCase(getLocale());
+            navigationElements.add(new NavigationElement(currentPath, name));
+            builder.append('/');
+        }
+    }
+
+    /**
+     * Configuration
+     */
+    @Override
+    protected void configure(ValueParser config)
+    {
+        if (navigationElements == null)
+        {
+            getLog().warn("cannot build breadcrumb: no provided request");
+            return;
+        }
+        for (NavigationElement elem : navigationElements)
+        {
+            Object obj = config.get(elem.getName());
+            if (obj != null && obj instanceof ValueParser)
+            {
+                ValueParser values = (ValueParser) obj;
+                elem.setName((String) values.getOrDefault("name", elem.getName()));
+                elem.setUrl((String) values.getOrDefault("url", elem.getUrl()));
+            }
+        }
+    }
+
+    /**
+     * Navigation elements iteration
+     * @return Iterator over navigation elements
+     */
+    @Override
+    public Iterator<NavigationElement> iterator()
+    {
+        return navigationElements.iterator();
+    }
+
+    /**
+     * Utility method to return URI file extension
+     * @param filename
+     * @return
+     */
+    protected static String getExtension(String filename)
+    {
+        if (filename == null) {
+            return null;
+        }
+        int extensionPos = filename.lastIndexOf('.');
+        int lastSeparator = filename.lastIndexOf('/');
+        int index = lastSeparator > extensionPos ? -1 : extensionPos;
+        if (index == -1)
+        {
+            return "";
+        }
+        else
+        {
+            return filename.substring(index + 1);
+        }
+    }
+
+    /**
+     * Default concatenation of navigation elements, separated by '>'
+     * @return string representation
+     */
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        int len = navigationElements.size();
+        for (int i = 0; i < len; ++i)
+        {
+            NavigationElement elem = navigationElements.get(i);
+            if (i > 0)
+            {
+                builder.append("&nbsp;&gt;&nbsp;");
+            }
+            if (i < len - 1)
+            {
+                builder.append("<a href=\"").append(elem.getUrl()).append("\">");
+            }
+            builder.append(elem.getName());
+            if (i < len - 1)
+            {
+                builder.append("</a>");
+            }
+        }
+        return builder.toString();
+    }
+}

Added: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BaseToolTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BaseToolTests.java?rev=1855537&view=auto
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BaseToolTests.java
(added)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BaseToolTests.java
Thu Mar 14 16:12:36 2019
@@ -0,0 +1,71 @@
+package org.apache.velocity.tools.test.blackbox;
+
+/*
+ * 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.
+ */
+
+import org.apache.velocity.tools.ClassUtils;
+import org.junit.Assert;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * A base class for blackbox tools testing
+ *
+ * @version $$
+ * @author Claude Brisson
+ * @since 3.1
+ */
+
+public class BaseToolTests extends Assert
+{
+    protected static <T> T newTool(Class<T> clazz, InvocationHandler requestHandler,
InvocationHandler responseHandler) throws Exception
+    {
+        ClassLoader classLoader = BaseToolTests.class.getClassLoader();
+        Object requestProxy
+            = Proxy.newProxyInstance(classLoader,
+            new Class[] { HttpServletRequest.class },
+            requestHandler);
+
+        Object responseProxy
+            = Proxy.newProxyInstance(classLoader,
+            new Class[] { HttpServletResponse.class },
+            responseHandler);
+
+        HttpServletRequest request = (HttpServletRequest)requestProxy;
+        HttpServletResponse response = (HttpServletResponse)responseProxy;
+
+        T tool = clazz.getConstructor(new Class[] {}).newInstance();
+        invokeMethodOrNOP(tool, "setRequest", request, HttpServletRequest.class);
+        invokeMethodOrNOP(tool, "setResponse", response, HttpServletResponse.class);
+        return tool;
+    }
+
+    private static void invokeMethodOrNOP(Object tool, String methodName, Object singleArg,
Class singleArgClass) throws Exception
+    {
+        Method method = ClassUtils.findMethod(tool.getClass(), methodName, new Class[] {
singleArgClass });
+        if (method != null)
+        {
+            method.invoke(tool, new Object[] { singleArg });
+        }
+    }
+}

Added: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BreadcrumbToolTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BreadcrumbToolTests.java?rev=1855537&view=auto
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BreadcrumbToolTests.java
(added)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BreadcrumbToolTests.java
Thu Mar 14 16:12:36 2019
@@ -0,0 +1,45 @@
+package org.apache.velocity.tools.test.blackbox;
+
+import org.apache.velocity.tools.view.BreadcrumbTool;
+import org.junit.Test;
+
+import java.lang.reflect.InvocationHandler;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Breadcrumb tool tool tests
+ *
+ * @version $$
+ * @author Claude Brisson
+ * @since 3.1
+ */
+
+public class BreadcrumbToolTests extends BaseToolTests
+{
+    private BreadcrumbTool newBreadcrumbTool(String uri) throws Exception
+    {
+        return newBreadcrumbTool(new RequestAdaptor("", uri, null), new ResponseAdaptor());
+    }
+
+    private BreadcrumbTool newBreadcrumbTool(InvocationHandler requestHandler, InvocationHandler
responseHandler) throws Exception
+    {
+        return newTool(BreadcrumbTool.class, requestHandler, responseHandler);
+    }
+
+    @Test
+    public void testBreadcrumb() throws Exception
+    {
+        Map<String, Object> params = new HashMap<>();
+        BreadcrumbTool bc = newBreadcrumbTool("/colors/red/nuances.vhtml");
+        bc.configure(params);
+        assertEquals("<a href=\"/index.vhtml\">home</a>&nbsp;&gt;&nbsp;<a
href=\"/colors/index.vhtml\">colors</a>&nbsp;&gt;&nbsp;<a href=\"/colors/red/index.vhtml\">red</a>&nbsp;&gt;&nbsp;nuances",
bc.toString());
+
+        params.put("home.name", "index");
+        params.put("home.url", "/welcome.vhtml");
+        params.put("nuances.name", "shades");
+        bc = newBreadcrumbTool("/colors/red/nuances.vhtml");
+        bc.configure(params);
+        assertEquals("<a href=\"/welcome.vhtml\">index</a>&nbsp;&gt;&nbsp;<a
href=\"/colors/index.vhtml\">colors</a>&nbsp;&gt;&nbsp;<a href=\"/colors/red/index.vhtml\">red</a>&nbsp;&gt;&nbsp;shades",
bc.toString());
+    }
+}

Modified: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/CookieToolTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/CookieToolTests.java?rev=1855537&r1=1855536&r2=1855537&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/CookieToolTests.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/CookieToolTests.java
Thu Mar 14 16:12:36 2019
@@ -38,42 +38,26 @@ import org.junit.Test;
  * @author Nathan Bubna
  * @version $Id$
  */
-public class CookieToolTests
+public class CookieToolTests extends BaseToolTests
 {
-    private CookieTool newCookieTool(InvocationHandler requestHandler, InvocationHandler
responseHandler)
+    private CookieTool newCookieTool(InvocationHandler requestHandler, InvocationHandler
responseHandler) throws Exception
     {
-        Object requestProxy
-            = Proxy.newProxyInstance(this.getClass().getClassLoader(),
-                                     new Class[] { HttpServletRequest.class },
-                                     requestHandler);
-
-        Object responseProxy
-                = Proxy.newProxyInstance(this.getClass().getClassLoader(),
-                new Class[] { HttpServletResponse.class },
-                responseHandler);
-
-        HttpServletRequest request = (HttpServletRequest)requestProxy;
-        HttpServletResponse response = (HttpServletResponse)responseProxy;
-
-        CookieTool cookies = new CookieTool();
-        cookies.setRequest(request);
-        cookies.setResponse(response);
-        return cookies;
+        return newTool(CookieTool.class, requestHandler, responseHandler);
     }
 
-    private CookieTool newCookieTool(Map cookies)
+    private CookieTool newCookieTool(Map cookies) throws Exception
     {
         return newCookieTool(new RequestAdaptor(cookies), new ResponseAdaptor(cookies));
     }
 
-    private CookieTool newCookieTool(String name, Object value)
+    private CookieTool newCookieTool(String name, Object value) throws Exception
     {
         Map cookies = new LinkedHashMap();
         cookies.put(name, value);
         return newCookieTool(cookies);
     }
 
-    public @Test void testCreate_StringString()
+    public @Test void testCreate_StringString() throws Exception
     {
         CookieTool cookies = newCookieTool(new LinkedHashMap());
         Cookie c = cookies.create("a", "b");
@@ -83,7 +67,7 @@ public class CookieToolTests
         assertEquals(-1, c.getMaxAge());
     }
 
-    public @Test void testCreate_StringStringObject()
+    public @Test void testCreate_StringStringObject() throws Exception
     {
         CookieTool cookies = newCookieTool(new LinkedHashMap());
         Cookie c = cookies.create("a", "b", 10);
@@ -98,13 +82,13 @@ public class CookieToolTests
         assertNull(c);
     }
 
-    public @Test void testGet_String()
+    public @Test void testGet_String() throws Exception
     {
         CookieTool cookies = newCookieTool("a", "b");
         assertEquals("b", cookies.get("a").toString());
     }
 
-    public @Test void testGetAll()
+    public @Test void testGetAll() throws Exception
     {
         CookieTool cookies = newCookieTool("a", "b");
         assertEquals("[b]", cookies.getAll().toString());
@@ -120,7 +104,7 @@ public class CookieToolTests
         assertEquals("foo", all.get(1).getName());
     }
 
-    public @Test void testToString()
+    public @Test void testToString() throws Exception
     {
         CookieTool cookies = newCookieTool("a", "b");
         assertEquals("[a=b]", cookies.toString());
@@ -132,7 +116,7 @@ public class CookieToolTests
         assertEquals("[a=b, foo=bar]", cookies.toString());
     }
 
-    public @Test void testAdd_StringString()
+    public @Test void testAdd_StringString() throws Exception
     {
         Map jar = new LinkedHashMap();
         jar.put("a", "b");
@@ -146,7 +130,7 @@ public class CookieToolTests
         assertEquals("b", cookies.get("a").getValue());
     }
 
-    public @Test void testAdd_StringStringObject()
+    public @Test void testAdd_StringStringObject() throws Exception
     {
         Map jar = new LinkedHashMap();
         jar.put("a", "b");
@@ -162,7 +146,7 @@ public class CookieToolTests
         assertEquals(10, c.getMaxAge());
     }
 
-    public @Test void testDelete_String()
+    public @Test void testDelete_String() throws Exception
     {
         Map jar = new LinkedHashMap();
         jar.put("a", "b");

Modified: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java?rev=1855537&r1=1855536&r2=1855537&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java
Thu Mar 14 16:12:36 2019
@@ -112,146 +112,150 @@ public class RequestAdaptor implements I
     {
         String methodName = method.getName();
 
-        if("getContextPath".equals(methodName))
+        switch (methodName)
         {
-            return _contextPath;
-        }
-        else if("getParameter".equals(methodName))
-        {
-            Object value = _params.get(args[0]);
+            case "getContextPath":
+            {
+                return _contextPath;
+            }
+            case "getParameter":
+            {
+                Object value = _params.get(args[0]);
+                if (value instanceof String)
+                {
+                    return value;
+                }
+                else if (value instanceof String[])
+                {
+                    return ((String[]) value)[0];
+                }
+                else
+                {
+                    throw new IllegalStateException("Parameter value must be either String
or String[].");
+                }
+            }
+            case "getParameterValues":
+            {
+                Object value = _params.get(args[0]);
 
-            if(value instanceof String)
+                if (value instanceof String)
+                {
+                    return new String[]{(String) value};
+                }
+                else if (value instanceof String[])
+                {
+                    return value;
+                }
+                else
+                {
+                    throw new IllegalStateException("Parameter value must be either String
or String[].");
+                }
+            }
+            case "getParameterMap":
+            {
+                return Collections.unmodifiableMap(_params);
+            }
+            case "getParameterNames":
             {
-                return value;
+                return new IteratorEnumeration(_params.keySet().iterator());
             }
-            else if (value instanceof String[])
+            case "getAttribute":
             {
-                return ((String[])value)[0];
+                if (((String) args[0]).equals("XHTML"))
+                {
+                    return Boolean.TRUE; // xhtml = true
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            case "setAttribute":
+            {
+                return null;
             }
-            else
+            case "removeAttribute":
             {
-                throw new IllegalStateException("Parameter value must be either String or
String[].");
+                return null;
+            }
+            case "getSession":
+            {
+                return null;
+            }
+            case "getScheme":
+            {
+                return "http";
+            }
+            case "getServerPort":
+            {
+                return new Integer(8081);
             }
-        }
-        else if("getParameterValues".equals(methodName))
-        {
-            Object value = _params.get(args[0]);
 
-            if(value instanceof String)
+
+            case "getServerName":
             {
-                return new String[] { (String)value };
+                return "localhost";
             }
-            else if (value instanceof String[])
+            case "getServletPath":
             {
-                return value;
+                return _contextPath;
             }
-            else
+            case "getPathInfo":
             {
-                throw new IllegalStateException("Parameter value must be either String or
String[].");
+                return _pathInfo;
             }
-        }
-        else if("getParameterMap".equals(methodName))
-        {
-            return Collections.unmodifiableMap(_params);
-        }
-        else if("getParameterNames".equals(methodName))
-        {
-            return new IteratorEnumeration(_params.keySet().iterator());
-        }
-        else if("getAttribute".equals(methodName))
-        {
-            return null;
-        }
-        else if("setAttribute".equals(methodName))
-        {
-            return null;
-        }
-        else if("removeAttribute".equals(methodName))
-        {
-            return null;
-        }
-        else if("getSession".equals(methodName))
-        {
-            return null;
-        }
-        else if("getAttribute".equals(methodName))
-        {
-            if(((String)args[0]).equals("XHTML"))
+            case "getRequestURI":
             {
-                return Boolean.TRUE; // xhtml = true
+                return _pathInfo;
             }
-            else
+            case "getCharacterEncoding":
             {
-                return null;
+                return "UTF-8";
             }
-        }
-        else if ("getScheme".equals(methodName))
-        {
-            return "http";
-        }
-        else if ("getServerPort".equals(methodName))
-        {
-            return new Integer(8081);
-        }
-        else if ("getServerName".equals(methodName))
-        {
-            return "localhost";
-        }
-        else if ("getServletPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else if ("getPathInfo".equals(methodName))
-        {
-            return _pathInfo;
-        }
-        else if("getCharacterEncoding".equals(methodName))
-        {
-            return "UTF-8";
-        }
-        else if ("getCookies".equals(methodName))
-        {
-            // just let params double as the cookie store
-            Cookie[] jar = new Cookie[_params.size()];
-            int i = 0;
-            for (Iterator iter = _params.keySet().iterator(); iter.hasNext(); i++)
-            {
-                Object key = iter.next();
-                Object val = _params.get(key);
-                if (val instanceof Cookie)
-                {
-                    jar[i] = (Cookie)val;
-                }
-                else
+            case "getCookies":
+            {
+                // just let params double as the cookie store
+                Cookie[] jar = new Cookie[_params.size()];
+                int i = 0;
+                for (Iterator iter = _params.keySet().iterator(); iter.hasNext(); i++)
                 {
-                    String name = String.valueOf(key);
-                    String value = String.valueOf(val);
-                    jar[i] = new Cookie(name, value);
-                    _params.put(name, jar[i]);
+                    Object key = iter.next();
+                    Object val = _params.get(key);
+                    if (val instanceof Cookie)
+                    {
+                        jar[i] = (Cookie) val;
+                    }
+                    else
+                    {
+                        String name = String.valueOf(key);
+                        String value = String.valueOf(val);
+                        jar[i] = new Cookie(name, value);
+                        _params.put(name, jar[i]);
+                    }
                 }
+                return jar;
+            }
+            case "getContentLength":
+            {
+                return getContentLength();
+            }
+            case "getContentType":
+            {
+                return getContentType();
+            }
+            case "getReader":
+            {
+                return getReader();
+            }
+            case "toString":
+            {
+                return toString();
+            }
+            default:
+            {
+                throw new IllegalStateException("Unexpected method call: "
+                    + method);
             }
-            return jar;
-        }
-        else if ("getContentLength".equals(methodName))
-        {
-            return getContentLength();
-        }
-        else if ("getContentType".equals(methodName))
-        {
-            return getContentType();
-        }
-        else if ("getReader".equals(methodName))
-        {
-            return getReader();
-        }
-        else if ("toString".equals(methodName))
-        {
-            return toString();
-        }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + method);
         }
     }
 



Mime
View raw message