[xwiki-notifications] r10956 - xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity
sdumitriu (SVN)
notifications at xwiki.org
Tue Jul 1 01:44:13 CEST 2008
Author: sdumitriu
Date: 2008-07-01 01:44:13 +0200 (Tue, 01 Jul 2008)
New Revision: 10956
Modified:
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityContextFactory.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityEngine.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityFactory.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityContextFactory.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityEngine.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityExecutionContextInitializer.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityFactory.java
xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityManager.java
Log:
[cleanup] Apply codestyle
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityContextFactory.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityContextFactory.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityContextFactory.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -37,8 +37,8 @@
*
* @version $Id$
*/
-public class DefaultVelocityContextFactory extends AbstractLogEnabled implements
- VelocityContextFactory, Initializable, Composable
+public class DefaultVelocityContextFactory extends AbstractLogEnabled implements VelocityContextFactory, Initializable,
+ Composable
{
/**
* The component manager we used to find all components implementing the
@@ -52,8 +52,8 @@
private Properties properties;
/**
- * An internal read-only Velocity Context containing the Tools defined in the component's
- * configuration. We reuse them across Contexts for better performance.
+ * An internal read-only Velocity Context containing the Tools defined in the component's configuration. We reuse
+ * them across Contexts for better performance.
*/
private Context toolsContext;
@@ -78,16 +78,14 @@
// Instantiate Velocity tools
if (this.properties != null) {
- for (Enumeration< ? > props = this.properties.propertyNames(); props
- .hasMoreElements();) {
+ for (Enumeration< ? > props = this.properties.propertyNames(); props.hasMoreElements();) {
String key = props.nextElement().toString();
String value = this.properties.getProperty(key);
Object toolInstance;
try {
toolInstance = Class.forName(value).newInstance();
} catch (Exception e) {
- throw new InitializationException(
- "Failed to initialize tool [" + value + "]", e);
+ throw new InitializationException("Failed to initialize tool [" + value + "]", e);
}
this.toolsContext.put(key, toolInstance);
getLogger().debug("Setting tool [" + key + "] = [" + value + "]");
@@ -107,13 +105,11 @@
// Call all components implementing the VelocityContextInitializer's role.
try {
- for (Object interceptor : this.componentManager
- .lookupList(VelocityContextInitializer.ROLE)) {
+ for (Object interceptor : this.componentManager.lookupList(VelocityContextInitializer.ROLE)) {
((VelocityContextInitializer) interceptor).initialize(context);
}
} catch (ComponentLookupException e) {
- throw new XWikiVelocityException(
- "Failed to locate some Velocity Context initializers", e);
+ throw new XWikiVelocityException("Failed to locate some Velocity Context initializers", e);
}
return context;
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityEngine.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityEngine.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityEngine.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -38,17 +38,17 @@
import org.xwiki.container.servlet.ServletApplicationContext;
/**
- * Default implementation of the Velocity service which initializes the Velocity system using
- * configuration values defined in the component's configuration. Note that the {@link #initialize}
- * method has to be executed before any other method can be called.
+ * Default implementation of the Velocity service which initializes the Velocity system using configuration values
+ * defined in the component's configuration. Note that the {@link #initialize} method has to be executed before any
+ * other method can be called.
*
* @version $Id$
*/
public class DefaultVelocityEngine extends AbstractLogEnabled implements VelocityEngine, LogChute
{
/**
- * The name of the Velocity configuration property that specifies the ResourceLoader that
- * Velocity should use when locating velocimacros.
+ * The name of the Velocity configuration property that specifies the ResourceLoader that Velocity should use when
+ * locating velocimacros.
*/
private static final String RESOURCE_LOADER = "resource.loader";
@@ -58,15 +58,14 @@
private org.apache.velocity.app.VelocityEngine engine;
/**
- * The list of properties to set on the Velocity Engine. These are injected automatically by the
- * Component subsystem.
+ * The list of properties to set on the Velocity Engine. These are injected automatically by the Component
+ * subsystem.
*/
private Properties properties;
/**
- * The Container component (Injected automatically by the Component subsystem). We need it in
- * order to store a the servlet context as a property in the Application Context so that the
- * Velocity Tools WebappLoader can find it.
+ * The Container component (Injected automatically by the Component subsystem). We need it in order to store a the
+ * servlet context as a property in the Application Context so that the Velocity Tools WebappLoader can find it.
*/
private Container container;
@@ -88,8 +87,7 @@
// <code>org.apache.velocity.tools.view.servlet.WebappLoader</code> Velocity Tools class
// then we need to set the ServletContext object as a Velocity Application Attribute as
// it's used to load resources from the webapp directory in WebapLoader.
- String resourceLoader =
- properties.getProperty(RESOURCE_LOADER, this.properties.getProperty(RESOURCE_LOADER));
+ String resourceLoader = properties.getProperty(RESOURCE_LOADER, this.properties.getProperty(RESOURCE_LOADER));
if (resourceLoader.equals("webapp")) {
ApplicationContext context = this.container.getApplicationContext();
if (context instanceof ServletApplicationContext) {
@@ -156,9 +154,8 @@
{
// Ensure that initialization has been called
if (this.engine == null) {
- throw new XWikiVelocityException(
- "This Velocity Engine has not yet been initialized. "
- + " You must call its initialize() method before you can use it.");
+ throw new XWikiVelocityException("This Velocity Engine has not yet been initialized. "
+ + " You must call its initialize() method before you can use it.");
}
// We override the default implementation here. See #init(RuntimeServices)
@@ -187,14 +184,13 @@
return false;
} catch (Exception e) {
- throw new XWikiVelocityException("Failed to evaluate content with id ["
- + templateName + "]", e);
+ throw new XWikiVelocityException("Failed to evaluate content with id [" + templateName + "]", e);
}
}
/**
- * Provides access to the {@link org.apache.velocity.app.VelocityEngine Velocity Engine}, which
- * can be used to call all Velocity services.
+ * Provides access to the {@link org.apache.velocity.app.VelocityEngine Velocity Engine}, which can be used to call
+ * all Velocity services.
*
* @return the initialized Velocity engine
*/
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityFactory.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityFactory.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/DefaultVelocityFactory.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -20,39 +20,37 @@
*/
package org.xwiki.velocity;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
import org.xwiki.component.logging.AbstractLogEnabled;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.phase.Composable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
/**
* Default implementation for {@link VelocityFactory}.
- *
+ *
* @see VelocityFactory
- * @version $Id$
+ * @version $Id$
*/
-public class DefaultVelocityFactory extends AbstractLogEnabled
- implements VelocityFactory, Composable
+public class DefaultVelocityFactory extends AbstractLogEnabled implements VelocityFactory, Composable
{
/**
- * The Component manager we use to lookup (and thus create since it's a singleton) the
- * VelocityEngine component.
+ * The Component manager we use to lookup (and thus create since it's a singleton) the VelocityEngine component.
*/
private ComponentManager componentManager;
/**
- * A cache of Velocity Engines. See {@link org.xwiki.velocity.VelocityFactory} for more details
- * as to why we need this cache.
+ * A cache of Velocity Engines. See {@link org.xwiki.velocity.VelocityFactory} for more details as to why we need
+ * this cache.
*/
private Map<String, VelocityEngine> velocityEngines = new HashMap<String, VelocityEngine>();
/**
* {@inheritDoc}
- *
+ *
* @see Composable#compose(ComponentManager)
*/
public void compose(ComponentManager componentManager)
@@ -62,7 +60,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see VelocityFactory#hasVelocityEngine(String)
*/
public boolean hasVelocityEngine(String key)
@@ -72,7 +70,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see VelocityFactory#getVelocityEngine(String)
*/
public VelocityEngine getVelocityEngine(String key)
@@ -82,11 +80,10 @@
/**
* {@inheritDoc}
- *
+ *
* @see VelocityFactory#createVelocityEngine(String, Properties)
*/
- public VelocityEngine createVelocityEngine(String key, Properties properties)
- throws XWikiVelocityException
+ public VelocityEngine createVelocityEngine(String key, Properties properties) throws XWikiVelocityException
{
VelocityEngine engine;
if (this.velocityEngines.containsKey(key)) {
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityContextFactory.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityContextFactory.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityContextFactory.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -23,10 +23,10 @@
import org.apache.velocity.VelocityContext;
/**
- * Creates Velocity Context instances, pre-populated with the Velocity Tools enabled in the
- * component's configuration, and by all the enabled {@link VelocityContextInitializer} components.
- * The returned context is supposed to be used only once, as otherwise data may leak between
- * different requests, and the parsing/rendering process would be affected by previous data.
+ * Creates Velocity Context instances, pre-populated with the Velocity Tools enabled in the component's configuration,
+ * and by all the enabled {@link VelocityContextInitializer} components. The returned context is supposed to be used
+ * only once, as otherwise data may leak between different requests, and the parsing/rendering process would be affected
+ * by previous data.
*
* @version $Id$
*/
@@ -40,8 +40,7 @@
/**
* Creates and initializes a new Velocity Context.
*
- * @return a new Velocity Context, populated with Tools and data pushed by
- * {@link VelocityContextInitializer}s
+ * @return a new Velocity Context, populated with Tools and data pushed by {@link VelocityContextInitializer}s
* @throws XWikiVelocityException if the context failed to be created or initialized properly
*/
VelocityContext createContext() throws XWikiVelocityException;
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityEngine.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityEngine.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityEngine.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -20,15 +20,15 @@
*/
package org.xwiki.velocity;
-import org.apache.velocity.context.Context;
-
import java.io.Reader;
import java.io.Writer;
import java.util.Properties;
+import org.apache.velocity.context.Context;
+
/**
* Initialize a Velocity Engine and make Velocity services available.
- *
+ *
* @version $Id$
*/
public interface VelocityEngine
@@ -39,41 +39,36 @@
String ROLE = VelocityEngine.class.getName();
/**
- * Initializes the Velocity engine by setting its configuration both from the component's
- * configuration and from the passed properties. This method must be called before any other
- * method from this class can be executed.
- *
- * @param properties the properties that will override the static properties defined in the
- * component's configuration
+ * Initializes the Velocity engine by setting its configuration both from the component's configuration and from the
+ * passed properties. This method must be called before any other method from this class can be executed.
+ *
+ * @param properties the properties that will override the static properties defined in the component's
+ * configuration
* @throws XWikiVelocityException in case of error
*/
void initialize(Properties properties) throws XWikiVelocityException;
/**
* Renders the input string using the context into the output writer.
- *
+ *
* @param context the Velocity context to use in rendering the input string
* @param out the writer in which to render the output
- * @param templateName the string to be used as the template name for log messages in case of
- * error
+ * @param templateName the string to be used as the template name for log messages in case of error
* @param source the input string containing the VTL to be rendered
* @return true if successful, false otherwise. If false, see the Velocity runtime log
* @throws XWikiVelocityException in case of error
*/
- boolean evaluate(Context context, Writer out, String templateName, String source)
- throws XWikiVelocityException;
+ boolean evaluate(Context context, Writer out, String templateName, String source) throws XWikiVelocityException;
/**
* Renders the input string using the context into the output writer.
- *
+ *
* @param context the Velocity context to use in rendering the input string
* @param out the writer in which to render the output
- * @param templateName the string to be used as the template name for log messages in case of
- * error
+ * @param templateName the string to be used as the template name for log messages in case of error
* @param source the input containing the VTL to be rendered, as a Reader
* @return true if successful, false otherwise. If false, see the Velocity runtime log
* @throws XWikiVelocityException in case of error
*/
- boolean evaluate(Context context, Writer out, String templateName, Reader source)
- throws XWikiVelocityException;
+ boolean evaluate(Context context, Writer out, String templateName, Reader source) throws XWikiVelocityException;
}
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityExecutionContextInitializer.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityExecutionContextInitializer.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityExecutionContextInitializer.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -1,14 +1,34 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
package org.xwiki.velocity;
import org.apache.velocity.VelocityContext;
+import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextInitializer;
-import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextInitializerException;
/**
- * Allow registering the Velocity Context in the Execution Context object since it's shared during
- * the whole execution of the current request.
- *
+ * Allow registering the Velocity Context in the Execution Context object since it's shared during the whole execution
+ * of the current request.
+ *
* @see org.xwiki.context.ExecutionContextInitializer
* @since 1.5M1
* @version $Id$
@@ -21,26 +41,23 @@
public static final String REQUEST_VELOCITY_CONTEXT = "velocityContext";
/**
- * The Velocity context factory component used for creating the Velocity Context (injected
- * automatically by the Component subsystem).
+ * The Velocity context factory component used for creating the Velocity Context (injected automatically by the
+ * Component subsystem).
*/
private VelocityContextFactory velocityContextFactory;
/**
* {@inheritDoc}
- *
+ *
* @see org.xwiki.context.ExecutionContextInitializer#initialize(org.xwiki.context.ExecutionContext)
*/
- public void initialize(ExecutionContext executionContext)
- throws ExecutionContextInitializerException
+ public void initialize(ExecutionContext executionContext) throws ExecutionContextInitializerException
{
try {
VelocityContext context = this.velocityContextFactory.createContext();
- executionContext.setProperty(
- VelocityExecutionContextInitializer.REQUEST_VELOCITY_CONTEXT, context);
+ executionContext.setProperty(VelocityExecutionContextInitializer.REQUEST_VELOCITY_CONTEXT, context);
} catch (XWikiVelocityException e) {
- throw new ExecutionContextInitializerException("Failed to initialize Velocity Context",
- e);
+ throw new ExecutionContextInitializerException("Failed to initialize Velocity Context", e);
}
}
}
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityFactory.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityFactory.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityFactory.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -23,11 +23,10 @@
import java.util.Properties;
/**
- * Allows creating different Velocity engine instances. This is useful when you need to have
- * different Velocity engines running in the same JVM but with different configurations. Since
- * global templates in Velocity are part of the configuration the only solution to use different
- * global templates is to use different Velocity engines. As an example we need this in XWiki since
- * we want to allow each Skin to provide its own global macros.
+ * Allows creating different Velocity engine instances. This is useful when you need to have different Velocity engines
+ * running in the same JVM but with different configurations. Since global templates in Velocity are part of the
+ * configuration the only solution to use different global templates is to use different Velocity engines. As an example
+ * we need this in XWiki since we want to allow each Skin to provide its own global macros.
*
* @version $Id$
*/
@@ -41,45 +40,39 @@
/**
* Check if an engine was already created for a certain key.
*
- * @param key the key under which the Velocity engine has been saved in cache. This is the key
- * used when the Velocity engine was created using
- * {@link #createVelocityEngine(String, java.util.Properties)}
- * @return <code>true</code> if there is a cached Velocity Engine matching the passed key,
- * <code>false</code> otherwise.
+ * @param key the key under which the Velocity engine has been saved in cache. This is the key used when the
+ * Velocity engine was created using {@link #createVelocityEngine(String, java.util.Properties)}
+ * @return <code>true</code> if there is a cached Velocity Engine matching the passed key, <code>false</code>
+ * otherwise.
*/
boolean hasVelocityEngine(String key);
/**
- * Retrieves from the cache the Velocity engine corresponding to a specific key, if such an
- * engine was already created.
+ * Retrieves from the cache the Velocity engine corresponding to a specific key, if such an engine was already
+ * created.
*
- * @param key the key under which the Velocity engine has been saved in cache. This is the key
- * used when the Velocity engine was created using
- * {@link #createVelocityEngine(String, java.util.Properties)}
- * @return the cached Velocity engine instance corresponding to the passed key or
- * <code>null</code> if not found
+ * @param key the key under which the Velocity engine has been saved in cache. This is the key used when the
+ * Velocity engine was created using {@link #createVelocityEngine(String, java.util.Properties)}
+ * @return the cached Velocity engine instance corresponding to the passed key or <code>null</code> if not found
*/
VelocityEngine getVelocityEngine(String key);
/**
- * Creates a new Velocity engine instance, which will be cached using a specific key for later
- * reuse. The key allows having different Velocity Engines, so that each one can have its own
- * special configuration. This is especially handy for having different sets of global Velocity
- * libraries (such as for different XWiki Skins for example). If another engine was previously
- * created for the same key, then that instance is returned instead, without creating any other
- * instance.
+ * Creates a new Velocity engine instance, which will be cached using a specific key for later reuse. The key allows
+ * having different Velocity Engines, so that each one can have its own special configuration. This is especially
+ * handy for having different sets of global Velocity libraries (such as for different XWiki Skins for example). If
+ * another engine was previously created for the same key, then that instance is returned instead, without creating
+ * any other instance.
*
* @param key the key used to cache the Velocity engine instance to return
- * @param properties the list of properties that will override the default properties when
- * creating the engine. For example it's possible to define a list of global
- * velocimacros by passing the <code>RuntimeConstants.VM_LIBRARY</code> property
- * key.
- * @return the newly created Velocity Engine, or an existing one, if an engine was previously
- * created for the same key.
+ * @param properties the list of properties that will override the default properties when creating the engine. For
+ * example it's possible to define a list of global velocimacros by passing the
+ * <code>RuntimeConstants.VM_LIBRARY</code> property key.
+ * @return the newly created Velocity Engine, or an existing one, if an engine was previously created for the same
+ * key.
* @throws XWikiVelocityException if the Velocity Engine cannot be initialized for some reason
- * @todo How to create a new engine instance when parameters have changed? Shouldn't this
- * discard the old instance and create a new one, instead?
+ * @todo How to create a new engine instance when parameters have changed? Shouldn't this discard the old instance
+ * and create a new one, instead?
*/
- VelocityEngine createVelocityEngine(String key, Properties properties)
- throws XWikiVelocityException;
+ VelocityEngine createVelocityEngine(String key, Properties properties) throws XWikiVelocityException;
}
Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityManager.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityManager.java 2008-06-30 23:14:26 UTC (rev 10955)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/VelocityManager.java 2008-06-30 23:44:13 UTC (rev 10956)
@@ -23,8 +23,8 @@
import org.apache.velocity.VelocityContext;
/**
- * Provides access to the main XWiki Velocity objects.
- *
+ * Provides access to the main XWiki Velocity objects.
+ *
* @since 1.5M2
* @version $Id$
*/
@@ -39,14 +39,14 @@
* @return the current Velocity Context retrieved from the Execution Context
*/
VelocityContext getVelocityContext();
-
+
/**
* Get the current Velocity Engine or create one if none has been created.
- *
+ *
* @return the current Velocity Engine retrieved from the Execution Context
* @throws XWikiVelocityException if the Velocity Engine cannot be created
- * @todo Move the engine creation to some initialization method instead and remove the need
- * for throwing an exception
+ * @todo Move the engine creation to some initialization method instead and remove the need for throwing an
+ * exception
*/
VelocityEngine getVelocityEngine() throws XWikiVelocityException;
}
More information about the notifications
mailing list