velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r671010 - in /velocity/tools/trunk: src/main/java/org/apache/velocity/tools/generic/ src/test/java/org/apache/velocity/tools/ xdocs/
Date Tue, 24 Jun 2008 03:40:42 GMT
Author: nbubna
Date: Mon Jun 23 20:40:41 2008
New Revision: 671010

URL: http://svn.apache.org/viewvc?rev=671010&view=rev
Log:
with apologies to anyone who extended AbstractLockConfig since beta1, but it really needn't
be abstract and is better fixed now, before beta2

Modified:
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AbstractLockConfig.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ClassTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ContextTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LocaleConfig.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
    velocity/tools/trunk/src/test/java/org/apache/velocity/tools/ClassToolTests.java
    velocity/tools/trunk/xdocs/creatingtools.xml

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AbstractLockConfig.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AbstractLockConfig.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AbstractLockConfig.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AbstractLockConfig.java
Mon Jun 23 20:40:41 2008
@@ -19,120 +19,24 @@
  * under the License.
  */
 
-import java.util.Map;
-
 /**
- * <p>Implements common logic and constants for tools which automatically
- * locks down the {@code public void configure(Map params)} method after
- * it is called once.
- * This keeps application or session scoped tools thread-safe in templates,
- * which generally have access to the tool after configuration has happened.
- * </p><p>
- * It also provides for a separate "safe mode" setting which tells
- * tools to block any functions that may pose a security threat. This,
- * of course, is set to {@code true} by default.
- * </p><p>
- * Once "locked down", the {@link #configure(Map)} may still be called,
- * however it will do nothing (unless some subclass is foolish enough to
- * override it and not check if {@link #isConfigLocked} before changing
- * configurations.  The proper method for subclasses to override is
- * {@link #configure(ValueParser)} which will only be called by 
- * {@link #configure(Map)} when the {@link #isConfigLocked} is false
- * (i.e. the first time only).
+ * <p>Apologies to anyone who stepped up to use Tools 2.0-beta1
+ * and made their tools extend this class.  Please just extend
+ * the SafeConfig class now.  It is better named and no longer
+ * requires implementation of {@link #configure(ValueParser)},
+ * as that may not be needed by subclasses that may simply want
+ * to know safeMode and/or lockConfig settings.
+ * </p>
+ * <p>
+ * Sorry for any inconvenience, but this class will be removed
+ * before Tools 2.0 goes final.  Please update your subclasses
+ * before that time.  Thanks.
  * </p>
  *
- * @author Nathan Bubna
  * @since VelocityTools 2.0
+ * @deprecated Use {@link SafeConfig} instead
  */
-public abstract class AbstractLockConfig
+@Deprecated
+public abstract class AbstractLockConfig extends SafeConfig
 {
-    /**
-     * The key used for specifying whether or not to prevent templates
-     * from reconfiguring this tool.  The default is true.
-     */
-    public static final String LOCK_CONFIG_KEY = "lockConfig";
-    @Deprecated
-    public static final String OLD_LOCK_CONFIG_KEY = "lock-config";
-
-    /**
-     * Many tools interested in locking configure() also have other
-     * things they wish to secure.  This key controls that property.
-     * The default value is true, of course.
-     */
-    public static final String SAFE_MODE_KEY = "safeMode";
-
-    private boolean configLocked = false;
-    private boolean safeMode = false;
-
-    /**
-     * Only allow subclass access to this.
-     */
-    protected void setLockConfig(boolean lock)
-    {
-        this.configLocked = lock;
-    }
-
-    protected void setSafeMode(boolean safe)
-    {
-        this.safeMode = safe;
-    }
-
-    /**
-     * Returns {@code true} if the {@link #configure(Map)} method
-     * has been locked.
-     */
-    public boolean isConfigLocked()
-    {
-        return this.configLocked;
-    }
-
-    /**
-     * Returns {@code true} if this tool is in "safe mode".
-     */
-    public boolean isSafeMode()
-    {
-        return this.safeMode;
-    }
-
-    /**
-     * If {@link #isConfigLocked} returns {@code true}, then this method
-     * does nothing; otherwise, if {@code false}, this will create a new
-     * {@link ValueParser} from the specified Map of params and call
-     * {@link #configure(ValueParser)} with it.  Then this will check
-     * the parameters itself to find out whether or not the configuration
-     * for this tool should be put into safe mode or have its config locked.
-     * The safe mode value should be a boolean under the key
-     * {@link #SAFE_MODE_KEY} and the lock value should be a boolean
-     * under the key {@link #LOCK_CONFIG_KEY}.
-     */
-    public void configure(Map params)
-    {
-        if (!isConfigLocked())
-        {
-            ValueParser values = new ValueParser(params);
-            configure(values);
-
-            setSafeMode(values.getBoolean(SAFE_MODE_KEY, true));
-
-            // check under the new key
-            Boolean lock = values.getBoolean(LOCK_CONFIG_KEY);
-            if (lock == null)
-            {
-                // now check the old key (for now)
-                // by default, lock down this method after use
-                // to prevent templates from re-configuring this instance
-                lock = values.getBoolean(OLD_LOCK_CONFIG_KEY, Boolean.TRUE);
-            }
-            setLockConfig(lock.booleanValue());
-        }
-    }
-
-    /**
-     * Does the actual configuration. This is protected, so
-     * subclasses may share the same ValueParser and call configure
-     * at any time, while preventing templates from doing so when 
-     * configure(Map) is locked.
-     */
-    protected abstract void configure(ValueParser values);
-
 }

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
Mon Jun 23 20:40:41 2008
@@ -56,7 +56,7 @@
  * @version $Revision$ $Date$
  */
 @DefaultKey("alternator")
