velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r544331 [1/2] - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: struts/ view/ view/i18n/ view/tools/
Date Tue, 05 Jun 2007 00:24:31 GMT
Author: nbubna
Date: Mon Jun  4 17:24:29 2007
New Revision: 544331

URL: http://svn.apache.org/viewvc?view=rev&rev=544331
Log:
- copy tools (sans deprecated methods) from the o.a.v.t.view.* subpackages to the o.a.v.t.view package for consistency with GenericTools and VelocityStruts package structures.
- leave deprecated versions (including deprecated methods) in old packages
- update VelocityStruts and o.a.v.t.view.tools.xml to use tools in new locations
- rename BrowserSnifferTool and ParameterParser to BrowserTool and ParameterTool for better consistency with other tools

Added:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractPagerTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/BrowserSnifferTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ContextTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ContextTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/CookieTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/CookieTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/MultiViewsTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ParameterParser.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewRenderTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewRenderTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewResourceTool.java
      - copied, changed from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewResourceTool.java
Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools.xml
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/BrowserSnifferTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ContextTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/CookieTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ParameterParser.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewRenderTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewResourceTool.java

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java?view=diff&rev=544331&r1=544330&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java Mon Jun  4 17:24:29 2007
@@ -25,7 +25,7 @@
 import org.apache.struts.action.SecurePlugInInterface;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.config.SecureActionConfig;
-import org.apache.velocity.tools.view.tools.LinkTool;
+import org.apache.velocity.tools.view.LinkTool;
 
 /**
  * Tool to be able to use Struts SSL Extensions with Velocity.

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java?view=diff&rev=544331&r1=544330&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java Mon Jun  4 17:24:29 2007
@@ -19,7 +19,7 @@
  * under the License.
  */
 
-import org.apache.velocity.tools.view.tools.LinkTool;
+import org.apache.velocity.tools.view.LinkTool;
 import org.apache.velocity.runtime.log.Log;
 
 /**

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractPagerTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractPagerTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractPagerTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractPagerTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -144,15 +144,6 @@
         }
         this.session = request.getSession(false);
         setup(request);
-    }
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewContext)
-        {
-            setRequest(((ViewContext)obj).getRequest());
-        }
     }
 
     /**

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/BrowserTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/BrowserSnifferTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/BrowserTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/BrowserSnifferTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/BrowserTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/BrowserSnifferTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/BrowserTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -31,7 +31,7 @@
  *  <p>browser-sniffing tool (session or request scope requested, session scope advised).</p>
  *  <p></p>
  * <p><b>Usage:</b></p>
- * <p>BrowserSniffer defines properties that are used to test the client browser, operating system, device...
+ * <p>BrowserTool defines properties that are used to test the client browser, operating system, device...
  * Apart from properties related to versioning, all properties are booleans.</p>
  * <p>The following properties are available:</p>
  * <ul>
@@ -61,7 +61,7 @@
  */
 @DefaultKey("browser")
 @InvalidScope("application")
-public class BrowserSnifferTool implements java.io.Serializable
+public class BrowserTool implements java.io.Serializable
 {
     private static final long serialVersionUID = 1734529350532353339L;
 
@@ -85,15 +85,6 @@
             throw new NullPointerException("request should not be null");
         }
         userAgent = request.getHeader("User-Agent").toLowerCase();
-    }
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewContext)
-        {
-            setRequest(((ViewContext)obj).getRequest());
-        }
     }
 
     /* Generic getter for unknown tests

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ContextTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ContextTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ContextTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ContextTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ContextTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ContextTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ContextTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -49,7 +49,7 @@
  * &lt;tool&gt;
  *   &lt;key&gt;context&lt;/key&gt;
  *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.ContextTool&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.ContextTool&lt;/class&gt;
  * &lt;/tool&gt;
  * </pre></p>
  *

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/CookieTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/CookieTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/CookieTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/CookieTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/CookieTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/CookieTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/CookieTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -24,7 +24,6 @@
 import javax.servlet.http.HttpServletResponse;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
-import org.apache.velocity.tools.view.ViewContext;
 
 /**
  * <p>View tool for convenient cookie access and creation.</p>
@@ -37,7 +36,7 @@
  * &lt;tool&gt;
  *   &lt;key&gt;cookie&lt;/key&gt;
  *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.CookieTool&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.CookieTool&lt;/class&gt;
  * &lt;/tool&gt;
  * </pre></p>
  *
@@ -57,17 +56,6 @@
     protected HttpServletResponse response;
 
     // --------------------------------------- Setup Methods -------------
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewContext)
-        {
-            ViewContext ctx = (ViewContext)obj;
-            setRequest(ctx.getRequest());
-            setResponse(ctx.getResponse());
-        }
-    }
 
     /**
      * Sets the current {@link HttpServletRequest}. This is required

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -22,7 +22,6 @@
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 import org.apache.velocity.tools.view.ImportSupport;
-import org.apache.velocity.tools.view.ViewContext;
 
 /**
  * General-purpose text-importing view tool for templates.
@@ -35,7 +34,7 @@
  * &lt;tool&gt;
  *   &lt;key&gt;import&lt;/key&gt;
  *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.ImportTool&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.ImportTool&lt;/class&gt;
  * &lt;/tool&gt;
  * </pre></p>
  *
@@ -47,24 +46,6 @@
 @ValidScope("request")
 public class ImportTool extends ImportSupport
 {
-    /**
-     * Default constructor. Tool must be initialized before use.
-     */
-    public ImportTool() {}
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewContext)
-        {
-            ViewContext ctx = (ViewContext)obj;
-            setRequest(ctx.getRequest());
-            setResponse(ctx.getResponse());
-            setServletContext(ctx.getServletContext());
-            setLog(ctx.getVelocityEngine().getLog());
-        }
-    }
-
     /**
      * Returns the supplied URL rendered as a String.
      *

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -33,7 +33,6 @@
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 import org.apache.velocity.tools.generic.ValueParser;
-import org.apache.velocity.tools.view.ViewContext;
 import org.apache.velocity.tools.view.ServletUtils;
 
 /**
@@ -48,7 +47,7 @@
  * &lt;tool&gt;
  *   &lt;key&gt;link&lt;/key&gt;
  *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.LinkTool&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.LinkTool&lt;/class&gt;
  * &lt;/tool&gt;
  * </pre></p>
  *
@@ -151,19 +150,6 @@
 
     // --------------------------------------- Setup Methods -------------
 
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewContext)
-        {
-            ViewContext ctx = (ViewContext)obj;
-            setRequest(ctx.getRequest());
-            setResponse(ctx.getResponse());
-            setServletContext(ctx.getServletContext());
-            setLog(ctx.getVelocityEngine().getLog());
-        }
-    }
-
     /**
      * Sets the current {@link HttpServletRequest}. This is required
      * for this tool to operate and will throw a NullPointerException
@@ -210,13 +196,6 @@
         this.LOG = log;
     }
 
-    @Deprecated
-    public void setXhtml(boolean useXhtml)
-    {
-        queryDataDelim =
-            (useXhtml) ? XHTML_QUERY_DELIMITER : HTML_QUERY_DELIMITER;
-    }
-
     /**
      * <p>Controls the delimiter used for separating query data pairs.
      *    By default, the standard '&' character is used.</p>
@@ -231,7 +210,8 @@
      */
     public void setXHTML(boolean useXhtml)
     {
-        setXhtml(useXhtml);
+        queryDataDelim =
+            (useXhtml) ? XHTML_QUERY_DELIMITER : HTML_QUERY_DELIMITER;
     }
     
     /**

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/MultiViewsTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/MultiViewsTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/MultiViewsTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/MultiViewsTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.i18n;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -61,7 +61,7 @@
     protected VelocityEngine engine;
 
     /**
-     * Creates a new uninitialized instance.  Call {@link #init}
+     * Creates a new uninitialized instance.  Call {@link #configure}
      * to initialize it.
      */
     public MultiViewsTool()
