Class XmlUtil

java.lang.Object
com.tccc.kos.commons.xml.XmlUtil

public final class XmlUtil extends Object
A few common utility methods for working with XML.
Since:
1.0
Version:
2023-03-01
  • Method Summary

    Modifier and Type
    Method
    Description
    static Element
    addTag(Element el, String tag)
    Sets a string tag value in the specified element.
    static Element
    addTag(Element el, String tag, Namespace ns)
    Sets a string tag value in the specified element.
    static boolean
    getBool(Element el, String key, boolean def, boolean required)
    Gets the specified XML attribute or child tag as a boolean, returning the default value if the attribute is not found or doesn't parse correctly.
    static boolean
    getBoolAttr(Element el, String attr, boolean def, boolean required)
    Gets the specified XML attribute as a boolean, returning the default value if the attribute is not found or doesn't parse correctly.
    static boolean
    getBoolAttr(Element el, String attr, boolean def, boolean required, Namespace ns)
    Gets the specified XML attribute as a boolean, returning the default value if the attribute is not found or doesn't parse correctly.
    static boolean
    getBoolTag(Element el, String tag, boolean def, boolean required)
    Gets the specified XML tag as a boolean, returning the default value if the tag is not found or doesn't parse correctly.
    static boolean
    getBoolTag(Element el, String tag, boolean def, boolean required, Namespace ns)
    Gets the specified XML tag as a boolean, returning the default value if the tag is not found or doesn't parse correctly.
    static double
    getDouble(Element el, String key, double def, boolean required)
    Gets the specified XML attribute or child tag as a double, returning the default value if the attribute is not found or doesn't parse correctly.
    static double
    getDoubleAttr(Element el, String attr, double def, boolean required)
    Gets the specified XML attribute as a double, returning the default value if the attribute is not found or doesn't parse correctly.
    static double
    getDoubleAttr(Element el, String attr, double def, boolean required, Namespace ns)
    Gets the specified XML attribute as a double, returning the default value if the attribute is not found or doesn't parse correctly.
    static double
    getDoubleTag(Element el, String tag, double def, boolean required)
    Gets the specified XML tag as a double, returning the default value if the tag is not found or doesn't parse correctly.
    static double
    getDoubleTag(Element el, String tag, double def, boolean required, Namespace ns)
    Gets the specified XML tag as a double, returning the default value if the tag is not found or doesn't parse correctly.
    static Element
    getElement(Element el, String key, boolean required)
    Gets the specified element.
    static Element
    getElement(Element el, String key, boolean required, Namespace ns)
    Gets the specified element.
    static List<Element>
    getElements(Element el, String key, boolean required)
    Gets a list of elements that match the key.
    static List<Element>
    getElements(Element el, String key, boolean required, Namespace ns)
    Gets a list of elements that match the key.
    static int
    getInt(Element el, String key, int def, boolean required)
    Gets the specified XML attribute or child tag as an int, returning the default value if the attribute is not found or doesn't parse correctly.
    static int
    getIntAttr(Element el, String attr, int def, boolean required)
    Gets the specified XML attribute as an int, returning the default value if the attribute is not found or doesn't parse correctly.
    static int
    getIntAttr(Element el, String attr, int def, boolean required, Namespace ns)
    Gets the specified XML attribute as an int, returning the default value if the attribute is not found or doesn't parse correctly.
    static int
    getIntTag(Element el, String tag, int def, boolean required)
    Gets the specified XML tag as an int, returning the default value if the tag is not found or doesn't parse correctly.
    static int
    getIntTag(Element el, String tag, int def, boolean required, Namespace ns)
    Gets the specified XML tag as an int, returning the default value if the tag is not found or doesn't parse correctly.
    static long
    getLong(Element el, String key, long def, boolean required)
    Gets the specified XML attribute or child tag as a long, returning the default value if the attribute is not found or doesn't parse correctly.
    static long
    getLongAttr(Element el, String attr, long def, boolean required)
    Gets the specified XML attribute as a long, returning the default value if the attribute is not found or doesn't parse correctly.
    static long
    getLongAttr(Element el, String attr, long def, boolean required, Namespace ns)
    Gets the specified XML attribute as a long, returning the default value if the attribute is not found or doesn't parse correctly.
    static long
    getLongTag(Element el, String tag, long def, boolean required)
    Gets the specified XML tag as a long, returning the default value if the tag is not found or doesn't parse correctly.
    static long
    getLongTag(Element el, String tag, long def, boolean required, Namespace ns)
    Gets the specified XML tag as a long, returning the default value if the tag is not found or doesn't parse correctly.
    static String
    getStr(Element el, String key, String def, boolean required)
    Try to get the specified key as an attribute and then a tag.
    static String
    getStrAttr(Element el, String attr, String def, boolean required)
    Gets the specified XML attribute as a string, returning the default value if the attribute is not found.
    static String
    getStrAttr(Element el, String attr, String def, boolean required, Namespace ns)
    Gets the specified XML attribute as a string, returning the default value if the attribute is not found.
    static String
    getStrTag(Element el, String tag, String def, boolean required)
    Gets the specified XML tag as a string, returning the default value if the tag is not found.
    static String
    getStrTag(Element el, String tag, String def, boolean required, Namespace ns)
    Gets the specified XML tag as a string, returning the default value if the tag is not found.
    static String
    getTrimStr(Element el, String key, String def, boolean required)
    Try to get the specified key as an attribute and then a tag.
    static Date
    getUTC(Element el, String key, long def, boolean required)
    Gets the specified XML attribute or child tag as a UTC value and return it as a date, returning the default value if the attribute is not found or doesn't parse correctly.
    static Date
    getUTCAttr(Element el, String attr, long def, boolean required)
    Gets the specified XML attribute as a UTC value and return it as a date, returning the default value if the attribute is not found or doesn't parse correctly.
    static Date
    getUTCAttr(Element el, String attr, long def, boolean required, Namespace ns)
    Gets the specified XML attribute as a UTC value and return it as a date, returning the default value if the attribute is not found or doesn't parse correctly.
    static Date
    getUTCTag(Element el, String tag, long def, boolean required, Namespace ns)
    Gets the specified XML tag as a UTC value and return it as a date, returning the default value if the tag is not found or doesn't parse correctly.
    static Element
    load(File file)
    Parses a file into an XML element.
    static Element
    Parses an XML stream into an XML element.
    static Document
    Parses a file into an XML element.
    static Document
    Parses an XML stream into an XML document.
    static Element
    Parses XML stored in a string into an XML document.
    static void
    save(Element el, File file)
    Outputs XML to the specified file.
    static void
    Wrapper for write().
    static void
    setAttr(Element el, String attr, boolean val)
    Sets a boolean attribute value in the specified element.
    static void
    setAttr(Element el, String attr, double val)
    Sets a double attribute value in the specified element.
    static void
    setAttr(Element el, String attr, int val)
    Sets an int attribute value in the specified element.
    static void
    setAttr(Element el, String attr, long val)
    Sets a long attribute value in the specified element.
    static void
    setAttr(Element el, String attr, String val)
    Sets a string attribute value in the specified element.
    static void
    setAttr(Element el, String attr, Date val)
    Sets a date attribute value in the specified element.
    static Element
    Sets a string tag value in the specified element.
    static Element
    setTag(Element el, String tag, boolean val)
    Sets a boolean tag value in the specified element.
    static Element
    setTag(Element el, String tag, double val)
    Sets a double tag value in the specified element.
    static Element
    setTag(Element el, String tag, int val)
    Sets an int tag value in the specified element.
    static Element
    setTag(Element el, String tag, long val)
    Sets a long tag value in the specified element.
    static Element
    setTag(Element el, String tag, String val)
    Sets a string tag value in the specified element.
    static Element
    setTag(Element el, String tag, Date val)
    Sets a date tag value in the specified element.
    static String[]
    split(String str, String delim)
    This is basically a wrapper around StringTokenizer that makes it look more like string.split() which isn't available 1.3.1.
    static String
    Outputs XML back into string form.
    static void
    Outputs XML to the specified output stream.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getStr

      public static String getStr(Element el, String key, String def, boolean required)
      Try to get the specified key as an attribute and then a tag.
      Parameters:
      el - the XML element
      key - the key name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching string
    • getTrimStr

      public static String getTrimStr(Element el, String key, String def, boolean required)
      Try to get the specified key as an attribute and then a tag.
      Parameters:
      el - the XML element
      key - the key name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching trimmed string
    • getInt

      public static int getInt(Element el, String key, int def, boolean required)
      Gets the specified XML attribute or child tag as an int, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      key - the attribute/tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching int
    • getLong

      public static long getLong(Element el, String key, long def, boolean required)
      Gets the specified XML attribute or child tag as a long, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      key - the attribute/tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching long
    • getUTC

      public static Date getUTC(Element el, String key, long def, boolean required)
      Gets the specified XML attribute or child tag as a UTC value and return it as a date, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      key - the attribute/tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching date
    • getDouble

      public static double getDouble(Element el, String key, double def, boolean required)
      Gets the specified XML attribute or child tag as a double, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      key - the attribute/tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching double
    • getBool

      public static boolean getBool(Element el, String key, boolean def, boolean required)
      Gets the specified XML attribute or child tag as a boolean, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      key - the attribute/tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching boolean
    • getElement

      public static Element getElement(Element el, String key, boolean required)
      Gets the specified element.
      Parameters:
      el - the XML element
      key - the tag name
      required - if true, throw an exception if not found
      Returns:
      the matching element
    • getElement

      public static Element getElement(Element el, String key, boolean required, Namespace ns)
      Gets the specified element.
      Parameters:
      el - the XML element
      key - the tag name
      required - if true, throw an exception if not found
      ns - namespace
      Returns:
      the matching element
    • getElements

      public static List<Element> getElements(Element el, String key, boolean required)
      Gets a list of elements that match the key.
      Parameters:
      el - the XML element
      key - the tag name
      required - if true, throw an exception if not found
      Returns:
      the matching elements
    • getElements

      public static List<Element> getElements(Element el, String key, boolean required, Namespace ns)
      Gets a list of elements that match the key.
      Parameters:
      el - the XML element
      key - the tag name
      required - if true, throw an exception if not found
      ns - namespace
      Returns:
      the matching elements
    • getStrAttr

      public static String getStrAttr(Element el, String attr, String def, boolean required, Namespace ns)
      Gets the specified XML attribute as a string, returning the default value if the attribute is not found. If the required flag is set and the attribute isn't found, throw an exception.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching string
    • getIntAttr

      public static int getIntAttr(Element el, String attr, int def, boolean required, Namespace ns)
      Gets the specified XML attribute as an int, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching int
    • getLongAttr

      public static long getLongAttr(Element el, String attr, long def, boolean required, Namespace ns)
      Gets the specified XML attribute as a long, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching long
    • getUTCAttr

      public static Date getUTCAttr(Element el, String attr, long def, boolean required, Namespace ns)
      Gets the specified XML attribute as a UTC value and return it as a date, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching date
    • getDoubleAttr

      public static double getDoubleAttr(Element el, String attr, double def, boolean required, Namespace ns)
      Gets the specified XML attribute as a double, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching double
    • getBoolAttr

      public static boolean getBoolAttr(Element el, String attr, boolean def, boolean required, Namespace ns)
      Gets the specified XML attribute as a boolean, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching boolean
    • getStrAttr

      public static String getStrAttr(Element el, String attr, String def, boolean required)
      Gets the specified XML attribute as a string, returning the default value if the attribute is not found. If the required flag is set and the attribute isn't found, throw an exception.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching string
    • getIntAttr

      public static int getIntAttr(Element el, String attr, int def, boolean required)
      Gets the specified XML attribute as an int, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching int
    • getLongAttr

      public static long getLongAttr(Element el, String attr, long def, boolean required)
      Gets the specified XML attribute as a long, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching long
    • getUTCAttr

      public static Date getUTCAttr(Element el, String attr, long def, boolean required)
      Gets the specified XML attribute as a UTC value and return it as a date, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching UTC value
    • getDoubleAttr

      public static double getDoubleAttr(Element el, String attr, double def, boolean required)
      Gets the specified XML attribute as a double, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching double
    • getBoolAttr

      public static boolean getBoolAttr(Element el, String attr, boolean def, boolean required)
      Gets the specified XML attribute as a boolean, returning the default value if the attribute is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      attr - the attribute name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching boolean
    • getStrTag

      public static String getStrTag(Element el, String tag, String def, boolean required, Namespace ns)
      Gets the specified XML tag as a string, returning the default value if the tag is not found. If the required flag is set and the tag isn't found, throw an exception.
      Parameters:
      el - the XML tag
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching string
    • getIntTag

      public static int getIntTag(Element el, String tag, int def, boolean required, Namespace ns)
      Gets the specified XML tag as an int, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching int
    • getLongTag

      public static long getLongTag(Element el, String tag, long def, boolean required, Namespace ns)
      Gets the specified XML tag as a long, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching long
    • getUTCTag

      public static Date getUTCTag(Element el, String tag, long def, boolean required, Namespace ns)
      Gets the specified XML tag as a UTC value and return it as a date, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching UTC value
    • getDoubleTag

      public static double getDoubleTag(Element el, String tag, double def, boolean required, Namespace ns)
      Gets the specified XML tag as a double, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching double
    • getBoolTag

      public static boolean getBoolTag(Element el, String tag, boolean def, boolean required, Namespace ns)
      Gets the specified XML tag as a boolean, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      ns - the namespace for the tag
      Returns:
      the matching boolean
    • getStrTag

      public static String getStrTag(Element el, String tag, String def, boolean required)
      Gets the specified XML tag as a string, returning the default value if the tag is not found. If the required flag is set and the tag isn't found, throw an exception.
      Parameters:
      el - the XML tag
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching string
    • getIntTag

      public static int getIntTag(Element el, String tag, int def, boolean required)
      Gets the specified XML tag as an int, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching int
    • getLongTag

      public static long getLongTag(Element el, String tag, long def, boolean required)
      Gets the specified XML tag as a long, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching long
    • getDoubleTag

      public static double getDoubleTag(Element el, String tag, double def, boolean required)
      Gets the specified XML tag as a double, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching double
    • getBoolTag

      public static boolean getBoolTag(Element el, String tag, boolean def, boolean required)
      Gets the specified XML tag as a boolean, returning the default value if the tag is not found or doesn't parse correctly.
      Parameters:
      el - the XML element
      tag - the child tag name
      def - the default value
      required - if true, throw an exception if not found
      Returns:
      the matching boolean
    • setAttr

      public static void setAttr(Element el, String attr, String val)
      Sets a string attribute value in the specified element. If the value is null then attribute won't be added.
      Parameters:
      el - the XML element to modify
      attr - the attribute name
      val - the value to set
    • setAttr

      public static void setAttr(Element el, String attr, int val)
      Sets an int attribute value in the specified element.
      Parameters:
      el - the XML element to modify
      attr - the attribute name
      val - the value to set
    • setAttr

      public static void setAttr(Element el, String attr, long val)
      Sets a long attribute value in the specified element.
      Parameters:
      el - the XML element to modify
      attr - the attribute name
      val - the value to set
    • setAttr

      public static void setAttr(Element el, String attr, double val)
      Sets a double attribute value in the specified element.
      Parameters:
      el - the XML element to modify
      attr - the attribute name
      val - the value to set
    • setAttr

      public static void setAttr(Element el, String attr, boolean val)
      Sets a boolean attribute value in the specified element.
      Parameters:
      el - the XML element to modify
      attr - the attribute name
      val - the value to set
    • setAttr

      public static void setAttr(Element el, String attr, Date val)
      Sets a date attribute value in the specified element.
      Parameters:
      el - the XML element to modify
      attr - the attribute name
      val - the value to set
    • addTag

      public static Element addTag(Element el, String tag)
      Sets a string tag value in the specified element. If the value is null then tag won't be added.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      Returns:
      the new element for the tag
    • addTag

      public static Element addTag(Element el, String tag, Namespace ns)
      Sets a string tag value in the specified element. If the value is null then tag won't be added.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      ns - the namespace for the tag
      Returns:
      the new element for the tag
    • setNonEmptyTag

      public static Element setNonEmptyTag(Element el, String tag, String val)
      Sets a string tag value in the specified element. If the value is null then tag won't be added.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for the tag
    • setTag

      public static Element setTag(Element el, String tag, String val)
      Sets a string tag value in the specified element. If the value is null then tag will be added regardless.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for that tag
    • setTag

      public static Element setTag(Element el, String tag, int val)
      Sets an int tag value in the specified element.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for the tag
    • setTag

      public static Element setTag(Element el, String tag, long val)
      Sets a long tag value in the specified element.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for the tag
    • setTag

      public static Element setTag(Element el, String tag, double val)
      Sets a double tag value in the specified element.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for the tag
    • setTag

      public static Element setTag(Element el, String tag, boolean val)
      Sets a boolean tag value in the specified element.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for the tag
    • setTag

      public static Element setTag(Element el, String tag, Date val)
      Sets a date tag value in the specified element.
      Parameters:
      el - the XML element to modify
      tag - the child tag name
      val - the value to set
      Returns:
      the new element for the tag
    • parse

      public static Element parse(String str)
      Parses XML stored in a string into an XML document.
      Parameters:
      str - the XML in string form
      Returns:
      the root element for the XML
    • load

      public static Element load(File file)
      Parses a file into an XML element.
      Parameters:
      file - the file to parse
      Returns:
      the root element for the XML
    • load

      public static Element load(InputStream is)
      Parses an XML stream into an XML element.
      Parameters:
      is - the input stream containing XML
      Returns:
      the root element for the XML
    • loadDocument

      public static Document loadDocument(File file)
      Parses a file into an XML element.
      Parameters:
      file - the file to parse
      Returns:
      the document for the XML
    • loadDocument

      public static Document loadDocument(InputStream is)
      Parses an XML stream into an XML document.
      Parameters:
      is - the XML stream containing XML
      Returns:
      the document for the XML
    • toString

      public static String toString(Element el) throws IOException
      Outputs XML back into string form.
      Parameters:
      el - the root element to output as a string
      Returns:
      the string representation of the element
      Throws:
      IOException - if there is an error rendering the string
    • write

      public static void write(Element el, OutputStream os) throws IOException
      Outputs XML to the specified output stream.
      Parameters:
      el - the root element to output as a string
      os - the stream to output to
      Throws:
      IOException - if there is an error outputting to the stream
    • save

      public static void save(Element el, OutputStream os) throws IOException
      Wrapper for write().
      Parameters:
      el - the element to write
      os - the output stream
      Throws:
      IOException - if there is an error outputting to the stream
    • save

      public static void save(Element el, File file) throws IOException
      Outputs XML to the specified file.
      Parameters:
      el - the root element to save
      file - the file to output to
      Throws:
      IOException - if there is an error writing to the file
    • split

      public static String[] split(String str, String delim)
      This is basically a wrapper around StringTokenizer that makes it look more like string.split() which isn't available 1.3.1.
      Parameters:
      str - the string to split
      delim - the delimiter string
      Returns:
      an array of split strings