Logo Search packages:      
Sourcecode: velocity version File versions  Download package

void org::apache::velocity::runtime::configuration::Configuration::addProperty ( String  key,
Object  token 
) [inline]

Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if

resource.loader = file

is already present in the configuration and you

addProperty("resource.loader", "classpath")

Then you will end up with a Vector like the following:

["file", "classpath"]

Parameters:
String key
String value

Definition at line 564 of file Configuration.java.

References addStringProperty(), org::apache::velocity::runtime::configuration::Configuration::PropertiesTokenizer::hasMoreTokens(), keysAsListed, and org::apache::velocity::runtime::configuration::Configuration::PropertiesTokenizer::nextToken().

Referenced by load(), and setProperty().

    {

        // $$$ GMJ : remove after 1.1 release
        // for deprecation help
        deprecationCrutch.addProperty( key, token );

        Object o = this.get(key);

        /*
         *  $$$ GMJ
         *  FIXME : post 1.0 release, we need to not assume
         *  that a scalar is a String - it can be an Object
         *  so we should make a little vector-like class
         *  say, Foo that wraps (not extends Vector),
         *  so we can do things like
         *  if ( !( o instanceof Foo) )
         *  so we know it's our 'vector' container
         *
         *  This applies throughout
         */
        
        if (o instanceof String)
        {
            Vector v = new Vector(2);
            v.addElement(o);
            v.addElement(token);
            put(key, v);
        }
        else if (o instanceof Vector)
        {
            ((Vector) o).addElement(token);
        }
        else
        {
            /*
             * This is the first time that we have seen
             * request to place an object in the 
             * configuration with the key 'key'. So
             * we just want to place it directly into
             * the configuration ... but we are going to
             * make a special exception for String objects
             * that contain "," characters. We will take
             * CSV lists and turn the list into a vector of
             * Strings before placing it in the configuration.
             * This is a concession for Properties and the
             * like that cannot parse multiple same key
             * values.
             */
            if (token instanceof String &&
                ((String)token).indexOf(PropertiesTokenizer.DELIMITER) > 0)
            {
                PropertiesTokenizer tokenizer = 
                    new PropertiesTokenizer((String)token);
                    
                while (tokenizer.hasMoreTokens())
                {
                    String value = tokenizer.nextToken();
                    
                    /*
                     * we know this is a string, so make sure it
                     * just goes in rather than risking vectorization
                     * if it contains an escaped comma
                     */
                    addStringProperty(key,value);
                }
            }
            else
            {
                /*
                 * We want to keep track of the order the keys
                 * are parsed, or dynamically entered into
                 * the configuration. So when we see a key
                 * for the first time we will place it in
                 * an ArrayList so that if a client class needs
                 * to perform operations with configuration
                 * in a definite order it will be possible.
                 */

                /*
                 * safety check
                 */

                if( !containsKey( key ) )
                {
                    keysAsListed.add(key);
                }

                /*
                 * and the value
                 */
                put(key, token);
            }                
        }
    }


Generated by  Doxygen 1.6.0   Back to index