@@ -99,15 +99,6 @@
         }
 
         this.engine = ctx.getVelocityEngine();
-    }
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewToolContext)
-        {
-            configure((ViewToolContext)obj);
-        }
     }
 
     /**

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ParameterParser.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ParameterParser.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ParameterParser.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -24,7 +24,6 @@
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 import org.apache.velocity.tools.generic.ValueParser;
-import org.apache.velocity.tools.view.ViewContext;
 
 /**
  * <p>Utility class for easy parsing of {@link ServletRequest} parameters.</p>
@@ -39,7 +38,7 @@
  * &lt;tool&gt;
  *   &lt;key&gt;params&lt;/key&gt;
  *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.ParameterParser&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.ParameterTool&lt;/class&gt;
  * &lt;/tool&gt;
  * </pre></p>
  *
@@ -52,14 +51,14 @@
  */
 @DefaultKey("params")
 @ValidScope("request")
-public class ParameterParser extends ValueParser
+public class ParameterTool extends ValueParser
 {
     private ServletRequest request;
 
     /**
      * Constructs a new instance
      */
-    public ParameterParser()
+    public ParameterTool()
     {}
 
     /**
@@ -67,17 +66,11 @@
      *
      * @param request the {@link ServletRequest} to be parsed
      */
-    public ParameterParser(ServletRequest request)
+    public ParameterTool(ServletRequest request)
     {
         setRequest(request);
     }
 
-    @Deprecated
-    public void init(Object obj)
-    {
-        //Does nothing
-    }
-
     /**
      * Sets the current {@link ServletRequest}
      *
@@ -98,7 +91,7 @@
     {
         if (request == null)
         {
-            throw new UnsupportedOperationException("Request is null. ParameterParser must be initialized first!");
+            throw new UnsupportedOperationException("Request is null. ParameterTool must be initialized first!");
         }
         return request;
     }

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewRenderTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewRenderTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewRenderTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewRenderTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewRenderTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewRenderTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewRenderTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -21,7 +21,6 @@
 
 import org.apache.velocity.context.Context;
 import org.apache.velocity.tools.generic.RenderTool;
-import org.apache.velocity.tools.view.ViewContext;
 import org.apache.velocity.tools.config.InvalidScope;
 
 /**
@@ -59,7 +58,7 @@
  * &lt;tool&gt;
  *   &lt;key&gt;render&lt;/key&gt;
  *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.ViewRenderTool&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.ViewRenderTool&lt;/class&gt;
  *   &lt;parameter name="parse.depth" value="10"/&gt;
  * &lt;/tool&gt;
  * </pre>
@@ -85,15 +84,6 @@
      */
     public ViewRenderTool()
     {}
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof Context)
-        {
-            setVelocityContext((Context)obj);
-        }
-    }
 
     /**
      * Sets the current {@link Context}. This is required

Copied: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewResourceTool.java (from r544152, velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewResourceTool.java)
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewResourceTool.java?view=diff&rev=544331&p1=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewResourceTool.java&r1=544152&p2=velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewResourceTool.java&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ViewResourceTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ViewResourceTool.java Mon Jun  4 17:24:29 2007
@@ -1,4 +1,4 @@
-package org.apache.velocity.tools.view.tools;
+package org.apache.velocity.tools.view;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -22,7 +22,6 @@
 import javax.servlet.http.HttpServletRequest;
 import org.apache.velocity.tools.config.InvalidScope;
 import org.apache.velocity.tools.generic.ResourceTool;
-import org.apache.velocity.tools.view.ViewContext;
 
 /**
  * <p>Tool for accessing ResourceBundles and formatting messages therein.</p>
@@ -39,7 +38,7 @@
  * Toolbox configuration example:
  * &lt;tool&gt;
  *   &lt;key&gt;text&lt;/key&gt;
- *   &lt;class&gt;org.apache.velocity.tools.view.tools.ViewResourceTool&lt;/class&gt;
+ *   &lt;class&gt;org.apache.velocity.tools.view.ViewResourceTool&lt;/class&gt;
  *   &lt;parameter name="bundles" value="resources,com.foo.moreResources"/&gt;
  * &lt;/tool&gt;
  * </pre></p>
@@ -65,16 +64,6 @@
 @InvalidScope({"application","session"})
 public class ViewResourceTool extends ResourceTool
 {
-
-    @Deprecated
-    public void init(Object obj)
-    {
-        if (obj instanceof ViewContext)
-        {
-            setRequest(((ViewContext)obj).getRequest());
-        }
-    }
-
     /**
      * Sets the current {@link ServletRequest}
      *

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java?view=diff&rev=544331&r1=544330&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/i18n/MultiViewsTool.java Mon Jun  4 17:24:29 2007
@@ -19,88 +19,14 @@
  * under the License.
  */
 
