xmlBlaster 2.1.0 API

org.xmlBlaster.util
Class StringPairTokenizer

java.lang.Object
  extended by org.xmlBlaster.util.StringPairTokenizer

public class StringPairTokenizer
extends java.lang.Object

StringPairTokenizer is a utility class used to parse a string giving back a map containing pairs of key/value strings.
The method parseLine respects quoted '"' tokens and ignores the separator inside the quotes.

Author:
Michele Laghi, Marcel Ruff

Field Summary
static char DEFAULT_INNER_SEPARATOR
           
static char DEFAULT_QUOTE_CHARACTER
           
static char DEFAULT_SEPARATOR
           
static char ESCAPE_CHARACTER
           
 
Constructor Summary
StringPairTokenizer()
           
 
Method Summary
static java.lang.String arrayToCSV(java.lang.String[] strs, java.lang.String sep)
           
static java.util.Map<java.lang.String,java.lang.String> CSVToMap(java.lang.String csv)
          Counterpart to #mapToCSV(Map) Fails if key contains token "=" and fails if value contains token """
static java.util.Map<java.lang.String,java.lang.String> CSVToMap(java.lang.String csv, char sep, char apos, char innerSeparator)
          Counterpart to #mapToCSV(Map) Fails if key contains token "=" and fails if value contains token """
static java.lang.String dumpMap(java.util.Map<java.lang.String,ClientProperty> map)
          Dumps the given map to a human readable string.
static void main(java.lang.String[] args)
           
static java.lang.String mapToCSV(java.util.Map map)
          Counterpart to #CSVToMap(String)
static java.lang.String mapToCSV(java.util.Map map, char sep, char apos)
          A '=' in the key is escaped with "=".
static java.lang.String mapToCSV(java.util.Map map, char sep, char apos, char innerSeparator)
           
static java.lang.String[] parseLine(java.lang.String nextLine)
           
static java.lang.String[] parseLine(java.lang.String[] nextLines, char separator, char quotechar, boolean trimEmpty, boolean preserveInsideQuoteChar)
          Split string to tokens and respect quotes.
static java.util.Map parseLine(java.lang.String[] nextLines, char separator, char quotechar, char innerSeparator, boolean trimEmpty, boolean wantClientProperties, boolean trimValue)
          Split string to tokens and respect quotes, then parse key/values into the returned map.
static java.lang.String[] parseLine(java.lang.String nextLine, char separator)
           
static java.lang.String[] parseLine(java.lang.String nextLine, char separator, char quotechar, boolean trimEmpty)
           
static java.lang.String[] parseLine(java.lang.String nextLine, char separator, char quotechar, boolean trimEmpty, boolean preserveInsideQuoteChar)
           
static java.util.Map parseLine(java.lang.String nextLine, char separator, char quotechar, char innerSeparator, boolean trimEmpty, boolean wantClientProperties)
           
static java.util.Map parseLineToProperties(java.lang.String nextLine)
          Parsing for example >org.xmlBlaster.protocol.soap.SoapDriver,"classpath=xerces.jar:soap.jar,all",MAXSIZE=100,a=10<.
private static java.util.Map parseStringProperties(java.lang.String rawString, java.lang.String outerToken, java.lang.String innerToken, boolean wantClientProperties)
          If a value is missing then a null object will be put into the map as value.
static java.util.Map<java.lang.String,ClientProperty> parseToStringClientPropertyPairs(java.lang.String rawString, java.lang.String outerToken, java.lang.String innerToken)
           
static java.util.Map parseToStringStringPairs(java.lang.String rawString, java.lang.String outerToken, java.lang.String innerToken)
           
static java.lang.String[] toArray(java.lang.String str, java.lang.String separator)
          Convert a separator based string to an array of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_QUOTE_CHARACTER

public static final char DEFAULT_QUOTE_CHARACTER
See Also:
Constant Field Values

ESCAPE_CHARACTER

public static final char ESCAPE_CHARACTER
See Also:
Constant Field Values

DEFAULT_SEPARATOR

public static final char DEFAULT_SEPARATOR
See Also:
Constant Field Values

DEFAULT_INNER_SEPARATOR

public static final char DEFAULT_INNER_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

StringPairTokenizer

public StringPairTokenizer()
Method Detail

