Knopflerfish OSGi 4.0.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

Miscellaneous static utility code.


Constructor Summary
Util()
           
 
Method Summary
static org.w3c.dom.Document createXML(java.lang.String rootElement)
          Create an empty DOM-document.
static java.lang.String getRelativePath(java.io.File fromFile, java.io.File toFile)
           
static java.lang.String load(java.lang.String fileOrURL)
          Load entire contents of a file or URL into a string.
static java.lang.String loadFile(java.lang.String fname)
           
static byte[] loadURL(java.net.URL url)
           
static org.w3c.dom.Document loadXML(java.io.File file)
          Load an XML-formated file into a DOM-document.
static java.util.Set makeSetFromStringList(java.lang.String s)
          Create a Set from a comma-separated string.
static java.util.Iterator parseEntries(java.lang.String a, java.lang.String s, boolean single, boolean unique, boolean single_entry)
          Parse strings of format: ENTRY (, ENTRY)* ENTRY = key (; key)* (; PARAM)* PARAM = attribute '=' value PARAM = directive ':=' value
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)
          Split a string into words separated by whitespace SPACE | TAB | NEWLINE | CR Citation chars '"' may be used to group words with embedded 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 void writeDocumentToFile(java.io.File outFile, org.w3c.dom.Document doc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

loadURL

public static byte[] loadURL(java.net.URL url)
                      throws java.io.IOException
Throws:
java.io.IOException

loadFile

public static java.lang.String loadFile(java.lang.String fname)
                                 throws java.io.IOException
Throws:
java.io.IOException

load

public static java.lang.String load(java.lang.String fileOrURL)
                             throws java.io.IOException
Load entire contents of a file or URL into a string.

Throws:
java.io.IOException

loadXML

public static org.w3c.dom.Document loadXML(java.io.File file)
Load an XML-formated file into a DOM-document.

Parameters:
file - The XML file to load.
Returns:
DOM document.

createXML

public static org.w3c.dom.Document createXML(java.lang.String rootElement)
Create an empty DOM-document.

Parameters:
rootElement - The name of the root element of the new document.
Returns:
DOM document with a root element.

makeSetFromStringList

public static java.util.Set makeSetFromStringList(java.lang.String s)
Create a Set from a comma-separated string.


getRelativePath

public static java.lang.String getRelativePath(java.io.File fromFile,
                                               java.io.File toFile)

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.

If no replacements are needed, the methods returns the original string.

Parameters:
s - Source string which will be scanned and modified. If null, return null
v1 - String to be replaced with v2. If null, return original string.
v2 - String replacing v1. If null, return original string.
Returns:
Modified string.

splitwords

public static java.lang.String[] splitwords(java.lang.String s)
Split a string into words separated by whitespace SPACE | TAB | NEWLINE | CR Citation chars '"' may be used to group words with embedded whitespace.


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.
citchar - citation char used for enclosing words containing whitespace

writeDocumentToFile

public static void writeDocumentToFile(java.io.File outFile,
                                       org.w3c.dom.Document doc)

parseEntries

public static java.util.Iterator parseEntries(java.lang.String a,
                                              java.lang.String s,
                                              boolean single,
                                              boolean unique,
                                              boolean single_entry)
Parse strings of format: ENTRY (, ENTRY)* ENTRY = key (; key)* (; PARAM)* PARAM = attribute '=' value PARAM = directive ':=' value

Parameters:
a - Name of attribute being parsed (for error messages).
s - The attribute value to parse.
single - If true, only allow one key per ENTRY.
unique - Only allow unique parameters for each ENTRY.
single_entry - If true, only allow one ENTRY is allowed.
Returns:
Iterator(Map(param -> value)) or null if input string is null.
Throws:
java.lang.IllegalArgumentException - If syntax error in input string.

Knopflerfish OSGi 4.0.0