-import java.util.Locale;
-import java.util.Map;
-import javax.servlet.ServletContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.context.Context;
-import org.apache.velocity.tools.config.DefaultKey;
-import org.apache.velocity.tools.config.InvalidScope;
 import org.apache.velocity.tools.view.ViewToolContext;
 
 /**
- * Allows for transparent content negotiation in a manner mimicking
- * Apache httpd's <a
- * href="http://httpd.apache.org/docs-2.0/content-negotiation.html">MultiViews</a>.
- *
- * <p>Reads the default language out of the ViewContext as
- * <code>org.apache.velocity.tools.view.i18n.defaultLanguage</code>.
- * See {@link #findLocalizedResource(String, String)} and {@link
- * #findLocalizedResource(String, Locale)} for usage.</p>
- *
- * @version $Id$
- * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
+ * Use {@link org.apache.velocity.tools.view.MultiViewsTool}.
  */
-@DefaultKey("i18n")
-@InvalidScope("application")
-public class MultiViewsTool
+@Deprecated
+public class MultiViewsTool extends org.apache.velocity.tools.view.MultiViewsTool
 {
-    /**
-     * The key used to search initialization, context, and JVM
-     * parameters for the default language to use.
-     */
-    protected static final String DEFAULT_LANGUAGE_KEY =
-        "org.apache.velocity.tools.view.i18n.defaultLanguage";
-
-    /**
-     * The two character abbreviation for the request's default
-     * language.
-     */
-    protected String defaultLanguage;
-
-    protected VelocityEngine engine;
-
-    /**
-     * Creates a new uninitialized instance.  Call {@link #init}
-     * to initialize it.
-     */
-    public MultiViewsTool()
-    {
-    }
-
-    /**
-     * Extracts the default language from the specified
-     * <code>ViewContext</code>, looking first at the Velocity
-     * context, then the servlet context, then lastly at the JVM
-     * default.  This "narrow scope to wide scope" pattern makes it
-     * easy to setup language overrides at different levels within
-     * your application.
-     *
-     * @param obj the current ViewContext
-     * @throws IllegalArgumentException if the param is not a ViewContext
-     */
-    public void configure(Map params)
-    {
-        configure((ViewToolContext)params.get(ViewToolContext.CONTEXT_KEY));
-    }
-
-    protected void configure(ViewToolContext ctx)
-    {
-        defaultLanguage = (String) ctx.get(DEFAULT_LANGUAGE_KEY);
-        if (defaultLanguage == null || defaultLanguage.trim().equals(""))
-        {
-            ServletContext sc = ctx.getServletContext();
-            defaultLanguage = (String) sc.getAttribute(DEFAULT_LANGUAGE_KEY);
-            if (defaultLanguage == null || defaultLanguage.trim().equals(""))
-            {
-                // Use JVM default.
-                defaultLanguage = Locale.getDefault().getLanguage();
-            }
-        }
-
-        this.engine = ctx.getVelocityEngine();
-    }
-
     @Deprecated
     public void init(Object obj)
     {
@@ -109,74 +35,4 @@
             configure((ViewToolContext)obj);
         }
     }
