net.simplace.util.service.XMLHelper

Provides some methods for performing xml operations. It's not implemented as static methods to share some resources. It's not implemented as singleton to avoid synchronization problems.


public final class XMLHelper {


// Class Methods
public static XMLHelper getInstance();

Creates a new instance of. Easier to use as constructor.
returns the Instance
public static String replace(String aString, String aToBeReplacedString,
String aReplaceWithString);

Replaces a String in a String.
returns converted String
public static String replaceAttribute(String aString, Map aReplacements,
String aAttribute);

Replaces in the string all key in the given Map by the values.
returns converted String
public static final Element addElement(Element aElement, String aName,
String aValue);

Adds a new element to the given element with the same namespace.
returns a new element
public static Element getOrCreateChild(Element aParentElement, String
aChildName);

Returns the Child-Element of aParentElement with the given name, if it doesn't exist the child element is created and attached to aParentElement.
returns the Child-Element of aParentElement with the given name
public static void addTextToChildThatMayExist(Element aParentElement, String
aChildName, String aValue);

Adds content to the child of aParent with the name aChildName if the child doesn't exist a new child is created an attached.
public static final String getAttributeValueOrEmptyString(Element aElement,
String aAtrributeValue);

Returns the value of the attribute specified be aAttributeName or returns "" if the it doesn't exists.
returns the value of the attribute specified be aAttributeName or returns "" if the it doesn't exist
public static final String getAttributeValueOrNull(Element aElement, String
aAtrributeValue);

Returns the value of the attribute specified by aAttributeName or returns null if the it doesn't exists or equals "" empty string.
returns the value of the attribute specified by aAttributeName or returns null if the it doesn't exist
public static final boolean getBooleanAttributeValue(Element aElement,
String aName, boolean aDefault);

Returns the value of the attribute specified be aAttributeName or returns the given default.
returns the value of the attribute specified be aAttributeName or the given default
public static Number getNumberAttributeValue(Element aElement, String aAttr,
Class aNumberType, Number aDefault);

Getting parameter value from map as a number.
returns parameter value from map as a number
public static Map transformElementToMap(Element aElement);

transforms a JDOM-Element to HashMap. Structure needed: modis.map.subXalt modis.map.ndsiresult
returns JDOM-Element transformed to HashMap
public static Element createParameterElement(String aParameter, Object
aValue);

create standard parameter Element
returns standard parameter Element
public static Element createTextElement(String aId, String aTitle, String
aRequired, String aEnabled, String aDefault);

create text field Element
returns standard parameter Element
public static Element createChoiceElement(String aId, String aTitle, String
aRequired, String aEnabled, String aType, String aLocalize, String
aMultiselect, String aDefault, Map aOptions);

create integer field Element
returns standard parameter Element
public static Element createDoubleElement(String aId, String aTitle, String
aRequired, String aEnabled, String aMin, String aMax, String aType,
String aDefault);

create integer field Element
returns standard parameter Element
public static Element createIntegerElement(String aId, String aTitle, String
aRequired, String aEnabled, String aMin, String aMax, String aType,
String aDefault);

create integer field Element
returns standard parameter Element
public static Element createFieldElement(String aName, String aTitle, String
aId, String aRequired, String aEnabled, String aDefault);

create standard field Element
returns standard parameter Element
public static List evaluateXPath(Document aDoc, String aExpression);

create standard field Element
returns standard parameter Element
public static String evaluateXPathSingleResult(Document aDoc, String
aExpression);

create standard field Element
returns standard parameter Element
public static Element transformMapToElement(Map aParameterMap, String
aNameOfRootElement);


returns Element
public static boolean checkAttributeExists(Element aVarElement, String
aString);


returns true if attribute exists
public static boolean checkValueExists(Element aVarElement);


returns true if value exists
public static Integer[] toIntArray(List aChildren);


returns Array of Integers
public static Double[] toDoubleArray(List aChildren);


returns Array of Doubles

// Public Instance Methods
public String getRootIDAttribute(String aXMLString);

Helper method to read the name Attribute from the root element of an XML-String.
returns RootIDAttribute
public String getRootNameAttribute(String aXMLString);

Helper method to read the name Attribute from the root element of an XML-String.
returns RootNameAttribute
public String outputToString(Element aElement) throws IOException;

Helper method to read the name Attribute from the root element of an XML-String.
returns the name Attribute from the root element of an XML-String
public String outputToString(Document aDocument) throws IOException;

Helper method to read the name Attribute from the root element of an XML-String.
returns the name Attribute from the root element of an XML-String
public Element getElementFromString(String aXMLContent) throws JDOMException,
IOException;

Helper method to read the name Attribute from the root element of an XML-String.
returns the name Attribute from the root element of an XML-String
public String outputToStringWithDefault(Element aElement, String aDefault);

Helper method to read the name Attribute from the root element of an XML-String. If an error occurs or if the element is null a default string is returned.
returns the name Attribute from the root element of an XML-String or a default string
public String getCommaSeparatedList(Element aElement, String aAttributeName);

Helper method to read the AttributeName from the child Elements of given Element. CommaSeaparated String is returned.
returns CommaSeaparated String
public String outputToStringWithDefault(Document aDocument, String aDefault);

Helper method to read the name Attribute from the root element of an XML-String. If an error occurs or if the element is null a default string is returned.
returns the name Attribute from the root element of an XML-String or a default string
public String getRootAttribute(String aXMLString, String aAttributeName);

Helper method to read the name Attribute from the root element of an XML-String.
returns the name Attribute from the root element of an XML-String
public String removeChildren(String aXMLString, String aName);

Helper method to remove all toplevel children of the XML String with a certain name.
returns converted String
public Element getElementFromStream(InputStream tFileIn)
throws JDOMException, IOException;

Parses the content of the Stream and returns the element.
returns the Element
public Document getDocumentFromStream(InputStream tFileIn)
throws JDOMException, IOException;

Parses the content of the Stream and returns the document.
returns the Document
public Document getDocumentFromString(String aString) throws JDOMException,
IOException;

Parses the given XML string and returns the document.
returns the Document
public Element getElementFromReader(Reader aReader) throws JDOMException,
IOException;

Parses the content of the Reader and returns the element.
returns the Element
public Element getElementFromFile(File aFile);

Parses the content of the file and returns the element.
returns the Element
public Element getElementFromFile(File aFile, String aEncoding);

Parses the content of the file and returns the element.
returns the Element
public boolean isXMLWellFormed(String aXMLString);

Checks the xml-structure of the given String.
returns success


}



Returned by: getInstance()