This class divides into tokens a property value. Token separator is "," but commas into the property value are escaped using the backslash in front.
Наследование: StringTokenizer
Пример #1
0
        public void AddProperty(string key, object token)
        {
            object obj = this[key];

            if (obj is string)
            {
                CollectionsUtil.PutElement(this, key, new ArrayList(2)
                {
                    obj,
                    token
                });
            }
            else if (obj is ArrayList)
            {
                ((ArrayList)obj).Add(token);
            }
            else if (token is string && ((string)token).IndexOf(",") > 0)
            {
                PropertiesTokenizer propertiesTokenizer = new PropertiesTokenizer((string)token);
                while (propertiesTokenizer.HasMoreTokens())
                {
                    string token2 = propertiesTokenizer.NextToken();
                    this.AddStringProperty(key, token2);
                }
            }
            else
            {
                this.AddPropertyDirect(key, token);
            }
        }
Пример #2
0
        public virtual void AddProperty(string key, object token)
        {
            object obj2 = this[key];

            if (obj2 is string)
            {
                ArrayList newValue = new ArrayList(2);
                newValue.Add(obj2);
                newValue.Add(token);
                CollectionsUtil.PutElement(this, key, newValue);
            }
            else if (obj2 is ArrayList)
            {
                ((ArrayList)obj2).Add(token);
            }
            else if ((token is string) && (((string)token).IndexOf(",") > 0))
            {
                PropertiesTokenizer tokenizer = new PropertiesTokenizer((string)token);
                while (tokenizer.HasMoreTokens())
                {
                    string str = tokenizer.NextToken();
                    this.AddStringProperty(key, str);
                }
            }
            else
            {
                this.AddPropertyDirect(key, token);
            }
        }
Пример #3
0
		/// <summary> 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"]
		/// *
		/// </summary>
		/// <param name="key"></param>
		/// <param name="token"></param>
		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);
				}
			}
		}