-
-    /**
-     * Calls {@link #findLocalizedResource(String, String)} using the
-     * language extracted from <code>locale</code>.
-     *
-     * @see #findLocalizedResource(String, String)
-     */
-    public String findLocalizedResource(String name, Locale locale)
-    {
-        return findLocalizedResource(name, locale.getLanguage());
-    }
-
-    /**
-     * Calls {@link #findLocalizedResource(String, String)} using the
-     * default language.
-     *
-     * @see #findLocalizedResource(String, String)
-     */
-    public String findLocalizedResource(String name)
-    {
-        return findLocalizedResource(defaultLanguage);
-    }
-
-    /**
-     * <p>Finds the a localized version of the requested Velocity
-     * resource (such as a file or template) which is most appropriate
-     * for the locale of the current request.  Use in conjuction with
-     * Apache httpd's <code>MultiViews</code>, or by itself.</p>
-     *
-     * <p>Usage from a template would be something like the following:
-     * <blockquote><code><pre>
-     * #parse ($multiviews.findLocalizedResource("header.vm", "en"))
-     * #include ($multiviews.findLocalizedResource("my_page.html", "en"))
-     * #parse ($multiviews.findLocalizedResource("footer.vm", "en"))
-     * </pre></code></blockquote>
-     *
-     * You might also wrap this method using another pull/view tool
-     * which does internationalization/localization/content negation
-     * for a single point of access.</p>
-     *
-     * @param name The unlocalized name of the file to find.
-     * @param language The language to find localized context for.
-     * @return The localized file name, or <code>name</code> if it is
-     * not localizable.
-     */
-    public String findLocalizedResource(String name, String language)
-    {
-        String localizedName = name + '.' + language;
-        // templateExists() checks for static content as well
-        if (!engine.resourceExists(localizedName))
-        {
-            // Fall back to the default lanaguage.
-            String defaultLangSuffix = '.' + defaultLanguage;
-            if (localizedName.endsWith(defaultLangSuffix))
-            {
-                // Assume no localized version of the resource.
-                localizedName = name;
-            }
-            else
-            {
-                localizedName = name + defaultLangSuffix;
-                if (!engine.resourceExists(localizedName))
-                {
-                    localizedName = name;
-                }
-            }
-        }
-        return localizedName;
-    }
-
 }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools.xml?view=diff&rev=544331&r1=544330&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools.xml (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools.xml Mon Jun  4 17:24:29 2007
@@ -22,20 +22,20 @@
 <tools> 
     <data type="boolean" key="VIEW_TOOLS_AVAILABLE" value="true"/>
     <toolbox scope="request">
-        <tool class="org.apache.velocity.tools.view.tools.ContextTool"/>
-        <tool class="org.apache.velocity.tools.view.tools.CookieTool"/>
-        <tool class="org.apache.velocity.tools.view.tools.ImportTool"/>
-        <tool class="org.apache.velocity.tools.view.tools.LinkTool"/>
-        <tool class="org.apache.velocity.tools.view.tools.ParameterParser"/>
-        <tool class="org.apache.velocity.tools.view.tools.ViewRenderTool"/>
-        <tool class="org.apache.velocity.tools.view.tools.ViewResourceTool"/>
+        <tool class="org.apache.velocity.tools.view.ContextTool"/>
+        <tool class="org.apache.velocity.tools.view.CookieTool"/>
+        <tool class="org.apache.velocity.tools.view.ImportTool"/>
+        <tool class="org.apache.velocity.tools.view.LinkTool"/>
+        <tool class="org.apache.velocity.tools.view.ParameterTool"/>
+        <tool class="org.apache.velocity.tools.view.ViewRenderTool"/>
+        <tool class="org.apache.velocity.tools.view.ViewResourceTool"/>
         <!-- 
         These are not directly useable.
-        <tool class="org.apache.velocity.tools.view.tools.AbstractPagerTool"/>
-        <tool class="org.apache.velocity.tools.view.tools.AbstractSearchTool"/>
+        <tool class="org.apache.velocity.tools.view.AbstractPagerTool"/>
+        <tool class="org.apache.velocity.tools.view.AbstractSearchTool"/>
         -->
     </toolbox>
     <toolbox scope="session" createSession="false">
-        <tool class="org.apache.velocity.tools.view.tools.BrowserSnifferTool"/>
+        <tool class="org.apache.velocity.tools.view.BrowserTool"/>
     </toolbox>
 </tools>

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java?view=diff&rev=544331&r1=544330&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractPagerTool.java Mon Jun  4 17:24:29 2007
@@ -19,133 +19,15 @@
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import org.apache.velocity.tools.config.DefaultKey;
-import org.apache.velocity.tools.config.InvalidScope;
 import org.apache.velocity.tools.view.ViewContext;
 
 /**
- * <p>Abstract view tool for doing request-based pagination of
- * items in an a list.
- * </p>
- * <p><b>Usage:</b><br>
- * To use this class, you must extend it and implement
- * the setup(HttpServletRequest) method.
- * <p>
- * The setup(HttpServletRequest) method ought to extract
- * from the current request the current list index and,
- * optionally, the number of items to display per page.
- * Upon extracting these parameters, they should be set using
- * the provided setIndex(int) and setItemsPerPage(int) methods.
- * A simple implementation would be:
- * <pre>
- * public void setup(HttpServletRequest req)
- * {
- *     ParameterParser pp = new ParameterParser(req);
- *     setIndex(pp.getInt("index", 0));
- *     setItemsPerPage(pp.getInt("show", DEFAULT_ITEMS_PER_PAGE));
- * }
- * </pre>
- * You can also set the list of items to be paged at this point
- * using the setItems(List) method, or you can always set the
- * item list at another point (even from within the template).
- * </p>
- * <p>
- * Here's an example of how your subclass would be used in a template:
- * <pre>
- *   #if( $pager.hasItems() )
- *   Showing $!pager.pageDescription&lt;br&gt;
- *     #set( $i = $pager.index )
- *     #foreach( $item in $pager.page )
- *       ${i}. $!item &lt;br&gt;
- *       #set( $i = $i + 1 )
- *     #end
- *     &lt;br&gt;
- *     #if ( $pager.pagesAvailable &gt; 1 )
- *       #set( $pagelink = $link.self.param("show",$!pager.itemsPerPage) )
- *       #if( $pager.prevIndex )
- *           &lt;a href="$pagelink.param('index',$!pager.prevIndex)"&gt;Prev&lt;/a&gt;
- *       #end
- *       #foreach( $index in $pager.slip )
- *         #if( $index == $pager.index )
- *           &lt;b&gt;$pager.pageNumber&lt;/b&gt;
- *         #else
- *           &lt;a href="$pagelink.param('index',$!index)"&gt;$!pager.getPageNumber($index)&lt;/a&gt;
- *         #end
- *       #end
- *       #if( $pager.nextIndex )
- *           &lt;a href="$pagelink.param('index',$!pager.nextIndex)"&gt;Next&lt;/a&gt;
- *       #end
- *     #end
- *   #else
- *   No items in list.
- *   #end
- * </pre>
- *
- * The output of this might look like:<br><br>
- *   Showing 1-5 of 8<br>
- *   1. foo<br>
- *   2. bar<br>
- *   3. blah<br>
- *   4. woogie<br>
- *   5. baz<br><br>
- *   <b>1</b> <a href="">2</a> <a href="">Next</a>
- * </p>
- * <p>
- * <b>Example toolbox.xml configuration:</b>
- * <pre>&lt;tool&gt;
- *   &lt;key&gt;pager&lt;/key&gt;
- *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;com.foo.tools.MyPagerTool&lt;/class&gt;
- * &lt;/tool&gt;
- * </pre>
- * </p>
- *
- * @author Nathan Bubna
- * @since VelocityTools 1.2
- * @version $Revision$ $Date$
+ * Use {@link org.apache.velocity.tools.view.AbstractPagerTool}
  */
-@DefaultKey("pager")
-@InvalidScope({"application","session"})
-public abstract class AbstractPagerTool
+@Deprecated
+public abstract class AbstractPagerTool extends
+    org.apache.velocity.tools.view.AbstractPagerTool
 {
-
-    /** the default number of items shown per page */
-    public static final int DEFAULT_ITEMS_PER_PAGE = 10;
-
-    /** the default max number of page indices to list */
-    public static final int DEFAULT_SLIP_SIZE = 20;
-
-    /** the key under which items are stored in session */
-    protected static final String STORED_ITEMS_KEY =
-        AbstractPagerTool.class.getName();
-
-    private List items;
-    private int index = 0;
-    private int slipSize = DEFAULT_SLIP_SIZE;
-    private int itemsPerPage = DEFAULT_ITEMS_PER_PAGE;
-    protected HttpSession session;
-
-    /**
-     * Initializes this tool with the specified {@link HttpServletRequest}.
-     * This is required for this tool to operate and will throw a
-     * NullPointerException if this is not set or is set to {@code null}.
-     */
-    public void setRequest(HttpServletRequest request)
-    {
-        if (request == null)
-        {
-            throw new NullPointerException("request should not be null");
-        }
-        this.session = request.getSession(false);
-        setup(request);
-    }
-
     @Deprecated
     public void init(Object obj)
     {
@@ -154,431 +36,4 @@
             setRequest(((ViewContext)obj).getRequest());
         }
     }
-
-    /**
-     * Abstract method to make it as obvious as possible just
-     * where implementing classes should be retrieving and configuring
-     * display parameters.
-     * <p>A simple implementation would be:
-     * <pre>
-     * public void setup(HttpServletRequest req)
-     * {
-     *     ParameterParser pp = new ParameterParser(req);
-     *     setIndex(pp.getInt("index", 0));
-     *     setItemsPerPage(pp.getInt("show", DEFAULT_ITEMS_PER_PAGE));
-     * }
-     * </pre>
-     *
-     * @param request the current HttpServletRequest
-     */
-    public abstract void setup(HttpServletRequest request);
-
-    /*  ---------------------- mutators ----------------------------- */
-
-
-    /**
-     * Sets the item list to null, page index to zero, and
-     * items per page to the default.
-     */
-    public void reset()
-    {
-        items = null;
-        index = 0;
-        itemsPerPage = DEFAULT_ITEMS_PER_PAGE;
-    }
-
-    /**
-     * Sets the List to page through.
-     *
-     * @param items - the  {@link List} of items to be paged through
-     */
-    public void setItems(List items)
-    {
-        this.items = items;
-        setStoredItems(items);
-    }
-
-    /**
-     * Sets the index of the first result in the current page
-     *
-     * @param index the result index to start the current page with
-     */
-    public void setIndex(int index)
-    {
-        if (index < 0)
-        {
-            /* quietly override to a reasonable value */
-            index = 0;
-        }
-        this.index = index;
-    }
-
-    /**
-     * Sets the number of items returned in a page of items
-     *
-     * @param itemsPerPage the number of items to be returned per page
-     */
-    public void setItemsPerPage(int itemsPerPage)
-    {
-        if (itemsPerPage < 1)
-        {
-            /* quietly override to a reasonable value */
-            itemsPerPage = DEFAULT_ITEMS_PER_PAGE;
-        }
-        this.itemsPerPage = itemsPerPage;
-    }
-
-    /**
-     * Sets the number of result page indices for {@link #getSlip} to list.
-     * (for google-ish result page links).
-     *
-     * @see #getSlip
-     * @param slipSize - the number of result page indices to list
-     */
-    public void setSlipSize(int slipSize)
-    {
-        if (slipSize < 2)
-        {
-            /* quietly override to a reasonable value */
-            slipSize = DEFAULT_SLIP_SIZE;
-        }
-        this.slipSize = slipSize;
-    }
-
-    /*  ---------------------- accessors ----------------------------- */
-
-    /**
-     * Returns the set number of items to be displayed per page of items
-     *
-     * @return current number of items shown per page
-     */
-    public int getItemsPerPage()
-    {
-        return itemsPerPage;
-    }
-
-    /**
-     * Returns the number of result page indices {@link #getSlip}
-     * will return per request (if available).
-     *
-     * @return the number of result page indices {@link #getSlip}
-     *         will try to return
-     */
-    public int getSlipSize()
-    {
-        return slipSize;
-    }
-
-
-    /**
-     * Returns the current search result index.
-     *
-     * @return the index for the beginning of the current page
-     */
-    public int getIndex()
-    {
-        return index;
-    }
-
-
-    /**
-     * Checks whether or not the result list is empty.
-     *
-     * @return <code>true</code> if the result list is not empty.
-     */
-    public boolean hasItems()
-    {
-        return !getItems().isEmpty();
-    }
-
-    /**
-     * Returns the item list. This is guaranteed
-     * to never return <code>null</code>.
-     *
-     * @return {@link List} of all the items
-     */
-    public List getItems()
-    {
-        if (items == null)
-        {
-            items = getStoredItems();
-        }
-
-        return (items != null) ? items : Collections.EMPTY_LIST;
-    }
-
-    /**
-     * Returns the index of the last item on the current page of results
-     * (as determined by the current index, items per page, and
-     * the number of items).  If there is no current page, then null is
-     * returned.
-     *
-     * @return index for the last item on this page or <code>null</code>
-     *         if none exists
-     * @since VelocityTools 1.3
-     */
-    public Integer getLastIndex()
-    {
-        if (!hasItems())
-        {
-            return null;
-        }
-        return new Integer(Math.min(getTotal() - 1, index + itemsPerPage - 1));
-    }
-
-    /**
-     * Returns the index for the next page of items
-     * (as determined by the current index, items per page, and
-     * the number of items).  If no "next page" exists, then null is
-     * returned.
-     *
-     * @return index for the next page or <code>null</code> if none exists
-     */
-    public Integer getNextIndex()
-    {
-        int next = index + itemsPerPage;
-        if (next < getTotal())
-        {
-            return new Integer(next);
-        }
-        return null;
-    }
-
-    /**
-     * Returns the index of the first item on the current page of results
-     * (as determined by the current index, items per page, and
-     * the number of items).  If there is no current page, then null is
-     * returned. This is different than {@link #getIndex()} in that it
-     * is adjusted to fit the reality of the items available and is not a
-     * mere accessor for the current, user-set index value.
-     *
-     * @return index for the first item on this page or <code>null</code>
-     *         if none exists
-     * @since VelocityTools 1.3
-     */
-    public Integer getFirstIndex()
-    {
-        if (!hasItems())
-        {
-            return null;
-        }
-        return new Integer(Math.min(getTotal() - 1, index));
-    }
-
-    /**
-     * Return the index for the previous page of items
-     * (as determined by the current index, items per page, and
-     * the number of items).  If no "next page" exists, then null is
-     * returned.
-     *
-     * @return index for the previous page or <code>null</code> if none exists
-     */
-    public Integer getPrevIndex()
-    {
-        int prev = Math.min(index, getTotal()) - itemsPerPage;
-        if (index > 0)
-        {
-            return new Integer(Math.max(0, prev));
-        }
-        return null;
-    }
-
-    /**
-     * Returns the number of pages that can be made from this list
-     * given the set number of items per page.
-     */
-    public int getPagesAvailable()
-    {
-        return (int)Math.ceil(getTotal() / (double)itemsPerPage);
-    }
-
-
-    /**
-     * Returns the current "page" of search items.
-     *
-     * @return a {@link List} of items for the "current page"
-     */
-    public List getPage()
-    {
-        /* return null if we have no items */
-        if (!hasItems())
-        {
-            return null;
-        }
-        /* quietly keep the page indices to legal values for robustness' sake */
-        int start = getFirstIndex().intValue();
-        int end = getLastIndex().intValue() + 1;
-        return getItems().subList(start, end);
-    }
-
-    /**
-     * Returns the "page number" for the specified index.  Because the page
-     * number is used for the user interface, the page numbers are 1-based.
-     *
-     * @param i the index that you want the page number for
-     * @return the approximate "page number" for the specified index or
-     *         <code>null</code> if there are no items
-     */
-    public Integer getPageNumber(int i)
-    {
-        if (!hasItems())
-        {
-            return null;
-        }
-        return new Integer(1 + i / itemsPerPage);
-    }
-
-
-    /**
-     * Returns the "page number" for the current index.  Because the page
-     * number is used for the user interface, the page numbers are 1-based.
-     *
-     * @return the approximate "page number" for the current index or
-     *         <code>null</code> if there are no items
-     */
-    public Integer getPageNumber()
-    {
-        return getPageNumber(index);
-    }
-
-    /**
-     * Returns the total number of items available.
-     * @since VelocityTools 1.3
-     */
-    public int getTotal()
-    {
-        if (!hasItems())
-        {
-            return 0;
-        }
-        return getItems().size();
-    }
-
-    /**
-     * <p>Returns a description of the current page.  This implementation
-     * displays a 1-based range of result indices and the total number
-     * of items.  (e.g. "1 - 10 of 42" or "7 of 7")  If there are no items,
-     * this will return "0 of 0".</p>
-     *
-     * <p>Sub-classes may override this to provide a customized
-     * description (such as one in another language).</p>
-     *
-     * @return a description of the current page
-     */
-    public String getPageDescription()
-    {
-        if (!hasItems())
-        {
-            return "0 of 0";
-        }
-
-        StringBuffer out = new StringBuffer();
-        int first = getFirstIndex().intValue() + 1;
-        int total = getTotal();
-        if (first >= total)
-        {
-            out.append(total);
-            out.append(" of ");
-            out.append(total);
-        }
-        else
-        {
-            int last = getLastIndex().intValue() + 1;
-            out.append(first);
-            out.append(" - ");
-            out.append(last);
-            out.append(" of ");
-            out.append(total);
-        }
-        return out.toString();
-    }
-
-    /**
-     * Returns a <b>S</b>liding <b>L</b>ist of <b>I</b>ndices for <b>P</b>ages
-     * of items.
-     *
-     * <p>Essentially, this returns a list of item indices that correspond
-     * to available pages of items (as based on the set items-per-page).
-     * This makes it relativly easy to do a google-ish set of links to
-     * available pages.</p>
-     *
-     * <p>Note that this list of Integers is 0-based to correspond with the
-     * underlying result indices and not the displayed page numbers (see
-     * {@link #getPageNumber}).</p>
-     *
-     * @return {@link List} of Integers representing the indices of result
-     *         pages or empty list if there's one or less pages available
-     */
-    public List getSlip()
-    {
-        /* return an empty list if there's no pages to list */
-        int totalPgs = getPagesAvailable();
-        if (totalPgs <= 1)
-        {
-            return Collections.EMPTY_LIST;
-        }
-
-        /* page number is 1-based so decrement it */
-        int curPg = getPageNumber().intValue() - 1;
-
-        /* start at zero or just under half of max slip size
-         * this keeps "forward" and "back" pages about even
-         * but gives preference to "forward" pages */
-        int slipStart = Math.max(0, (curPg - (slipSize / 2)));
-
-        /* push slip end as far as possible */
-        int slipEnd = Math.min(totalPgs, (slipStart + slipSize));
-
-        /* if we're out of "forward" pages, then push the
-         * slip start toward zero to maintain slip size */
-        if (slipEnd - slipStart < slipSize)
-        {
-            slipStart = Math.max(0, slipEnd - slipSize);
-        }
-
-        /* convert 0-based page numbers to indices and create list */
-        List slip = new ArrayList(slipEnd - slipStart);
-        for (int i=slipStart; i < slipEnd; i++)
-        {
-            slip.add(new Integer(i * itemsPerPage));
-        }
-        return slip;
-    }
-
-    /*  ---------------------- protected methods ------------------------  */
-
-    /**
-     * Retrieves stored search items (if any) from the user's
-     * session attributes.
-     *
-     * @return the {@link List} retrieved from memory
-     */
-    protected List getStoredItems()
-    {
-        if (session != null)
-        {
-            return (List)session.getAttribute(STORED_ITEMS_KEY);
-        }
-        return null;
-    }
-
-
-    /**
-     * Stores current search items in the user's session attributes
-     * (if one currently exists) in order to do efficient result pagination.
-     *
-     * <p>Override this to store search items somewhere besides the
-     * HttpSession or to prevent storage of items across requests. In
-     * the former situation, you must also override getStoredItems().</p>
-     *
-     * @param items the {@link List} to be stored
-     */
-    protected void setStoredItems(List items)
-    {
-        if (session != null)
-        {
-            session.setAttribute(STORED_ITEMS_KEY, items);
-        }
-    }
-
 }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java?view=diff&rev=544331&r1=544330&r2=544331
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/AbstractSearchTool.java Mon Jun  4 17:24:29 2007
@@ -19,169 +19,15 @@
  * under the License.
  */
 