-public class AlternatorTool extends AbstractLockConfig
+public class AlternatorTool extends SafeConfig
 {
     @Deprecated
     public static final String OLD_AUTO_ALTERNATE_DEFAULT_KEY = "auto-alternate";

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ClassTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ClassTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ClassTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ClassTool.java Mon
Jun 23 20:40:41 2008
@@ -65,7 +65,7 @@
  * @version $Id: ClassTool.java 463298 2006-10-12 16:10:32Z henning $
  */
 @DefaultKey("class")
-public class ClassTool extends AbstractLockConfig
+public class ClassTool extends SafeConfig
 {
     public static final String INSPECT_KEY = "inspect";
     public static final String SHOW_DEPRECATED_KEY = "showDeprecated";

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ContextTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ContextTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ContextTool.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ContextTool.java
Mon Jun 23 20:40:41 2008
@@ -57,7 +57,7 @@
  */
 @DefaultKey("context")
 @InvalidScope({Scope.APPLICATION,Scope.SESSION})
-public class ContextTool extends AbstractLockConfig
+public class ContextTool extends SafeConfig
 {
     protected Context context;
     protected Map<String,Object> toolbox;

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
Mon Jun 23 20:40:41 2008
@@ -68,7 +68,7 @@
  * @version $Id: DisplayTool.java 463298 2006-10-12 16:10:32Z henning $
  */
 @DefaultKey("display")
-public class DisplayTool extends AbstractLockConfig
+public class DisplayTool extends SafeConfig
 {
     public static final String LIST_DELIM_KEY = "listDelim";
     public static final String LIST_FINAL_DELIM_KEY = "listFinalDelim";

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java Mon
Jun 23 20:40:41 2008
@@ -93,7 +93,7 @@
  * @see StringEscapeUtils
  */
 @DefaultKey("esc")
-public class EscapeTool extends AbstractLockConfig
+public class EscapeTool extends SafeConfig
 {
     public static final String DEFAULT_KEY = "esc";
     

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/FieldTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/FieldTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/FieldTool.java Mon
Jun 23 20:40:41 2008
@@ -75,7 +75,7 @@
  * @version $Id: FieldTool.java 463298 2006-10-12 16:10:32Z henning $
  */
 @DefaultKey("field")
-public class FieldTool extends AbstractLockConfig
+public class FieldTool extends SafeConfig
 {
     /**
      * The key used for specifying which classes should be inspected

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java Mon
Jun 23 20:40:41 2008
@@ -77,7 +77,7 @@
  */
 @DefaultKey("link")
 @ValidScope(Scope.REQUEST)
-public class LinkTool extends AbstractLockConfig implements Cloneable
+public class LinkTool extends SafeConfig implements Cloneable
 {
     /** Standard HTML delimiter for query data ('&') */
     public static final String HTML_QUERY_DELIMITER = "&";
@@ -955,7 +955,7 @@
      * If the tool is not in "safe mode"--which it is by default--
      * this will return the {@link URI} representation of this instance,
      * if any.
-     * @see AbstractLockConfig#isSafeMode()
+     * @see SafeConfig#isSafeMode()
      */
     public URI getUri()
     {

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LocaleConfig.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LocaleConfig.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LocaleConfig.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LocaleConfig.java
Mon Jun 23 20:40:41 2008
@@ -29,7 +29,7 @@
  * @author Nathan Bubna
  * @since VelocityTools 2.0
  */
-public class LocaleConfig extends AbstractLockConfig
+public class LocaleConfig extends SafeConfig
 {
     /**
      * The default {@link Locale} to be used when none is specified.

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/RenderTool.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/RenderTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/RenderTool.java Mon
Jun 23 20:40:41 2008
@@ -99,7 +99,7 @@
  * @version $Revision$ $Date$
  */
 @DefaultKey("render")
-public class RenderTool extends AbstractLockConfig
+public class RenderTool extends SafeConfig
 {
     /**
      * The maximum number of loops allowed when recursing.

Modified: velocity/tools/trunk/src/test/java/org/apache/velocity/tools/ClassToolTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/java/org/apache/velocity/tools/ClassToolTests.java?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/src/test/java/org/apache/velocity/tools/ClassToolTests.java (original)
+++ velocity/tools/trunk/src/test/java/org/apache/velocity/tools/ClassToolTests.java Mon Jun
23 20:40:41 2008
@@ -29,6 +29,7 @@
 import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.generic.ValueParser;
+import org.apache.velocity.tools.view.AbstractSearchTool;
 
 /**
  * <p>Tests for {@link ClassTool}</p>
@@ -195,7 +196,7 @@
         // default type is java.lang.Object which has no super
         assertNull(classTool.inspectSuper());
         classTool.setType(ClassTool.class);
-        assertEquals(classTool.inspectSuper().getType(), AbstractLockConfig.class);
+        assertEquals(classTool.inspectSuper().getType(), SafeConfig.class);
     }
 
     public @Test void methodInspect_Class() throws Exception
@@ -226,7 +227,7 @@
         ClassTool classTool = new ClassTool();
         // default type is java.lang.Object
         assertFalse(classTool.isAbstract());
-        classTool.setType(AbstractLockConfig.class);
+        classTool.setType(AbstractSearchTool.class);
         assertTrue(classTool.isAbstract());
     }
 

Modified: velocity/tools/trunk/xdocs/creatingtools.xml
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/xdocs/creatingtools.xml?rev=671010&r1=671009&r2=671010&view=diff
==============================================================================
--- velocity/tools/trunk/xdocs/creatingtools.xml (original)
+++ velocity/tools/trunk/xdocs/creatingtools.xml Mon Jun 23 20:40:41 2008
@@ -129,7 +129,7 @@
             on your template authors to avoid using those setters or just want
             to make sure nothing can be changed from within the template,
             you will probably want to use the configure() method and have
-            your tool extend AbstractLockConfig or one of its subclasses.
+            your tool extend SafeConfig or one of its subclasses.
             (This is discussed more later.)
             </p>
         </subsection>
@@ -168,7 +168,7 @@
     <section name="Support Classes">
         <subsection name="Base Classes">
             <p>
-            <a href="javadoc/org/apache/velocity/tools/generic/AbstractLockConfig.html">AbstractLockConfig</a>
+            <a href="javadoc/org/apache/velocity/tools/generic/SafeConfig.html">SafeConfig</a>
             - This serves as a base class for tools who need to have
             their configuration be read-only for thread-safety or
             other reasons.  By default, tools which extend this can
@@ -176,7 +176,7 @@
             </p>
             <p>
             <a href="javadoc/org/apache/velocity/tools/generic/LocaleConfig.html">LocaleConfig</a>
-            - Subclass of AbstractLockConfig that has standardized
+            - Subclass of SafeConfig that has standardized
             support for configuring a Locale for the tool to use as
             its default.
             </p>
@@ -294,7 +294,7 @@
             its permissions, its class's permissions or else put some sort of
             guard into the implementation of the method that renders it harmless
             when used by a template.  See the implementation of <code>configure(Map)</code>
-            in <a href="javadoc/org/apache/velocity/tools/generic/AbstractLockConfig.html">AbstractLockConfig</a>
+            in <a href="javadoc/org/apache/velocity/tools/generic/SafeConfig.html">SafeConfig</a>
             for an example of the latter option.
             </p>
             <p>
@@ -318,7 +318,7 @@
             that may not know what each other are doing at any one time.
             </p>
             <p>
-            <a href="javadoc/org/apache/velocity/tools/generic/AbstractLockConfig.html">AbstractLockConfig</a>
+            <a href="javadoc/org/apache/velocity/tools/generic/SafeConfig.html">SafeConfig</a>
             and its subclasses can help you have safely configurable tools
             in any scope.  They do this by only allowing the public
             <code>configure(Map)</code> method to be called once.  All other



Mime
View raw message