geirm 00/12/29 11:21:30
Added: whiteboard/geir_context_20001228 AbstractContext.java
Context.java HashMapContext.java
MultiContextTest.class MultiContextTest.java
README.txt TreeMapContext.java VelocityContext.java
velocity-0.71.jar
Log:
Another implementation of lots of the Context ideas... see the README.txt
Revision Changes Path
1.1
jakarta-velocity/whiteboard/geir_context_20001228/AbstractContext.java
Index: AbstractContext.java
===================================================================
package org.apache.velocity;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Hashtable;
import java.util.Properties;
import java.io.Serializable;
import java.io.FileInputStream;
import java.io.File;
import java.util.Enumeration;
import org.apache.velocity.util.ArrayIterator;
import org.apache.velocity.InternalContextBase;
/**
* This class is the abstract base class for all Velocity Context
* implementations. Simply extend this class and implement the
* abstract routines that access your preferred storage method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: AbstractContext.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
*/
public abstract class AbstractContext implements Context, Serializable
{
/**
* we handle the context wrapping
*/
private Context innerContext = null;
/**
* for Velocity internal use : for introspection caching et al
*/
private InternalContextBase icb = new InternalContextBase();
/** implement to return a value from the context storage */
public abstract Object internalGet( String key );
/** implement to put a value into the context storage */
public abstract Object internalPut( String key, Object value );
/** implement to determine if a key is in the storage */
public abstract boolean internalContainsKey(Object key);
/** implement to return an object array of key strings from your storage */
public abstract Object[] internalGetKeys();
/** implement to remove an item from your storage */
public abstract Object internalRemove(Object key);
/**
* CTOR's
*/
public AbstractContext()
{
}
public AbstractContext( Context inner )
{
innerContext = inner;
}
public boolean loadTools( String propsfilename, boolean doGlobal )
{
/*
* if we get a props file name, make a properties to call the
* global toolsmith
*/
try
{
Properties p = null;
if ( propsfilename != null)
{
p = new Properties();
p.load(new FileInputStream( new File(propsfilename)));;
}
/*
* do it all in one place, the other loadTools()
*/
return loadTools(p, doGlobal);
}
catch( Exception e)
{
return false;
}
}
public boolean loadTools( Properties props, boolean doGlobal )
{
/*
* call the global toolsmith :) and get the toolset
* comprised of globals if request, as well as locals
* if specified
*/
Hashtable h = new Hashtable(); // Runtime.toolsmith( props, doGlobal );
/*
* iterate through the hash, adding tools to the Context
*/
for( Enumeration e = h.keys(); e.hasMoreElements(); )
{
String reference = (String) e.nextElement();
Object o = h.get( reference );
internalPut( reference, o );
}
return true;
}
/**
* Adds a name/value pair to the context.
*
* @param key The name to key the provided value with.
* @param value The corresponding value.
*/
public Object put(String key, Object value)
{
try
{
return internalPut(key, value);
}
catch (NullPointerException npe)
{
if (key == null)
{
org.apache.velocity.runtime.Runtime.error ("Context key was null!
Value was: " + value);
}
else if (value == null)
{
org.apache.velocity.runtime.Runtime.error ("Context value was null!
Key was: " + key);
}
return null;
}
}
/**
* Gets the value corresponding to the provided key from the context.
*
* @param key The name of the desired value.
* @return The value corresponding to the provided key.
*/
public Object get(String key)
{
if (key == null)
{
org.apache.velocity.runtime.Runtime.debug ("Context key was null!");
}
Object o = internalGet( key );
if (o == null && innerContext != null)
{
o = innerContext.get( key );
}
return o;
}
/**
* Indicates whether the specified key is in the context.
*
* @param key The key to look for.
* @return Whether the key is in the context.
*/
public boolean containsKey(Object key)
{
if (key == null)
{
org.apache.velocity.runtime.Runtime.debug ("Context key was null!");
}
return internalContainsKey(key);
}
/*
* Get all the keys for the values in the context
*/
public Object[] getKeys()
{
return internalGetKeys();
}
/**
* Removes the value associated with the specified key from the context.
*
* @param key The name of the value to remove.
* @return The value that the key was mapped to, or <code>null</code>
* if unmapped.
*/
public Object remove(Object key)
{
if (key == null)
{
org.apache.velocity.runtime.Runtime.debug ("Context key was null!");
}
return internalRemove(key);
}
public InternalContext getInternalContext()
{
return icb;
}
}
1.1 jakarta-velocity/whiteboard/geir_context_20001228/Context.java
Index: Context.java
===================================================================
package org.apache.velocity;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Hashtable;
import java.io.Serializable;
import org.apache.velocity.util.ArrayIterator;
import org.apache.velocity.InternalContext;
/**
* This class provides the storage location for all dynamic
* information that is used to create a document. A final
* document is created by processing a template against
* the contents of the context. The context may include
* an valid object derived from Object. These objects
* are stored in a Hashtable.
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: Context.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
*/
public interface Context
{
/**
* Adds a name/value pair to the context.
*
* @param key The name to key the provided value with.
* @param value The corresponding value.
*/
public Object put(String key, Object value);
/**
* Gets the value corresponding to the provided key from the context.
*
* @param key The name of the desired value.
* @return The value corresponding to the provided key.
*/
public Object get(String key);
/**
* Indicates whether the specified key is in the context.
*
* @param key The key to look for.
* @return Whether the key is in the context.
*/
public boolean containsKey(Object key);
/*
* Get all the keys for the values in the context
*/
public Object[] getKeys();
/**
* Removes the value associated with the specified key from the context.
*
* @param key The name of the value to remove.
* @return The value that the key was mapped to, or <code>null</code>
* if unmapped.
*/
public Object remove(Object key);
/*
* for internal use
*/
public InternalContext getInternalContext();
}
1.1
jakarta-velocity/whiteboard/geir_context_20001228/HashMapContext.java
Index: HashMapContext.java
===================================================================
package org.apache.velocity;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.HashMap;
import java.io.Serializable;
/**
* Example context impl that uses a HashMap
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: HashMapContext.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
*/
public class HashMapContext extends AbstractContext
{
private HashMap context = new HashMap();
public HashMapContext()
{
super();
}
public HashMapContext( Context inner )
{
super( inner );
}
public Object internalGet( String key )
{
return context.get( key );
}
public Object internalPut( String key, Object value )
{
return context.put( key, value );
}
public boolean internalContainsKey(Object key)
{
return context.containsKey( key );
}
public Object[] internalGetKeys()
{
return context.keySet().toArray();
}
public Object internalRemove(Object key)
{
return context.remove( key );
}
}
1.1
jakarta-velocity/whiteboard/geir_context_20001228/MultiContextTest.class
<<Binary file>>
1.1
jakarta-velocity/whiteboard/geir_context_20001228/MultiContextTest.java
Index: MultiContextTest.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Stack;
import java.util.Vector;
import org.apache.velocity.Context;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.HashMapContext;
import org.apache.velocity.TreeMapContext;
import org.apache.velocity.Template;
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.test.provider.TestProvider;
/**
* This class the testbed for Velocity. It is used to
* test all the directives support by Velocity.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: MultiContextTest.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
*/
public class MultiContextTest
{
/**
* Cache of writers
*/
private static Stack writerStack = new Stack();
public MultiContextTest(String templateFile)
{
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!");
/*
* adding simple vector with strings for testing late introspection stuff
*/
Vector v = new Vector();
v.addElement( new String("hello") );
v.addElement( new String("hello2") );
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... */
}
/*
* add some individual properties if you wish
*/
p.setProperty(Runtime.RUNTIME_LOG_ERROR_STACKTRACE, "true");
p.setProperty(Runtime.RUNTIME_LOG_WARN_STACKTRACE, "true");
p.setProperty(Runtime.RUNTIME_LOG_INFO_STACKTRACE, "true");
/*
* and now call init
*/
Runtime.init(p);
/*
* now, do what we want to do. First, get the Template
*/
if (templateFile == null)
templateFile = "examples/example.vm";
Template template = Runtime.getTemplate(templateFile);
/*
* now, make a Context object and populate it.
*/
VelocityContext context = new VelocityContext();
TreeMapContext tmc = new TreeMapContext( context );
HashMapContext c2 = new HashMapContext( tmc );
tmc.put("provider", provider);
context.put("name", "jason");
tmc.put("providers", provider.getCustomers2());
context.put("list", al);
context.put("hashtable", h);
tmc.put("search", provider.getSearch());
c2.put("relatedSearches", provider.getRelSearches());
context.put("searchResults", provider.getRelSearches());
tmc.put("menu", provider.getMenu());
context.put("stringarray", provider.getArray());
c2.put("vector", v);
tmc.put("mystring", new String());
/*
* make a writer, and merge the template 'against' the context
*/
Properties toolsp = new Properties();
toolsp.load(new FileInputStream( new File("/tmp/tool.properties" )));
c2.loadTools( toolsp, false );
writer = new BufferedWriter(new OutputStreamWriter(System.out));
template.merge(c2, writer);
writer.flush();
writer.close();
}
catch( Exception e )
{
Runtime.error(e);
}
}
public static void main(String[] args)
{
MultiContextTest t;
t = new MultiContextTest(args[0]);
}
}
1.1 jakarta-velocity/whiteboard/geir_context_20001228/README.txt
Index: README.txt
===================================================================
Here is my impl of all the context stuff we have been
talking about for a while.
Note that this code won't drop in and run as it requires
small non-functional mods to a few AST nodes to decouple
the internal context stuff from the app-level context stuff,
which is a Good Thing. There are also changes to
everything from VelocityServlet to Anakia to Texen etc to
use the replacement for Context, namely VelocityContext.
If we agree that this is ok I will check the whole pile in
with whatever mods we want. If not, I'll chuck it!
The important changes from the current way things are :
1) Fedor's wrapping/chaining context stuff is supported.
2) Jason's quest for a tool manager in Velocity is supported.
This supports the idea of a global tool manager (specify tools
in the vel.props file) for ease of use along with the ability
for the app to not use the globals and just specify their own
through a separate props file or a Properties. Note that
there is just support for a tool manager, not one in here.
Figure jason has one already....
3) Everyone's desire for a flexible way to make new kinds of
contexts that do strange and different things, like LDAP,
a DB, a bunny rabbit, whatever.
4) Geir's desire that less major machinery is put into the
Vel runtime core if it can be avoided.
Included
---------
Context.java : basic interface defintion. It looks exactly like
the current Context, for the most part, except that put optionally
returns the Object it replaces, and the InternalContext crap is
gotten as an object by the nodes rather than have the methods
implemented by the Context.
AbstractContext.java : abstract class for a usable app-level Context.
Handles the wrapping/chaining support as well as interfacing with the
maybe upcoming 'toolsmith', the global context tool manager/dispenser.
VelocityContext.java : replaces the current Context.java implementation.
This is a working hashtable-based concrete implementation of
AbstractContext.java. You would use it wherever you use Context now.
(and indeed, it is used in the included jar)
HashMapContext.java : example of creating another kind of Context, it uses
a HashMap for storage.
TreeMapContext.java : another example of creating a new kind of Context, it uses
a TreeMap for storage.
[yes, the two above aren't that interesting. But show how one goes about
doing it. I'll try for a DBContext later when I have more time]
MultiContextTest.java : the Test program but now uses the three above contexts
together, wrapped/chained in a chain to demonstrate that it indeed works.
velocity-0.71.jar : working jar to work with the above test program.
(remember, there are some small nonfunctional tweaks to everything to get
this to work. I will check all in if we decide this is the way to go...)
You can also use this against the testbed - chaining is used within the
TemplateTestCase.
geir
1.1
jakarta-velocity/whiteboard/geir_context_20001228/TreeMapContext.java
Index: TreeMapContext.java
===================================================================
package org.apache.velocity;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.TreeMap;
import java.io.Serializable;
/**
* Example context impl that uses a HashMap
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: TreeMapContext.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
*/
public class TreeMapContext extends AbstractContext
{
private TreeMap context = new TreeMap();
public TreeMapContext()
{
super();
}
public TreeMapContext( Context inner )
{
super( inner );
}
public Object internalGet( String key )
{
return context.get( key );
}
public Object internalPut( String key, Object value )
{
return context.put( key, value );
}
public boolean internalContainsKey(Object key)
{
return context.containsKey( key );
}
public Object[] internalGetKeys()
{
return context.keySet().toArray();
}
public Object internalRemove(Object key)
{
return context.remove( key );
}
}
1.1
jakarta-velocity/whiteboard/geir_context_20001228/VelocityContext.java
Index: VelocityContext.java
===================================================================
package org.apache.velocity;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Hashtable;
import java.util.Properties;
import java.io.Serializable;
/**
* Default basic implementation of a Context object
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: VelocityContext.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
*/
public class VelocityContext extends AbstractContext implements Cloneable
{
private Hashtable context = new Hashtable();
public VelocityContext()
{
super();
}
public VelocityContext( Context inner )
{
super( inner );
}
public Object internalGet( String key )
{
return context.get( key );
}
public Object internalPut( String key, Object value )
{
return context.put( key, value );
}
public boolean internalContainsKey(Object key)
{
return context.containsKey( key );
}
public Object[] internalGetKeys()
{
return context.keySet().toArray();
}
public Object internalRemove(Object key)
{
return context.remove( key );
}
/**
* Clones this context object
* @return Object an instance of this Context
*/
public Object clone()
{
VelocityContext clone = null;
try
{
clone = (VelocityContext) super.clone();
clone.context = (Hashtable) context.clone();
}
catch (CloneNotSupportedException cnse)
{
}
return clone;
}
}
1.1
jakarta-velocity/whiteboard/geir_context_20001228/velocity-0.71.jar
<<Binary file>>