-import java.util.Collections;
 import java.util.List;
-import org.apache.velocity.tools.config.DefaultKey;
-import org.apache.velocity.tools.config.InvalidScope;
 
 /**
- * <p>Abstract view tool for doing "searching" and robust
- * pagination of search results.  The goal here is to provide a simple
- * and uniform API for "search tools" that can be used in velocity
- * templates (or even a standard Search.vm template).  In particular,
- * this class provides good support for result pagination and some
- * very simple result caching.
- * </p>
- * <p><b>Usage:</b><br>
- * To use this class, you must extend it and implement
- * the setup(HttpServletRequest) and executeQuery(Object)
- * methods.
- * <p>
- * The setup(HttpServletRequest) method ought to extract
- * from the current request the search criteria, the current
- * list index, and optionally, the number of items to display
- * per page of results.  Upon extracting these parameters, they
- * should be set using the provided setCriteria(Object),
- * setIndex(int), and setItemsPerPage(int) methods. A simple
- * implementation would be:
- * <pre>
- * public void setup(HttpServletRequest req)
- * {
- *     ParameterParser pp = new ParameterParser(req);
- *     setCriteria(pp.getString("find"));
- *     setIndex(pp.getInt("index", 0));
- *     setItemsPerPage(pp.getInt("show", DEFAULT_ITEMS_PER_PAGE));
- * }
- * </pre>
- * <p>
- * The setCriteria(Object) method takes an Object in order to
- * allow the search criteria to meet your needs.  Your criteria
- * may be as simple as a single string, an array of strings, or
- * whatever you like.  The value passed into this method is that
- * which will ultimately be passed into executeQuery(Object) to
- * perform the search and return a list of results.  A simple
- * implementation might be like:
- * <pre>
- * protected List executeQuery(Object crit)
- * {
- *     return MyDbUtils.getFooBarsMatching((String)crit);
- * }
- * </pre>
- * <p>
- * Here's an example of how your subclass would be used in a template:
- * <pre>
- *   &lt;form name="search" method="get" action="$link.setRelative('search.vm')"&gt;
- *     &lt;input type="text"name="find" value="$!search.criteria"&gt;
- *     &lt;input type="submit" value="Find"&gt;
- *   &lt;/form&gt;
- *   #if( $search.hasItems() )
- *   Showing $!search.pageDescription&lt;br&gt;
- *     #set( $i = $search.index )
- *     #foreach( $item in $search.page )
- *       ${i}. $!item &lt;br&gt;
- *       #set( $i = $i + 1 )
- *     #end
- *     &lt;br&gt;
- *     #if ( $search.pagesAvailable &gt; 1 )
- *       #set( $pagelink = $link.setRelative('search.vm').addQueryData("find",$!search.criteria).addQueryData("show",$!search.itemsPerPage) )
- *       #if( $search.prevIndex )
- *           &lt;a href="$pagelink.addQueryData('index',$!search.prevIndex)"&gt;Prev&lt;/a&gt;
- *       #end
- *       #foreach( $index in $search.slip )
- *         #if( $index == $search.index )
- *           &lt;b&gt;$search.pageNumber&lt;/b&gt;
- *         #else
- *           &lt;a href="$pagelink.addQueryData('index',$!index)"&gt;$!search.getPageNumber($index)&lt;/a&gt;
- *         #end
- *       #end
- *       #if( $search.nextIndex )
- *           &lt;a href="$pagelink.addQueryData('index',$!search.nextIndex)"&gt;Next&lt;/a&gt;
- *       #end
- *     #end
- *   #elseif( $search.criteria )
- *   Sorry, no matches were found for "$!search.criteria".
- *   #else
- *   Please enter a search term
- *   #end
- * </pre>
- *
- * The output of this might look like:<br><br>
- *   <form method="get" action="">
- *    <input type="text" value="foo">
- *    <input type="submit" value="Find">
- *   </form>
- *   Showing 1-5 of 8<br>
- *   1. foo<br>
- *   2. bar<br>
- *   3. blah<br>
- *   4. woogie<br>
- *   5. baz<br><br>
- *   <b>1</b> <a href="">2</a> <a href="">Next</a>
- * </p>
- * <p>
- * <b>Example toolbox.xml configuration:</b>
- * <pre>&lt;tool&gt;
- *   &lt;key&gt;search&lt;/key&gt;
- *   &lt;scope&gt;request&lt;/scope&gt;
- *   &lt;class&gt;com.foo.tools.MySearchTool&lt;/class&gt;
- * &lt;/tool&gt;
- * </pre>
- * </p>
- *
- * @author Nathan Bubna
- * @since VelocityTools 1.0
- * @version $Revision$ $Date$
+ * Use {@link org.apache.velocity.tools.view.tools.AbstractSearchTool}
  */
