Commons.Collections.ExtendedProperties.AddProperty C# (CSharp) Method

AddProperty() public method

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"] *
public AddProperty ( String key, Object token ) : void
key String
token Object
return void
        public void AddProperty(String key, Object token)
        {
            Object o = this[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 is String)
            {
                ArrayList v = new ArrayList(2);
                v.Add(o);
                v.Add(token);
                CollectionsUtil.PutElement(this, key, v);
            }
            else if (o is ArrayList)
            {
                ((ArrayList) o).Add(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 is String && ((String) token).IndexOf(PropertiesTokenizer.DELIMITER) > 0)
                {
                    PropertiesTokenizer tokenizer = new PropertiesTokenizer((String) token);

                    while(tokenizer.HasMoreTokens())
                    {
                        String s = 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, s);
                    }
                }
                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.
            */
                    AddPropertyDirect(key, token);
                }
            }
        }

Usage Example

Beispiel #1
1
 static NVelocity()
 {
     filePath = Utils.GetMapPath(BaseConfigs.GetForumPath);
     engine = new VelocityEngine();
     props = new ExtendedProperties();
     props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
     props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
     props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, filePath);
     engine.Init(props);
 }
All Usage Examples Of Commons.Collections.ExtendedProperties::AddProperty