parseLine

public static java.lang.String[] parseLine(java.lang.String nextLine)
See Also:
#parseLine(String[] nextLines, char separator, char quotechar, boolean trimEmpty)

parseLine

public static java.lang.String[] parseLine(java.lang.String nextLine,
                                           char separator)
See Also:
#parseLine(String[] nextLines, char separator, char quotechar, boolean trimEmpty)

parseLine

public static java.lang.String[] parseLine(java.lang.String nextLine,
                                           char separator,
                                           char quotechar,
                                           boolean trimEmpty)
See Also:
parseLine(String[] nextLines, char separator, char quotechar, boolean trimEmpty, boolean)

parseLine

public static java.lang.String[] parseLine(java.lang.String nextLine,
                                           char separator,
                                           char quotechar,
                                           boolean trimEmpty,
                                           boolean preserveInsideQuoteChar)
See Also:
parseLine(String[] nextLines, char separator, char quotechar, boolean trimEmpty, boolean)

parseLine

public static java.lang.String[] parseLine(java.lang.String[] nextLines,
                                           char separator,
                                           char quotechar,
                                           boolean trimEmpty,
                                           boolean preserveInsideQuoteChar)
Split string to tokens and respect quotes.
 /node/heron/client/\"joe/the/great\"

  'node'
  'heron'
  'client'
  'joe/the/great'
Thanks to http://opencsv.sourceforge.net/ (under Apache license)

Parameters:
nextLines - An array of lines, followup lines will only be parsed if an open quotechar exists
separator - Defaults to StringPairTokenizer.DEFAULT_SEPARATOR=','
quotechar - Defaults to StringPairTokenizer.DEFAULT_QUOTE_CHARACTER='"'
trimEmpty - if true removes silently empty tokens
preserveInsideQuoteChar - true: Preserve the inside quotes of "bla, bla, "blu blu", bli"
Returns:
Never null, if nextLines is null or empty we return an empty array

parseLine

public static java.util.Map parseLine(java.lang.String[] nextLines,
                                      char separator,
                                      char quotechar,
                                      char innerSeparator,
                                      boolean trimEmpty,
                                      boolean wantClientProperties,
                                      boolean trimValue)
Split string to tokens and respect quotes, then parse key/values into the returned map. If a value is missing then a null object will be put into the map as value. The map returns pairs 'String,ClientProperty' if wantClientProperties is true, otherwise it returns 'String,String' pairs.

Parameters:
nextLines - e.g. String[] nextLines = { "org.xmlBlaster.protocol.soap.SoapDriver,\"classpath=xerces.jar:soap.jar,all\",MAXSIZE=100,a=10,\"b=", "20\",c=30" }; Followup lines will only be parsed if an open quotechar exists
innerSeparator - is for example StringPairTokenizer.DEFAULT_INNER_SEPARATOR "=" or " "
wantClientProperties - if set to true returns pairs 'String,ClientProperty', returns 'String,String' pairs otherwise.
trimValue - If true the value is trimmed (removed white spaces in front and back)
Returns:
Never null,
 classpath=xerces.jar:soap.jar,all
 org.xmlBlaster.protocol.soap.SoapDriver=null
 MAXSIZE=100
 a=10
 c=30
 b=20
 
See Also:
#parseLine(String[] nextLines, char separator, char quotechar, boolean trimEmpty)

parseLine

public static java.util.Map parseLine(java.lang.String nextLine,
                                      char separator,
                                      char quotechar,
                                      char innerSeparator,
                                      boolean trimEmpty,
                                      boolean wantClientProperties)
See Also:
parseLine(String[] nextLines, char separator, char quotechar, char innerSeparator, boolean trimEmpty, boolean wantClientProperties, boolean trimEmpty)

parseLineToProperties

public static java.util.Map parseLineToProperties(java.lang.String nextLine)
Parsing for example >org.xmlBlaster.protocol.soap.SoapDriver,"classpath=xerces.jar:soap.jar,all",MAXSIZE=100,a=10<.

Using default separator chars and quote chars: return parseLine(nextLines, DEFAULT_SEPARATOR, DEFAULT_QUOTE_CHARACTER, DEFAULT_INNER_SEPARATOR, true, false, false);

