incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cframp...@apache.org
Subject svn commit: r1343781 [10/17] - in /incubator/flex/trunk/modules: ./ thirdparty/velocity/ thirdparty/velocity/build/ thirdparty/velocity/build/lib/ thirdparty/velocity/build/xsl/ thirdparty/velocity/src/java/org/apache/velocity/anakia/ thirdparty/veloci...
Date Tue, 29 May 2012 15:35:15 GMT
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java Tue May 29 15:35:01 2012
@@ -0,0 +1,637 @@
+package org.apache.velocity.runtime.resource;
+
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+import org.apache.velocity.runtime.resource.ResourceFactory;
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+import org.apache.velocity.runtime.resource.loader.ResourceLoaderFactory;
+
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.ParseErrorException;
+
+import org.apache.commons.collections.ExtendedProperties;
+
+/**
+ * Class to manage the text resource for the Velocity
+ * Runtime.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:paulo.gaspar@krankikom.de">Paulo Gaspar</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ResourceManagerImpl.java,v 1.7.4.1 2004/03/03 23:23:01 geirm Exp $
+ */
+public class ResourceManagerImpl implements ResourceManager
+{
+    /**
+     * A template resources.
+     */
+    public static final int RESOURCE_TEMPLATE = 1;
+    
+    /**
+     * A static content resource.
+     */
+    public static final int RESOURCE_CONTENT = 2;
+
+    /**
+     * token used to identify the loader internally
+     */
+    private static final String RESOURCE_LOADER_IDENTIFIER = "_RESOURCE_LOADER_IDENTIFIER_";
+
+    /**
+     *  Object implementing ResourceCache to 
+     *  be our resource manager's Resource cache.
+     */
+    protected ResourceCache globalCache = null;
+    
+    /**
+     * The List of templateLoaders that the Runtime will
+     * use to locate the InputStream source of a template.
+     */
+    protected  ArrayList resourceLoaders = new ArrayList();
+    
+    /**
+     * This is a list of the template input stream source
+     * initializers, basically properties for a particular
+     * template stream source. The order in this list
+     * reflects numbering of the properties i.e.
+     *
+     * <loader-id>.resource.loader.<property> = <value>
+     */
+    private  ArrayList sourceInitializerList = new ArrayList();
+    
+    /**
+     * This is a map of public name of the template
+     * stream source to it's initializer. This is so
+     * that clients of velocity can set properties of
+     * a template source stream with its public name.
+     * So for example, a client could set the 
+     * File.resource.path property and this would
+     * change the resource.path property for the
+     * file template stream source.
+     */
+    private  Hashtable sourceInitializerMap = new Hashtable();
+
+    /**
+     * Each loader needs a configuration object for
+     * its initialization, this flags keeps track of whether
+     * or not the configuration objects have been created
+     * for the resource loaders.
+     */
+    private  boolean resourceLoaderInitializersActive = false;
+
+    /**
+     *  switch to turn off log notice when a resource is found for
+     *  the first time.
+     */
+    private  boolean logWhenFound = true;
+
+    protected RuntimeServices rsvc = null;
+
+    /**
+     * Initialize the ResourceManager.
+     */
+    public void initialize( RuntimeServices rs ) 
+        throws Exception
+    {
+        rsvc = rs;
+        
+        rsvc.info("Default ResourceManager initializing. (" + this.getClass() + ")");
+
+        ResourceLoader resourceLoader;
+        
+        assembleResourceLoaderInitializers();
+        
+        for (int i = 0; i < sourceInitializerList.size(); i++)
+        {
+            ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList.get(i);
+            String loaderClass = configuration.getString("class");
+
+            if ( loaderClass == null)
+            {
+                rsvc.error(  "Unable to find '"
+                                + configuration.getString(RESOURCE_LOADER_IDENTIFIER)
+                                + ".resource.loader.class' specification in configuation."
+                                + " This is a critical value.  Please adjust configuration.");
+                continue;
+            }
+
+            resourceLoader = ResourceLoaderFactory.getLoader( rsvc, loaderClass);
+            resourceLoader.commonInit( rsvc, configuration);
+            resourceLoader.init(configuration);
+            resourceLoaders.add(resourceLoader);
+
+        }
+
+        /*
+         * now see if this is overridden by configuration
+         */
+
+        logWhenFound = rsvc.getBoolean( RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true );
+
+        /*
+         *  now, is a global cache specified?
+         */
+         
+        String claz = rsvc.getString( RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS );
+        
+        Object o = null;
+        
+        if ( claz != null && claz.length() > 0 )
+        {
+            try
+            {
+               o = Class.forName( claz ).newInstance();
+            }
+            catch (ClassNotFoundException cnfe )
+            {
+                String err = "The specified class for ResourceCache ("
+                    + claz    
+                    + ") does not exist (or is not accessible to the current classlaoder).";
+                 rsvc.error( err );
+                 
+                 o = null;
+            }
+            
+            if (!(o instanceof ResourceCache) )
+            {
+                String err = "The specified class for ResourceCache ("
+                    + claz 
+                    + ") does not implement org.apache.runtime.resource.ResourceCache."
+                    + " ResourceManager. Using default ResourceCache implementation.";
+                    
+                rsvc.error( err);
+                
+                o = null;
+            }
+        }
+        
+        /*
+         *  if we didn't get through that, just use the default.
+         */
+         
+        if ( o == null)
+            o = new ResourceCacheImpl();
+            
+         globalCache = (ResourceCache) o;
+            
+         globalCache.initialize( rsvc );        
+
+         rsvc.info("Default ResourceManager initialization complete.");
+
+        }
+
+    /**
+     * This will produce a List of Hashtables, each
+     * hashtable contains the intialization info for
+     * a particular resource loader. This Hastable
+     * will be passed in when initializing the
+     * the template loader.
+     */
+    private void assembleResourceLoaderInitializers()
+    {
+        if (resourceLoaderInitializersActive)
+        {
+            return;
+        }            
+
+        Vector resourceLoaderNames = 
+            rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);
+
+        for (int i = 0; i < resourceLoaderNames.size(); i++)
+        {
+            /*
+             * The loader id might look something like the following:
+             *
+             * file.resource.loader
+             *
+             * The loader id is the prefix used for all properties
+             * pertaining to a particular loader.
+             */
+            String loaderID = 
+                resourceLoaderNames.get(i) + "." + RuntimeConstants.RESOURCE_LOADER;
+
+            ExtendedProperties loaderConfiguration =
+                rsvc.getConfiguration().subset(loaderID);
+
+            /*
+             *  we can't really count on ExtendedProperties to give us an empty set
+             */
+
+            if ( loaderConfiguration == null)
+            {
+                rsvc.warn("ResourceManager : No configuration information for resource loader named '" 
+                          + resourceLoaderNames.get(i) + "'. Skipping.");
+                continue;
+            }
+
+            /*
+             *  add the loader name token to the initializer if we need it
+             *  for reference later. We can't count on the user to fill
+             *  in the 'name' field
+             */
+
+            loaderConfiguration.setProperty( RESOURCE_LOADER_IDENTIFIER, resourceLoaderNames.get(i));
+
+            /*
+             * Add resources to the list of resource loader
+             * initializers.
+             */
+            sourceInitializerList.add(loaderConfiguration);
+        }
+        
+        resourceLoaderInitializersActive = true;
+    }
+
+    /**
+     * Gets the named resource.  Returned class type corresponds to specified type
+     * (i.e. <code>Template</code> to <code>RESOURCE_TEMPLATE</code>).
+     *
+     * @param resourceName The name of the resource to retrieve.
+     * @param resourceType The type of resource (<code>RESOURCE_TEMPLATE</code>,
+     *                     <code>RESOURCE_CONTENT</code>, etc.).
+     * @param encoding  The character encoding to use.
+     * @return Resource with the template parsed and ready.
+     * @throws ResourceNotFoundException if template not found
+     *          from any available source.
+     * @throws ParseErrorException if template cannot be parsed due
+     *          to syntax (or other) error.
+     * @throws Exception if a problem in parse
+     */
+    public Resource getResource(String resourceName, int resourceType, String encoding )
+        throws ResourceNotFoundException, ParseErrorException, Exception
+    {
+        /* 
+         * Check to see if the resource was placed in the cache.
+         * If it was placed in the cache then we will use
+         * the cached version of the resource. If not we
+         * will load it.
+         */
+        
+        Resource resource = globalCache.get(resourceName);
+
+        if( resource != null)
+        {
+            /*
+             *  refresh the resource
+             */
+             
+            try
+            {
+                refreshResource( resource, encoding );
+            }
+            catch( ResourceNotFoundException rnfe )
+            {
+                /*
+                 *  something exceptional happened to that resource
+                 *  this could be on purpose, 
+                 *  so clear the cache and try again
+                 */
+                 
+                 globalCache.remove( resourceName );
+     
+                 return getResource( resourceName, resourceType, encoding );
+            }
+            catch( ParseErrorException pee )
+            {
+                rsvc.error(
+                    "ResourceManager.getResource() exception: " + pee);
+                
+                throw pee;
+            }
+            catch( Exception eee )
+            {
+                rsvc.error(
+                    "ResourceManager.getResource() exception: " + eee);
+                
+                throw eee;
+            }
+        }
+        else
+        {            
+            try
+            {
+                /*
+                 *  it's not in the cache, so load it.
+                 */
+
+                resource = loadResource( resourceName, resourceType, encoding );
+                      
+                if (resource.getResourceLoader().isCachingOn())
+                {
+                    globalCache.put(resourceName, resource);
+                }                    
+            }
+            catch( ResourceNotFoundException rnfe2 )
+            {
+                rsvc.error(
+                    "ResourceManager : unable to find resource '" + resourceName + 
+                        "' in any resource loader.");
+                
+                throw rnfe2;
+            }
+            catch( ParseErrorException pee )
+            {
+                rsvc.error(
+                    "ResourceManager.getResource() parse exception: " + pee);
+                
+                throw pee;
+            }
+            catch( Exception ee )
+            {
+                rsvc.error(
+                    "ResourceManager.getResource() exception new: " + ee);
+
+                throw ee;
+            }
+        }
+
+        return resource;
+    }
+    
+    /**
+     *  Loads a resource from the current set of resource loaders
+     *
+     * @param resourceName The name of the resource to retrieve.
+     * @param resourceType The type of resource (<code>RESOURCE_TEMPLATE</code>,
+     *                     <code>RESOURCE_CONTENT</code>, etc.).
+     * @param encoding  The character encoding to use.
+     * @return Resource with the template parsed and ready.
+     * @throws ResourceNotFoundException if template not found
+     *          from any available source.
+     * @throws ParseErrorException if template cannot be parsed due
+     *          to syntax (or other) error.
+     * @throws Exception if a problem in parse
+     */    
+    protected Resource loadResource(String resourceName, int resourceType, String encoding )
+        throws ResourceNotFoundException, ParseErrorException, Exception
+    {
+        Resource resource = ResourceFactory.getResource(resourceName, resourceType);
+                
+        resource.setRuntimeServices( rsvc );
+
+        resource.setName( resourceName );
+        resource.setEncoding( encoding );
+                
+        /* 
+         * Now we have to try to find the appropriate
+         * loader for this resource. We have to cycle through
+         * the list of available resource loaders and see
+         * which one gives us a stream that we can use to
+         * make a resource with.
+         */
+
+        long howOldItWas = 0;  // Initialize to avoid warnings
+
+        ResourceLoader resourceLoader = null;
+
+        for (int i = 0; i < resourceLoaders.size(); i++)
+        {
+            resourceLoader = (ResourceLoader) resourceLoaders.get(i);
+            resource.setResourceLoader(resourceLoader);
+            
+            /*
+             *  catch the ResourceNotFound exception
+             *  as that is ok in our new multi-loader environment
+             */
+
+            try 
+            {
+                if (resource.process())
+                {
+                     /*
+                      *  FIXME  (gmj)
+                      *  moved in here - technically still 
+                      *  a problem - but the resource needs to be 
+                      *  processed before the loader can figure 
+                      *  it out due to to the new 
+                      *  multi-path support - will revisit and fix
+                      */
+
+                     if ( logWhenFound )
+                     {
+                         rsvc.info("ResourceManager : found " + resourceName + 
+                                      " with loader " + resourceLoader.getClassName() );
+                     }
+   
+                     howOldItWas = resourceLoader.getLastModified( resource );
+                     break;
+                 }
+            }
+            catch( ResourceNotFoundException rnfe )
+            {
+                /*
+                 *  that's ok - it's possible to fail in
+                 *  multi-loader environment
+                 */
+            }
+        }
+                
+        /*
+         * Return null if we can't find a resource.
+         */
+        if (resource.getData() == null)
+        {
+            throw new ResourceNotFoundException(
+                "Unable to find resource '" + resourceName + "'");
+        }
+
+        /*
+         *  some final cleanup
+         */
+         
+        resource.setLastModified( howOldItWas );
+         
+        resource.setModificationCheckInterval(
+            resourceLoader.getModificationCheckInterval());
+        
+        resource.touch();
+    
+        return resource;            
+    }
+    
+    /**
+     *  Takes an existing resource, and 'refreshes' it.  This
+     *  generally means that the source of the resource is checked
+     *  for changes according to some cache/check algorithm
+     *  and if the resource changed, then the resource data is
+     *  reloaded and re-parsed.
+     *
+     *  @param resource resource to refresh
+     *
+     * @throws ResourceNotFoundException if template not found
+     *          from current source for this Resource
+     * @throws ParseErrorException if template cannot be parsed due
+     *          to syntax (or other) error.
+     * @throws Exception if a problem in parse
+     */
+    protected void refreshResource( Resource resource, String encoding )
+        throws ResourceNotFoundException, ParseErrorException, Exception
+    {
+        /* 
+         * The resource knows whether it needs to be checked
+         * or not, and the resource's loader can check to
+         * see if the source has been modified. If both
+         * these conditions are true then we must reload
+         * the input stream and parse it to make a new
+         * AST for the resource.
+         */
+        if ( resource.requiresChecking() )
+        {
+            /*
+             *  touch() the resource to reset the counters
+             */
+
+            resource.touch();
+            
+            if(  resource.isSourceModified() )
+            {
+                /*
+                 *  now check encoding info.  It's possible that the newly declared
+                 *  encoding is different than the encoding already in the resource
+                 *  this strikes me as bad...
+                 */
+                
+                if (!resource.getEncoding().equals( encoding ) )
+                {
+                    rsvc.error("Declared encoding for template '" + resource.getName() 
+                                  + "' is different on reload.  Old = '" + resource.getEncoding()
+                                  + "'  New = '" + encoding );
+    
+                    resource.setEncoding( encoding );
+                }
+
+                /*
+                 *  read how old the resource is _before_
+                 *  processing (=>reading) it
+                 */
+                long howOldItWas = resource.getResourceLoader().getLastModified( resource );
+
+                /*
+                 *  read in the fresh stream and parse
+                 */
+
+                resource.process();
+
+                /*
+                 *  now set the modification info and reset
+                 *  the modification check counters
+                 */
+                
+                resource.setLastModified( howOldItWas );
+            }
+        }
+    }
+
+     /**
+     * Gets the named resource.  Returned class type corresponds to specified type
+     * (i.e. <code>Template</code> to <code>RESOURCE_TEMPLATE</code>).
+     *
+     * @param resourceName The name of the resource to retrieve.
+     * @param resourceType The type of resource (<code>RESOURCE_TEMPLATE</code>,
+     *                     <code>RESOURCE_CONTENT</code>, etc.).
+     * @return Resource with the template parsed and ready.
+     * @throws ResourceNotFoundException if template not found
+     *          from any available source.
+     * @throws ParseErrorException if template cannot be parsed due
+     *          to syntax (or other) error.
+     * @throws Exception if a problem in parse
+     *
+     *  @deprecated Use
+     *  {@link #getResource(String resourceName, int resourceType, 
+     *          String encoding )}
+     */
+    public Resource getResource(String resourceName, int resourceType  )
+        throws ResourceNotFoundException, ParseErrorException, Exception
+    {  
+        return getResource( resourceName, resourceType, RuntimeConstants.ENCODING_DEFAULT);
+    }
+
+    /**
+     *  Determines is a template exists, and returns name of the loader that 
+     *  provides it.  This is a slightly less hokey way to support
+     *  the Velocity.templateExists() utility method, which was broken
+     *  when per-template encoding was introduced.  We can revisit this.
+     *
+     *  @param resourceName Name of template or content resource
+     *  @return class name of loader than can provide it
+     */
+    public String getLoaderNameForResource(String resourceName )
+    {
+        ResourceLoader resourceLoader = null;
+       
+        /*
+         *  loop through our loaders...
+         */
+        for (int i = 0; i < resourceLoaders.size(); i++)
+        { 
+            resourceLoader = (ResourceLoader) resourceLoaders.get(i);
+
+            InputStream is = null;
+
+            /*
+             *  if we find one that can provide the resource,
+             *  return the name of the loaders's Class
+             */
+            try
+            {
+                is=resourceLoader.getResourceStream( resourceName );
+               
+                if( is != null)
+                {
+                    return resourceLoader.getClass().toString();
+                }
+            }
+            catch( ResourceNotFoundException e)
+            {
+                /*
+                 * this isn't a problem.  keep going
+                 */
+            }
+            finally
+            {
+                /*
+                 *  if we did find one, clean up because we were 
+                 *  returned an open stream
+                 */
+                if (is != null)
+                {
+                    try
+                    {
+                        is.close();
+                    }
+                    catch( IOException ioe)
+                    {
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+}
+
+

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java Tue May 29 15:35:01 2012
@@ -0,0 +1,136 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+import java.io.InputStream;
+
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+import org.apache.commons.collections.ExtendedProperties;
+
+/**
+ *  ClasspathResourceLoader is a simple loader that will load
+ *  templates from the classpath.
+ *  <br>
+ *  <br>
+ *  Will load templates from  from multiple instances of 
+ *  and arbitrary combinations of :
+ *  <ul>
+ *  <li> jar files
+ *  <li> zip files
+ *  <li> template directories (any directory containing templates)
+ *  </ul>
+ *  This is a configuration-free loader, in that there are no
+ *  parameters to be specified in the configuration properties,
+ *  other than specifying this as the loader to use.  For example
+ *  the following is all that the loader needs to be functional :
+ *  <br>
+ *  <br>
+ *  resource.loader = class
+ *  class.resource.loader.class =
+ *    org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
+ *  <br>
+ *  <br>
+ *  To use, put your template directories, jars
+ *  and zip files into the classpath or other mechanisms that make
+ *  resources accessable to the classloader.
+ *  <br>
+ *  <br>
+ *  This makes deployment trivial for web applications running in
+ *  any Servlet 2.2 compliant servlet runner, such as Tomcat 3.2 
+ *  and others.
+ *  <br>
+ *  <br>
+ *  For a Servlet Spec v2.2 servlet runner, 
+ *  just drop the jars of template files into the WEB-INF/lib
+ *  directory of your webapp, and you won't have to worry about setting
+ *  template paths or altering them with the root of the webapp
+ *  before initializing.
+ *  <br>
+ *  <br>
+ *  I have also tried it with a WAR deployment, and that seemed to
+ *  work just fine.
+ *  
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ClasspathResourceLoader.java,v 1.8.4.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public class ClasspathResourceLoader extends ResourceLoader
+{
+
+    /**
+     *  This is abstract in the base class, so we need it
+     */
+    public void init( ExtendedProperties configuration)
+    {
+        rsvc.info("ClasspathResourceLoader : initialization starting.");
+        rsvc.info("ClasspathResourceLoader : initialization complete.");
+    }
+
+    /**
+     * Get an InputStream so that the Runtime can build a
+     * template with it.
+     *
+     * @param name name of template to get
+     * @return InputStream containing the template
+     * @throws ResourceNotFoundException if template not found
+     *         in  classpath.
+     */
+    public synchronized InputStream getResourceStream( String name )
+        throws ResourceNotFoundException
+    {
+        InputStream result = null;
+        
+        if (name == null || name.length() == 0)
+        {
+            throw new ResourceNotFoundException ("No template name provided");
+        }
+        
+        try 
+        {
+            ClassLoader classLoader = this.getClass().getClassLoader();
+            result= classLoader.getResourceAsStream( name );
+        }
+        catch( Exception fnfe )
+        {
+            /*
+             *  log and convert to a general Velocity ResourceNotFoundException
+             */
+            
+            throw new ResourceNotFoundException( fnfe.getMessage() );
+        }
+        
+        return result;
+    }
+    
+    /**
+     * Defaults to return false.
+     */
+    public boolean isSourceModified(Resource resource)
+    {
+        return false;
+    }
+
+    /**
+     * Defaults to return 0
+     */
+    public long getLastModified(Resource resource)
+    {
+        return 0;
+    }
+}
+

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java Tue May 29 15:35:01 2012
@@ -0,0 +1,324 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001-2002,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.util.Hashtable;
+
+import javax.sql.DataSource;
+import javax.naming.InitialContext;
+
+import org.apache.velocity.runtime.Runtime;
+import org.apache.velocity.runtime.resource.Resource;
+
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+import org.apache.commons.collections.ExtendedProperties;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+/**
+ * This is a simple template file loader that loads templates
+ * from a DataSource instead of plain files.
+ *
+ * It can be configured with a datasource name, a table name,
+ * id column (name), content column (the template body) and a
+ * datetime column (for last modification info).
+ * <br>
+ * <br>
+ * Example configuration snippet for velocity.properties:
+ * <br>
+ * <br>
+ * resource.loader = file, ds <br>
+ * <br>
+ * ds.resource.loader.public.name = DataSource <br>
+ * ds.resource.loader.description = Velocity DataSource Resource Loader <br>
+ * ds.resource.loader.class = org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader <br>
+ * ds.resource.loader.resource.datasource = java:comp/env/jdbc/Velocity <br>
+ * ds.resource.loader.resource.table = tb_velocity_template <br>
+ * ds.resource.loader.resource.keycolumn = id_template <br>
+ * ds.resource.loader.resource.templatecolumn = template_definition <br>
+ * ds.resource.loader.resource.timestampcolumn = template_timestamp <br>
+ * ds.resource.loader.cache = false <br>
+ * ds.resource.loader.modificationCheckInterval = 60 <br>
+ * <br>
+ * Example WEB-INF/web.xml: <br>
+ * <br>
+ *	<resource-ref> <br>
+ *	 <description>Velocity template DataSource</description> <br>
+ *	 <res-ref-name>jdbc/Velocity</res-ref-name> <br>
+ *	 <res-type>javax.sql.DataSource</res-type> <br>
+ *	 <res-auth>Container</res-auth> <br>
+ *	</resource-ref> <br>
+ * <br>
+ *  <br>
+ * and Tomcat 4 server.xml file: <br>
+ *  [...] <br>
+ *  <Context path="/exampleVelocity" docBase="exampleVelocity" debug="0"> <br>
+ *  [...] <br>
+ *   <ResourceParams name="jdbc/Velocity"> <br>
+ *    <parameter> <br>
+ *      <name>driverClassName</name> <br>
+ *      <value>org.hsql.jdbcDriver</value> <br>
+ *    </parameter> <br>
+ *    <parameter> <br>
+ *     <name>driverName</name> <br>
+ *     <value>jdbc:HypersonicSQL:database</value> <br>
+ *    </parameter> <br>
+ *    <parameter> <br>
+ *     <name>user</name> <br>
+ *     <value>database_username</value> <br>
+ *    </parameter> <br>
+ *    <parameter> <br>
+ *     <name>password</name> <br>
+ *     <value>database_password</value> <br>
+ *    </parameter> <br>
+ *   </ResourceParams> <br>
+ *  [...] <br>
+ *  </Context> <br>
+ *  [...] <br>
+ * <br>
+ *  Example sql script:<br>
+ *  CREATE TABLE tb_velocity_template ( <br>
+ *	id_template varchar (40) NOT NULL , <br>
+ *	template_definition text (16) NOT NULL , <br>
+ *	template_timestamp datetime NOT NULL  <br>
+ *	) <br>
+ *
+ * @author <a href="mailto:david.kinnvall@alertir.com">David Kinnvall</a>
+ * @author <a href="mailto:paulo.gaspar@krankikom.de">Paulo Gaspar</a>
+ * @author <a href="mailto:lachiewicz@plusnet.pl">Sylwester Lachiewicz</a>
+ * @version $Id: DataSourceResourceLoader.java,v 1.8.8.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public class DataSourceResourceLoader extends ResourceLoader
+{
+     private String dataSourceName;
+     private String tableName;
+     private String keyColumn;
+     private String templateColumn;
+     private String timestampColumn;
+     private InitialContext ctx;
+     private DataSource dataSource;
+
+     public void init( ExtendedProperties configuration)
+     {
+         dataSourceName  = configuration.getString("resource.datasource");
+         tableName       = configuration.getString("resource.table");
+         keyColumn       = configuration.getString("resource.keycolumn");
+         templateColumn  = configuration.getString("resource.templatecolumn");
+         timestampColumn = configuration.getString("resource.timestampcolumn");
+
+         Runtime.info("Resources Loaded From: " + dataSourceName + "/" + tableName);
+         Runtime.info( "Resource Loader using columns: " + keyColumn + ", "
+                       + templateColumn + " and " + timestampColumn);
+         Runtime.info("Resource Loader Initalized.");
+     }
+
+     public boolean isSourceModified(Resource resource)
+     {
+         return (resource.getLastModified() !=
+                 readLastModified(resource, "checking timestamp"));
+     }
+
+     public long getLastModified(Resource resource)
+     {
+         return readLastModified(resource, "getting timestamp");
+     }
+
+     /**
+      * Get an InputStream so that the Runtime can build a
+      * template with it.
+      *
+      *  @param name name of template
+      *  @return InputStream containing template
+      */
+     public synchronized InputStream getResourceStream( String name )
+         throws ResourceNotFoundException
+     {
+         if (name == null || name.length() == 0)
+         {
+             throw new ResourceNotFoundException ("Need to specify a template name!");
+         }
+
+         try
+         {
+             Connection conn = openDbConnection();
+
+             try
+             {
+                 ResultSet rs = readData(conn, templateColumn, name);
+
+                 try
+                 {
+                     if (rs.next())
+                     {
+                         return new
+                             BufferedInputStream(rs.getAsciiStream(templateColumn));
+                     }
+                     else
+                     {
+                         String msg = "DataSourceResourceLoader Error: cannot find resource "
+                             + name;
+                         Runtime.error(msg );
+
+                         throw new ResourceNotFoundException (msg);
+                     }
+                 }
+                 finally
+                 {
+                     rs.close();
+                 }
+             }
+             finally
+             {
+                 closeDbConnection(conn);
+             }
+         }
+         catch(Exception e)
+         {
+             String msg =  "DataSourceResourceLoader Error: database problem trying to load resource "
+                 + name + ": " + e.toString();
+
+             Runtime.error( msg );
+
+             throw new ResourceNotFoundException (msg);
+
+         }
+
+     }
+
+    /**
+     *  Fetches the last modification time of the resource
+     *
+     *  @param resource Resource object we are finding timestamp of
+     *  @param i_operation string for logging, indicating caller's intention
+     *
+     *  @return timestamp as long
+     */
+     private long readLastModified(Resource resource, String i_operation)
+     {
+         /*
+          *  get the template name from the resource
+          */
+
+         String name = resource.getName();
+         try
+         {
+             Connection conn = openDbConnection();
+
+             try
+             {
+                 ResultSet rs = readData(conn, timestampColumn, name);
+                 try
+                 {
+                     if (rs.next())
+                     {
+	                     return rs.getTimestamp(timestampColumn).getTime();
+                     }
+                     else
+                     {
+                         Runtime.error("DataSourceResourceLoader Error: while "
+                                       + i_operation
+                                       + " could not find resource " + name);
+                     }
+                 }
+                 finally
+                 {
+                     rs.close();
+                 }
+             }
+             finally
+             {
+                 closeDbConnection(conn);
+             }
+         }
+         catch(Exception e)
+         {
+             Runtime.error( "DataSourceResourceLoader Error: error while "
+                 + i_operation + " when trying to load resource "
+                 + name + ": " + e.toString() );
+         }
+         return 0;
+     }
+
+    /**
+     *   gets connection to the datasource specified through the configuration
+     *  parameters.
+     *
+     *  @return connection
+     */
+     private Connection openDbConnection()
+         throws Exception
+    {
+         if(ctx == null)
+         {
+             ctx = new InitialContext();
+         }
+
+         if(dataSource == null)
+         {
+             dataSource = (DataSource)ctx.lookup(dataSourceName);
+         }
+
+         return dataSource.getConnection();
+     }
+
+    /**
+     *  Closes connection to the datasource
+     */
+     private void closeDbConnection(Connection conn)
+     {
+         try
+         {
+             conn.close();
+         }
+         catch (Exception e)
+         {
+             Runtime.info(
+                 "DataSourceResourceLoader Quirk: problem when closing connection: "
+                 + e.toString());
+         }
+     }
+
+    /**
+     *  Reads the data from the datasource.  It simply does the following query :
+     *  <br>
+     *   SELECT <i>columnNames</i> FROM <i>tableName</i> WHERE <i>keyColumn</i>
+     *      = '<i>templateName</i>'
+     *  <br>
+     *  where <i>keyColumn</i> is a class member set in init()
+     *
+     *  @param conn connection to datasource
+     *  @param columnNames columns to fetch from datasource
+     *  @param templateName name of template to fetch
+     *  @return result set from query
+     */
+     private ResultSet readData(Connection conn, String columnNames, String templateName)
+         throws SQLException
+     {
+         Statement stmt = conn.createStatement();
+
+         String sql = "SELECT " + columnNames
+                      + " FROM " + tableName
+                      + " WHERE " + keyColumn + " = '" + templateName + "'";
+
+         return stmt.executeQuery(sql);
+     }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java Tue May 29 15:35:01 2012
@@ -0,0 +1,257 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.FileNotFoundException;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.velocity.util.StringUtils;
+
+import org.apache.velocity.runtime.resource.Resource;
+
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+import org.apache.commons.collections.ExtendedProperties;
+
+/**
+ * A loader for templates stored on the file system.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: FileResourceLoader.java,v 1.19.4.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public class FileResourceLoader extends ResourceLoader
+{
+    /**
+     * The paths to search for templates.
+     */
+    private Vector paths = null;
+
+    /**
+     * Used to map the path that a template was found on
+     * so that we can properly check the modification
+     * times of the files.
+     */
+    private Hashtable templatePaths = new Hashtable();
+
+    public void init( ExtendedProperties configuration)
+    {
+        rsvc.info("FileResourceLoader : initialization starting.");
+        
+        paths = configuration.getVector("path");
+        
+        /*
+         *  lets tell people what paths we will be using
+         */
+
+        int sz = paths.size();
+
+        for( int i=0; i < sz; i++)
+        {
+            rsvc.info("FileResourceLoader : adding path '" + (String) paths.get(i) + "'");
+        }
+
+        rsvc.info("FileResourceLoader : initialization complete.");
+    }
+
+    /**
+     * Get an InputStream so that the Runtime can build a
+     * template with it.
+     *
+     * @param name name of template to get
+     * @return InputStream containing the template
+     * @throws ResourceNotFoundException if template not found
+     *         in the file template path.
+     */
+    public synchronized InputStream getResourceStream(String templateName)
+        throws ResourceNotFoundException
+    {
+        /*
+         * Make sure we have a valid templateName.
+         */
+        if (templateName == null || templateName.length() == 0)
+        {
+            /*
+             * If we don't get a properly formed templateName then
+             * there's not much we can do. So we'll forget about
+             * trying to search any more paths for the template.
+             */
+            throw new ResourceNotFoundException(
+                "Need to specify a file name or file path!");
+        }
+
+        String template = StringUtils.normalizePath(templateName);
+        if ( template == null || template.length() == 0 )
+        {
+            String msg = "File resource error : argument " + template + 
+                " contains .. and may be trying to access " + 
+                "content outside of template root.  Rejected.";
+
+            rsvc.error( "FileResourceLoader : " + msg );
+      
+            throw new ResourceNotFoundException ( msg );
+        }
+
+        /*
+         *  if a / leads off, then just nip that :)
+         */
+        if (template.startsWith("/"))
+        {
+            template = template.substring(1);
+        }
+
+        int size = paths.size();
+        for (int i = 0; i < size; i++)
+        {
+            String path = (String) paths.get(i);
+            InputStream inputStream = findTemplate(path, template);
+            
+            if (inputStream != null)
+            {
+                /*
+                 * Store the path that this template came
+                 * from so that we can check its modification
+                 * time.
+                 */
+
+                templatePaths.put(templateName, path);
+                return inputStream;
+            }                
+        }
+    
+        /*
+         * We have now searched all the paths for
+         * templates and we didn't find anything so
+         * throw an exception.
+         */
+         String msg = "FileResourceLoader Error: cannot find resource " +
+          template;
+    
+         throw new ResourceNotFoundException( msg );
+    }
+    
+    /**
+     * Try to find a template given a normalized path.
+     * 
+     * @param String a normalized path
+     * @return InputStream input stream that will be parsed
+     *
+     */
+    private InputStream findTemplate(String path, String template)
+    {
+        try 
+        {
+            File file = new File( path, template );   
+        
+            if ( file.canRead() )
+            {
+                return new BufferedInputStream(
+                    new FileInputStream(file.getAbsolutePath()));
+            }
+            else
+            {                
+                return null;
+            }                
+        }
+        catch( FileNotFoundException fnfe )
+        {
+            /*
+             *  log and convert to a general Velocity ResourceNotFoundException
+             */
+            return null;
+        }
+    }
+    
+    /**
+     * How to keep track of all the modified times
+     * across the paths.  Note that a file might have
+     * appeared in a directory which is earlier in the
+     * path; so we should search the path and see if
+     * the file we find that way is the same as the one
+     * that we have cached.
+     */
+    public boolean isSourceModified(Resource resource)
+    {
+        /*
+         * we assume that the file needs to be reloaded; 
+         * if we find the original file and it's unchanged,
+         * then we'll flip this.
+         */
+        boolean modified = true;
+
+        String fileName = resource.getName();
+        String path = (String) templatePaths.get(fileName);
+        File currentFile = null;
+
+        for (int i = 0; currentFile == null && i < paths.size(); i++)
+        {
+            String testPath = (String) paths.get(i);
+            File testFile = new File(testPath, fileName);
+            if (testFile.canRead())
+            {
+                currentFile = testFile;
+            }
+        }
+        File file = new File(path, fileName);
+        if (currentFile == null || !file.exists())
+        {
+            /*
+             * noop: if the file is missing now (either the cached
+             * file is gone, or the file can no longer be found)
+             * then we leave modified alone (it's set to true); a 
+             * reload attempt will be done, which will either use
+             * a new template or fail with an appropriate message
+             * about how the file couldn't be found.
+             */
+        }
+        else if (currentFile.equals(file) && file.canRead())
+        {
+            /*
+             * if only if currentFile is the same as file and
+             * file.lastModified() is the same as
+             * resource.getLastModified(), then we should use the
+             * cached version.
+             */
+            modified = (file.lastModified() != resource.getLastModified());
+        }
+
+        /*
+         * rsvc.debug("isSourceModified for " + fileName + ": " + modified);
+         */
+        return modified;
+    }
+
+    public long getLastModified(Resource resource)
+    {
+        String path = (String) templatePaths.get(resource.getName());
+        File file = new File(path, resource.getName());
+
+        if (file.canRead())
+        {
+            return file.lastModified();
+        }            
+        else
+        {
+            return 0;
+        }            
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java Tue May 29 15:35:01 2012
@@ -0,0 +1,141 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.Hashtable;
+
+import org.apache.velocity.runtime.RuntimeServices;
+
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+/**
+ * A small wrapper around a Jar
+ *
+ * @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
+ * @version $Id: JarHolder.java,v 1.8.4.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public class JarHolder
+{
+    private String urlpath = null;
+    private JarFile theJar = null;
+    private JarURLConnection conn = null;
+        
+    private RuntimeServices rsvc = null;
+
+    public JarHolder( RuntimeServices rs, String urlpath )
+    {
+        rsvc = rs;
+
+        this.urlpath=urlpath;
+        init();
+        
+        rsvc.info("  JarHolder : initialized JAR: " + urlpath );
+    }
+
+    public void init()
+    {
+        try
+        {
+            rsvc.info("  JarHolder : attempting to connect to "+ urlpath);
+            URL url = new URL( urlpath );
+            conn = (JarURLConnection) url.openConnection();
+            conn.setAllowUserInteraction(false);
+            conn.setDoInput(true);
+            conn.setDoOutput(false);
+            conn.connect();
+            theJar = conn.getJarFile();
+        } 
+        catch (Exception e)
+        {
+            rsvc.error("  JarHolder : error establishing connection to JAR "+ e);
+        }
+    }
+
+    public void close() 
+    {
+        try
+        {
+            theJar.close();
+        }
+        catch ( Exception e )
+        {
+            rsvc.error("  JarHolder : error Closing JAR the file " +  e);
+        }
+        theJar = null;
+        conn = null;
+
+        rsvc.info("  JarHolder : JAR file closed");
+    }
+    
+    public InputStream getResource( String theentry )
+     throws ResourceNotFoundException {
+        InputStream data = null;
+        
+        try 
+        {
+            JarEntry entry = theJar.getJarEntry( theentry );
+            
+            if ( entry != null )
+            {                
+                data =  theJar.getInputStream( entry );
+            }
+        }
+        catch( Exception fnfe )
+        {
+            rsvc.error("  JarHolder : getResource() error : exception : " + fnfe );
+            throw new ResourceNotFoundException( fnfe.getMessage() );
+        }
+        
+        return data;
+    }
+
+    public Hashtable getEntries()
+    {
+        Hashtable allEntries = new Hashtable(559);
+        
+        Enumeration all  = theJar.entries();
+        while ( all.hasMoreElements() )
+        {
+            JarEntry je = (JarEntry)all.nextElement();
+            
+            // We don't map plain directory entries
+            if ( !je.isDirectory() )
+            {
+                allEntries.put( je.getName(), this.urlpath );   
+            }
+        }
+        return allEntries;
+    }
+    
+    public String getUrlPath()
+    {
+        return urlpath;
+    }
+}
+
+
+
+
+
+
+

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java Tue May 29 15:35:01 2012
@@ -0,0 +1,242 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStream;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.velocity.util.StringUtils;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.commons.collections.ExtendedProperties;
+
+/**
+ * <p>
+ * ResourceLoader to load templates from multiple Jar files.
+ * </p>
+ * <p>
+ * The configuration of the JarResourceLoader is straightforward -
+ * You simply add the JarResourceLoader to the configuration via
+ * </p>
+ * <p><pre>
+ *    resource.loader = jar
+ *    jar.resource.loader.class = org.apache.velocity.runtime.resource.loader.JarResourceLoader
+ *    jar.resource.loader.path = list of JAR &lt;URL&gt;s
+ * </pre></p>
+ *
+ * <p> So for example, if you had a jar file on your local filesystem, you could simply do
+ *    <pre>
+ *    jar.resource.loader.path = jar:file:/opt/myfiles/jar1.jar
+ *    </pre>
+ * </p>
+ * <p> Note that jar specification for the <code>.path</code> configuration property
+ * conforms to the same rules for the java.net.JarUrlConnection class.
+ * </p>
+ *
+ * <p> For a working example, see the unit test case, 
+ *  org.apache.velocity.test.MultiLoaderTestCase class
+ * </p>
+ * 
+ * @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
+ * @version $Id: JarResourceLoader.java,v 1.16.4.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public class JarResourceLoader extends ResourceLoader
+{
+    /**
+     * Maps entries to the parent JAR File
+     * Key = the entry *excluding* plain directories
+     * Value = the JAR URL
+     */
+    private Hashtable entryDirectory = new Hashtable(559);
+    
+    /**
+     * Maps JAR URLs to the actual JAR
+     * Key = the JAR URL
+     * Value = the JAR
+     */
+    private Hashtable jarfiles = new Hashtable(89);
+   
+    /**
+     * Called by Velocity to initialize the loader
+     */
+    public void init( ExtendedProperties configuration)
+    {
+        rsvc.info("JarResourceLoader : initialization starting.");
+
+        Vector paths = configuration.getVector("path");
+
+        /*
+         *  support the old version but deprecate with a log message
+         */
+
+        if( paths == null || paths.size() == 0)
+        {
+            paths = configuration.getVector("resource.path");
+
+            if (paths != null && paths.size() > 0)
+            {
+                rsvc.warn("JarResourceLoader : you are using a deprecated configuration"
+                             + " property for the JarResourceLoader -> '<name>.resource.loader.resource.path'."
+                             + " Please change to the conventional '<name>.resource.loader.path'.");
+            }
+        }
+                             
+        rsvc.info("JarResourceLoader # of paths : " + paths.size() );
+        
+        for ( int i=0; i<paths.size(); i++ )
+        {
+            loadJar( (String)paths.get(i) );
+        }
+        
+        rsvc.info("JarResourceLoader : initialization complete.");
+    }
+    
+    private void loadJar( String path )
+    {
+        rsvc.info("JarResourceLoader : trying to load: " + path);
+
+        // Check path information
+        if ( path == null )
+        {
+            rsvc.error("JarResourceLoader : can not load JAR - JAR path is null");
+        }
+        if ( !path.startsWith("jar:") )
+        {
+            rsvc.error("JarResourceLoader : JAR path must start with jar: -> " +
+                "see java.net.JarURLConnection for information");
+        }
+        if ( !path.endsWith("!/") )
+        {
+            path += "!/";
+        }
+        
+        // Close the jar if it's already open
+        // this is useful for a reload
+        closeJar( path );
+        
+        // Create a new JarHolder
+        JarHolder temp = new JarHolder( rsvc,  path );
+        // Add it's entries to the entryCollection
+        addEntries( temp.getEntries() );
+        // Add it to the Jar table
+        jarfiles.put( temp.getUrlPath(), temp );
+    }
+
+    /**
+     * Closes a Jar file and set its URLConnection 
+     * to null.
+     */
+    private void closeJar( String path )
+    {
+        if ( jarfiles.containsKey(path) )
+        {
+            JarHolder theJar = (JarHolder)jarfiles.get(path);
+            theJar.close();
+        }
+    }
+    
+    /**
+     * Copy all the entries into the entryDirectory
+     * It will overwrite any duplicate keys.
+     */
+    private synchronized void addEntries( Hashtable entries )
+    {
+        entryDirectory.putAll( entries );
+    }
+    
+    /**
+     * Get an InputStream so that the Runtime can build a
+     * template with it.
+     *
+     * @param name name of template to get
+     * @return InputStream containing the template
+     * @throws ResourceNotFoundException if template not found
+     *         in the file template path.
+     */
+    public synchronized InputStream getResourceStream( String source )
+        throws ResourceNotFoundException
+    {
+        InputStream results = null;
+
+        if ( source == null || source.length() == 0)
+        {
+            throw new ResourceNotFoundException("Need to have a resource!");
+        }
+        
+        String normalizedPath = StringUtils.normalizePath( source );
+        
+        if ( normalizedPath == null || normalizedPath.length() == 0 )
+        {
+            String msg = "JAR resource error : argument " + normalizedPath + 
+                " contains .. and may be trying to access " + 
+                "content outside of template root.  Rejected.";
+            
+            rsvc.error( "JarResourceLoader : " + msg );
+            
+            throw new ResourceNotFoundException ( msg );
+        }
+        
+        /*
+         *  if a / leads off, then just nip that :)
+         */
+        if ( normalizedPath.startsWith("/") )
+        {
+            normalizedPath = normalizedPath.substring(1);
+        }
+    
+        if ( entryDirectory.containsKey( normalizedPath ) )
+        {
+            String jarurl  = (String)entryDirectory.get( normalizedPath );
+            
+            if ( jarfiles.containsKey( jarurl ) )
+            {
+                JarHolder holder = (JarHolder)jarfiles.get( jarurl );
+                results =  holder.getResource( normalizedPath );
+                return results;
+            }
+        }
+        
+        throw new ResourceNotFoundException( "JarResourceLoader Error: cannot find resource " +
+          source );
+
+    }
+        
+        
+    // TO DO BELOW 
+    // SHOULD BE DELEGATED TO THE JARHOLDER
+    public boolean isSourceModified(Resource resource)
+    {
+        return true;
+    }
+
+    public long getLastModified(Resource resource)
+    {
+        return 0;
+    }
+}
+
+
+
+
+
+
+
+
+
+

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java Tue May 29 15:35:01 2012
@@ -0,0 +1,160 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStream;
+
+import org.apache.velocity.runtime.RuntimeServices;
+
+import org.apache.velocity.runtime.resource.Resource;
+
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+import org.apache.commons.collections.ExtendedProperties;
+
+/**
+ * This is abstract class the all text resource loaders should
+ * extend.
+ * 
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ResourceLoader.java,v 1.14.4.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public abstract class ResourceLoader
+{
+    /** 
+     * Does this loader want templates produced with it
+     * cached in the Runtime.
+     */
+     protected boolean isCachingOn = false;
+    
+    /**
+     * This property will be passed on to the templates
+     * that are created with this loader.
+     */
+    protected long modificationCheckInterval = 2;
+   
+    /**
+     * Class name for this loader, for logging/debuggin
+     * purposes.
+     */
+    protected String className = null;
+
+    protected RuntimeServices rsvc = null;
+
+    /**
+     * This initialization is used by all resource
+     * loaders and must be called to set up common
+     * properties shared by all resource loaders
+     */
+    public void commonInit( RuntimeServices rs, ExtendedProperties configuration)
+    {
+        this.rsvc = rs;
+
+        /*
+         *  these two properties are not required for all loaders.
+         *  For example, for ClasspathLoader, what would cache mean? 
+         *  so adding default values which I think are the safest
+         *
+         *  don't cache, and modCheckInterval irrelevant...
+         */
+
+        isCachingOn = configuration.getBoolean("cache", false);
+        modificationCheckInterval = configuration.getLong("modificationCheckInterval", 0);
+        
+        /*
+         * this is a must!
+         */
+
+        className = configuration.getString("class");
+    }
+
+    /** 
+     * Initialize the template loader with a
+     * a resources class.
+     */
+    public abstract void init( ExtendedProperties configuration);
+
+    /** 
+     * Get the InputStream that the Runtime will parse
+     * to create a template.
+     */
+    public abstract InputStream getResourceStream( String source ) 
+        throws ResourceNotFoundException;
+
+    /**
+     * Given a template, check to see if the source of InputStream
+     * has been modified.
+     */
+    public abstract boolean isSourceModified(Resource resource);
+    
+    /**
+     * Get the last modified time of the InputStream source
+     * that was used to create the template. We need the template
+     * here because we have to extract the name of the template
+     * in order to locate the InputStream source.
+     */
+    public abstract long getLastModified(Resource resource);
+
+    /**
+     * Return the class name of this resource Loader
+     */
+    public String getClassName()
+    {
+        return className;
+    }
+
+    /**
+     * Set the caching state. If true, then this loader
+     * would like the Runtime to cache templates that
+     * have been created with InputStreams provided
+     * by this loader.
+     */
+    public void setCachingOn(boolean value)
+    {
+        isCachingOn = value;
+    }
+
+    /**
+     * The Runtime uses this to find out whether this
+     * template loader wants the Runtime to cache
+     * templates created with InputStreams provided
+     * by this loader.
+     */
+    public boolean isCachingOn()
+    {
+        return isCachingOn;
+    }
+
+    /**
+     * Set the interval at which the InputStream source
+     * should be checked for modifications.
+     */
+    public void setModificationCheckInterval(long modificationCheckInterval)
+    {
+        this.modificationCheckInterval = modificationCheckInterval;
+    }
+    
+    /**
+     * Get the interval at which the InputStream source
+     * should be checked for modifications.
+     */
+    public long getModificationCheckInterval()
+    {
+        return modificationCheckInterval;
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoaderFactory.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoaderFactory.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoaderFactory.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoaderFactory.java Tue May 29 15:35:01 2012
@@ -0,0 +1,60 @@
+package org.apache.velocity.runtime.resource.loader;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.util.StringUtils;
+
+/**
+ * Factory to grab a template loader.
+ * 
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: ResourceLoaderFactory.java,v 1.6.8.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public class ResourceLoaderFactory
+{
+    /**
+     * Gets the loader specified in the configuration file.
+     * @return TemplateLoader
+     */
+    public static ResourceLoader getLoader(RuntimeServices rs, String loaderClassName)
+     throws Exception
+    {
+        ResourceLoader loader = null;
+        
+        try
+        {
+            loader = ((ResourceLoader)Class.forName(loaderClassName)
+                .newInstance());
+            
+            rs.info("Resource Loader Instantiated: " + 
+                loader.getClass().getName());
+            
+            return loader;
+        }
+        catch( Exception e)
+        {
+            rs.error("Problem instantiating the template loader.\n" +
+                          "Look at your properties file and make sure the\n" +
+                          "name of the template loader is correct. Here is the\n" +
+                          "error: " + StringUtils.stackTrace(e));
+            
+            throw new Exception("Problem initializing template loader: " + loaderClassName + 
+            "\nError is: " + StringUtils.stackTrace(e));
+        }
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoaderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java Tue May 29 15:35:01 2012
@@ -0,0 +1,261 @@
+package org.apache.velocity.runtime.visitor;
+
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.Writer;
+
+import org.apache.velocity.context.InternalContextAdapter;
+
+import org.apache.velocity.runtime.parser.node.*;
+
+/**
+ * This is the base class for all visitors.
+ * For each AST node, this class will provide
+ * a bare-bones method for traversal.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: BaseVisitor.java,v 1.12.4.1 2004/03/03 23:23:02 geirm Exp $
+ */
+public abstract class BaseVisitor implements ParserVisitor
+{
+    /** Context used during traversal */
+    protected InternalContextAdapter context;
+    
+    /** Writer used as the output sink */
+    protected Writer writer;
+    
+    public void setWriter( Writer writer )
+    {
+        this.writer = writer;
+    }        
+
+    public void setContext( InternalContextAdapter context)
+    {
+        this.context = context;
+    }
+    
+    public Object visit(SimpleNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTprocess node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTExpression node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTAssignment node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTOrNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTAndNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTEQNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTNENode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTLTNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTGTNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTLENode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTGENode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTAddNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTSubtractNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTMulNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTDivNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTModNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTNotNode node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTNumberLiteral node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTStringLiteral node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTIdentifier node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTMethod node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTReference node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTTrue node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTFalse node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTBlock node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTText node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTIfStatement node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTElseStatement node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTElseIfStatement node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+    
+    public Object visit(ASTComment node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTObjectArray node, Object data)
+    { 
+        data = node.childrenAccept(this, data); 
+        return data; 
+    }
+
+    public Object visit(ASTWord node, Object data)
+    { 
+        data = node.childrenAccept(this, data);   
+        return data;
+    }
+    
+    public Object visit(ASTSetDirective node, Object data)
+    { 
+        data = node.childrenAccept(this, data);   
+        return data;
+    }
+    
+    public Object visit(ASTDirective node, Object data)
+    { 
+        data = node.childrenAccept(this, data);   
+        return data;
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/NodeViewMode.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/NodeViewMode.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/NodeViewMode.java Tue May 29 15:35:01 2012
@@ -0,0 +1,277 @@
+package org.apache.velocity.runtime.visitor;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.velocity.runtime.parser.Token;
+import org.apache.velocity.runtime.parser.node.*;
+
+/**
+ * This class is simply a visitor implementation
+ * that traverses the AST, produced by the Velocity
+ * parsing process, and creates a visual structure
+ * of the AST. This is primarily used for
+ * debugging, but it useful for documentation
+ * as well.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: NodeViewMode.java,v 1.6.4.1 2004/03/03 23:23:03 geirm Exp $
+ */
+public class NodeViewMode extends BaseVisitor
+{
+    private int indent = 0;
+    private boolean showTokens = true;
+
+    /** Indent child nodes to help visually identify
+      *  the structure of the AST.
+      */
+    private String indentString()
+    {
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < indent; ++i)
+        {
+            sb.append("  ");
+        }
+        return sb.toString();
+    }
+
+    /**
+      * Display the type of nodes and optionally the
+      * first token.
+      */
+    private Object showNode(Node node, Object data)
+    {
+        String tokens = "";
+        String special = "";
+        Token t;
+        
+        if (showTokens)
+        {
+            t = node.getFirstToken();
+            
+            if (t.specialToken != null && ! t.specialToken.image.startsWith("##"))
+                special = t.specialToken.image;
+            
+            tokens = " -> " + special + t.image;
+        }            
+        
+        System.out.println(indentString() + node + tokens);
+        ++indent;
+        data = node.childrenAccept(this, data);
+        --indent;
+        return data;
+    }
+
+    /** Display a SimpleNode */
+    public Object visit(SimpleNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTprocess node */
+    public Object visit(ASTprocess node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTExpression node */
+    public Object visit(ASTExpression node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTAssignment node ( = ) */
+    public Object visit(ASTAssignment node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTOrNode ( || ) */
+    public Object visit(ASTOrNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTAndNode ( && ) */
+    public Object visit(ASTAndNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTEQNode ( == ) */
+    public Object visit(ASTEQNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTNENode ( != ) */
+    public Object visit(ASTNENode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTLTNode ( < ) */
+    public Object visit(ASTLTNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTGTNode ( > ) */
+    public Object visit(ASTGTNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTLENode ( <= ) */
+    public Object visit(ASTLENode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTGENode ( >= ) */
+    public Object visit(ASTGENode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTAddNode ( + ) */
+    public Object visit(ASTAddNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTSubtractNode ( - ) */
+    public Object visit(ASTSubtractNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTMulNode ( * ) */
+    public Object visit(ASTMulNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTDivNode ( / ) */
+    public Object visit(ASTDivNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTModNode ( % ) */
+    public Object visit(ASTModNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTNotNode ( ! ) */
+    public Object visit(ASTNotNode node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTNumberLiteral node  */
+    public Object visit(ASTNumberLiteral node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTStringLiteral node */
+    public Object visit(ASTStringLiteral node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTIdentifier node */
+    public Object visit(ASTIdentifier node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTMethod node */
+    public Object visit(ASTMethod node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTReference node */
+    public Object visit(ASTReference node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTTrue node */
+    public Object visit(ASTTrue node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTFalse node */
+    public Object visit(ASTFalse node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTBlock node */
+    public Object visit(ASTBlock node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTText node */
+    public Object visit(ASTText node, Object data)
+    { 
+        return showNode(node,data); 
+    }
+    
+    /** Display an ASTIfStatement node */
+    public Object visit(ASTIfStatement node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTElseStatement node */
+    public Object visit(ASTElseStatement node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    /** Display an ASTElseIfStatement node */
+    public Object visit(ASTElseIfStatement node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    public Object visit(ASTObjectArray node, Object data)
+    { 
+        return showNode(node,data);
+    }
+
+    public Object visit(ASTDirective node, Object data)
+    { 
+        return showNode(node,data);
+    }
+
+    public Object visit(ASTWord node, Object data)
+    { 
+        return showNode(node,data);
+    }
+    
+    public Object visit(ASTSetDirective node, Object data)
+    { 
+        return showNode(node,data);
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message