You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cf...@apache.org on 2012/05/29 17:35:15 UTC

svn commit: r1343781 [13/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...

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityServletTest.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityServletTest.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityServletTest.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityServletTest.java Tue May 29 15:35:01 2012
@@ -0,0 +1,395 @@
+package org.apache.velocity.test;
+
+/*
+ * 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.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Properties;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.runtime.RuntimeSingleton;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.servlet.VelocityServlet;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests our VelocityServlet implementation.
+ *
+ * @author <a href="mailto:dlr@apache.org">Daniel Rall</a>
+ */
+public class VelocityServletTest extends TestCase
+{
+    /**
+     * Default constructor.
+     */
+    public VelocityServletTest()
+    {
+        super("VelocityServletTest");
+    }
+
+    public static junit.framework.Test suite ()
+    {
+        return new VelocityServletTest();
+    }
+
+    /**
+     * Runs the test.
+     */
+    public void runTest()
+    {
+        /*
+         * Assure we have the encoding we think we should.
+         */
+
+        MockVelocityServlet servlet = new MockVelocityServlet();
+        try
+        {
+            servlet.init(new MockServletConfig());
+        }
+        catch (ServletException e)
+        {
+            e.printStackTrace();
+        }
+        System.out.println(RuntimeConstants.OUTPUT_ENCODING + "=" +
+                           RuntimeSingleton.getProperty
+                           (RuntimeConstants.OUTPUT_ENCODING));
+        HttpServletResponse res = new MockHttpServletResponse();
+        servlet.visibleSetContentType(null, res);
+        assertEquals("Character encoding not set to UTF-8",
+                     "UTF-8", res.getCharacterEncoding());
+    }
+
+    class MockVelocityServlet extends VelocityServlet
+    {
+        void visibleSetContentType(HttpServletRequest req,
+                                   HttpServletResponse res)
+        {
+            setContentType(req, res);
+        }
+
+        protected Properties loadConfiguration(ServletConfig config)
+            throws IOException
+        {
+            Properties p = new Properties();
+            p.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
+            return p;
+        }
+
+        public ServletConfig getServletConfig()
+        {
+            return new MockServletConfig();
+        }
+    }
+
+    static class MockServletConfig implements ServletConfig
+    {
+        public String getInitParameter(String ignored)
+        {
+            return null;
+        }
+
+        public Enumeration getInitParameterNames()
+        {
+            return null;
+        }
+
+        public ServletContext getServletContext()
+        {
+            return new MockServletContext();
+        }
+
+        public String getServletName()
+        {
+            return "VelocityServlet";
+        }            
+    }
+
+    static class MockServletContext implements ServletContext
+    {
+        public Object getAttribute(String ignored)
+        {
+            return null;
+        }
+
+        public Enumeration getAttributeNames()
+        {
+            return null;
+        }
+
+        public ServletContext getContext(String ignored)
+        {
+            return this;
+        }
+
+        public String getInitParameter(String ignored)
+        {
+            return null;
+        }
+
+        public Enumeration getInitParameterNames()
+        {
+            return null;
+        }
+
+        public int getMajorVersion()
+        {
+            return -1;
+        }
+
+        public String getMimeType(String ignored)
+        {
+            return null;
+        }
+
+        public int getMinorVersion()
+        {
+            return -1;
+        }
+
+        public RequestDispatcher getNamedDispatcher(String ignored)
+        {
+            return null;
+        }
+
+        public String getRealPath(String ignored)
+        {
+            return null;
+        }
+
+        public RequestDispatcher getRequestDispatcher(String ignored)
+        {
+            return null;
+        }
+
+        public URL getResource(String ignored)
+            throws MalformedURLException
+        {
+            return null;
+        }
+
+        public InputStream getResourceAsStream(String ignored)
+        {
+            return null;
+        }
+
+        public String getServerInfo()
+        {
+            return "Velocity Test Suite";
+        }
+
+        public Servlet getServlet(String ignored)
+            throws ServletException
+        {
+            return null;
+        }
+
+        public Enumeration getServletNames()
+        {
+            return null;
+        }
+
+        public Enumeration getServlets()
+        {
+            return null;
+        }
+
+        public void log(Exception e, String msg)
+        {
+        }
+
+        public void log(String msg)
+        {
+        }
+
+        public void log(String msg, Throwable t)
+        {
+        }
+
+        public void removeAttribute(String name)
+        {
+        }
+
+        public void setAttribute(String name, Object value)
+        {
+        }
+    }
+
+    static class MockHttpServletResponse implements HttpServletResponse
+    {
+        private String encoding;
+
+        // ---- ServletResponse implementation -----------------------------
+
+        public void flushBuffer() throws IOException
+        {
+        }
+
+        public int getBufferSize()
+        {
+            return -1;
+        }
+
+        public String getCharacterEncoding()
+        {
+            return (encoding != null ? encoding : "ISO-8859-1");
+        }
+
+        public java.util.Locale getLocale()
+        {
+            return null;
+        }
+
+        public javax.servlet.ServletOutputStream getOutputStream()
+            throws IOException
+        {
+            return null;
+        }
+
+        public java.io.PrintWriter getWriter() throws IOException
+        {
+            return null;
+        }
+
+        public boolean isCommitted()
+        {
+            return false;
+        }
+
+        public void reset()
+        {
+        }
+
+        public void setBufferSize(int i)
+        {
+        }
+
+        public void setContentLength(int i)
+        {
+        }
+
+        /**
+         * Records the character encoding.
+         */
+        public void setContentType(String contentType)
+        {
+            if (contentType != null)
+            {
+                int index = contentType.lastIndexOf(';') + 1;
+                if (0 <= index || index < contentType.length())
+                {
+                    index = contentType.indexOf("charset=", index);
+                    if (index != -1)
+                    {
+                        index += 8;
+                        this.encoding = contentType.substring(index).trim();
+                    }
+                }
+            }
+        }
+
+        public void setLocale(java.util.Locale l)
+        {
+        }
+
+
+        // ---- HttpServletResponse implementation ------------------------- 
+
+        public void addCookie(javax.servlet.http.Cookie c)
+        {
+        }
+
+        public void addDateHeader(String s, long l)
+        {
+        }
+
+        public void addHeader(String name, String value)
+        {
+        }
+
+        public void addIntHeader(String name, int value)
+        {
+        }
+
+        public boolean containsHeader(String name)
+        {
+            return false;
+        }
+
+        public String encodeRedirectURL(String url)
+        {
+            return url;
+        }
+
+        public String encodeRedirectUrl(String url)
+        {
+            return url;
+        }
+
+        public String encodeURL(String url)
+        {
+            return url;
+        }
+
+        public String encodeUrl(String url)
+        {
+            return url;
+        }
+
+        public void sendError(int i) throws IOException
+        {
+        }
+
+        public void sendError(int i, String s) throws IOException
+        {
+        }
+
+        public void sendRedirect(String s) throws IOException
+        {
+        }
+
+        public void setDateHeader(String s, long l)
+        {
+        }
+
+        public void setHeader(String name, String value)
+        {
+        }
+
+        public void setIntHeader(String s, int i)
+        {
+        }
+
+        public void setStatus(int i)
+        {
+        }
+
+        public void setStatus(int i , String s)
+        {
+        }
+    }
+}

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

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/misc/Test.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/misc/Test.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/misc/Test.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/misc/Test.java Tue May 29 15:35:01 2012
@@ -0,0 +1,317 @@
+package org.apache.velocity.test.misc;
+
+/*
+ * 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.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.io.StringWriter;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Stack;
+import java.util.Vector;
+import java.util.Enumeration;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.Template;
+
+import org.apache.velocity.app.FieldMethodizer;
+import org.apache.velocity.app.Velocity;
+
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.MethodInvocationException;
+
+import org.apache.velocity.runtime.RuntimeSingleton;
+import org.apache.velocity.test.provider.TestProvider;
+
+import org.apache.velocity.app.event.EventCartridge;
+import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.app.event.MethodExceptionEventHandler;
+import org.apache.velocity.app.event.NullSetEventHandler;
+
+import org.apache.velocity.context.Context;
+
+
+/**
+ * This class the testbed for Velocity. It is used to
+ * test all the directives support by Velocity.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: Test.java,v 1.34.8.1 2004/03/03 23:23:05 geirm Exp $
+ */
+public class Test implements ReferenceInsertionEventHandler, 
+                             NullSetEventHandler,
+                             MethodExceptionEventHandler
+{
+    /**
+     * Cache of writers
+     */
+    private static Stack writerStack = new Stack();
+
+    public Test(String templateFile, String encoding)
+    {
+        Writer writer = null;
+        TestProvider provider = new TestProvider();
+        ArrayList al = provider.getCustomers();
+        Hashtable h = new Hashtable();
+  
+        /*
+         *  put this in to test introspection $h.Bar or $h.get("Bar") etc
+         */
+        
+        h.put("Bar", "this is from a hashtable!");
+        h.put("Foo", "this is from a hashtable too!");
+       
+        /*
+         *  adding simple vector with strings for testing late introspection stuff
+         */
+
+        Vector v = new Vector();
+
+        String str = "mystr";
+
+        v.addElement( new String("hello") );
+        v.addElement( new String("hello2") );
+        v.addElement( str );
+
+        try
+        {
+            /*
+             *  this is another way to do properties when initializing Runtime.
+             *  make a Properties 
+             */
+
+            Properties p = new Properties();
+
+            /*
+             *  now, if you want to, load it from a file (or whatever)
+             */
+            
+            try
+            {
+                FileInputStream fis =  new FileInputStream( 
+                    new File("velocity.properties" ));
+            
+                if( fis != null)
+                    p.load( fis );
+            }
+            catch (Exception ex)
+            {
+                /* no worries. no file... */
+            }
+
+            /*
+             *  iterate out the properties
+             */
+
+            for( Enumeration e = p.propertyNames(); e.hasMoreElements(); )
+            {
+                String el = (String) e.nextElement();
+
+                Velocity.setProperty( el, p.getProperty( el ) );
+            }
+
+            /*
+             *  add some individual properties if you wish
+             */
+
+
+            Velocity.setProperty(Velocity.RUNTIME_LOG_ERROR_STACKTRACE, "true");
+            Velocity.setProperty(Velocity.RUNTIME_LOG_WARN_STACKTRACE, "true");
+            Velocity.setProperty(Velocity.RUNTIME_LOG_INFO_STACKTRACE, "true");
+
+            /*
+             *  use an alternative logger.  Set it up here and pass it in.
+             */
+            
+            //            SimpleLogSystem sls = new SimpleLogSystem("velocity_simple.log");
+            
+            // Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, sls );
+          
+            /*
+             *  and now call init
+             */
+
+            Velocity.init();
+
+            /*
+             *  now, do what we want to do.  First, get the Template
+             */
+
+            if (templateFile == null)
+            {
+                templateFile = "examples/example.vm";
+            }                
+         
+
+            Template template = null;
+
+            try 
+            {
+                template = RuntimeSingleton.getTemplate(templateFile, encoding);
+            }
+            catch( ResourceNotFoundException rnfe )
+            {
+                System.out.println("Test : RNFE : Cannot find template " + templateFile );
+            }
+            catch( ParseErrorException pee )
+            {
+                System.out.println("Test : Syntax error in template " + templateFile + ":" + pee );
+            }
+
+            /*
+             * now, make a Context object and populate it.
+             */
+
+            VelocityContext context = new VelocityContext();
+
+            context.put("provider", provider);
+            context.put("name", "jason");
+            context.put("providers", provider.getCustomers2());
+            context.put("list", al);
+            context.put("hashtable", h);
+            context.put("search", provider.getSearch());
+            context.put("relatedSearches", provider.getRelSearches());
+            context.put("searchResults", provider.getRelSearches());
+            context.put("menu", provider.getMenu());
+            context.put("stringarray", provider.getArray());
+            context.put("vector", v);
+            context.put("mystring", new String());
+            context.put("hashmap", new HashMap() );
+            context.put("runtime", new FieldMethodizer( "org.apache.velocity.runtime.RuntimeSingleton" ));
+            context.put("fmprov", new FieldMethodizer( provider ));
+            context.put("Floog", "floogie woogie");
+            context.put("geirstring", str );
+            context.put("mylong", new Long(5) );
+            
+            /*
+             *  we want to make sure we test all types of iterative objects
+             *  in #foreach()
+             */
+             
+            int intarr[] = { 10, 20, 30, 40, 50 };
+
+            Object[] oarr = { "a","b","c","d" } ;
+            
+            context.put( "collection", v );
+            context.put("iterator", v.iterator());
+            context.put("map", h );
+            context.put("obarr", oarr );
+            context.put("intarr", intarr );
+            
+            String stest = " My name is $name -> $Floog";
+            StringWriter w = new StringWriter();
+            //            Velocity.evaluate( context, w, "evaltest",stest );
+            //            System.out.println("Eval = " + w );
+
+            w = new StringWriter();
+            //Velocity.mergeTemplate( "mergethis.vm",  context, w );
+            //System.out.println("Merge = " + w );
+
+            w = new StringWriter();
+            //Velocity.invokeVelocimacro( "floog", "test", new String[2],  context,  w );
+            //System.out.println("Invoke = " + w );
+
+
+            /*
+             *  event cartridge stuff
+             */
+
+            EventCartridge ec = new EventCartridge();
+            ec.addEventHandler(this);
+            ec.attachToContext( context );
+
+            /*
+             *  make a writer, and merge the template 'against' the context
+             */
+
+            VelocityContext vc = new VelocityContext( context );
+
+            if( template != null)
+            {
+                writer = new BufferedWriter(new OutputStreamWriter(System.out, encoding));
+                template.merge( vc , writer);
+                writer.flush();
+                writer.close();
+            }
+ 
+        }
+        catch( MethodInvocationException mie )
+        {
+            System.out.println("MIE : " + mie );
+        }
+        catch( Exception e )
+        {
+            RuntimeSingleton.error( "Test- exception : " + e);
+            e.printStackTrace();
+
+        }
+    }
+
+    public Object referenceInsert( String reference, Object value  )
+    {
+        if (value != null)
+            ; // System.out.println("Woo! referenceInsert : " + reference + " = " + value.toString() );
+        return value;
+    }
+
+    public boolean shouldLogOnNullSet( String lhs, String rhs )
+    {
+        //        System.out.println("Woo2! nullSetLogMessage : " + lhs + " :  RHS = " + rhs);
+
+        if (lhs.equals("$woogie"))
+            return false;
+        
+        return true;
+    }
+
+   public Object methodException( Class claz, String method, Exception e )
+         throws Exception
+    {
+        if (method.equals("getThrow"))
+            return "I should have thrown";
+
+        throw e;
+    }
+
+
+    public static void main(String[] args)
+    {
+        Test t;
+
+        String encoding = "ISO-8859-1";
+
+        if( args.length > 1 )
+            encoding = args[1];
+
+        t = new Test(args[0], encoding);
+    }
+}
+
+
+
+
+
+
+

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/misc/Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/BoolObj.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/BoolObj.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/BoolObj.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/BoolObj.java Tue May 29 15:35:01 2012
@@ -0,0 +1,43 @@
+package org.apache.velocity.test.provider;
+
+/*
+ * 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.
+ */
+
+/**
+ *  simple class to test boolean property
+ *  introspection - can't use TestProvider
+ *  as there is a get( String )
+ *  and that comes before isProperty
+ *  in the search pattern
+ *
+ *  @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ */
+public class BoolObj
+{
+    public boolean isBoolean()
+    {
+        return true;
+    }
+
+    /*
+     *  not isProperty as it's not
+     *  boolean return valued...
+     */
+    public String  isNotboolean()
+    {
+        return "hello";
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/BoolObj.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Child.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Child.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Child.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Child.java Tue May 29 15:35:01 2012
@@ -0,0 +1,33 @@
+package org.apache.velocity.test.provider;
+
+/*
+ * 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.
+ */
+
+/**
+ * Rudimentary class used in the testbed to test
+ * introspection with subclasses of a particular
+ * class.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: Child.java,v 1.5.8.1 2004/03/03 23:23:06 geirm Exp $
+ */
+public class Child extends Person
+{
+    public String getName()
+    {
+        return "Child";
+    }        
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Child.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Person.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Person.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Person.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Person.java Tue May 29 15:35:01 2012
@@ -0,0 +1,36 @@
+package org.apache.velocity.test.provider;
+
+/*
+ * 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.
+ */
+
+/**
+ * Rudimentary class used in the testbed to test
+ * introspection with subclasses of a particular
+ * class.
+ *
+ * This class need to be greatly extended to
+ * be useful :-)
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: Person.java,v 1.5.8.1 2004/03/03 23:23:06 geirm Exp $
+ */
+public class Person
+{
+    public String getName()
+    {
+        return "Person";
+    }        
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/Person.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/TestProvider.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/TestProvider.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/TestProvider.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/TestProvider.java Tue May 29 15:35:01 2012
@@ -0,0 +1,359 @@
+package org.apache.velocity.test.provider;
+
+/*
+ * 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.util.*;
+
+/**
+ * This class is used by the testbed. Instances of the class
+ * are fed into the context that is set before the AST
+ * is traversed and dynamic content generated.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: TestProvider.java,v 1.21.8.1 2004/03/03 23:23:06 geirm Exp $
+ */
+public class TestProvider
+{
+    String title = "lunatic";
+    boolean state;
+    Object ob = null;
+
+    public static String PUB_STAT_STRING = "Public Static String";
+
+    int stateint = 0;
+
+
+    public String getName()
+    {
+        return "jason";
+    }
+
+    public Stack getStack()
+    {
+        Stack stack = new Stack();
+        stack.push("stack element 1");
+        stack.push("stack element 2");
+        stack.push("stack element 3");
+        return stack;
+    }
+
+    public List getEmptyList()
+    {
+        List list = new ArrayList();
+        return list;
+    }
+
+    public List getList()
+    {
+        List list = new ArrayList();
+        list.add("list element 1");
+        list.add("list element 2");
+        list.add("list element 3");
+        
+        return list;
+    }
+    
+    public Hashtable getSearch()
+    {
+        Hashtable h = new Hashtable();
+        h.put("Text", "this is some text");
+        h.put("EscText", "this is escaped text");
+        h.put("Title", "this is the title");
+        h.put("Index", "this is the index");
+        h.put("URL", "http://periapt.com");
+
+        ArrayList al = new ArrayList();
+        al.add(h);
+        
+        h.put("RelatedLinks", al);
+
+        return h;
+    }        
+
+    public Hashtable getHashtable()
+    {
+        Hashtable h = new Hashtable();
+        h.put("key0", "value0");
+        h.put("key1", "value1");
+        h.put("key2", "value2");
+        
+        return h;
+    }        
+
+    public ArrayList getRelSearches()
+    {
+        ArrayList al = new ArrayList();
+        al.add(getSearch());
+        
+        return al;
+    }        
+
+    public String getTitle()
+    {
+        return title;
+    }
+
+    public void setTitle(String title)
+    {
+        this.title = title;
+    }
+
+    public Object[] getMenu()
+    {
+        //ArrayList al = new ArrayList();
+        Object[] menu = new Object[3];
+        for (int i = 0; i < 3; i++)
+        {
+            Hashtable item = new Hashtable();
+            item.put("id", "item" + Integer.toString(i+1));
+            item.put("name", "name" + Integer.toString(i+1));
+            item.put("label", "label" + Integer.toString(i+1));
+            //al.add(item);
+            menu[i] = item;
+        }            
+            
+        //return al;
+        return menu;
+    }
+
+    public ArrayList getCustomers()
+    {
+        ArrayList list = new ArrayList();
+
+        list.add("ArrayList element 1");
+        list.add("ArrayList element 2");
+        list.add("ArrayList element 3");
+        list.add("ArrayList element 4");
+
+        return list;
+    }
+
+    public ArrayList getCustomers2()
+    {
+        ArrayList list = new ArrayList();
+
+        list.add(new TestProvider());
+        list.add(new TestProvider());
+        list.add(new TestProvider());
+        list.add(new TestProvider());
+
+        return list;
+    }
+
+    public Object me()
+    {
+        return this;
+    }        
+
+    public String toString()
+    {
+        return ("test provider");
+    }        
+
+    public Vector getVector()
+    {
+        Vector list = new Vector();
+
+        list.addElement("vector element 1");
+        list.addElement("vector element 2");
+        
+        return list;
+    }
+
+    public String[] getArray()
+    {
+        String[] strings = new String[2];
+        strings[0] = "first element";
+        strings[1] = "second element";
+        return strings;
+    }
+
+    public boolean theAPLRules()
+    {
+        return true;
+    }
+
+    public boolean getStateTrue()
+    {
+        return true;
+    }
+    
+    public boolean getStateFalse()
+    {
+        return false;
+    }        
+
+    public String objectArrayMethod(Object[] o)
+    {
+        return "result of objectArrayMethod";
+    }
+
+    public String concat(Object[] strings)
+    {
+        StringBuffer result = new StringBuffer();
+        
+        for (int i = 0; i < strings.length; i++)
+        {
+            result.append((String) strings[i]).append(' ');
+        }
+        
+        return result.toString();
+    }
+
+    public String concat(List strings)
+    {
+        StringBuffer result = new StringBuffer();
+        
+        for (int i = 0; i < strings.size(); i++)
+        {
+            result.append((String) strings.get(i)).append(' ');
+        }
+        
+        return result.toString();
+    }
+
+    public String objConcat(List objects)
+    {
+        StringBuffer result = new StringBuffer();
+
+        for (int i = 0; i < objects.size(); i++)
+        {
+            result.append(objects.get(i)).append(' ');
+        }
+
+        return result.toString();
+    }
+
+    public String parse(String a, Object o, String c, String d)
+    {
+        return a + o.toString() + c + d;
+    }
+
+    public String concat(String a, String b)
+    {
+        return a + b;
+    }        
+
+    // These two are for testing subclasses.
+
+    public Person getPerson()
+    {
+        return new Person();
+    }
+    
+    public Child getChild()
+    {
+        return new Child();
+    }        
+
+    public String showPerson(Person person)
+    {
+        return person.getName();
+    }        
+
+    /**
+     * Chop i characters off the end of a string.
+     *
+     * @param string String to chop.
+     * @param i Number of characters to chop.
+     * @return String with processed answer.
+     */
+    public String chop(String string, int i)
+    {
+        return(string.substring(0, string.length() - i));
+    }
+
+    public boolean allEmpty(Object[] list)
+    {
+        int size = list.length;
+        
+        for (int i = 0; i < size; i++)
+            if (list[i].toString().length() > 0)
+                return false;
+        
+        return true;
+    }
+
+    /*
+     * This can't have the signature
+    
+    public void setState(boolean state)
+    
+    or dynamically invoking the method
+    doesn't work ... you would have to
+    put a wrapper around a method for a
+    real boolean property that takes a 
+    Boolean object if you wanted this to
+    work. Not really sure how useful it
+    is anyway. Who cares about boolean
+    values you can just set a variable.
+    
+    */
+
+    public void setState(Boolean state)
+    {
+    }
+
+    public void setBangStart( Integer i )
+    {
+        System.out.println("SetBangStart() : called with val = " + i );
+        stateint = i.intValue();
+    }
+    public Integer bang()
+    {
+        System.out.println("Bang! : " + stateint );
+        Integer ret = new Integer( stateint );
+        stateint++;
+        return ret;
+    }
+
+    /**
+     * Test the ability of vel to use a get(key)
+     * method for any object type, not just one
+     * that implements the Map interface.
+     */
+    public String get(String key)
+    {
+        return key;
+    }        
+
+    /**
+     * Test the ability of vel to use a put(key)
+     * method for any object type, not just one
+     * that implements the Map interface.
+     */
+    public String put(String key, Object o)
+    {
+        ob = o;
+        return key;
+    }        
+
+    public String getFoo()
+        throws Exception
+    {
+        System.out.println("Hello from getfoo");
+
+        throw new Exception("From getFoo()");
+    }
+
+    public String getThrow()
+        throws Exception
+    {
+        System.out.println("Hello from geThrow");
+       throw new Exception("From getThrow()");
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/provider/TestProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/view/TemplateNodeView.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/view/TemplateNodeView.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/view/TemplateNodeView.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/view/TemplateNodeView.java Tue May 29 15:35:01 2012
@@ -0,0 +1,87 @@
+package org.apache.velocity.test.view;
+
+/*
+ * 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.IOException;
+import java.io.PrintWriter;
+import java.io.FileInputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.apache.velocity.runtime.RuntimeSingleton;
+
+import org.apache.velocity.runtime.visitor.NodeViewMode;
+import org.apache.velocity.runtime.parser.node.SimpleNode;
+
+/**
+ * Simple class for dumping the AST for a template.
+ * Good for debugging and writing new directives.
+ */
+public class TemplateNodeView
+{
+    /** 
+     * Root of the AST node structure that results from
+     * parsing a template.
+     */
+    private SimpleNode document;
+    
+    /**
+     * Visitor used to traverse the AST node structure
+     * and produce a visual representation of the
+     * node structure. Very good for debugging and
+     * writing new directives.
+     */
+    private NodeViewMode visitor;
+
+    /**
+     * Default constructor: sets up the Velocity
+     * Runtime, creates the visitor for traversing
+     * the node structure and then produces the
+     * visual representation by the visitation.
+     */
+    public TemplateNodeView(String template)
+    {
+        try
+        {
+            RuntimeSingleton.init("velocity.properties");
+
+            InputStreamReader isr = new InputStreamReader(
+                                       new FileInputStream(template),
+                                       RuntimeSingleton.getString(RuntimeSingleton.INPUT_ENCODING));
+
+            BufferedReader br = new BufferedReader( isr );
+                                         
+            document = RuntimeSingleton.parse( br, template);
+
+            visitor = new NodeViewMode();
+            visitor.setContext(null);
+            visitor.setWriter(new PrintWriter(System.out));
+            document.jjtAccept(visitor, null);
+        }
+        catch (Exception e)
+        {
+            System.out.println(e);
+            e.printStackTrace();
+        }
+    }
+
+    /** For testing */
+    public static void main(String args[])
+    {
+        TemplateNodeView v = new TemplateNodeView(args[0]);
+    }        
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/view/TemplateNodeView.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/Generator.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/Generator.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/Generator.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/Generator.java Tue May 29 15:35:01 2012
@@ -0,0 +1,535 @@
+package org.apache.velocity.texen;
+
+/*
+ * 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.Writer;
+import java.io.FileWriter;
+import java.io.StringWriter;
+import java.io.OutputStreamWriter;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * A text/code generator class
+ *
+ * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: Generator.java,v 1.20.4.1 2004/03/03 23:23:07 geirm Exp $ 
+ */
+public class Generator
+{
+    /**
+     * Where the texen output will placed.
+     */
+    public static final String OUTPUT_PATH = "output.path";
+    
+    /**
+     * Where the velocity templates live.
+     */
+    public static final String TEMPLATE_PATH = "template.path";
+    
+    /**
+     * Default properties file used for controlling the
+     * tools placed in the context.
+     */
+    private static final String DEFAULT_TEXEN_PROPERTIES =
+        "org/apache/velocity/texen/defaults/texen.properties";
+
+    /**
+     * Default properties used by texen.
+     */
+    private Properties props = new Properties();
+    
+    /**
+     * Context used for generating the texen output.
+     */
+    private Context controlContext;
+
+    /**
+     * Keep track of the file writers used for outputting
+     * to files. If we come across a file writer more
+     * then once then the additional output will be
+     * appended to the file instead of overwritting
+     * the contents.
+     */
+    private Hashtable writers = new Hashtable();
+
+    /**
+     * The generator tools used for creating additional
+     * output withing the control template. This could
+     * use some cleaning up.
+     */
+    private static Generator instance = new Generator();
+
+    /**
+     * This is the encoding for the output file(s).
+     */
+    protected String outputEncoding;
+
+    /**
+     * This is the encoding for the input file(s)
+     * (templates).
+     */
+    protected String inputEncoding;
+    
+    /**
+     * Velocity engine.
+     */
+    protected VelocityEngine ve;
+
+    /**
+     * Default constructor.
+     */
+    private Generator()
+    {
+        setDefaultProps();
+    }
+
+    /**
+     * Create a new generator object with default properties.
+     *
+     * @return Generator generator used in the control context.
+     */
+    public static Generator getInstance()
+    {
+        return instance;
+    }
+    
+    /**
+     * Set the velocity engine.
+     */
+    public void setVelocityEngine(VelocityEngine ve)
+    {
+        this.ve = ve;
+    }        
+
+    /**
+     * Create a new generator object with properties loaded from
+     * a file.  If the file does not exist or any other exception
+     * occurs during the reading operation the default properties
+     * are used.
+     *
+     * @param String properties used to help populate the control context.
+     * @return Generator generator used in the control context.
+     */
+    public Generator (String propFile)
+    {
+        try
+        {
+            BufferedInputStream bi = null;
+            try
+            {
+                bi = new BufferedInputStream (new FileInputStream (propFile));
+                props.load (bi);
+            }
+            finally
+            {
+                if (bi != null)
+                {
+                    bi.close();
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            /*
+             * If something goes wrong we use default properties
+             */
+            setDefaultProps();
+        }
+    }
+    
+    /**
+     * Create a new Generator object with a given property
+     * set. The property set will be duplicated.
+     *
+     * @param Properties properties object to help populate the control context.
+     */
+    public Generator (Properties props)
+    {
+        this.props = (Properties)props.clone();
+    }
+    
+    /**
+     * Set default properties.
+     */
+    protected void setDefaultProps()
+    {
+        ClassLoader classLoader = VelocityEngine.class.getClassLoader();
+        try
+        {
+            InputStream inputStream = null;
+            try
+            {
+                inputStream = classLoader.getResourceAsStream(
+                    DEFAULT_TEXEN_PROPERTIES);
+            
+                props.load( inputStream );
+            }
+            finally
+            {
+                if (inputStream != null)
+                {
+                    inputStream.close();
+                }
+            }
+        }
+        catch (Exception ioe)
+        {
+            System.err.println("Cannot get default properties!");
+        }
+    }
+    
+    /**
+     * Set the template path, where Texen will look
+     * for Velocity templates.
+     *
+     * @param String template path for velocity templates.
+     */
+    public void setTemplatePath(String templatePath)
+    {
+        props.put(TEMPLATE_PATH, templatePath);
+    }
+
+    /**
+     * Get the template path.
+     *
+     * @return String template path for velocity templates.
+     */
+    public String getTemplatePath()
+    {
+        return props.getProperty(TEMPLATE_PATH);
+    }
+
+    /**
+     * Set the output path for the generated
+     * output.
+     *
+     * @return String output path for texen output.
+     */
+    public void setOutputPath(String outputPath)
+    {
+        props.put(OUTPUT_PATH, outputPath);
+    }
+
+    /**
+     * Get the output path for the generated
+     * output.
+     *
+     * @return String output path for texen output.
+     */
+    public String getOutputPath()
+    {
+        return props.getProperty(OUTPUT_PATH);
+    }
+
+    /**
+     * Set the output encoding.
+     */
+    public void setOutputEncoding(String outputEncoding)
+    {
+        this.outputEncoding = outputEncoding;
+    }
+
+    /**
+     * Set the input (template) encoding.
+     */
+    public void setInputEncoding(String inputEncoding)
+    {
+        this.inputEncoding = inputEncoding;
+    }
+
+    /**
+     * Returns a writer, based on encoding and path.
+     *
+     * @param path      path to the output file
+     * @param encoding  output encoding
+     */
+    public Writer getWriter(String path, String encoding) throws Exception {
+        Writer writer;
+        if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1")) {
+            writer = new FileWriter(path);
+        }
+        else {
+            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), encoding));
+        }
+        return writer;
+    }
+
+    /**
+     * Returns a template, based on encoding and path.
+     *
+     * @param templateName  name of the template
+     * @param encoding      template encoding
+     */
+    public Template getTemplate(String templateName, String encoding) throws Exception {
+        Template template;
+        if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1")) {
+            template = ve.getTemplate(templateName);
+        }
+        else {
+            template = ve.getTemplate(templateName, encoding);
+        }
+        return template;
+    }
+
+    /**
+     * Parse an input and write the output to an output file.  If the
+     * output file parameter is null or an empty string the result is
+     * returned as a string object.  Otherwise an empty string is returned.
+     *
+     * @param String input template
+     * @param String output file
+     */ 
+    public String parse (String inputTemplate, String outputFile) 
+        throws Exception
+    {
+        return parse(inputTemplate, outputFile, null, null);
+    }
+    
+    /**
+     * Parse an input and write the output to an output file.  If the
+     * output file parameter is null or an empty string the result is
+     * returned as a string object.  Otherwise an empty string is returned.
+     * You can add objects to the context with the objs Hashtable.
+     *
+     * @param String input template
+     * @param String output file
+     * @param String id for object to be placed in the control context
+     * @param String object to be placed in the context
+     * @return String generated output from velocity
+     */
+    public String parse (String inputTemplate,
+                         String outputFile,
+                         String objectID,
+                         Object object)
+        throws Exception
+    {
+        return parse(inputTemplate, null, outputFile, null, objectID, object);
+    }
+    /**
+     * Parse an input and write the output to an output file.  If the
+     * output file parameter is null or an empty string the result is
+     * returned as a string object.  Otherwise an empty string is returned.
+     * You can add objects to the context with the objs Hashtable.
+     *
+     * @param String input template
+     * @param String inputEncoding template encoding
+     * @param String output file
+     * @param String outputEncoding encoding of output file
+     * @param String id for object to be placed in the control context
+     * @param String object to be placed in the context
+     * @return String generated output from velocity
+     */ 
+    public String parse (String inputTemplate, 
+                         String intputEncoding,
+                         String outputFile,
+                         String outputEncoding,
+                         String objectID,
+                         Object object)
+        throws Exception
+    {
+        if (objectID != null && object != null)
+        {
+            controlContext.put(objectID, object);
+        }            
+        
+        Template template = getTemplate(inputTemplate, inputEncoding != null ? inputEncoding : this.inputEncoding);
+        
+        if (outputFile == null || outputFile.equals(""))
+        {
+            StringWriter sw = new StringWriter();
+            template.merge (controlContext,sw);
+            return sw.toString();
+        }
+        else
+        {
+            Writer writer = null;
+            
+            if (writers.get(outputFile) == null)
+            {
+                /*
+                 * We have never seen this file before so create
+                 * a new file writer for it.
+                 */
+                writer = getWriter(
+                            getOutputPath() + File.separator + outputFile,
+                            outputEncoding != null ? outputEncoding : this.outputEncoding
+                         );
+                    
+                /*
+                 * Place the file writer in our collection
+                 * of file writers.
+                 */
+                writers.put(outputFile, writer);
+            }
+            else
+            {
+                writer = (Writer) writers.get(outputFile);
+            }                
+            
+            VelocityContext vc = new VelocityContext( controlContext );
+            template.merge (vc,writer);
+
+            // commented because it is closed in shutdown();
+            //fw.close();
+            
+            return "";
+        }
+    }
+
+    /**
+     * Parse the control template and merge it with the control
+     * context. This is the starting point in texen.
+     *
+     * @param String control template
+     * @param Context control context
+     * @return String generated output
+     */
+    public String parse (String controlTemplate, Context controlContext)
+        throws Exception
+    {
+        this.controlContext = controlContext;
+        fillContextDefaults(this.controlContext);
+        fillContextProperties(this.controlContext);
+
+        Template template = getTemplate(controlTemplate, inputEncoding);
+        StringWriter sw = new StringWriter();
+        template.merge (controlContext,sw);
+        
+        return sw.toString();
+    }
+
+
+    /**
+     * Create a new context and fill it with the elements of the
+     * objs Hashtable.  Default objects and objects that comes from
+     * the properties of this Generator object is also added.
+     *
+     * @param Hashtable objects to place in the control context
+     * @return Context context filled with objects
+     */ 
+    protected Context getContext (Hashtable objs)
+    {
+        fillContextHash (controlContext,objs);
+        return controlContext;
+    }
+
+    /** 
+     * Add all the contents of a Hashtable to the context.
+     *
+     * @param Context context to fill with objects
+     * @param Hashtable source of objects
+     */
+    protected void fillContextHash (Context context, Hashtable objs)
+    {
+        Enumeration enum = objs.keys();
+        while (enum.hasMoreElements())
+        {
+            String key = enum.nextElement().toString();
+            context.put (key, objs.get(key));
+        }
+    }
+
+    /**
+     * Add properties that will aways be in the context by default
+     *
+     * @param Context control context to fill with default values.
+     */
+    protected void fillContextDefaults (Context context)
+    {
+        context.put ("generator", instance);
+        context.put ("outputDirectory", getOutputPath());
+    }
+    
+    /**
+     * Add objects to the context from the current properties.
+     *
+     * @param Context control context to fill with objects
+     *                that are specified in the default.properties
+     *                file
+     */
+    protected void fillContextProperties (Context context)
+    {
+        Enumeration enum = props.propertyNames();
+        
+        while (enum.hasMoreElements())
+        {
+            String nm = (String)enum.nextElement();
+            if (nm.startsWith ("context.objects."))
+            {
+                
+                String contextObj = props.getProperty (nm);
+                int colon = nm.lastIndexOf ('.');
+                String contextName = nm.substring (colon+1);
+                
+                try
+                {
+                    Class cls = Class.forName (contextObj);
+                    Object o = cls.newInstance();
+                    context.put (contextName,o);
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                    //TO DO: Log Something Here
+                }
+            }
+        }
+    }
+
+    /**
+     * Properly shut down the generator, right now
+     * this is simply flushing and closing the file
+     * writers that we have been holding on to.
+     */
+    public void shutdown()
+    {
+        Iterator iterator = writers.values().iterator();
+        
+        while(iterator.hasNext())
+        {
+            Writer writer = (Writer) iterator.next();
+                        
+            try
+            {
+                writer.flush();
+                writer.close();
+            }
+            catch (Exception e)
+            {
+                /* do nothing */
+            }
+        }
+        // clear the file writers cache
+        writers.clear();
+    }
+}

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

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java Tue May 29 15:35:01 2012
@@ -0,0 +1,585 @@
+package org.apache.velocity.texen.ant;
+
+/*
+ * 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.util.StringTokenizer;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import java.io.File;
+import java.io.Writer;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.texen.Generator;
+import org.apache.velocity.util.StringUtils;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.commons.collections.ExtendedProperties;
+
+/**
+ * An ant task for generating output by using Velocity
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="robertdonkin@mac.com">Robert Burrell Donkin</a>
+ * @version $Id: TexenTask.java,v 1.39.4.1 2004/03/03 23:23:07 geirm Exp $
+ */
+public class TexenTask 
+    extends Task
+{
+    /**
+     * This message fragment (telling users to consult the log or
+     * invoke ant with the -debug flag) is appended to rethrown
+     * exception messages.
+     */
+    private final static String ERR_MSG_FRAGMENT = 
+        ". For more information consult the velocity log, or invoke ant " +
+        "with the -debug flag.";
+    
+    /**
+     * This is the control template that governs the output.
+     * It may or may not invoke the services of worker
+     * templates.
+     */
+    protected String controlTemplate;
+    
+    /**
+     * This is where Velocity will look for templates
+     * using the file template loader.
+     */
+    protected String templatePath;
+    
+    /**
+     * This is where texen will place all the output
+     * that is a product of the generation process.
+     */
+    protected String outputDirectory;
+    
+    /**
+     * This is the file where the generated text
+     * will be placed.
+     */
+    protected String outputFile;
+    
+    /**
+     * This is the encoding for the output file(s).
+     */
+    protected String outputEncoding;
+
+    /**
+     * This is the encoding for the input file(s)
+     * (templates).
+     */
+    protected String inputEncoding;
+
+    /**
+     * <p>
+     * These are properties that are fed into the
+     * initial context from a properties file. This
+     * is simply a convenient way to set some values
+     * that you wish to make available in the context.
+     * </p>
+     * <p>
+     * These values are not critical, like the template path
+     * or output path, but allow a convenient way to
+     * set a value that may be specific to a particular
+     * generation task.
+     * </p>
+     * <p>
+     * For example, if you are generating scripts to allow
+     * user to automatically create a database, then
+     * you might want the <code>$databaseName</code> 
+     * to be placed
+     * in the initial context so that it is available
+     * in a script that might look something like the
+     * following:
+     * <code><pre>
+     * #!bin/sh
+     * 
+     * echo y | mysqladmin create $databaseName
+     * </pre></code>
+     * The value of <code>$databaseName</code> isn't critical to
+     * output, and you obviously don't want to change
+     * the ant task to simply take a database name.
+     * So initial context values can be set with
+     * properties file.
+     */
+    protected ExtendedProperties contextProperties;
+
+    /**
+     * Property which controls whether the classpath
+     * will be used when trying to locate templates.
+     */
+    protected boolean useClasspath;
+
+    /**
+     * Path separator.
+     */
+    private String fileSeparator = System.getProperty("file.separator");
+
+    /**
+     * [REQUIRED] Set the control template for the
+     * generating process.
+     */
+    public void setControlTemplate (String controlTemplate)
+    {
+        this.controlTemplate = controlTemplate;
+    }
+
+    /**
+     * Get the control template for the
+     * generating process.
+     */
+    public String getControlTemplate()
+    {
+        return controlTemplate;
+    }
+
+    /**
+     * [REQUIRED] Set the path where Velocity will look
+     * for templates using the file template
+     * loader.
+     */
+    
+    public void setTemplatePath(String templatePath) throws Exception
+    {
+        StringBuffer resolvedPath = new StringBuffer();
+        StringTokenizer st = new StringTokenizer(templatePath, ",");
+        while ( st.hasMoreTokens() )
+        {
+            // resolve relative path from basedir and leave
+            // absolute path untouched.
+            File fullPath = project.resolveFile(st.nextToken());
+            resolvedPath.append(fullPath.getCanonicalPath());
+            if ( st.hasMoreTokens() )
+            {
+                resolvedPath.append(",");
+            }
+        }
+        this.templatePath = resolvedPath.toString();
+        
+        System.out.println(templatePath);
+     }
+
+    /**
+     * Get the path where Velocity will look
+     * for templates using the file template
+     * loader.
+     */
+    public String getTemplatePath()
+    {
+        return templatePath;
+    }        
+
+    /**
+     * [REQUIRED] Set the output directory. It will be
+     * created if it doesn't exist.
+     */
+    public void setOutputDirectory(File outputDirectory)
+    {
+        try
+        {
+            this.outputDirectory = outputDirectory.getCanonicalPath();
+        }
+        catch (java.io.IOException ioe)
+        {
+            throw new BuildException(ioe);
+        }
+    }
+      
+    /**
+     * Get the output directory.
+     */
+    public String getOutputDirectory()
+    {
+        return outputDirectory;
+    }        
+
+    /**
+     * [REQUIRED] Set the output file for the
+     * generation process.
+     */
+    public void setOutputFile(String outputFile)
+    {
+        this.outputFile = outputFile;
+    }
+    
+    /**
+     * Set the output encoding.
+     */
+    public void setOutputEncoding(String outputEncoding)
+    {
+        this.outputEncoding = outputEncoding;
+    }
+
+    /**
+     * Set the input (template) encoding.
+     */
+    public void setInputEncoding(String inputEncoding)
+    {
+        this.inputEncoding = inputEncoding;
+    }
+
+    /**
+     * Get the output file for the
+     * generation process.
+     */
+    public String getOutputFile()
+    {
+        return outputFile;
+    }        
+
+    /**
+     * Set the context properties that will be
+     * fed into the initial context be the
+     * generating process starts.
+     */
+    public void setContextProperties( String file )
+    {
+        String[] sources = StringUtils.split(file,",");
+        contextProperties = new ExtendedProperties();
+        
+        // Always try to get the context properties resource
+        // from a file first. Templates may be taken from a JAR
+        // file but the context properties resource may be a 
+        // resource in the filesystem. If this fails than attempt
+        // to get the context properties resource from the
+        // classpath.
+        for (int i = 0; i < sources.length; i++)
+        {
+            ExtendedProperties source = new ExtendedProperties();
+            
+            try
+            {
+                // resolve relative path from basedir and leave
+                // absolute path untouched.
+                File fullPath = project.resolveFile(sources[i]);
+                log("Using contextProperties file: " + fullPath);
+                source.load(new FileInputStream(fullPath));
+            }
+            catch (Exception e)
+            {
+                ClassLoader classLoader = this.getClass().getClassLoader();
+            
+                try
+                {
+                    InputStream inputStream = classLoader.getResourceAsStream(sources[i]);
+                
+                    if (inputStream == null)
+                    {
+                        throw new BuildException("Context properties file " + sources[i] +
+                            " could not be found in the file system or on the classpath!");
+                    }
+                    else
+                    {
+                        source.load(inputStream);
+                    }
+                }
+                catch (IOException ioe)
+                {
+                    source = null;
+                }
+            }
+        
+            Iterator j = source.getKeys();
+            
+            while (j.hasNext())
+            {
+                String name = (String) j.next();
+                String value = source.getString(name);
+                contextProperties.setProperty(name,value);
+            }
+        }
+    }
+
+    /**
+     * Get the context properties that will be
+     * fed into the initial context be the
+     * generating process starts.
+     */
+    public ExtendedProperties getContextProperties()
+    {
+        return contextProperties;
+    }
+    
+    /**
+     * Set the use of the classpath in locating templates
+     *
+     * @param boolean true means the classpath will be used.
+     */
+    public void setUseClasspath(boolean useClasspath)
+    {
+        this.useClasspath = useClasspath;
+    }        
+    
+    /**
+     * Creates a VelocityContext.
+     *
+     * @return new Context
+     * @throws Exception the execute method will catch 
+     *         and rethrow as a <code>BuildException</code>
+     */
+    public Context initControlContext() 
+        throws Exception
+    {
+        return new VelocityContext();
+    }
+    
+    /**
+     * Execute the input script with Velocity
+     *
+     * @throws BuildException  
+     * BuildExceptions are thrown when required attributes are missing.
+     * Exceptions thrown by Velocity are rethrown as BuildExceptions.
+     */
+    public void execute () 
+        throws BuildException
+    {
+        // Make sure the template path is set.
+        if (templatePath == null && useClasspath == false)
+        {
+            throw new BuildException(
+                "The template path needs to be defined if you are not using " +
+                "the classpath for locating templates!");
+        }            
+    
+        // Make sure the control template is set.
+        if (controlTemplate == null)
+        {
+            throw new BuildException("The control template needs to be defined!");
+        }            
+
+        // Make sure the output directory is set.
+        if (outputDirectory == null)
+        {
+            throw new BuildException("The output directory needs to be defined!");
+        }            
+        
+        // Make sure there is an output file.
+        if (outputFile == null)
+        {
+            throw new BuildException("The output file needs to be defined!");
+        }            
+        
+        VelocityEngine ve = new VelocityEngine();
+        
+        try
+        {
+            // Setup the Velocity Runtime.
+            if (templatePath != null)
+            {
+            	log("Using templatePath: " + templatePath, project.MSG_VERBOSE);
+                ve.setProperty(
+                    ve.FILE_RESOURCE_LOADER_PATH, templatePath);
+            }
+            
+            if (useClasspath)
+            {
+            	log("Using classpath");
+                ve.addProperty(
+                    VelocityEngine.RESOURCE_LOADER, "classpath");
+            
+                ve.setProperty(
+                    "classpath." + VelocityEngine.RESOURCE_LOADER + ".class",
+                        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+
+                ve.setProperty(
+                    "classpath." + VelocityEngine.RESOURCE_LOADER + 
+                        ".cache", "false");
+
+                ve.setProperty(
+                    "classpath." + VelocityEngine.RESOURCE_LOADER + 
+                        ".modificationCheckInterval", "2");
+            }
+            
+            ve.init();
+
+            // Create the text generator.
+            Generator generator = Generator.getInstance();
+            generator.setVelocityEngine(ve);
+            generator.setOutputPath(outputDirectory);
+            generator.setInputEncoding(inputEncoding);
+            generator.setOutputEncoding(outputEncoding);
+
+            if (templatePath != null)
+            {
+                generator.setTemplatePath(templatePath);
+            }
+            
+            // Make sure the output directory exists, if it doesn't
+            // then create it.
+            File file = new File(outputDirectory);
+            if (! file.exists())
+            {
+                file.mkdirs();
+            }
+            
+            String path = outputDirectory + File.separator + outputFile;
+            log("Generating to file " + path, project.MSG_INFO);
+            Writer writer = generator.getWriter(path, outputEncoding);
+            
+            // The generator and the output path should
+            // be placed in the init context here and
+            // not in the generator class itself.
+            Context c = initControlContext();
+            
+            // Everything in the generator class should be
+            // pulled out and placed in here. What the generator
+            // class does can probably be added to the Velocity
+            // class and the generator class can probably
+            // be removed all together.
+            populateInitialContext(c);
+            
+            // Feed all the options into the initial
+            // control context so they are available
+            // in the control/worker templates.
+            if (contextProperties != null)
+            {
+                Iterator i = contextProperties.getKeys();
+        
+                while (i.hasNext())
+                {
+                    String property = (String) i.next();
+                    String value = contextProperties.getString(property);
+                    
+                    // Now lets quickly check to see if what
+                    // we have is numeric and try to put it
+                    // into the context as an Integer.
+                    try
+                    {
+                        c.put(property, new Integer(value)); 
+                    }
+                    catch (NumberFormatException nfe)
+                    {
+                        // Now we will try to place the value into
+                        // the context as a boolean value if it
+                        // maps to a valid boolean value.
+                        String booleanString = 
+                            contextProperties.testBoolean(value);
+                        
+                        if (booleanString != null)
+                        {    
+                            c.put(property, new Boolean(booleanString));
+                        }
+                        else
+                        {
+                            // We are going to do something special
+                            // for properties that have a "file.contents"
+                            // suffix: for these properties will pull
+                            // in the contents of the file and make
+                            // them available in the context. So for
+                            // a line like the following in a properties file:
+                            //
+                            // license.file.contents = license.txt
+                            //
+                            // We will pull in the contents of license.txt
+                            // and make it available in the context as
+                            // $license. This should make texen a little
+                            // more flexible.
+                            if (property.endsWith("file.contents"))
+                            {
+                                // We need to turn the license file from relative to
+                                // absolute, and let Ant help :)
+                                value = StringUtils.fileContentsToString(   
+                                    project.resolveFile(value).getCanonicalPath());
+                            
+                                property = property.substring(
+                                    0, property.indexOf("file.contents") - 1);
+                            }
+                        
+                            c.put(property, value);
+                        }
+                    }
+                }
+            }
+            
+            writer.write(generator.parse(controlTemplate, c));
+            writer.flush();
+            writer.close();
+            generator.shutdown();
+            cleanup();
+        }
+        catch( BuildException e)
+        {
+            throw e;
+        }
+        catch( MethodInvocationException e )
+        {
+            throw new BuildException(
+                "Exception thrown by '" + e.getReferenceName() + "." + 
+                    e.getMethodName() +"'" + ERR_MSG_FRAGMENT,
+                        e.getWrappedThrowable());
+        }       
+        catch( ParseErrorException e )
+        {
+            throw new BuildException("Velocity syntax error" + ERR_MSG_FRAGMENT ,e);
+        }        
+        catch( ResourceNotFoundException e )
+        {
+            throw new BuildException("Resource not found" + ERR_MSG_FRAGMENT,e);
+        }
+        catch( Exception e )
+        {
+            throw new BuildException("Generation failed" + ERR_MSG_FRAGMENT ,e);
+        }
+    }
+
+    /**
+     * <p>Place useful objects into the initial context.</p>
+     *
+     * <p>TexenTask places <code>Date().toString()</code> into the
+     * context as <code>$now</code>.  Subclasses who want to vary the
+     * objects in the context should override this method.</p>
+     *
+     * <p><code>$generator</code> is not put into the context in this
+     * method.</p>
+     *
+     * @param context The context to populate, as retrieved from
+     * {@link #initControlContext()}.
+     *
+     * @throws Exception Error while populating context.  The {@link
+     * #execute()} method will catch and rethrow as a
+     * <code>BuildException</code>.
+     */
+    protected void populateInitialContext(Context context) 
+        throws Exception
+    {
+        context.put("now", new Date().toString());
+    }
+
+    /**
+     * A hook method called at the end of {@link #execute()} which can
+     * be overridden to perform any necessary cleanup activities (such
+     * as the release of database connections, etc.).  By default,
+     * does nothing.
+     *
+     * @exception Exception Problem cleaning up.
+     */
+    protected void cleanup()
+        throws Exception
+    {
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/defaults/texen.properties
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/defaults/texen.properties?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/defaults/texen.properties (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/defaults/texen.properties Tue May 29 15:35:01 2012
@@ -0,0 +1,4 @@
+path.output=output
+context.objects.strings=org.apache.velocity.util.StringUtils
+context.objects.files=org.apache.velocity.texen.util.FileUtil
+context.objects.properties=org.apache.velocity.texen.util.PropertiesUtil

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/defaults/texen.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/FileUtil.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/FileUtil.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/FileUtil.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/FileUtil.java Tue May 29 15:35:01 2012
@@ -0,0 +1,75 @@
+package org.apache.velocity.texen.util;
+
+/*
+ * 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;
+
+/**
+ * A general file utility for use in the context
+ *
+ * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: FileUtil.java,v 1.9.8.1 2004/03/03 23:23:07 geirm Exp $ 
+ */
+public class FileUtil
+{
+    /**
+     * Creates the directory s (and any parent directories needed).
+     *
+     * @param String path/directory to create.
+     * @param String report of path/directory creation.
+     */
+    static public String mkdir (String s)
+    {
+        try
+        {
+            if ((new File(s)).mkdirs())
+                return "Created dir: "+s;
+            else
+                return "Failed to create dir or dir already exists: "+s;
+        }
+        catch (Exception e)
+        {
+            return e.toString();
+        }
+    }
+
+    /**
+     * A method to get a File object.
+     *
+     * @param String path to file object to create.
+     * @return File created file object.
+     */
+    public static File file(String s)
+    {
+        File f = new File(s);
+        return f;
+    }
+    
+    /**
+     * A method to get a File object.
+     *
+     * @param String base path
+     * @param String file name
+     * @return File created file object.
+     */
+    public static File file(String base, String s)
+    {
+        File f = new File(base, s);
+        return f;
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/FileUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/PropertiesUtil.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/PropertiesUtil.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/PropertiesUtil.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/PropertiesUtil.java Tue May 29 15:35:01 2012
@@ -0,0 +1,167 @@
+package org.apache.velocity.texen.util;
+
+/*
+ * 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.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import org.apache.velocity.texen.Generator;
+
+/**
+ * A property utility class for the texen text/code generator
+ * Usually this class is only used from a Velocity context.
+ *
+ * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
+ * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
+ * @version $Id: PropertiesUtil.java,v 1.9.8.1 2004/03/03 23:23:07 geirm Exp $ 
+ */
+public class PropertiesUtil
+{
+    /**
+     * Load properties from either a file in the templatePath if there
+     * is one or the classPath.
+     *
+     * @param propertiesFile the properties file to load through
+     * either the templatePath or the classpath.
+     * @return a properties instance filled with the properties found
+     * in the file or an empty instance if no file was found.
+     */
+    public Properties load(String propertiesFile)
+    {
+        Properties properties = new Properties();
+        String templatePath = Generator.getInstance().getTemplatePath();
+        if (templatePath != null)
+        {
+            properties = loadFromTemplatePath(propertiesFile);
+        }
+        else
+        {
+            properties = loadFromClassPath(propertiesFile);
+        }
+    
+        return properties;
+        
+    }
+    
+    /**
+     * Load a properties file from the templatePath defined in the
+     * generator. As the templatePath can contains multiple paths,
+     * it will cycle through them to find the file. The first file
+     * that can be successfully loaded is considered. (kind of
+     * like the java classpath), it is done to clone the Velocity
+     * process of loading templates.
+     *
+     * @param propertiesFile the properties file to load. It must be
+     * a relative pathname.
+     * @return a properties instance loaded with the properties from
+     * the file. If no file can be found it returns an empty instance.
+     */
+    protected Properties loadFromTemplatePath(String propertiesFile)
+    {
+        Properties properties = new Properties();
+        String templatePath = Generator.getInstance().getTemplatePath();
+        
+        // We might have something like the following:
+        //
+        // #set ($dbprops = $properties.load("$generator.templatePath/path/props")
+        //
+        // as we have in Torque but we want people to start using
+        //
+        // #set ($dbprops = $properties.load("path/props")
+        //
+        // so that everything works from the filesystem or from
+        // a JAR. So the actual Generator.getTemplatePath()
+        // is not deprecated but it's use in templates
+        // should be.
+        StringTokenizer st = new StringTokenizer(templatePath, ",");
+        while (st.hasMoreTokens())
+        {
+            String templateDir = st.nextToken();
+            try
+            {
+                // If the properties file is being pulled from the
+                // file system and someone is using the method whereby
+                // the properties file is assumed to be in the template
+                // path and they are simply using:
+                //
+                // #set ($dbprops = $properties.load("props") (1)
+                // 
+                // than we have to tack on the templatePath in order
+                // for the properties file to be found. We want (1)
+                // to work whether the generation is being run from
+                // the file system or from a JAR file.
+                String fullPath = propertiesFile;
+                
+                // FIXME probably not that clever since there could be
+                // a mix of file separators and the test will fail :-(
+                if (!fullPath.startsWith(templateDir))
+                {
+                    fullPath = templateDir + "/" + propertiesFile;
+                }
+
+                properties.load(new FileInputStream(fullPath));
+                // first pick wins, we don't need to go further since
+                // we found a valid file.
+                break;
+            }
+            catch (Exception e)
+            {
+                // do nothing
+            }
+        } 
+        return properties;
+    }
+
+    /**
+     * Load a properties file from the classpath
+     *
+     * @param propertiesFile the properties file to load.
+     * @return a properties instance loaded with the properties from
+     * the file. If no file can be found it returns an empty instance.
+     */ 
+    protected Properties loadFromClassPath(String propertiesFile)
+    {
+        Properties properties = new Properties();
+        ClassLoader classLoader = this.getClass().getClassLoader();
+        
+        try
+        {
+            // This is a hack for now to make sure that properties
+            // files referenced in the filesystem work in
+            // a JAR file. We have to deprecate the use
+            // of $generator.templatePath in templates first
+            // and this hack will allow those same templates
+            // that use $generator.templatePath to work in
+            // JAR files.
+            if (propertiesFile.startsWith("$generator"))
+            {
+                propertiesFile = propertiesFile.substring(
+                    "$generator.templatePath/".length());
+            }
+            
+            InputStream inputStream = classLoader.getResourceAsStream(propertiesFile);
+            properties.load(inputStream);
+        }
+        catch (IOException ioe)
+        {
+            // do nothing
+        }
+        return properties;
+    }
+}

Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/texen/util/PropertiesUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native