|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sage.orion.sdata.servlet.XMLHelper
public final class XMLHelper
group of helper routines to make processing XML files easier.
Field Summary | |
---|---|
static javax.xml.parsers.DocumentBuilderFactory |
DOC_BUILDER_FACTORY
|
Method Summary | |
---|---|
static java.lang.String |
convertElementToString(org.w3c.dom.Element element)
Converts the Element to its string representation. |
static org.w3c.dom.Document |
createDocument()
Create a new Document |
static void |
createElementResponse(org.w3c.dom.Element element,
javax.servlet.http.HttpServletResponse response)
Add the provided XML element as the document element onto the response. |
static org.w3c.dom.Element |
createTextElement(org.w3c.dom.Document doc,
java.lang.String name,
java.lang.String value)
Create a new Element and text node |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Node node,
java.lang.String name)
returns the Element that is a direct child of the provided node
and has the given tag name. |
static java.lang.String |
getTextValue(org.w3c.dom.Element node)
Returns the text value of the given element node, or null if there is no true content. |
static boolean |
isUsableElementName(java.lang.String name)
checks if the given name can be used as an XML element name |
static org.w3c.dom.Document |
loadXMLDocument(java.lang.String filename)
Loads the document object from an XML file. |
static java.lang.String |
makeUsableElementName(java.lang.String name)
Returns a modification of the given name such that isUsableElementName(java.lang.String) returns true. |
static java.lang.String |
removeTabsandLineFeeds(java.lang.String s)
Returns the given string with the tabs ('\t'), end of line ('\n') and carriage return ('\r') characters removed. |
static void |
writeToStream(org.w3c.dom.Element element,
java.lang.String charset,
java.io.OutputStream outputStream)
writes the provided XML element as the document element to the given stream using the given character set |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final javax.xml.parsers.DocumentBuilderFactory DOC_BUILDER_FACTORY
Method Detail |
---|
public static java.lang.String removeTabsandLineFeeds(java.lang.String s)
s
- the input string.
public static java.lang.String getTextValue(org.w3c.dom.Element node)
Returns the text value of the given element node, or null if there is no true content.
The text value is a concatenation of right-trimmed text nodes (which includes spaces being trimmed even within quotes) and any CDATA nodes (whose contents left as-is) that are children of the node under which the text value lives.
NOTE: Unlike Node.getTextContent
, this
method does right-trimming of the text nodes (though it does not trim
CDATA nodes) and does not look at text of nested children (for example,
this method would ignore a child element that itself has some text). One
other difference is that this method returns null if there is no true
content (in other words, if all we have is whitespace).
node
- the node under which the text value is
public static org.w3c.dom.Document createDocument()
Document
Document
public static org.w3c.dom.Element createTextElement(org.w3c.dom.Document doc, java.lang.String name, java.lang.String value)
Element
and text node
doc
- the document to which to add the nodename
- the name of the node (which must not be null)value
- the value of the text. If this is null then no text is added.
Element
with the text under it.public static void createElementResponse(org.w3c.dom.Element element, javax.servlet.http.HttpServletResponse response)
element
- the element that is the body of the responseresponse
- the http servlet response to which to add the elementpublic static void writeToStream(org.w3c.dom.Element element, java.lang.String charset, java.io.OutputStream outputStream) throws java.io.IOException
element
- the Element
to be writtencharset
- the name of the character set to be usedoutputStream
- the OutputStream
to which to write
java.io.IOException
- on any input/output failurepublic static org.w3c.dom.Document loadXMLDocument(java.lang.String filename)
filename
- the name of the file
Document
containing the XML loaded from the file whose
name is givenpublic static org.w3c.dom.Element getChildElement(org.w3c.dom.Node node, java.lang.String name)
Element
that is a direct child of the provided node
and has the given tag name.
This is frequently what we want rather than iterating over all the children or getting all the elements with the given tag name (which does not guarantee to return a direct child)
node
- the node that is the parent of the requested Element.name
- the name of the node
public static boolean isUsableElementName(java.lang.String name)
name
- the name
public static java.lang.String makeUsableElementName(java.lang.String name)
isUsableElementName(java.lang.String)
returns true.
The scheme for changing the name is currently only sufficient for normal use. There are names that cannot currently be changed; for these an exception is thrown.
name
- the name
java.lang.IllegalArgumentException
- if the name cannot be made XML compatible with the current
schemepublic static java.lang.String convertElementToString(org.w3c.dom.Element element)
Element
to its string representation.
element
- The Element
.
Element
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |