Package net.simplace.core.service
Klasse XMLHelper
java.lang.Object
net.simplace.core.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.
- Autor:
- Andreas Enders
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic final org.jdom2.ElementaddElement(org.jdom2.Element aElement, String aName, String aValue) Adds a new element to the given element with the same namespace.static voidaddTextToChildThatMayExist(org.jdom2.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.static booleancheckAttributeExists(org.jdom2.Element aVarElement, String aString) static booleancheckAttributeNotEmpty(org.jdom2.Element aVarElement, String aString) static booleancheckValueExists(org.jdom2.Element aVarElement) static org.jdom2.ElementcreateChoiceElement(String aId, String aTitle, String aRequired, String aEnabled, String aType, String aLocalize, String aMultiselect, String aDefault, Map<String, String> aOptions) create integer field Elementstatic org.jdom2.ElementcreateDoubleElement(String aId, String aTitle, String aRequired, String aEnabled, String aMin, String aMax, String aType, String aDefault) create integer field Elementstatic org.jdom2.ElementcreateFieldElement(String aName, String aTitle, String aId, String aRequired, String aEnabled, String aDefault) create standard field Elementstatic org.jdom2.ElementcreateIntegerElement(String aId, String aTitle, String aRequired, String aEnabled, String aMin, String aMax, String aType, String aDefault) create integer field Elementstatic org.jdom2.ElementcreateParameterElement(String aParameter, Object aValue) create standard parameter Elementstatic org.jdom2.Elementcreate text field Elementstatic List<org.jdom2.Element> evaluateXPath(org.jdom2.Document aDoc, String aExpression) create standard field Elementstatic List<org.jdom2.Element> evaluateXPath(org.jdom2.Element aElement, String aExpression) create standard field Elementstatic StringevaluateXPathSingleResult(org.jdom2.Document aDoc, String aExpression) create standard field Elementstatic org.jdom2.DocumentgenerateProjectXML(String aProjectDataFile, List<FWSimVariable<?>> aVars, org.apache.commons.collections15.map.LinkedMap<FWSimVariable<?>, String> aSensitivityVarsMap, org.jdom2.Element aOutputsElement) static final StringgetAttributeValueOrEmptyString(org.jdom2.Element aElement, String aAtrributeValue) Returns the value of the attribute specified be aAttributeName or returns "" if the it doesn't exists.static final StringgetAttributeValueOrNull(org.jdom2.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.static final booleangetBooleanAttributeValue(org.jdom2.Element aElement, String aName, boolean aDefault) Returns the value of the attribute specified be aAttributeName or returns the given default.getCommaSeparatedList(org.jdom2.Element aElement, String aAttributeName) Helper method to read the AttributeName from the child Elements of given Element.org.jdom2.DocumentgetDocumentFromStream(InputStream tFileIn) Parses the content of the Stream and returns the document.org.jdom2.DocumentgetDocumentFromString(String aString) Parses the given XML string and returns the document.org.jdom2.ElementgetElementFromFile(File aFile) Parses the content of the file and returns the element.org.jdom2.ElementgetElementFromFile(File aFile, String aEncoding) Parses the content of the file and returns the element.org.jdom2.ElementgetElementFromReader(Reader aReader) Parses the content of the Reader and returns the element.org.jdom2.ElementgetElementFromStream(InputStream tFileIn) Parses the content of the Stream and returns the element.org.jdom2.ElementgetElementFromString(String aXMLContent) Helper method to read the name Attribute from the root element of an XML-String.static XMLHelperCreates a new instance of.static <T extends Number>
TgetNumberAttributeValue(org.jdom2.Element aElement, String aAttr, Class<T> aNumberType, T aDefault) Getting parameter value from map as a number.static org.jdom2.ElementgetOrCreateChild(org.jdom2.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.getRootAttribute(String aXMLString, String aAttributeName) Helper method to read the name Attribute from the root element of an XML-String.getRootIDAttribute(String aXMLString) Helper method to read the name Attribute from the root element of an XML-String.getRootNameAttribute(String aXMLString) Helper method to read the name Attribute from the root element of an XML-String.booleanisXMLWellFormed(String aXMLString) Checks the xml-structure of the given String.outputToString(org.jdom2.Document aDocument) Helper method to read the name Attribute from the root element of an XML-String.outputToString(org.jdom2.Element aElement) Helper method to read the name Attribute from the root element of an XML-String.outputToStringWithDefault(org.jdom2.Document aDocument, String aDefault) Helper method to read the name Attribute from the root element of an XML-String.outputToStringWithDefault(org.jdom2.Element aElement, String aDefault) Helper method to read the name Attribute from the root element of an XML-String.removeChildren(String aXMLString, String aName) Helper method to remove all toplevel children of the XML String with a certain name.static StringReplaces a String in a String.static StringReplaces in the string all key in the given Map by the values.static Double[]toDoubleArray(List<org.jdom2.Element> aChildren) static Double[][]toDoubleMatrix(List<org.jdom2.Element> aChildren) static Integer[]toIntArray(List<org.jdom2.Element> aChildren) static String[]toStringArray(List<org.jdom2.Element> aChildren) transformElementToMap(org.jdom2.Element aElement) transforms a JDOM-Element to HashMap.static org.jdom2.ElementtransformMapToElement(Map<String, Object> aParameterMap, String aNameOfRootElement)
-
Methodendetails
-
getInstance
Creates a new instance of. Easier to use as constructor.- Gibt zurück:
- the Instance
-
getRootIDAttribute
Helper method to read the name Attribute from the root element of an XML-String.- Parameter:
aXMLString-- Gibt zurück:
- RootIDAttribute
-
replace
Replaces a String in a String.- Parameter:
aString-aToBeReplacedString-aReplaceWithString-- Gibt zurück:
- converted String
-
replaceAttribute
public static String replaceAttribute(String aString, Map<String, Object> aReplacements, String aAttribute) Replaces in the string all key in the given Map by the values.- Parameter:
aString-aReplacements-aAttribute-- Gibt zurück:
- converted String
-
getRootNameAttribute
Helper method to read the name Attribute from the root element of an XML-String.- Parameter:
aXMLString-- Gibt zurück:
- RootNameAttribute
-
outputToString
Helper method to read the name Attribute from the root element of an XML-String.- Parameter:
aElement-- Gibt zurück:
- the name Attribute from the root element of an XML-String
- Löst aus:
IOException
-
outputToString
Helper method to read the name Attribute from the root element of an XML-String.- Parameter:
aDocument-- Gibt zurück:
- the name Attribute from the root element of an XML-String
- Löst aus:
IOException
-
getElementFromString
public org.jdom2.Element getElementFromString(String aXMLContent) throws org.jdom2.JDOMException, IOException Helper method to read the name Attribute from the root element of an XML-String.- Parameter:
aXMLContent-- Gibt zurück:
- the name Attribute from the root element of an XML-String
- Löst aus:
org.jdom2.JDOMExceptionIOException
-
outputToStringWithDefault
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.- Parameter:
aElement-aDefault-- Gibt zurück:
- the name Attribute from the root element of an XML-String or a default string
-
getCommaSeparatedList
Helper method to read the AttributeName from the child Elements of given Element. CommaSeaparated String is returned.- Parameter:
aElement-aAttributeName-- Gibt zurück:
- CommaSeaparated String
-
outputToStringWithDefault
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.- Parameter:
aDocument-aDefault-- Gibt zurück:
- the name Attribute from the root element of an XML-String or a default string
-
getRootAttribute
Helper method to read the name Attribute from the root element of an XML-String.- Parameter:
aXMLString-aAttributeName-- Gibt zurück:
- the name Attribute from the root element of an XML-String
-
removeChildren
Helper method to remove all toplevel children of the XML String with a certain name.- Parameter:
aXMLString-aName-- Gibt zurück:
- converted String
-
addElement
public static final org.jdom2.Element addElement(org.jdom2.Element aElement, String aName, String aValue) Adds a new element to the given element with the same namespace.- Parameter:
aElement-aName-aValue-- Gibt zurück:
- a new element
-
getOrCreateChild
public static org.jdom2.Element getOrCreateChild(org.jdom2.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.- Parameter:
aParentElement-aChildName-- Gibt zurück:
- the Child-Element of aParentElement with the given name
-
addTextToChildThatMayExist
public static void addTextToChildThatMayExist(org.jdom2.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.- Parameter:
aParentElement-aChildName-aValue-
-
getElementFromStream
public org.jdom2.Element getElementFromStream(InputStream tFileIn) throws org.jdom2.JDOMException, IOException Parses the content of the Stream and returns the element.- Parameter:
tFileIn-- Gibt zurück:
- the Element
- Löst aus:
org.jdom2.JDOMExceptionIOException
-
getDocumentFromStream
public org.jdom2.Document getDocumentFromStream(InputStream tFileIn) throws org.jdom2.JDOMException, IOException Parses the content of the Stream and returns the document.- Parameter:
tFileIn-- Gibt zurück:
- the Document
- Löst aus:
org.jdom2.JDOMExceptionIOException
-
getDocumentFromString
public org.jdom2.Document getDocumentFromString(String aString) throws org.jdom2.JDOMException, IOException Parses the given XML string and returns the document.- Parameter:
aString-- Gibt zurück:
- the Document
- Löst aus:
org.jdom2.JDOMExceptionIOException
-
getElementFromReader
public org.jdom2.Element getElementFromReader(Reader aReader) throws org.jdom2.JDOMException, IOException Parses the content of the Reader and returns the element.- Parameter:
aReader-- Gibt zurück:
- the Element
- Löst aus:
org.jdom2.JDOMExceptionIOException
-
getElementFromFile
Parses the content of the file and returns the element.- Parameter:
aFile-- Gibt zurück:
- the Element
-
getElementFromFile
Parses the content of the file and returns the element.- Parameter:
aFile-aEncoding-- Gibt zurück:
- the Element
-
getAttributeValueOrEmptyString
public static final String getAttributeValueOrEmptyString(org.jdom2.Element aElement, String aAtrributeValue) Returns the value of the attribute specified be aAttributeName or returns "" if the it doesn't exists.- Parameter:
aElement-aAtrributeValue-- Gibt zurück:
- the value of the attribute specified be aAttributeName or returns "" if the it doesn't exist
-
getAttributeValueOrNull
public static final String getAttributeValueOrNull(org.jdom2.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.- Parameter:
aElement-aAtrributeValue-- Gibt zurück:
- the value of the attribute specified by aAttributeName or returns null if the it doesn't exist
-
getBooleanAttributeValue
public static final boolean getBooleanAttributeValue(org.jdom2.Element aElement, String aName, boolean aDefault) Returns the value of the attribute specified be aAttributeName or returns the given default.- Parameter:
aElement-aName-aDefault-- Gibt zurück:
- the value of the attribute specified be aAttributeName or the given default
-
getNumberAttributeValue
public static <T extends Number> T getNumberAttributeValue(org.jdom2.Element aElement, String aAttr, Class<T> aNumberType, T aDefault) Getting parameter value from map as a number.- Typparameter:
T-- Parameter:
aElement-aAttr-aNumberType- number type, the determined value is converted to (subclass ofNumber)aDefault- default value, which is returned if parameter not set or value can not be converted toaNumberType.- Gibt zurück:
- parameter value from map as a number
-
isXMLWellFormed
Checks the xml-structure of the given String.- Parameter:
aXMLString-- Gibt zurück:
- success
-
transformElementToMap
transforms a JDOM-Element to HashMap. Structure needed:modis.map.subXalt modis.map.ndsiresult - Parameter:
aElement-- Gibt zurück:
- JDOM-Element transformed to HashMap
-
createParameterElement
create standard parameter Element- Parameter:
aParameter-aValue-- Gibt zurück:
- standard parameter Element
-
createTextElement
public static org.jdom2.Element createTextElement(String aId, String aTitle, String aRequired, String aEnabled, String aDefault) create text field Element- Parameter:
aId-aTitle-aRequired-aEnabled-aDefault-- Gibt zurück:
- standard parameter Element
-
createChoiceElement
public static org.jdom2.Element createChoiceElement(String aId, String aTitle, String aRequired, String aEnabled, String aType, String aLocalize, String aMultiselect, String aDefault, Map<String, String> aOptions) create integer field Element- Parameter:
aId-aTitle-aRequired-aEnabled-aType-aLocalize-aMultiselect-aDefault-aOptions-- Gibt zurück:
- standard parameter Element
-
createDoubleElement
public static org.jdom2.Element createDoubleElement(String aId, String aTitle, String aRequired, String aEnabled, String aMin, String aMax, String aType, String aDefault) create integer field Element- Parameter:
aId-aTitle-aRequired-aEnabled-aMin-aMax-aType-aDefault-- Gibt zurück:
- standard parameter Element
-
createIntegerElement
public static org.jdom2.Element createIntegerElement(String aId, String aTitle, String aRequired, String aEnabled, String aMin, String aMax, String aType, String aDefault) create integer field Element- Parameter:
aId-aTitle-aRequired-aEnabled-aMin-aMax-aType-aDefault-- Gibt zurück:
- standard parameter Element
-
createFieldElement
public static org.jdom2.Element createFieldElement(String aName, String aTitle, String aId, String aRequired, String aEnabled, String aDefault) create standard field Element- Parameter:
aName-aTitle-aId-aRequired-aEnabled-aDefault-- Gibt zurück:
- standard parameter Element
-
evaluateXPath
create standard field Element- Parameter:
aDoc-aExpression-- Gibt zurück:
- standard parameter Element
-
evaluateXPath
create standard field Element- Parameter:
aExpression-aDoc-- Gibt zurück:
- standard parameter Element
-
evaluateXPathSingleResult
create standard field Element- Parameter:
aDoc-aExpression-- Gibt zurück:
- standard parameter Element
-
transformMapToElement
public static org.jdom2.Element transformMapToElement(Map<String, Object> aParameterMap, String aNameOfRootElement) - Parameter:
aParameterMap-aNameOfRootElement-- Gibt zurück:
- Element
-
checkAttributeExists
- Parameter:
aVarElement-aString-- Gibt zurück:
- true if attribute exists
-
checkAttributeNotEmpty
- Parameter:
aVarElement-aString-- Gibt zurück:
- true if attribute not empty
-
checkValueExists
public static boolean checkValueExists(org.jdom2.Element aVarElement) - Parameter:
aVarElement-- Gibt zurück:
- true if value exists
-
toIntArray
- Parameter:
aChildren-- Gibt zurück:
- Array of Integers
-
toDoubleArray
- Parameter:
aChildren-- Gibt zurück:
- Array of Doubles
-
toDoubleMatrix
- Parameter:
aChildren-- Gibt zurück:
-
generateProjectXML
public static org.jdom2.Document generateProjectXML(String aProjectDataFile, List<FWSimVariable<?>> aVars, org.apache.commons.collections15.map.LinkedMap<FWSimVariable<?>, String> aSensitivityVarsMap, org.jdom2.Element aOutputsElement) throws org.jdom2.JDOMException, IOException- Parameter:
aOutputsElement-tSensitivityVarsMap-aChildren-- Gibt zurück:
- Array of Strings
- Löst aus:
IOExceptionorg.jdom2.JDOMException
-
toStringArray
- Parameter:
aChildren-- Gibt zurück:
- Array of Strings
-