org.mmbase.util
Class StringTagger

java.lang.Object
  |
  +--org.mmbase.util.StringTagger
All Implemented Interfaces:
java.util.Map

public class StringTagger
extends java.lang.Object
implements java.util.Map

StringTagger, Creates a object with tags and fields from a String. Its ideal for name-value pairs and name-value pairs with multivalues. It also provides support for quoted values, and recognizes values that are 'function' calls with their own parameter list (allowing to ignore any tokens within these lists when parsing).

Version:
18 Apr 2001
Author:
Daniel Ockeloen, Pierre van Rooden

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
StringTagger(java.lang.String line)
          Creates a StringTag for the given line.
StringTagger(java.lang.String line, char TagStart, char TagSeperator, char FieldSeperator, char QuoteChar)
          Creates a StringTag for the given line.
StringTagger(java.lang.String line, char TagStart, char TagSeperator, char FieldSeperator, char QuoteChar, char FunctionOpen, char FunctionClose)
          Creates a StringTag for the given line.
 
Method Summary
 void clear()
          Clears all data
 boolean containsKey(java.lang.Object ob)
          Checks whether a key exits.
 boolean containsValue(java.lang.Object ob)
          Checks whether a value exits.
 java.util.Enumeration elements()
          Returns a Enumeration of the values as String.
 java.util.Set entrySet()
          returns all values
 boolean equals(java.lang.Object ob)
          Returns whether two objects are the same
 java.lang.Object get(java.lang.Object ob)
          Returns the value of a key as an Object.
 int hashCode()
          Hashcode for sorting and comparing
 boolean isEmpty()
          Checks whether the tagger is empty
 java.util.Enumeration keys()
          Returns a Enumeration of the name keys.
 java.util.Set keySet()
          Returns a Set of the name keys.
static void main(java.lang.String[] args)
          For testing
 java.util.Enumeration multiElements(java.lang.String token)
          Returns a Enumeration of the values as Vectors that contain the seperated values.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          sets a value (for the Map interface).
 void putAll(java.util.Map map)
          Manually sets a set of values (for the Map interface).
 java.lang.Object remove(java.lang.Object key)
          remove a value (for the Map interface).
 void setValue(java.lang.String token, java.lang.String val)
          Manually sets a single value.
 void setValues(java.lang.String token, java.util.Vector values)
          Manually sets a multi-value value.
 int size()
          sets a value (for the Map interface).
 java.lang.String toString()
          toString
 java.lang.String Value(java.lang.String token)
          Returns the first value as a String.
 java.util.Collection values()
          returns all values
 java.util.Vector Values(java.lang.String token)
          Returns the values as a Vector that contains the separated values.
Use get(java.lang.Object) to get the list of values as a String
Use Value(java.lang.String) to get the first value as a String
 java.lang.String ValuesString(java.lang.String token)
          Returns the original parsed line
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringTagger

public StringTagger(java.lang.String line,
                    char TagStart,
                    char TagSeperator,
                    char FieldSeperator,
                    char QuoteChar,
                    char FunctionOpen,
                    char FunctionClose)
Creates a StringTag for the given line. Example : StringTagger("cmd=lookup names='Daniel Ockeloen, Rico Jansen'",' ','=',','\'','('.')')
Parameters:
line - : to be tagged line
TagStart - : Seperator for the Tags
TagSeperator - : Seperator inside the Tag (between name and value)
FieldSeperator - : Seperator inside the value
QuoteChar - : Char used if a quoted value
FunctionOpen - char used to open a function parameter list
FunctionClose - char used to close a function parameter list

StringTagger

public StringTagger(java.lang.String line,
                    char TagStart,
                    char TagSeperator,
                    char FieldSeperator,
                    char QuoteChar)
Creates a StringTag for the given line. Uses default characters for the function parameter list tokens. Example : StringTagger("cmd=lookup names='Daniel Ockeloen, Rico Jansen'",' ','=',','\'')
Parameters:
line - : to be tagged line
TagStart - : Seperator for the Tags
TagSeperator - : Seperator inside the Tag (between name and value)
FieldSeperator - : Seperator inside the value
QuoteChar - : Char used if a quoted value

StringTagger

public StringTagger(java.lang.String line)
Creates a StringTag for the given line. Uses default characters for all tokens.
Parameters:
line - : to be tagged line
Method Detail

clear

public void clear()
Clears all data
Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object ob)
Checks whether a key exits.
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object ob)
Checks whether a value exits.
Specified by:
containsValue in interface java.util.Map

entrySet

public java.util.Set entrySet()
returns all values
Specified by:
entrySet in interface java.util.Map

equals

public boolean equals(java.lang.Object ob)
Returns whether two objects are the same
Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object
Parameters:
ob - the key of the value to retrieve

get

public java.lang.Object get(java.lang.Object ob)
Returns the value of a key as an Object. The value returned is a single, unseparated, string.
Use Values(java.lang.String) to get a list of multi-values as a Vector.
Use Value(java.lang.String) to get the first value as a String
Specified by:
get in interface java.util.Map
Parameters:
ob - the key of the value to retrieve

hashCode

public int hashCode()
Hashcode for sorting and comparing
Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class java.lang.Object

isEmpty

public boolean isEmpty()
Checks whether the tagger is empty
Specified by:
isEmpty in interface java.util.Map

keySet

public java.util.Set keySet()
Returns a Set of the name keys.
Specified by:
keySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
sets a value (for the Map interface).
Specified by:
put in interface java.util.Map

putAll

public void putAll(java.util.Map map)
Manually sets a set of values (for the Map interface).
Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
remove a value (for the Map interface).
Specified by:
remove in interface java.util.Map

size

public int size()
sets a value (for the Map interface).
Specified by:
size in interface java.util.Map

values

public java.util.Collection values()
returns all values
Specified by:
values in interface java.util.Map

keys

public java.util.Enumeration keys()
Returns a Enumeration of the name keys.

toString

public java.lang.String toString()
toString
Overrides:
toString in class java.lang.Object

elements

public java.util.Enumeration elements()
Returns a Enumeration of the values as String. The values returned are all single, unsepartated, strings. Use multiElements(java.lang.String) to get a list of multi-values.

multiElements

public java.util.Enumeration multiElements(java.lang.String token)
Returns a Enumeration of the values as Vectors that contain the seperated values. Use elements() to get a list of single, unseparated, values.

Values

public java.util.Vector Values(java.lang.String token)
Returns the values as a Vector that contains the separated values.
Use get(java.lang.Object) to get the list of values as a String
Use Value(java.lang.String) to get the first value as a String
Parameters:
token - the key of the value to retrieve

ValuesString

public java.lang.String ValuesString(java.lang.String token)
Returns the original parsed line
Parameters:
token - unused

Value

public java.lang.String Value(java.lang.String token)
Returns the first value as a String. In case of a single value, it returns that value. In case of multiple values, it returns the Use get(java.lang.Object) to get the list of values as a String
Use Values(java.lang.String) to get a list of multi-values as a Vector.
Parameters:
token - the key of the value to retrieve

setValue

public void setValue(java.lang.String token,
                     java.lang.String val)
Manually sets a single value.

setValues

public void setValues(java.lang.String token,
                      java.util.Vector values)
Manually sets a multi-value value.

main

public static void main(java.lang.String[] args)
For testing


MMBase 2001