diff options
author | Claude Brisson <cbrisson@apache.org> | 2019-03-06 21:19:34 +0000 |
---|---|---|
committer | Claude Brisson <cbrisson@apache.org> | 2019-03-06 21:19:34 +0000 |
commit | f31d3d3f1e419db9f7400b0f1e3d7844f5493693 (patch) | |
tree | d5717ccd03fa2c51363f608005d8e3206554105d /velocity-engine-core/src/main/java/org/apache/velocity/runtime | |
parent | edbabf4c93e8b1cd5f94f157fdde403a7b5c8d31 (diff) | |
download | apache-velocity-engine-f31d3d3f1e419db9f7400b0f1e3d7844f5493693.tar.gz |
[engine] configuration key names refactoring proposal
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/branches/VELOCITY-909@1854947 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/main/java/org/apache/velocity/runtime')
12 files changed, 466 insertions, 94 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/DeprecatedRuntimeConstants.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/DeprecatedRuntimeConstants.java new file mode 100644 index 00000000..32ffdaf5 --- /dev/null +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/DeprecatedRuntimeConstants.java @@ -0,0 +1,262 @@ +package org.apache.velocity.runtime; + +/* + * 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. + */ + +/** + * This class gathers deprecated runtime constants + * + * @author <a href="mailto:claude@renegat.net">Claude Brisson</a> + * @version $$ + */ + +@Deprecated +public interface DeprecatedRuntimeConstants +{ + /** + * Logging of invalid references. + * @deprecated see {@link RuntimeConstants#RUNTIME_LOG_REFERENCE_LOG_INVALID} + */ + String OLD_RUNTIME_LOG_REFERENCE_LOG_INVALID = "runtime.log.invalid.references"; + + /** + * Maximum allowed number of loops. + * @deprecated see {@link RuntimeConstants#MAX_NUMBER_LOOPS} + */ + String OLD_MAX_NUMBER_LOOPS = "directive.foreach.maxloops"; + + /** + * Whether to throw an exception or just skip bad iterables. Default is true. + * @since 1.6 + * @deprecated see {@link RuntimeConstants#SKIP_INVALID_ITERATOR} + */ + String OLD_SKIP_INVALID_ITERATOR = "directive.foreach.skip.invalid"; + + /** + * An empty object (string, collection) or zero number is false. + * @since 2.0 + * @deprecated see {@link RuntimeConstants#CHECK_EMPTY_OBJECTS} + */ + String OLD_CHECK_EMPTY_OBJECTS = "directive.if.emptycheck"; + + /** + * Starting tag for error messages triggered by passing a parameter not allowed in the #include directive. Only string literals, + * and references are allowed. + * @deprecated see {@link RuntimeConstants#ERRORMSG_START} + */ + String OLD_ERRORMSG_START = "directive.include.output.errormsg.start"; + + /** + * Ending tag for error messages triggered by passing a parameter not allowed in the #include directive. Only string literals, + * and references are allowed. + * @deprecated see {@link RuntimeConstants#ERRORMSG_END} + */ + String OLD_ERRORMSG_END = "directive.include.output.errormsg.end"; + + /** + * Maximum recursion depth allowed for the #parse directive. + * @deprecated see {@link RuntimeConstants#PARSE_DIRECTIVE_MAXDEPTH} + */ + String OLD_PARSE_DIRECTIVE_MAXDEPTH = "directive.parse.max.depth"; + + /** + * Maximum recursion depth allowed for the #define directive. + * @deprecated see {@link RuntimeConstants#DEFINE_DIRECTIVE_MAXDEPTH} + */ + String OLD_DEFINE_DIRECTIVE_MAXDEPTH = "directive.define.max.depth"; + + /** + * Vector of custom directives + * @deprecated see {@link RuntimeConstants#CUSTOM_DIRECTIVES} + */ + String OLD_CUSTOM_DIRECTIVES = "userdirective"; + + /** + * The <code>resource.manager.cache.size</code> property specifies the cache upper bound (if relevant). + * @deprecated see {@link RuntimeConstants#RESOURCE_MANAGER_DEFAULTCACHE_SIZE} + */ + String OLD_RESOURCE_MANAGER_DEFAULTCACHE_SIZE = "resource.manager.defaultcache.size"; + + /** + * controls if the finding of a resource is logged. + * @deprecated see {@link RuntimeConstants#RESOURCE_MANAGER_LOGWHENFOUND} + */ + String OLD_RESOURCE_MANAGER_LOGWHENFOUND = "resource.manager.logwhenfound"; + + /** + * Key used to retrieve the names of the resource loaders to be used. In a properties file they may appear as the following: + * <p>resource.loader = file,classpath</p> + * @deprecated see {@link RuntimeConstants#RESOURCE_LOADERS} + */ + String OLD_RESOURCE_LOADERS = "resource.loader"; + + /** + * The public handle for setting a path in the FileResourceLoader. + * @deprecated see {@link RuntimeConstants#FILE_RESOURCE_LOADER_PATH} + */ + String OLD_FILE_RESOURCE_LOADER_PATH = "file.resource.loader.path"; + + /** + * The public handle for turning the caching on in the FileResourceLoader. + * @deprecated see {@link RuntimeConstants#FILE_RESOURCE_LOADER_CACHE} + */ + String OLD_FILE_RESOURCE_LOADER_CACHE = "file.resource.loader.cache"; + + /** + * Resource loader modification check interval property suffix + */ + String OLD_RESOURCE_LOADER_CHECK_INTERVAL = "modificationCheckInterval"; + + /** + * The <code>eventhandler.referenceinsertion.class</code> property specifies a list of the + * {@link org.apache.velocity.app.event.ReferenceInsertionEventHandler} implementations to use. + * @deprecated see {@link RuntimeConstants#EVENTHANDLER_REFERENCEINSERTION} + */ + String OLD_EVENTHANDLER_REFERENCEINSERTION = "eventhandler.referenceinsertion.class"; + + /** + * The <code>eventhandler.methodexception.class</code> property specifies a list of the + * {@link org.apache.velocity.app.event.MethodExceptionEventHandler} implementations to use. + * @deprecated see {@link RuntimeConstants#EVENTHANDLER_METHODEXCEPTION} + */ + String OLD_EVENTHANDLER_METHODEXCEPTION = "eventhandler.methodexception.class"; + + /** + * The <code>eventhandler.include.class</code> property specifies a list of the + * {@link org.apache.velocity.app.event.IncludeEventHandler} implementations to use. + * @deprecated see {@link RuntimeConstants#EVENTHANDLER_INCLUDE} + */ + String OLD_EVENTHANDLER_INCLUDE = "eventhandler.include.class"; + + /** + * The <code>eventhandler.invalidreferences.class</code> property specifies a list of the + * {@link org.apache.velocity.app.event.InvalidReferenceEventHandler} implementations to use. + * @deprecated see {@link RuntimeConstants#EVENTHANDLER_INVALIDREFERENCES} + */ + String OLD_EVENTHANDLER_INVALIDREFERENCES = "eventhandler.invalidreferences.class"; + + /** + * Name of local Velocimacro library template. + * @deprecated see {@link RuntimeConstants#VM_LIBRARY} + */ + String OLD_VM_LIBRARY = "velocimacro.library"; + + /** + * Default Velocimacro library template. + * @deprecated see {@link RuntimeConstants#VM_LIBRARY_DEFAULT} + */ + String OLD_VM_LIBRARY_DEFAULT = "VM_global_library.vm"; + + /** + * boolean (true/false) default true: allow inline (in-template) macro definitions. + * @deprecated see {@link RuntimeConstants#VM_PERM_ALLOW_INLINE} + */ + String OLD_VM_PERM_ALLOW_INLINE = "velocimacro.permissions.allow.inline"; + + /** + * boolean (true/false) default false: allow inline (in-template) macro definitions to replace existing. + * @deprecated see {@link RuntimeConstants#VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL} + */ + String OLD_VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL = "velocimacro.permissions.allow.inline.to.replace.global"; + + /** + * Switch for forcing inline macros to be local: default false. + * @deprecated see {@link RuntimeConstants#VM_PERM_INLINE_LOCAL} + */ + String OLD_VM_PERM_INLINE_LOCAL = "velocimacro.permissions.allow.inline.local.scope"; + + /** + * Specify the maximum depth for macro calls + * @since 1.6 + * @deprecated see {@link RuntimeConstants#VM_MAX_DEPTH} + */ + String OLD_VM_MAX_DEPTH = "velocimacro.max.depth"; + + /** + * Defines name of the reference that can be used to get the AST block passed to block macro calls. + * @since 1.7 + * @deprecated see {@link RuntimeConstants#VM_BODY_REFERENCE} + */ + String OLD_VM_BODY_REFERENCE = "velocimacro.body.reference"; + + /** + * When displaying null or invalid non-quiet references, use the argument literal reference + * instead of the one in the macro block. Defaults to false. + * @since 2.1 + * @deprecated see {@link RuntimeConstants#VM_PRESERVE_ARGUMENTS_LITERALS} + */ + String OLD_VM_PRESERVE_ARGUMENTS_LITERALS = "velocimacro.preserve.arguments.literals"; + + /** + * Properties referenced in the template are required to exist the object + * @deprecated see {@link RuntimeConstants#RUNTIME_REFERENCES_STRICT} + */ + String OLD_RUNTIME_REFERENCES_STRICT = "runtime.references.strict"; + + /** + * Indicates we are going to use modified escape behavior in strict mode + * @deprecated see {@link RuntimeConstants#RUNTIME_REFERENCES_STRICT_ESCAPE} + */ + String OLD_RUNTIME_REFERENCES_STRICT_ESCAPE = "runtime.references.strict.escape"; + + /** + * key name for uberspector. Multiple classnames can be specified,in which case uberspectors will be chained. + * @deprecated see {@link RuntimeConstants#UBERSPECT_CLASSNAME} + */ + String OLD_UBERSPECT_CLASSNAME = "runtime.introspector.uberspect"; + + /** + * key for Conversion Manager instance + * @deprecated see {@link RuntimeConstants#CONVERSION_HANDLER_INSTANCE} + */ + String OLD_CONVERSION_HANDLER_INSTANCE = "runtime.conversion.handler.instance"; + + /** + * Switch for the interpolation facility for string literals. + * @deprecated see {@link RuntimeConstants#INTERPOLATE_STRINGLITERALS} + */ + String OLD_INTERPOLATE_STRINGLITERALS = "runtime.interpolate.string.literals"; + + /** + * Switch for ignoring nulls in math equations vs throwing exceptions. + * @deprecated see {@link RuntimeConstants#STRICT_MATH} + */ + String OLD_STRICT_MATH = "runtime.strict.math"; + + /** + * Key upon which a context should be accessible within itself + * @deprecated see {@link RuntimeConstants#CONTEXT_AUTOREFERENCE_KEY} + */ + String OLD_CONTEXT_AUTOREFERENCE_KEY = "context.autoreference.key"; + + /** + * Allow dash in identifiers (backward compatibility option) + * @since 2.1 + * @deprecated see {@link RuntimeConstants#PARSER_HYPHEN_ALLOWED} + */ + String OLD_PARSER_HYPHEN_ALLOWED = "parser.allows.dash.in.identifiers"; + + /** + * Space gobbling mode + * @since 2.0 + * @deprecated see {@link RuntimeConstants#SPACE_GOBBLING} + */ + String OLD_SPACE_GOBBLING = "space.gobbling"; + +} diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java index b5d3c0f3..28682cd6 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java @@ -28,7 +28,8 @@ package org.apache.velocity.runtime; * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> * @version $Id$ */ -public interface RuntimeConstants + +public interface RuntimeConstants extends DeprecatedRuntimeConstants { /* * ---------------------------------------------------------------------- @@ -51,10 +52,13 @@ public interface RuntimeConstants String RUNTIME_LOG_NAME = "runtime.log.name"; /** Logging of invalid references. */ - String RUNTIME_LOG_REFERENCE_LOG_INVALID = "runtime.log.invalid.references"; + String RUNTIME_LOG_REFERENCE_LOG_INVALID = "runtime.log.log_invalid_references"; + + /** Logging of invalid method calls. */ + String RUNTIME_LOG_METHOD_CALL_LOG_INVALID = "runtime.log.log_invalid_method_calls"; /** Whether to use string interning. */ - String RUNTIME_STRING_INTERNING = "runtime.string.interning"; + String RUNTIME_STRING_INTERNING = "runtime.string_interning"; /* * ---------------------------------------------------------------------- @@ -67,44 +71,61 @@ public interface RuntimeConstants */ /** Maximum allowed number of loops. */ - String MAX_NUMBER_LOOPS = "directive.foreach.maxloops"; + String MAX_NUMBER_LOOPS = "directive.foreach.max_loops"; /** * Whether to throw an exception or just skip bad iterables. Default is true. * @since 1.6 */ - String SKIP_INVALID_ITERATOR = "directive.foreach.skip.invalid"; + String SKIP_INVALID_ITERATOR = "directive.foreach.skip_invalid"; /** * An empty object (string, collection) or zero number is false. * @since 2.0 */ - String CHECK_EMPTY_OBJECTS = "directive.if.emptycheck"; + String CHECK_EMPTY_OBJECTS = "directive.if.empty_check"; /** * Starting tag for error messages triggered by passing a parameter not allowed in the #include directive. Only string literals, * and references are allowed. */ - String ERRORMSG_START = "directive.include.output.errormsg.start"; + String ERRORMSG_START = "directive.include.output_error_start"; /** * Ending tag for error messages triggered by passing a parameter not allowed in the #include directive. Only string literals, * and references are allowed. */ - String ERRORMSG_END = "directive.include.output.errormsg.end"; + String ERRORMSG_END = "directive.include.output_error_end"; /** Maximum recursion depth allowed for the #parse directive. */ - String PARSE_DIRECTIVE_MAXDEPTH = "directive.parse.max.depth"; + String PARSE_DIRECTIVE_MAXDEPTH = "directive.parse.max_depth"; /** Maximum recursion depth allowed for the #define directive. */ - String DEFINE_DIRECTIVE_MAXDEPTH = "directive.define.max.depth"; + String DEFINE_DIRECTIVE_MAXDEPTH = "directive.define.max_depth"; /** - * Used to suppress various scope control objects. + * Used to suppress various scope control objects (property suffix). * @since 1.7 + * @deprecated use <code>context.scope_control.<scope_name> = true/false</code> + * @see #CONTEXT_SCOPE_CONTROL */ + @Deprecated String PROVIDE_SCOPE_CONTROL = "provide.scope.control"; - + + /** + * Used to enable or disable a scope control (false by default): + * <code>context.scope_control.<scope_name> = true/false</code> + * where <i>scope_name</i> is one of: <code>template, evaluate, foreach, macro, define</code> + * or the name of a body macro. + * @since 2.1 + */ + String CONTEXT_SCOPE_CONTROL = "context.scope_control"; + + /** + * Vector of custom directives + */ + String CUSTOM_DIRECTIVES = "runtime.custom_directives"; + /* * ---------------------------------------------------------------------- * R E S O U R C E M A N A G E R C O N F I G U R A T I O N @@ -130,7 +151,7 @@ public interface RuntimeConstants String RESOURCE_MANAGER_CACHE_CLASS = "resource.manager.cache.class"; /** The <code>resource.manager.cache.size</code> property specifies the cache upper bound (if relevant). */ - String RESOURCE_MANAGER_DEFAULTCACHE_SIZE = "resource.manager.defaultcache.size"; + String RESOURCE_MANAGER_DEFAULTCACHE_SIZE = "resource.manager.cache.default_size"; /* * ---------------------------------------------------------------------- @@ -139,20 +160,55 @@ public interface RuntimeConstants */ /** controls if the finding of a resource is logged. */ - String RESOURCE_MANAGER_LOGWHENFOUND = "resource.manager.logwhenfound"; + String RESOURCE_MANAGER_LOGWHENFOUND = "resource.manager.log_when_found"; /** * Key used to retrieve the names of the resource loaders to be used. In a properties file they may appear as the following: * * <p>resource.loader = file,classpath</p> */ + String RESOURCE_LOADERS = "resource.loaders"; + + /** + * Key prefix for a specific resource loader properties + * + * <p>resource.loader.file.path = ...</p> + */ String RESOURCE_LOADER = "resource.loader"; - /** The public handle for setting a path in the FileResourceLoader. */ - String FILE_RESOURCE_LOADER_PATH = "file.resource.loader.path"; + /** The public handle for setting paths in the FileResourceLoader. + * (this constant is used by test cases only) + */ + String FILE_RESOURCE_LOADER_PATH = "resource.loader.file.path"; /** The public handle for turning the caching on in the FileResourceLoader. */ - String FILE_RESOURCE_LOADER_CACHE = "file.resource.loader.cache"; + String FILE_RESOURCE_LOADER_CACHE = "resource.loader.file.cache"; + + /** + * Resource loader class property suffix + */ + String RESOURCE_LOADER_CLASS = "class"; + + /** + * Resource loader instance property suffix + */ + String RESOURCE_LOADER_INSTANCE = "instance"; + + /** + * Resource loader cache property suffix + */ + String RESOURCE_LOADER_CACHE = "cache"; + + /** + * File resource loader paths property suffix + */ + String RESOURCE_LOADER_PATHS = "path"; + + /** + * Resource loader modification check interval property suffix + */ + String RESOURCE_LOADER_CHECK_INTERVAL = "modification_check_interval"; + /* * ---------------------------------------------------------------------- @@ -164,25 +220,25 @@ public interface RuntimeConstants * The <code>eventhandler.referenceinsertion.class</code> property specifies a list of the * {@link org.apache.velocity.app.event.ReferenceInsertionEventHandler} implementations to use. */ - String EVENTHANDLER_REFERENCEINSERTION = "eventhandler.referenceinsertion.class"; + String EVENTHANDLER_REFERENCEINSERTION = "event_handler.reference_insertion.class"; /** * The <code>eventhandler.methodexception.class</code> property specifies a list of the * {@link org.apache.velocity.app.event.MethodExceptionEventHandler} implementations to use. */ - String EVENTHANDLER_METHODEXCEPTION = "eventhandler.methodexception.class"; + String EVENTHANDLER_METHODEXCEPTION = "event_handler.method_exception.class"; /** * The <code>eventhandler.include.class</code> property specifies a list of the * {@link org.apache.velocity.app.event.IncludeEventHandler} implementations to use. */ - String EVENTHANDLER_INCLUDE = "eventhandler.include.class"; + String EVENTHANDLER_INCLUDE = "event_handler.include.class"; /** * The <code>eventhandler.invalidreferences.class</code> property specifies a list of the * {@link org.apache.velocity.app.event.InvalidReferenceEventHandler} implementations to use. */ - String EVENTHANDLER_INVALIDREFERENCES = "eventhandler.invalidreferences.class"; + String EVENTHANDLER_INVALIDREFERENCES = "event_handler.invalid_references.class"; /* @@ -191,48 +247,45 @@ public interface RuntimeConstants * ---------------------------------------------------------------------- */ - /** Name of local Velocimacro library template. */ - String VM_LIBRARY = "velocimacro.library"; + /** Filename of local Velocimacro library template. */ + String VM_LIBRARY = "velocimacro.library.path"; /** Default Velocimacro library template. */ - String VM_LIBRARY_DEFAULT = "VM_global_library.vm"; + String VM_LIBRARY_DEFAULT = "velocimacros.vtl"; /** switch for autoloading library-sourced VMs (for development). */ String VM_LIBRARY_AUTORELOAD = "velocimacro.library.autoreload"; /** boolean (true/false) default true: allow inline (in-template) macro definitions. */ - String VM_PERM_ALLOW_INLINE = "velocimacro.permissions.allow.inline"; + String VM_PERM_ALLOW_INLINE = "velocimacro.inline.allow"; /** boolean (true/false) default false: allow inline (in-template) macro definitions to replace existing. */ - String VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL = "velocimacro.permissions.allow.inline.to.replace.global"; + String VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL = "velocimacro.inline.replace_global"; /** Switch for forcing inline macros to be local: default false. */ - String VM_PERM_INLINE_LOCAL = "velocimacro.permissions.allow.inline.local.scope"; - - /** Switch for VM blather: default true. */ - String VM_MESSAGES_ON = "velocimacro.messages.on"; + String VM_PERM_INLINE_LOCAL = "velocimacro.inline.local_scope"; /** if true, throw an exception for wrong number of arguments **/ String VM_ARGUMENTS_STRICT = "velocimacro.arguments.strict"; /** + * When displaying null or invalid non-quiet references, use the argument literal reference + * instead of the one in the macro block. Defaults to false. + * @since 2.1 + **/ + String VM_PRESERVE_ARGUMENTS_LITERALS = "velocimacro.arguments.preserve_literals"; + + /** * Specify the maximum depth for macro calls * @since 1.6 */ - String VM_MAX_DEPTH = "velocimacro.max.depth"; + String VM_MAX_DEPTH = "velocimacro.max_depth"; /** * Defines name of the reference that can be used to get the AST block passed to block macro calls. * @since 1.7 */ - String VM_BODY_REFERENCE = "velocimacro.body.reference"; - - /** - * When displaying null or invalid non-quiet references, use the argument literal reference - * instead of the one in the macro block. Defaults to false. - * @since 2.1 - **/ - String VM_PRESERVE_ARGUMENTS_LITERALS = "velocimacro.preserve.arguments.literals"; + String VM_BODY_REFERENCE = "velocimacro.body_reference"; /* * ---------------------------------------------------------------------- @@ -243,12 +296,12 @@ public interface RuntimeConstants /** * Properties referenced in the template are required to exist the object */ - String RUNTIME_REFERENCES_STRICT = "runtime.references.strict"; + String RUNTIME_REFERENCES_STRICT = "runtime.strict_mode.enable"; /** * Indicates we are going to use modified escape behavior in strict mode */ - String RUNTIME_REFERENCES_STRICT_ESCAPE = "runtime.references.strict.escape"; + String RUNTIME_REFERENCES_STRICT_ESCAPE = "runtime.strict_mode.escape"; /* * ---------------------------------------------------------------------- @@ -257,13 +310,7 @@ public interface RuntimeConstants */ /** key name for uberspector. Multiple classnames can be specified,in which case uberspectors will be chained. */ - String UBERSPECT_CLASSNAME = "runtime.introspector.uberspect"; - - /** key for Conversion Manager instance */ - String CONVERSION_HANDLER_INSTANCE = "runtime.conversion.handler.instance"; - - /** key for Conversion Manager class */ - String CONVERSION_HANDLER_CLASS = "runtime.conversion.handler.class"; + String UBERSPECT_CLASSNAME = "introspector.uberspect"; /** A comma separated list of packages to restrict access to in the SecureIntrospector. */ String INTROSPECTOR_RESTRICT_PACKAGES = "introspector.restrict.packages"; @@ -271,6 +318,11 @@ public interface RuntimeConstants /** A comma separated list of classes to restrict access to in the SecureIntrospector. */ String INTROSPECTOR_RESTRICT_CLASSES = "introspector.restrict.classes"; + /** key for Conversion Manager class */ + String CONVERSION_HANDLER_CLASS = "introspector.conversion_handler.class"; + + /** key for Conversion Manager instance */ + String CONVERSION_HANDLER_INSTANCE = "introspector.conversion_handler.instance"; /* * ---------------------------------------------------------------------- @@ -279,7 +331,7 @@ public interface RuntimeConstants */ /** Switch for the interpolation facility for string literals. */ - String INTERPOLATE_STRINGLITERALS = "runtime.interpolate.string.literals"; + String INTERPOLATE_STRINGLITERALS = "runtime.interpolate_string_literals"; /** The character encoding for the templates. Used by the parser in processing the input streams. */ String INPUT_ENCODING = "input.encoding"; @@ -288,10 +340,10 @@ public interface RuntimeConstants String ENCODING_DEFAULT = "UTF-8"; /** Switch for ignoring nulls in math equations vs throwing exceptions. */ - String STRICT_MATH = "runtime.strict.math"; + String STRICT_MATH = "runtime.strict_math"; /** Key upon which a context should be accessible within itself */ - String CONTEXT_AUTOREFERENCE_KEY = "context.autoreference.key"; + String CONTEXT_AUTOREFERENCE_KEY = "context.self_reference_key"; /** * The <code>parser.pool.class</code> property specifies the name of the {@link org.apache.velocity.util.SimplePool} @@ -314,7 +366,7 @@ public interface RuntimeConstants * Space gobbling mode * @since 2.0 */ - String SPACE_GOBBLING = "space.gobbling"; + String SPACE_GOBBLING = "parser.space_gobbling"; /** * Space gobbling modes diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java index 180128f5..318bb0a2 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java @@ -62,12 +62,15 @@ import java.io.StringReader; import java.io.Writer; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; import java.util.Properties; +import java.util.Set; /** * This is the Runtime system for Velocity. It is the @@ -174,27 +177,39 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices */ private EventCartridge eventCartridge = null; - /* + /** * Whether to use string interning */ private boolean stringInterning = false; - /* - * Settings for provision of root scope for evaluate(...) calls. + /** + * Scope name for evaluate(...) calls. */ private String evaluateScopeName = "evaluate"; - private boolean provideEvaluateScope = false; - /* + /** + * Scope names for which to provide scope control objects in the context + */ + private Set<String> enabledScopeControls = new HashSet<String>(); + + /** * Opaque reference to something specified by the * application for use in application supplied/specified * pluggable components */ private Map applicationAttributes = null; + + /** + * Uberspector + */ private Uberspect uberSpect; + + /** + * Default encoding + */ private String defaultEncoding; - /* + /** * Space gobbling mode */ private SpaceGobbling spaceGobbling; @@ -249,7 +264,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices initializeParserPool(); initializeIntrospection(); - initializeEvaluateScopeSettings(); + initializeScopeSettings(); /* * initialize the VM Factory. It will use the properties * accessible from Runtime, so keep this here at the end. @@ -293,7 +308,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices this.initializing = false; this.overridingProperties = null; this.parserPool = null; - this.provideEvaluateScope = false; + this.enabledScopeControls.clear(); this.resourceManager = null; this.runtimeDirectives = new Hashtable(); this.runtimeDirectivesShared = null; @@ -697,15 +712,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices */ public void init(String configurationFile) { - try - { - setConfiguration(new ExtProperties(configurationFile)); - } - catch (IOException e) - { - throw new VelocityException("Error reading properties from '" - + configurationFile + "'", e); - } + setProperties(configurationFile); init(); } @@ -1028,7 +1035,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices * now the user's directives */ - String[] userdirective = configuration.getStringArray("userdirective"); + String[] userdirective = configuration.getStringArray(CUSTOM_DIRECTIVES); for (String anUserdirective : userdirective) { @@ -1252,10 +1259,19 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices } } - private void initializeEvaluateScopeSettings() + private void initializeScopeSettings() { - String property = evaluateScopeName+'.'+PROVIDE_SCOPE_CONTROL; - provideEvaluateScope = getBoolean(property, provideEvaluateScope); + ExtProperties scopes = configuration.subset(CONTEXT_SCOPE_CONTROL); + if (scopes != null) + { + Iterator<String> scopeIterator = scopes.getKeys(); + while (scopeIterator.hasNext()) + { + String scope = scopeIterator.next(); + boolean enabled = scopes.getBoolean(scope); + if (enabled) enabledScopeControls.add(scope); + } + } } /** @@ -1395,7 +1411,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices try { - if (provideEvaluateScope) + if (isScopeControlEnabled(evaluateScopeName)) { Object previous = ica.get(evaluateScopeName); context.put(evaluateScopeName, new Scope(this, previous)); @@ -1426,7 +1442,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices finally { ica.popCurrentTemplateName(); - if (provideEvaluateScope) + if (isScopeControlEnabled(evaluateScopeName)) { Object obj = ica.get(evaluateScopeName); if (obj instanceof Scope) @@ -1856,4 +1872,15 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices { return hyphenAllowedInIdentifiers; } + + /** + * Get whether to provide a scope control object for this scope + * @param scopeName + * @return scope control enabled + * @since 2.1 + */ + public boolean isScopeControlEnabled(String scopeName) + { + return enabledScopeControls.contains(scopeName); + } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java index 0f813220..553337fe 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java @@ -469,8 +469,17 @@ public interface RuntimeServices SpaceGobbling getSpaceGobbling(); /** - * get whether hyphens are allowed in identifiers + * Get whether hyphens are allowed in identifiers * @return configured boolean flag + * @since 2.1 */ boolean isHyphenAllowedInIdentifiers(); + + /** + * Get whether to provide a scope control object for this scope + * @param scopeName + * @return scope control enabled + * @since 2.1 + */ + boolean isScopeControlEnabled(String scopeName); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java index 12635cac..78f31e9f 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java @@ -157,6 +157,17 @@ public class RuntimeSingleton implements RuntimeConstants } /** + * Set an entire configuration at once from a named properties file + * + * @param propsFilename properties filename + * @since 2.1 + */ + public static void setProperties(String propsFilename) + { + ri.setProperties(propsFilename); + } + + /** * Add a property to the configuration. If it already * exists then the value stated here will be added * to the configuration entry. For example, if diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java index 09305632..da66d8fb 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java @@ -158,7 +158,16 @@ public class VelocimacroFactory } else { - log.debug("Default library not found."); + // try the old default library + log.debug("Default library {} not found. Trying old default library: {}", RuntimeConstants.VM_LIBRARY_DEFAULT, DeprecatedRuntimeConstants.OLD_VM_LIBRARY_DEFAULT); + if (rsvc.getLoaderNameForResource(RuntimeConstants.OLD_VM_LIBRARY_DEFAULT) != null) + { + libfiles = RuntimeConstants.OLD_VM_LIBRARY_DEFAULT; + } + else + { + log.debug("Old default library {} not found.", DeprecatedRuntimeConstants.OLD_VM_LIBRARY_DEFAULT); + } } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java index 9ec64889..33320bcb 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java @@ -160,8 +160,7 @@ public abstract class Directive implements DirectiveConstants, Cloneable rsvc = rs; log = rsvc.getLog("directive." + getName()); - String property = getScopeName()+'.'+RuntimeConstants.PROVIDE_SCOPE_CONTROL; - this.provideScope = rsvc.getBoolean(property, provideScope); + provideScope = rsvc.isScopeControlEnabled(getScopeName()); } /** diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java index 4e0fa834..8f953b65 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java @@ -60,6 +60,7 @@ public class ASTMethod extends SimpleNode private String methodName = ""; private int paramCount = 0; + private boolean logOnInvalid = true; protected Info uberInfo; @@ -120,6 +121,7 @@ public class ASTMethod extends SimpleNode paramCount = jjtGetNumChildren() - 1; strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false); + logOnInvalid = rsvc.getBoolean(RuntimeConstants.RUNTIME_LOG_METHOD_CALL_LOG_INVALID, true); cleanupParserAndTokens(); @@ -165,8 +167,8 @@ public class ASTMethod extends SimpleNode VelMethod method = ClassUtils.getMethod(methodName, params, paramClasses, o, context, this, strictRef); - // warn if method wasn't found (if strictRef is true, then ClassUtils did thorw an exception) - if (o != null && method == null) + // warn if method wasn't found (if strictRef is true, then ClassUtils did throw an exception) + if (o != null && method == null && logOnInvalid) { StringBuilder plist = new StringBuilder(); for (int i = 0; i < params.length; i++) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java index c256239f..91058d68 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java @@ -34,7 +34,6 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; @@ -117,8 +116,8 @@ public class ResourceManagerImpl * in as an instance. */ - String loaderClass = StringUtils.trim(configuration.getString("class")); - ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance"); + String loaderClass = StringUtils.trim(configuration.getString(RuntimeConstants.RESOURCE_LOADER_CLASS)); + ResourceLoader loaderInstance = (ResourceLoader) configuration.get(RuntimeConstants.RESOURCE_LOADER_INSTANCE); if (loaderInstance != null) { @@ -209,7 +208,7 @@ public class ResourceManagerImpl */ private void assembleResourceLoaderInitializers() { - Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER); + Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADERS); for (ListIterator<String> it = resourceLoaderNames.listIterator(); it.hasNext(); ) { @@ -223,8 +222,8 @@ public class ResourceManagerImpl */ String loaderName = StringUtils.trim(it.next()); it.set(loaderName); - StringBuilder loaderID = new StringBuilder(loaderName); - loaderID.append(".").append(RuntimeConstants.RESOURCE_LOADER); + StringBuilder loaderID = new StringBuilder(); + loaderID.append(RuntimeConstants.RESOURCE_LOADER).append('.').append(loaderName); ExtProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID.toString()); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java index 363ba563..f8c5a811 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java @@ -21,6 +21,7 @@ package org.apache.velocity.runtime.resource.loader; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.exception.VelocityException; +import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.ExtProperties; @@ -72,7 +73,7 @@ public class FileResourceLoader extends ResourceLoader { log.trace("FileResourceLoader: initialization starting."); - paths.addAll( configuration.getVector("path") ); + paths.addAll( configuration.getVector(RuntimeConstants.RESOURCE_LOADER_PATHS) ); // trim spaces from all paths for (ListIterator<String> it = paths.listIterator(); it.hasNext(); ) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java index be4ce328..8ed76835 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java @@ -21,6 +21,7 @@ package org.apache.velocity.runtime.resource.loader; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.exception.VelocityException; +import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.ExtProperties; @@ -91,7 +92,7 @@ public class JarResourceLoader extends ResourceLoader { log.trace("JarResourceLoader: initialization starting."); - List paths = configuration.getList("path"); + List paths = configuration.getList(RuntimeConstants.RESOURCE_LOADER_PATHS); if (paths != null) { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java index 354514bb..e2fc7b43 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java @@ -92,23 +92,23 @@ public abstract class ResourceLoader try { - isCachingOn = configuration.getBoolean("cache", false); + isCachingOn = configuration.getBoolean(RuntimeConstants.RESOURCE_LOADER_CACHE, false); } catch (Exception e) { isCachingOn = false; - String msg = "Exception parsing cache setting: " + configuration.getString("cache"); + String msg = "Exception parsing cache setting: " + configuration.getString(RuntimeConstants.RESOURCE_LOADER_CACHE); log.error(msg, e); throw new VelocityException(msg, e); } try { - modificationCheckInterval = configuration.getLong("modificationCheckInterval", 0); + modificationCheckInterval = configuration.getLong(RuntimeConstants.RESOURCE_LOADER_CHECK_INTERVAL, 0); } catch (Exception e) { modificationCheckInterval = 0; - String msg = "Exception parsing modificationCheckInterval setting: " + configuration.getString("modificationCheckInterval"); + String msg = "Exception parsing modificationCheckInterval setting: " + RuntimeConstants.RESOURCE_LOADER_CHECK_INTERVAL; log.error(msg, e); throw new VelocityException(msg, e); } @@ -119,7 +119,7 @@ public abstract class ResourceLoader className = ResourceCacheImpl.class.getName(); try { - className = configuration.getString("class", className); + className = configuration.getString(RuntimeConstants.RESOURCE_LOADER_CLASS, className); } catch (Exception e) { |