|
Regain 2.1.0-STABLE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.regain.XmlToolkit
public class XmlToolkit
enthält Hilfsmethoden für die Extraktion von Daten aus dem DOM-Dokument einer XML-Datei.
Constructor Summary | |
---|---|
XmlToolkit()
|
Method Summary | |
---|---|
static org.w3c.dom.Node |
addChild(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String childNodeName)
Adds a child node to a node. |
static org.w3c.dom.Node |
addChildWithCData(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String childNodeName,
String text)
Adds a child node to a node and gives it a CDATA section. |
static org.w3c.dom.Node |
addChildWithText(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String childNodeName,
String text)
Adds a child node to a node and gives it a text. |
static String |
getAttribute(org.w3c.dom.Node node,
String attributeName)
Gets an attribute value from a node. |
static String |
getAttribute(org.w3c.dom.Node node,
String attributeName,
boolean mandatory)
Gibt den Attributwert eines Knotens zurück. |
static boolean |
getAttributeAsBoolean(org.w3c.dom.Node node,
String attributeName)
Gets an attribute value from a node and converts it to a boolean. |
static boolean |
getAttributeAsBoolean(org.w3c.dom.Node node,
String attributeName,
boolean defaultValue)
Gets an attribute value from a node and converts it to a boolean. |
static int |
getAttributeAsInt(org.w3c.dom.Node node,
String attributeName)
Gets an attribute value from a node and converts it to an int. |
static int |
getAttributeAsInt(org.w3c.dom.Node node,
String attributeName,
int defaultValue)
Gets an attribute value from a node and converts it to an int. |
static org.w3c.dom.Node |
getCascadedChild(org.w3c.dom.Node node,
org.w3c.dom.Node defaultNode,
String childNodeName)
Gets a child node from a parent node. |
static org.w3c.dom.Node |
getCascadedChild(org.w3c.dom.Node node,
org.w3c.dom.Node defaultNode,
String childNodeName,
boolean mandatory)
Gets a child node from a parent node. |
static String |
getCData(org.w3c.dom.Node node)
Gets the CDATA value of a node. |
static String |
getCData(org.w3c.dom.Node node,
boolean mandatory)
Returns the CDATA value from an node. |
static String |
getCData(org.w3c.dom.Node node,
boolean mandatory,
boolean trimmed)
Returns the CDATA value from an node (optional trimmed). |
static org.w3c.dom.Node |
getChild(org.w3c.dom.Node node,
String childNodeName)
Gets a child node with a certain name. |
static org.w3c.dom.Node |
getChild(org.w3c.dom.Node node,
String childNodeName,
boolean mandatory)
Gibt den Kindknoten mit einem bestimmten Namen zurück. |
static org.w3c.dom.Node[] |
getChildArr(org.w3c.dom.Node node,
String childNodeName)
Gibt alle Kindknoten mit einem bestimmten Namen zurück. |
static String |
getChildText(org.w3c.dom.Node node,
String childNodeName,
boolean mandatory)
Gets the text of a child node. |
static org.w3c.dom.Node |
getOrAddChild(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String childNodeName)
Gets a child node or creates it if no such node exists. |
static String |
getText(org.w3c.dom.Node node)
Gets the text of a node. |
static String |
getText(org.w3c.dom.Node node,
boolean mandatory)
Gibt den Text eines Knotens zurück. |
static String |
getText(org.w3c.dom.Node node,
boolean mandatory,
boolean trimmed)
Gibt den Text eines Knotens zurück. |
static boolean |
getTextAsBoolean(org.w3c.dom.Node node)
Extrahiert den Text eines Knotens, wandelt ihn in einen boolean und gibt das Ergebnis zurück. |
static double |
getTextAsDouble(org.w3c.dom.Node node)
Extrahiert den Text eines Knotens, wandelt ihn in ein double und gibt das Ergebnis zurück. |
static int |
getTextAsInt(org.w3c.dom.Node node)
Extrahiert den Text eines Knotens, wandelt ihn in ein int und gibt das Ergebnis zurück. |
static String[] |
getTextAsWordList(org.w3c.dom.Node node,
boolean mandatory)
Extrahiert den Text eines Knotens, wandelt ihn in ein String-Array um, das alle durch Leerzeichen getrennte Worte enthält. |
static String |
getTextOrCData(org.w3c.dom.Node node,
boolean mandatory)
Returns text from a text or CDATA node. |
static String |
getTextOrCDataAsUrl(org.w3c.dom.Node node)
Gibt den Text eines Knotens zurück und Prüft, ob er eine g�ltige URL ist. |
static org.w3c.dom.Document |
loadXmlDocument(File xmlFile)
Loads an XML file and returns its content as Document. |
static void |
prettyPrint(org.w3c.dom.Document doc,
org.w3c.dom.Node node)
Pretty prints a node. |
private static void |
prettyPrint(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String prefix)
Pretty prints a node. |
private static void |
printNode(PrintStream out,
String prefix,
org.w3c.dom.Node node)
Prints a XML node. |
static void |
removeAllChildren(org.w3c.dom.Node node)
Removes all child nodes from a node. |
static void |
removeAllChildren(org.w3c.dom.Node node,
String childNodeName)
Removes all child nodes with a certain name. |
static void |
saveXmlDocument(File xmlFile,
org.w3c.dom.Document doc)
Saves an XML Document to a file. |
static void |
setAttribute(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String attribName,
String attribValue)
Sets an attribute of a node. |
static void |
setCData(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String text)
Set the text as a CDATA section of a node. |
static void |
setText(org.w3c.dom.Document doc,
org.w3c.dom.Node node,
String text)
Sets the text of a node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XmlToolkit()
Method Detail |
---|
public static org.w3c.dom.Document loadXmlDocument(File xmlFile) throws RegainException
xmlFile
- The XML file to load.
RegainException
- If loading the XML file failed.public static void saveXmlDocument(File xmlFile, org.w3c.dom.Document doc) throws RegainException
xmlFile
- The XML file to save to.doc
- The XML document to save.
RegainException
- If saving the XML file failed.private static void printNode(PrintStream out, String prefix, org.w3c.dom.Node node) throws IOException
out
- The PrintStream where to print the node.prefix
- The prefix to put before every line.node
- The node to print.
IOException
- If printing failed.public static boolean getTextAsBoolean(org.w3c.dom.Node node) throws RegainException
node
- Der Knoten, dessen Text zurückgeben werden soll.
RegainException
- Falls der Knoten keinen Text hat oder falls der
Text nicht true
oder false
ist.public static int getTextAsInt(org.w3c.dom.Node node) throws RegainException
node
- Der Knoten, dessen Text zurückgeben werden soll.
RegainException
- Falls der Knoten keinen Text hat oder falls der
Text keine Ganzzahl ist.public static double getTextAsDouble(org.w3c.dom.Node node) throws RegainException
node
- Der Knoten, dessen Text zurückgeben werden soll.
RegainException
- Falls der Knoten keinen Text hat oder falls der
Text kein Gleitkommawert ist.public static String[] getTextAsWordList(org.w3c.dom.Node node, boolean mandatory) throws RegainException
node
- Der Knoten, dessen Text zurückgeben werden soll.mandatory
- Gibt an, ob eine Exception geworfen werden soll, falls der
Text fehlt.
RegainException
- Falls der Knoten keinen Text hat.public static String getTextOrCDataAsUrl(org.w3c.dom.Node node) throws RegainException
Der Text wird als g�ltige URL angesehen, wenn er keinen Backslash enthält.
node
- Der Knoten, dessen Text als URL zurückgeben werden soll.
RegainException
- Wenn der Knoten keinen Text hat oder wenn der Text
keine g�ltige URL ist.public static String getText(org.w3c.dom.Node node)
node
- The node to get the text from.
null
if the node has no text.public static String getCData(org.w3c.dom.Node node, boolean mandatory) throws RegainException
node
- from which the cdata will be readmandatory
- should an exception be thrown in case of an empty node
RegainException
public static String getCData(org.w3c.dom.Node node, boolean mandatory, boolean trimmed) throws RegainException
node
- from which the cdata will be readmandatory
- should an exception be thrown in case of an empty nodetrimmed
- should the value from the node be trimmed
RegainException
public static String getCData(org.w3c.dom.Node node)
node
- The node to get the CDATA value from.
null
if the node has no CDATA value.public static String getTextOrCData(org.w3c.dom.Node node, boolean mandatory) throws RegainException
node
- The node from which to read.mandatory
- Sets whether the result ( a text with minimal 1 char) has to be present or not.
RegainException
public static String getText(org.w3c.dom.Node node, boolean mandatory) throws RegainException
Wenn der Knoten keinen Text hat, dann entscheidet mandatory
darüber,
ob eine Exception geworfen (mandatory
ist true
) oder
ob null
zurückgegeben werden soll (mandatory
ist
false
)
node
- Der Knoten, dessen Text zurückgeben werden soll.mandatory
- Gibt an, ob eine Exception geworfen werden soll, falls der
Text fehlt.
RegainException
- Wenn der Knoten keinen Text hat und
mandatory
true
ist.public static String getText(org.w3c.dom.Node node, boolean mandatory, boolean trimmed) throws RegainException
Wenn der Knoten keinen Text hat, dann entscheidet mandatory
darüber,
ob eine Exception geworfen (mandatory
ist true
) oder
ob null
zurückgegeben werden soll (mandatory
ist
false
)
node
- Der Knoten, dessen Text zurückgeben werden soll.mandatory
- Gibt an, ob eine Exception geworfen werden soll, falls der
Text fehlt.trimmed
- Specifies whether the text should be trimmed.
RegainException
- Wenn der Knoten keinen Text hat und
mandatory
true
ist.public static org.w3c.dom.Node getChild(org.w3c.dom.Node node, String childNodeName)
If the node has more than one such children, then the first child is returned.
node
- The node whichs child should be returned.childNodeName
- The name of the child node.
null
if there is no such child.public static org.w3c.dom.Node getChild(org.w3c.dom.Node node, String childNodeName, boolean mandatory) throws RegainException
Falls der Knoten mehrere Kinder mit diesem Namen hat, so wird das erste Kind zurückgegeben.
Falls der Knoten kein Kind mit diesem Name hat, dann entscheidet
mandatory
darüber, ob eine Exception geworfen
(mandatory
ist true
) oder ob null
zurückgegeben werden soll (mandatory
ist false
)
node
- Der Knoten, dessen Kind zurückgegeben werden soll.childNodeName
- Der Name des Kindknotens.mandatory
- Gibt an, ob eine Exception geworfen werden soll, falls der
Knoten kein Kind mit diesem Namen hat.
RegainException
- Wenn der Knoten kein Kind mit diesem Namen hat und
mandatory
true
ist.public static org.w3c.dom.Node[] getChildArr(org.w3c.dom.Node node, String childNodeName)
Falls der Knoten kein Kind mit diesem Namen hat, so wird ein leeres Array zurückgegeben.
node
- Der Knoten, dessen Kinder zurückgegeben werden soll.childNodeName
- Der Name der Kindknoten.
public static org.w3c.dom.Node getCascadedChild(org.w3c.dom.Node node, org.w3c.dom.Node defaultNode, String childNodeName)
defaultNode
is used.
node
- The node to get the child from.defaultNode
- The node to get the child from if node
has
no such child.childNodeName
- The name of the child.
null
if both the
node
and the defaultNode
have no child
with the given name.public static org.w3c.dom.Node getCascadedChild(org.w3c.dom.Node node, org.w3c.dom.Node defaultNode, String childNodeName, boolean mandatory) throws RegainException
defaultNode
is used.
node
- The node to get the child from.defaultNode
- The node to get the child from if node
has
no such child.childNodeName
- The name of the child.mandatory
- Specifies whether to throw an exception if none of the
nodes have such a child.
RegainException
- If both the node
and the
defaultNode
have no child with the given name and
mandatory
is true
.public static String getChildText(org.w3c.dom.Node node, String childNodeName, boolean mandatory) throws RegainException
node
- The (parent) node that has the child to get the text from.childNodeName
- The name of the child node.mandatory
- Specifies whether an exception should be thrown if the
child has no text.
null
if the child has no
text and mandatory
is false
.
RegainException
- If the given node has no child with the given name
of if the child node has no text and mandatory
is
true
.public static boolean getAttributeAsBoolean(org.w3c.dom.Node node, String attributeName) throws RegainException
node
- The node to get the attribute value from.attributeName
- The name of the attribute to get.
defaultValue
if there is
no such attribute.
RegainException
- If there is no such attribute or if the attribute
value is no boolean.public static boolean getAttributeAsBoolean(org.w3c.dom.Node node, String attributeName, boolean defaultValue) throws RegainException
node
- The node to get the attribute value from.attributeName
- The name of the attribute to get.defaultValue
- The default value to return if there is no such
attribute.
defaultValue
if there is
no such attribute.
RegainException
- If the attribute value is no boolean.public static int getAttributeAsInt(org.w3c.dom.Node node, String attributeName) throws RegainException
node
- The node to get the attribute value from.attributeName
- The name of the attribute to get.
defaultValue
if there is
no such attribute.
RegainException
- If there is no such attribute or if the attribute
value is no int.public static int getAttributeAsInt(org.w3c.dom.Node node, String attributeName, int defaultValue) throws RegainException
node
- The node to get the attribute value from.attributeName
- The name of the attribute to get.defaultValue
- The default value to return if there is no such
attribute.
defaultValue
if there is
no such attribute.
RegainException
- If the attribute value is no int.public static String getAttribute(org.w3c.dom.Node node, String attributeName)
node
- The node to get the attribute value from.attributeName
- The name of the wanted attribute.
null
if there is no such
attribute.public static String getAttribute(org.w3c.dom.Node node, String attributeName, boolean mandatory) throws RegainException
node
- Der Knoten, dessen Attribut zurückgegeben werden soll.attributeName
- Der Name des Attributs, das zurückgegeben werden soll.mandatory
- Gibt an, ob eine Exception geworfen werden soll, falls der
Knoten kein solches Attribut hat.
RegainException
- Falls der Knoten kein solches Attribut hat und
mandatory
true
ist.public static void setText(org.w3c.dom.Document doc, org.w3c.dom.Node node, String text)
doc
- The document the node comes from.node
- The node whichs text should be changed.text
- The text to set.public static void setCData(org.w3c.dom.Document doc, org.w3c.dom.Node node, String text)
doc
- The document the node comes from.node
- The node whichs CDATA section should be changed.text
- The text to set.public static void removeAllChildren(org.w3c.dom.Node node)
node
- The node to remove the children from.public static void removeAllChildren(org.w3c.dom.Node node, String childNodeName)
node
- The node to remove the children from.childNodeName
- The name of the children to remove.public static org.w3c.dom.Node addChild(org.w3c.dom.Document doc, org.w3c.dom.Node node, String childNodeName)
doc
- The document the node comes from.node
- The node were to add the child.childNodeName
- The name of the child node to add.
public static org.w3c.dom.Node getOrAddChild(org.w3c.dom.Document doc, org.w3c.dom.Node node, String childNodeName)
doc
- The document the node comes from.node
- The node were to get the child from or where to add the child.childNodeName
- The name of the child node to get or add.
public static org.w3c.dom.Node addChildWithText(org.w3c.dom.Document doc, org.w3c.dom.Node node, String childNodeName, String text)
doc
- The document the node comes from.node
- The node where to add the child.childNodeName
- The name of the child node to add.text
- The text to set to the child.
public static org.w3c.dom.Node addChildWithCData(org.w3c.dom.Document doc, org.w3c.dom.Node node, String childNodeName, String text)
doc
- The document the node comes from.node
- The node where to add the child.childNodeName
- The name of the child node to add.text
- The text (as CDATA section) to set to the child.
public static void setAttribute(org.w3c.dom.Document doc, org.w3c.dom.Node node, String attribName, String attribValue)
doc
- The document the node comes from.node
- The node where to set the attribute.attribName
- The name of the attribute to set.attribValue
- The value of the attribute to set.public static void prettyPrint(org.w3c.dom.Document doc, org.w3c.dom.Node node)
doc
- The document the node comes from.node
- The node that should be pretty printed.private static void prettyPrint(org.w3c.dom.Document doc, org.w3c.dom.Node node, String prefix)
doc
- The document the node comes from.node
- The node that should be pretty printed.prefix
- The prefix the node should get.
|
Regain 2.1.0-STABLE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |