Package rma.util

Class RmaBaseXmlUtilities

java.lang.Object
rma.util.RmaBaseXmlUtilities
Direct Known Subclasses:
BaseXMLUtilities

public class RmaBaseXmlUtilities extends Object
A base base xml utilities class.
  • Field Details

  • Constructor Details

    • RmaBaseXmlUtilities

      public RmaBaseXmlUtilities()
  • Method Details

    • addXMLSchemaNamespaceDeclaration

      public static void addXMLSchemaNamespaceDeclaration(org.jdom.Element elem)
      add the default XML schema location to the element. This is the xmlns:xsi entry in the Element. Typically set to http://www.w3.org/2001/XMLSchema-instance
      Parameters:
      elem - the element to add the default XML schema to.
    • addXSLTLocation

      public static void addXSLTLocation(org.jdom.Document doc, String xsltLocation)
      add the XML stylesheet information to the XML Document.
      Parameters:
      doc - The XML Document
      xsltLocation - the XML stylesheet information.
    • addXSDLocation

      public static void addXSDLocation(org.jdom.Element elem, String schemaLocation)
      add the schema location to the Element elem.
      Parameters:
      elem - the Element (typically the root Element) to attach the XML Schema to
      schemaLocation - the location of the XML schema
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, int[] array)
      add the Elements that represent the array to the Element base with the DEFAULT_STEP number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, int[] array, int step)
      add the Elements that represent the array to the Element base with the step number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      step - the number of array positions to store in each array Element
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, double[][] array)
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, double[] array)
      add the Elements that represent the array to the Element base with the DEFAULT_STEP number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, double[] array, int step)
      add the Elements that represent the array to the Element base with the step number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      step - the number of array positions to store in each array Element
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, float[] array)
      add the Elements that represent the array to the Element base with the DEFAULT_STEP number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, float[] array, int step)
      add the Elements that represent the array to the Element base with the step number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      step - the number of array positions to store in each array Element
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, byte[] array)
      add the Elements that represent the array to the Element base with the DEFAULT_STEP number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, byte[] array, int step)
      add the Elements that represent the array to the Element base with the step number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      step - the number of array positions to store in each array Element
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, char[] array)
      add the Elements that represent the array to the Element base with the DEFAULT_STEP number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, char[] array, int step)
      add the Elements that represent the array to the Element base with the step number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      step - the number of array positions to store in each array Element
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, String[] array)
      add the Elements that represent the array to the Element base with the DEFAULT_STEP number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      Returns:
      true if the array Elements were successfully added to the base Element
    • createArrayElements

      public static boolean createArrayElements(org.jdom.Element base, String[] array, int step)
      add the Elements that represent the array to the Element base with the step number of array entries per array Element
      Parameters:
      base - the Element to add the array Elements to
      array - the array to save
      step - the number of array positions to store in each array Element
      Returns:
      true if the array Elements were successfully added to the base Element
    • getDoubleArrayElements

      public static double[] getDoubleArrayElements(org.jdom.Element elem)
    • getIntArrayElements

      public static int[] getIntArrayElements(org.jdom.Element elem)
    • getFloatArrayElements

      public static float[] getFloatArrayElements(org.jdom.Element elem)
    • getStringArrayElements

      public static String[] getStringArrayElements(org.jdom.Element elem)
    • getStepSize

      protected static int getStepSize(Object array)
      return the step size to write the arrays out with
      Parameters:
      length - the length of the array
      Returns:
      the step size
    • displayArrays

      protected static boolean displayArrays(org.jdom.Document doc)
    • saveDescription

      public static void saveDescription(org.jdom.Element parent, String desc)
      This saves the description as an Element with each line of description stored as a child Element. XML doesn't preserve the newlines when just an attribute is used.
      Parameters:
      parent - the parent to add the description Element to.
      desc - the description
    • getDescription

      public static String getDescription(org.jdom.Element descElem)
      get the description.
      Parameters:
      descElem -
      Returns:
    • getAttributeValueAsInt

      public static int getAttributeValueAsInt(org.jdom.Element elem, String attributeName, int defaultValue)
      get an attribute as an int.
      Parameters:
      elem - the Element that holds the attribute
      attributeName - the Attribute name
      defaultValue - the default value if the Attribute can't be found or converted into an int
      Returns:
      the int value of Attribute or defaultValue
    • getAttributeValueAsShort

      public static short getAttributeValueAsShort(org.jdom.Element elem, String attributeName, short defaultValue)
      Parameters:
      myElem -
      string -
      elementType -
    • getAttributeValueAsLong

      public static long getAttributeValueAsLong(org.jdom.Element elem, String attributeName, long defaultValue)
      get an attribute as a long.
      Parameters:
      elem - the Element that holds the attribute
      attributeName - the Attribute name
      defaultValue - the default value if the Attribute can't be found or converted into an long
      Returns:
      the long value of Attribute or defaultValue
    • setAttributeValueAsLong

      public static void setAttributeValueAsLong(org.jdom.Element elem, String attributeName, long value)
      Creates a named attribute on the element for the long value.
      Parameters:
      elem - the Element that owns the attribute
      attributeName - the Attribute name
      value - the long value.
    • getAttributeValueAsFloat

      public static float getAttributeValueAsFloat(org.jdom.Element elem, String attributeName, float defaultValue)
      get an attribute as a float.
      Parameters:
      elem - the Element that holds the attribute
      attributeName - the Attribute name
      defaultValue - the default value if the Attribute can't be found or converted into an float
      Returns:
      the float value of Attribute or defaultValue
    • getAttributeValueAsDouble

      public static double getAttributeValueAsDouble(org.jdom.Element elem, String attributeName, double defaultValue)
      get an attribute as an double.
      Parameters:
      elem - the Element that holds the attribute
      attributeName - the Attribute name
      defaultValue - the default value if the Attribute can't be found or converted into an double
      Returns:
      the double value of Attribute or defaultValue
    • setAttributeValueAsDouble

      public static void setAttributeValueAsDouble(org.jdom.Element elem, String attributeName, double value)
      Creates a named attribute on the element for the double value.
      Parameters:
      elem - the Element that owns the attribute
      attributeName - the Attribute name
      value - the double value.
    • getAttributeValueAsBoolean

      public static boolean getAttributeValueAsBoolean(org.jdom.Element elem, String attributeName, boolean defaultValue)
      get an attribute as an boolean.
      Parameters:
      elem - the Element that holds the attribute
      attributeName - the Attribute name
      defaultValue - the default value if the Attribute can't be found or converted into an boolean
      Returns:
      the boolean value of Attribute or defaultValue
    • saveColor

      public static void saveColor(org.jdom.Element elem, String attributeName, Color color)
      save the Color color to the Element elem with the attribute name of attributeName
      Parameters:
      elem - the Element to save to
      attributeName - the name of the attribute
      color - the Color to save
    • loadColor

      public static Color loadColor(org.jdom.Element elem, String attributeName, Color defaultColor)
      get the Color saved in Element elem with the attribute name of attributeName
      Parameters:
      elem - the Element to get the color attribute from
      attributeName - the name of the color attribute
      defaultColor - the default Color
      Returns:
      the Color or the defaultColor if elem or attributeName is null or the attribute doesn't exist in the Element
    • loadDocument

      public static org.jdom.Document loadDocument(Reader reader)
      create and load the XML Document from the Reader reader. The reader isn't closed after the read is finished. That's up to the caller
      Parameters:
      reader - the reader to read from.
      Returns:
    • addAttributes

      public static void addAttributes(org.jdom.Element elem, Map attributes)
      Store the key/value pairs in the Map attributes as XML Attributes in the Element elem
      Parameters:
      elem - XML Element to store the Attributes in
      attributes - Map of attributes to store
    • attributeListToMap

      public static Map attributeListToMap(List attributes)
      Parameters:
      attributes -
      Returns:
    • saveWindowSizeAndLocation

      public static void saveWindowSizeAndLocation(org.jdom.Element node, Window w)
    • setWindowSizeAndLocation

      public static void setWindowSizeAndLocation(org.jdom.Element node, Window window)
    • getChildElementAsString

      public static String getChildElementAsString(org.jdom.Element parent, String childElementName, String defaultValue)
      Returns the child element text as an String value.
      Parameters:
      parent - Parent that holds the String element.
      childElementName - Name of the child String element.
      defaultValue - Default String value.
      Returns:
      The String value defined in the child element or the default value if parent/child are null or element text doesnt parse.
    • getChildElementAsString

      public static String getChildElementAsString(org.jdom.Element parent, String childElementName, boolean trim, String defaultValue)
    • getChildElementAsBoolean

      public static boolean getChildElementAsBoolean(org.jdom.Element parent, String childElementName, boolean defaultValue)
      Returns the child element text as an boolean value.
      Parameters:
      parent - Parent that holds the boolean element.
      childElementName - Name of the child boolean element.
      defaultValue - Default boolean value.
      Returns:
      The boolean value defined in the child element or the default value if parent/child are null or element text doesnt parse.
    • getContentAsString

      public static String getContentAsString(org.jdom.Element elem, String defaultValue)
      Returns the element content as an String value.
      Parameters:
      elem - The element with the String content.
      defaultValue - The default String value.
      Returns:
      The String value defined in the element content or the default value if the element is null or the element text does not parse.
    • getContentAsString

      public static String getContentAsString(org.jdom.Element elem, boolean trim, String defaultValue)
    • getContentAsBoolean

      public static boolean getContentAsBoolean(org.jdom.Element elem, boolean defaultValue)
      Returns the element content as an boolean value.
      Parameters:
      elem - The element with the boolean content.
      defaultValue - The default boolean value.
      Returns:
      The boolean value defined in the element content or the default value if the element is null or the element text does not parse.
    • setChildElementAsInt

      public static void setChildElementAsInt(org.jdom.Element parent, String childElementName, int value)
      Sets the child element text to an int value. Note that this method will create the child if it does not exist.
      Parameters:
      parent - The parent element of the child int element.
      childElementName - The name fo the child int element.
      value - The value to set as the child text.
    • getChildElementAsDouble

      public static double getChildElementAsDouble(org.jdom.Element parent, String childElementName, double defaultValue)
      Returns the child element text as a double value.
      Parameters:
      parent - Parent that holds the double element.
      childElementName - Name of the child double element.
      defaultValue - Default double value.
      Returns:
      The double value defined in the child element or the default value if parent/child are null or element text doesnt parse.
    • getChildElementAsColor

      public static Color getChildElementAsColor(org.jdom.Element parent, String childElementName, Color defaultColor)
      Gets the Color saved in the element text of the parent's child.
      Parameters:
      parent - Parent that holds the color element.
      childElementName - Name of the child color element.
      defaultColor - Default color.
      Returns:
      The Color defined in the child element or the default color if the parent, child, or color text is not defined.
    • setChildElementAsColor

      public static void setChildElementAsColor(org.jdom.Element parent, String childElementName, Color color)
      Sets the element text for the named child of the parent to a color string. Note that this method will create the child element if it does not exist.
      Parameters:
      parent - The parent of the color element.
      childElementName - The name of the color element.
      color - The color to be set.
    • getContentAsDouble

      public static double getContentAsDouble(org.jdom.Element elem, double defaultValue)
      Returns the content of the element as a double value.
      Parameters:
      elem - The element with the double content.
      defaultValue - The default double value.
      Returns:
      The double value defined in the element or default value if content is null or element text doesnt parse.
    • setChildElementAsDouble

      public static void setChildElementAsDouble(org.jdom.Element parent, String childElementName, double value)
      Sets the child element text to a double value. Note that this method will create the child if it does not exist.
      Parameters:
      parent - The parent element of the child double element.
      childElementName - The name fo the child double element.
      value - The value to set as the child text.
    • getContentAsInt

      public static int getContentAsInt(org.jdom.Element elem, int defaultValue)
      Returns the element content as an int value.
      Parameters:
      elem - The element with the int content.
      defaultValue - The default int value.
      Returns:
      The int value defined in the element content or the default value if the element is null or the element text does not parse.
    • getContentAsLong

      public static long getContentAsLong(org.jdom.Element elem, long defaultValue)
    • getChildElementAsInt

      public static int getChildElementAsInt(org.jdom.Element parent, String childElementName, int defaultValue)
      Returns the child element text as an int value.
      Parameters:
      parent - Parent that holds the int element.
      childElementName - Name of the child int element.
      defaultValue - Default int value.
      Returns:
      The int value defined in the child element or the default value if parent/child are null or element text doesnt parse.
    • getChildElementAsLong

      public static long getChildElementAsLong(org.jdom.Element parent, String childElementName, long defaultValue)
    • getOrCreateChild

      @Deprecated public static org.jdom.Element getOrCreateChild(org.jdom.Element parent, String childElementName)
      Deprecated.
      Returns the child from the parent if it exists otherwise creates the child, adds it to the parent and returns the child.
      Parameters:
      childElementName - The name of the child to add.
      parent - The parent that the child will be attached to.
      Returns:
      The child element.
      See Also:
      • XMLUtilities.getOrCreateChild(Element, String)
    • getChildElementAttribute

      public static String getChildElementAttribute(org.jdom.Element parent, String childElementName, String attribute)
      Will return the attribute value from the child of the parent.
      Parameters:
      parent - The parent element
      childElementName - The name of the child element
      attribute - The name of the attribute
      Returns:
      The attribute value or null if parent, child, or attribute value are null
    • setChildElementAttribute

      public static void setChildElementAttribute(org.jdom.Element parent, String childElementName, String attribute, String value)
      Will set the attribute value of the child of the parent creating the child element if necessary.
      Parameters:
      parent - The parent element
      childElementName - The name of the child element
      attribute - The name of the attribute
      value - The value for the attribute
    • buildElement

      public static org.jdom.Element buildElement(Reader reader) throws org.jdom.JDOMException, IOException
      Throws:
      org.jdom.JDOMException
      IOException
    • buildElement

      public static org.jdom.Element buildElement(String xml) throws org.jdom.JDOMException, IOException
      Throws:
      org.jdom.JDOMException
      IOException
    • toXmlString

      public static String toXmlString(org.jdom.Element element) throws IOException
      Throws:
      IOException
    • toXmlString

      public static String toXmlString(org.jdom.Element element, org.jdom.output.Format format) throws IOException
      Throws:
      IOException
    • saveChildElement

      public static org.jdom.Element saveChildElement(org.jdom.Element parent, String childName, double textValue)
      create a new Element with name childName, containing the value textValue, add it to parent and return the child
      Parameters:
      parent - the parent to add the new child Element to
      childName - the name the new child Element
      textValue - double for the text value of the new child Element
      Returns:
      the new child
    • saveChildElement

      public static org.jdom.Element saveChildElement(org.jdom.Element parent, String childName, int textValue)
      create a new Element with name childName, containing the value textValue, add it to parent and return the child
      Parameters:
      parent - the parent to add the new child Element to
      childName - the name the new child Element
      textValue - int for the text value of the new child Element
      Returns:
      the new child
    • saveChildElement

      public static org.jdom.Element saveChildElement(org.jdom.Element parent, String childName, String textValue)
      create a new Element with name childName, containing the value textValue, add it to parent and return the child
      Parameters:
      parent - the parent to add the new child Element to
      childName - the name the new child Element
      textValue - String for the text value of the new child Element
      Returns:
      the new child
    • saveChildElement

      public static org.jdom.Element saveChildElement(org.jdom.Element parent, String childName, boolean boolValue)
      create a new Element with name childName, containing the value boolValue, add it to parent and return the child
      Parameters:
      parent - the parent to add the new child Element to
      childName - the name the new child Element
      boolValue - boolean for the text value of the new child Element
      Returns:
      the new child