See Also:
parseLine(String[] nextLines, char separator, char quotechar, char innerSeparator, boolean trimEmpty, boolean wantClientProperties, boolean trimEmpty)

toArray

public static final java.lang.String[] toArray(java.lang.String str,
                                               java.lang.String separator)
Convert a separator based string to an array of strings.

Example:
NameList=Josua,David,Ken,Abel
Will return each name separately in the array.

Note: An empty field ",," is ommitted

Parameters:
key - the key to look for
defaultVal - The default value to return if key is not found
separator - The separator, typically ","
Returns:
The String array for the given key, the elements are trimmed (no leading/following white spaces), is never null

dumpMap

public static java.lang.String dumpMap(java.util.Map<java.lang.String,ClientProperty> map)
Dumps the given map to a human readable string.

Parameters:
map -
Returns:
e.g. "key1=15,name=joe"

parseStringProperties

private static java.util.Map parseStringProperties(java.lang.String rawString,
                                                   java.lang.String outerToken,
                                                   java.lang.String innerToken,
                                                   boolean wantClientProperties)
If a value is missing then a null object will be put into the map as value. The map returns pairs 'String,ClientProperty' if wantClientProperties is true, otherwise it returns 'String,String' pairs.

Parameters:
rawString - e.g. "org.xmlBlaster.protocol.soap.SoapDriver,classpath=xerces.jar:soap.jar,MAXSIZE=100"
outerToken - is for example ";" or ","
innterToken - is for example "=" or " "
wantClientProperties - if set to true returns pairs 'String,ClientProperty', returns 'String,String' pairs otherwise.

parseToStringClientPropertyPairs

public static java.util.Map<java.lang.String,ClientProperty> parseToStringClientPropertyPairs(java.lang.String rawString,
                                                                                              java.lang.String outerToken,
                                                                                              java.lang.String innerToken)
Parameters:
rawString - e.g. "org.xmlBlaster.protocol.soap.SoapDriver,classpath=xerces.jar:soap.jar,MAXSIZE=100"
outerToken - is for example ";" or ","
innerToken - is for example "=" or " " If a value is missing then a null object as value. the map returns pairs 'String,ClientProperty'.

CSVToMap

public static java.util.Map<java.lang.String,java.lang.String> CSVToMap(java.lang.String csv)
Counterpart to #mapToCSV(Map) Fails if key contains token "=" and fails if value contains token """

Parameters:
csv -
Returns:
never null

CSVToMap

public static java.util.Map<java.lang.String,java.lang.String> CSVToMap(java.lang.String csv,
                                                                        char sep,
                                                                        char apos,
                                                                        char innerSeparator)
Counterpart to #mapToCSV(Map) Fails if key contains token "=" and fails if value contains token """

Parameters:
csv -
sep - Defaults to ","
apos - Only '"' or "'" is supported, defaults to '"'
innerSeparator - '='
Returns:
never null

mapToCSV

public static java.lang.String mapToCSV(java.util.Map map)
Counterpart to #CSVToMap(String)

Parameters:
map -
Returns:

mapToCSV

public static java.lang.String mapToCSV(java.util.Map map,
                                        char sep,
                                        char apos)
A '=' in the key is escaped with "=". A '"' or '\'' is escaped with " respectively '

Parameters:
map - (not yet )
sep - Defaults to ","
apos - Only '"' or "'" is supported, defaults to '"'
Returns:
aKey="a value with " apost, and semicolon",otherKey=2300,third=Key=a key with assignment,key4="Hello, == world"

mapToCSV

public static java.lang.String mapToCSV(java.util.Map map,
                                        char sep,
                                        char apos,
                                        char innerSeparator)

parseToStringStringPairs

public static java.util.Map parseToStringStringPairs(java.lang.String rawString,
                                                     java.lang.String outerToken,
                                                     java.lang.String innerToken)
Parameters:
rawString - e.g. "org.xmlBlaster.protocol.soap.SoapDriver,classpath=xerces.jar:soap.jar,MAXSIZE=100"
outerToken - is for example ";" or ","
innterToken - is for example "=" or " " If a value is missing then a null object as value. the map returns pairs 'String,String'.

arrayToCSV

public static java.lang.String arrayToCSV(java.lang.String[] strs,
                                          java.lang.String sep)

main

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

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.