Knopflerfish OSGi 5.2.0

org.knopflerfish.ant.taskdefs.bundle
Class Util

java.lang.Object
  extended by org.knopflerfish.ant.taskdefs.bundle.Util

public class Util
extends java.lang.Object


Nested Class Summary
static class Util.HeaderEntry
          A class that holds the parse result for one entry of a manifest header following the general OSGi manifest header syntax.
 
Field Summary
protected static char CITCHAR
          Default citation char for splitwords().
protected static java.lang.String WHITESPACE
          Default whitespace string for splitwords().
 
Constructor Summary
Util()
           
 
Method Summary
static java.util.Set<java.lang.String> parseEnumeration(java.lang.String d, java.lang.String s)
          Parse strings of format: ENTRY (, ENTRY)*
static java.util.List<Util.HeaderEntry> parseManifestHeader(java.lang.String a, java.lang.String s, boolean single, boolean unique, boolean single_entry)
          Parse manifest header values on format:
static java.lang.String replace(java.lang.String s, java.lang.String v1, java.lang.String v2)
          Replace all occurrences of a substring with another string.
static java.lang.String[] splitwords(java.lang.String s)
          Utility method to split a string into words separated by whitespace.
static java.util.List<java.lang.String> splitWords(java.lang.String s, char sepChar, boolean trim)
          Split a string into words separated by a separator char.
static java.lang.String[] splitwords(java.lang.String s, java.lang.String whiteSpace)
          Utility method to split a string into words separated by whitespace.
static java.lang.String[] splitwords(java.lang.String s, java.lang.String whiteSpace, char citChar)
          Split a string into words separated by whitespace.
static java.lang.String toString(java.util.List<Util.HeaderEntry> hes)
          Convert a list of Util.HeaderEntry-objects into a valid manifest header value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WHITESPACE

protected static java.lang.String WHITESPACE
Default whitespace string for splitwords(). Value is " \t\n\r")


CITCHAR

protected static char CITCHAR
Default citation char for splitwords(). Value is '"'

Constructor Detail

Util

public Util()
Method Detail

parseEnumeration

public static java.util.Set<java.lang.String> parseEnumeration(java.lang.String d,
                                                               java.lang.String s)
Parse strings of format: ENTRY (, ENTRY)*

Parameters:
d - Directive being parsed
s - String to parse
Returns:
A HashSet with enumeration or null if enumeration string was null.
Throws:
java.lang.IllegalArgumentException - If syntax error in input string.

parseManifestHeader

public static java.util.List<Util.HeaderEntry> parseManifestHeader(java.lang.String a,
                                                                   java.lang.String s,
                                                                   boolean single,
                                                                   boolean unique,
                                                                   boolean single_entry)
Parse manifest header values on format:
 ENTRY (',' ENTRY)*
 ENTRY = key (';' key)* (';' PARAM)*
 PARAM = attribute (':' TYPE)? '=' value
 PARAM = directive ':=' value
 TYPE = SCALAR | LIST
 SCALAR = 'String' | 'Version' | 'Long' | 'Double'
 LIST = 'List<' SCALAR '>'
 
The default attribute value type is 'String'. For list values the 'List' and its following '<' are treated as separate tokens to comply with the OSGi TCK. The parse result is one Util.HeaderEntry-instance for each entry. If single is true then the entry only contains one key that can be accesses by calling Util.HeaderEntry.getKey(). If unique is true the attribute values in the map are scalars otherwise the values from different attribute definitions with the same name are wrapped in a List<?>.

Parameters:
a - Name of attribute being parsed, for error messages.
s - String to parse.
single - If true, only allow one key per ENTRY.
unique - Only allow unique attributes for each ENTRY.
single_entry - If true, only allow one ENTRY in s.
Returns:
List of Util.HeaderEntry-object, one per entry in s.
Throws:
java.lang.IllegalArgumentException - If syntax error in input string.

splitwords

public static java.lang.String[] splitwords(java.lang.String s)
Utility method to split a string into words separated by whitespace.

Equivalent to splitwords(s, WHITESPACE)


splitwords

public static java.lang.String[] splitwords(java.lang.String s,
                                            java.lang.String whiteSpace)
Utility method to split a string into words separated by whitespace.

Equivalent to splitwords(s, WHITESPACE, CITCHAR)


splitwords

public static java.lang.String[] splitwords(java.lang.String s,
                                            java.lang.String whiteSpace,
                                            char citChar)
Split a string into words separated by whitespace.

Citation chars may be used to group words with embedded whitespace.

Parameters:
s - String to split.
whiteSpace - whitespace to use for splitting. Any of the characters in the whiteSpace string are considered whitespace between words and will be removed from the result. If no words are found, return an array of length zero.
citChar - Citation character used for grouping words with embedded whitespace. Typically '"'

splitWords

public static java.util.List<java.lang.String> splitWords(java.lang.String s,
                                                          char sepChar,
                                                          boolean trim)
Split a string into words separated by a separator char. If the separator char shall be part of a word it must be escaped with a '\' (\). One level of escaping is consumed by this method.

Parameters:
s - String to split.
sepChar - separator char to split on.
trim - trim whitespace from the words if true.
Returns:
List with the words of the specified string.

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String v1,
                                       java.lang.String v2)
Replace all occurrences of a substring with another string.

The returned string will shrink or grow as necessary depending on the lengths of v1 and v2.

Implementation note: This method avoids using the standard String manipulation methods to increase execution speed. Using the replace method does however include two new operations in the case when matches are found.

Parameters:
s - Source string.
v1 - String to be replaced with v2.
v2 - String replacing v1.
Returns:
Modified string. If any of the input strings are null, the source string s will be returned unmodified. If v1.length == 0, v1.equals(v2) or no occurrences of v1 is found, also return s unmodified.

toString

public static java.lang.String toString(java.util.List<Util.HeaderEntry> hes)
Convert a list of Util.HeaderEntry-objects into a valid manifest header value.

Parameters:
hes - The list of header entries to make a string of.
Returns:
Manifest value that follows the generic OSGi manifest syntax.

Knopflerfish OSGi 5.2.0