-@DefaultKey("search")
-@InvalidScope({"application","session"})
-public abstract class AbstractSearchTool extends AbstractPagerTool
+@Deprecated
+public abstract class AbstractSearchTool extends
+    org.apache.velocity.tools.view.AbstractSearchTool
 {
-    /** the key under which StoredResults are kept in session */
-    protected static final String STORED_RESULTS_KEY =
-        StoredResults.class.getName();
-
-    private Object criteria;
-
-
-    /*  ---------------------- mutators -----------------------------  */
-
-    /**
-     * Sets the criteria and results to null, page index to zero, and
-     * items per page to the default.
-     */
-    public void reset()
-    {
-        super.reset();
-        criteria = null;
-    }
-
-
-    /**
-     * Sets the criteria for this search.
-     *
-     * @param criteria - the criteria used for this search
-     */
-    public void setCriteria(Object criteria)
-    {
-        this.criteria = criteria;
-    }
-
-
-    /*  ---------------------- accessors -----------------------------  */
-
-    /**
-     * Return the criteria object for this request.
-     * (for a simple search mechanism, this will typically be
-     *  just a java.lang.String)
-     *
-     * @return criteria object
-     */
-    public Object getCriteria()
-    {
-        return criteria;
-    }
-
-
     /**
      * @deprecated Use {@link AbstractPagerTool#hasItems()}
      */
@@ -198,169 +44,5 @@
     {
         return getItems();
     }
-
-
-    /**
-     * Gets the results for the given criteria either in memory
-     * or by performing a new query for them.  If the criteria
-     * is null, an empty list will be returned.
-     *
-     * @return {@link List} of all items for the criteria
-     */
-    public List getItems()
-    {
-        /* return empty list if we have no criteria */
-        if (criteria == null)
-        {
-            return Collections.EMPTY_LIST;
-        }
-
-        /* get the current list (should never return null!) */
-        List list = super.getItems();
-
-        /* if empty, execute a query for the criteria */
-        if (list.isEmpty())
-        {
-            /* perform a new query */
-            list = executeQuery(criteria);
-
-            /* because we can't trust executeQuery() not to return null
-               and getItems() must _never_ return null... */
-            if (list == null)
-            {
-                list = Collections.EMPTY_LIST;
-            }
-
-            /* save the new results */
-            setItems(list);
-        }
-        return list;
-    }
-
-
-    /*  ---------------------- protected methods -----------------------------  */
-
-    protected List getStoredItems()
-    {
-        StoredResults sr = getStoredResults();
-
-        /* if the criteria equals that of the stored results,
-         * then return the stored result list */
-        if (sr != null && criteria.equals(sr.getCriteria()))
-        {
-            return sr.getList();
-        }
-        return null;
-    }
-
-
-    protected void setStoredItems(List items)
-    {
-        setStoredResults(new StoredResults(criteria, items));
-    }
-
-
-    /**
-     * Executes a query for the specified criteria.
-     *
-     * <p>This method must be implemented! A simple
-     * implementation might be something like:
-     * <pre>
-     * protected List executeQuery(Object crit)
-     * {
-     *     return MyDbUtils.getFooBarsMatching((String)crit);
-     * }
-     * </pre>
-     *
-     * @return a {@link List} of results for this query
-     */
-    protected abstract List executeQuery(Object criteria);
-
-
-    /**
-     * Retrieves stored search results (if any) from the user's
-     * session attributes.
-     *
-     * @return the {@link StoredResults} retrieved from memory
-     */
-    protected StoredResults getStoredResults()
-    {
-        if (session != null)
-        {
-            return (StoredResults)session.getAttribute(STORED_RESULTS_KEY);
-        }
-        return null;
-    }
-
-
-    /**
-     * Stores current search results in the user's session attributes
-     * (if one currently exists) in order to do efficient result pagination.
-     *
-     * <p>Override this to store search results somewhere besides the
-     * HttpSession or to prevent storage of results across requests. In
-     * the former situation, you must also override getStoredResults().</p>
-     *
-     * @param results the {@link StoredResults} to be stored
-     */
-    protected void setStoredResults(StoredResults results)
-    {
-        if (session != null)
-        {
-            session.setAttribute(STORED_RESULTS_KEY, results);
-        }
-    }
-
-
-    /*  ---------------------- utility class -----------------------------  */
-
-    /**
-     * Simple utility class to hold a criterion and its result list.
-     * <p>
-     * This class is by default stored in a user's session,
-     * so it implements Serializable, but its members are
-     * transient. So functionally, it is not serialized and
-     * the last results/criteria will not be persisted if
-     * the session is serialized.
-     * </p>
-     */
-    public static class StoredResults implements java.io.Serializable
-    {
-        /** serial version id */
-        private static final long serialVersionUID = 4503130168585978169L;
-
-        private transient Object crit;
-        private transient List list;
-
-        /**
-         * Creates a new instance.
-         *
-         * @param crit the criteria for these results
-         * @param list the {@link List} of results to store
-         */
-        public StoredResults(Object crit, List list)
-        {
-            this.crit = crit;
-            this.list = list;
-        }
-
-        /**
-         * @return the stored criteria object
-         */
-        public Object getCriteria()
-        {
-            return crit;
-        }
-
-        /**
-         * @return the stored {@link List} of results
-         */
-        public List getList()
-        {
-            return list;
-        }
-
-    }
-
 
 }



Mime
View raw message