|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.stanwood.media.xml.XMLParser
public class XMLParser
This is a helper class that should be extend by classes that need to parse XML
Field Summary | |
---|---|
static java.lang.String |
DTD_WEB_LOCATION
The (@link XMLStore2 schema |
static java.lang.String |
SCHEMA_WEB_LOCATION
The application configuration schema |
Constructor Summary | |
---|---|
XMLParser()
|
Method Summary | |
---|---|
static javax.xml.parsers.DocumentBuilder |
createDocBuilder(javax.xml.parsers.DocumentBuilderFactory factory)
Create a XML document builder. |
static javax.xml.parsers.DocumentBuilderFactory |
createFactory(java.lang.String schemaName)
Used to create a DOM document builder factory |
protected void |
deleteNode(org.w3c.dom.Element parent,
java.lang.String name)
|
static java.lang.String |
domToStr(org.w3c.dom.Document document)
Used to convert a DOM document to a string |
static java.lang.String |
encodeAttributeValue(java.lang.String value)
This is used to make sure a value can be written to a XML document by encoding the characters that should be XML entities. |
static org.w3c.dom.Element |
firstChild(org.w3c.dom.Node parent)
Used to get the first XML element under a parent element |
protected java.lang.String |
getAttribute(org.w3c.dom.Element node,
java.lang.String attributeName)
|
protected org.w3c.dom.Element |
getElement(org.w3c.dom.Element parent,
java.lang.String name)
|
protected org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Node parent,
java.lang.String name)
|
protected float |
getFloatFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a float from the XML |
protected java.lang.Integer |
getIntegerFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a integer from the XML |
protected org.w3c.dom.Element |
getLastChildElement(org.w3c.dom.Node parent,
java.lang.String name)
|
protected java.lang.Long |
getLongFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a long from the XML |
static javax.xml.validation.Schema |
getSchema(java.lang.String name)
Used to create a Schema that can be used to validate XML documents |
protected java.lang.String |
getStringFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a string from the XML |
protected java.lang.String |
getStringFromXMLOrNull(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a string from the XML, if it can't be found then return null |
protected java.net.URL |
getURLFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a URL from the XML |
protected java.net.URL |
getURLFromXMLOrNull(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a URL; from the XML, if it can't be found then return null |
static boolean |
hasNode(org.w3c.dom.Document document,
java.lang.String path)
Used to see if a XML document contains a node |
static org.w3c.dom.Document |
parse(java.io.File file,
java.lang.String schemaName)
Used to convert a XML file to a XML document. |
static org.w3c.dom.Document |
parse(java.io.InputStream is,
java.lang.String schemaName)
Used to convert a XML InputStream to a XML document. |
static org.w3c.dom.Document |
parse(java.lang.String contents,
java.lang.String schemaName)
Used to convert a XML String to a XML document. |
java.lang.String |
quoteXPathQuery(java.lang.String s)
Used to quote xpath queries |
static java.util.List<org.w3c.dom.Element> |
selectChildNodes(org.w3c.dom.Node parent,
java.lang.String childName)
Used to get a list of children nodes under a parent XML node that match a given name |
static IterableNodeList |
selectNodeList(org.w3c.dom.Node contextNode,
java.lang.String path)
Used to get a list of XML nodes using a XPath path |
static org.w3c.dom.Node |
selectSingleNode(org.w3c.dom.Node contextNode,
java.lang.String path)
Used to return a single XML node using a XPath path |
static org.w3c.dom.Document |
strToDom(java.io.File file)
Used to convert a XML file to a DOM document |
static org.w3c.dom.Document |
strToDom(java.lang.String str)
Used to convert a XML string to a DOM document |
static org.w3c.dom.Document |
strToDom(java.lang.String str,
java.lang.String schemaName)
Used to convert a XML string to a DOM document |
static void |
writeXML(java.io.File file,
org.w3c.dom.Document doc)
Used to write a XML document to a file |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DTD_WEB_LOCATION
XMLStore2
schema
public static final java.lang.String SCHEMA_WEB_LOCATION
Constructor Detail |
---|
public XMLParser()
Method Detail |
---|
protected java.lang.Integer getIntegerFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the integer
XMLParserException
- Thrown if their is a XML problem
XMLParserNotFoundException
- Thrown if the value can't be readprotected java.lang.Long getLongFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the long
XMLParserException
- Thrown if their is a XML problem
XMLParserNotFoundException
- Thrown if the value can't be readprotected java.lang.String getStringFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the string
XMLParserException
- Thrown if their is a XML problem
XMLParserNotFoundException
- Thrown if the value can't be readprotected java.lang.String getStringFromXMLOrNull(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the string
XMLParserException
- Thrown if their is a XML problemprotected java.net.URL getURLFromXML(org.w3c.dom.Node parent, java.lang.String path) throws java.net.MalformedURLException, XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the URL
XMLParserException
- Thrown if their is a XML problem
XMLParserNotFoundException
- Thrown if the value can't be read
java.net.MalformedURLException
protected java.net.URL getURLFromXMLOrNull(org.w3c.dom.Node parent, java.lang.String path) throws java.net.MalformedURLException, XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the URL
XMLParserException
- Thrown if their is a XML problem
java.net.MalformedURLException
protected float getFloatFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the float
XMLParserException
- Thrown if their is a XML problem
XMLParserNotFoundException
- Thrown if the value can't be readpublic static org.w3c.dom.Document strToDom(java.lang.String str, java.lang.String schemaName) throws XMLParserException
str
- The string to convertschemaName
- the name of the schema, or null if one should not be used
XMLParserException
- Thrown if their is a parsing problempublic static org.w3c.dom.Document strToDom(java.lang.String str) throws XMLParserException
str
- The string to convert
XMLParserException
- Thrown if their is a parsing problempublic static org.w3c.dom.Document strToDom(java.io.File file) throws XMLParserException, java.io.IOException
file
- the XML file
XMLParserException
- Thrown if their is a parsing problem
java.io.IOException
- Thrown if their is a problem reading the filepublic static java.lang.String domToStr(org.w3c.dom.Document document) throws XMLParserException
document
- The DOM document
XMLParserException
- Thrown if their is a parsing problemprotected org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent, java.lang.String name)
protected org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node parent, java.lang.String name)
public static org.w3c.dom.Element firstChild(org.w3c.dom.Node parent)
parent
- The parent element
public static java.util.List<org.w3c.dom.Element> selectChildNodes(org.w3c.dom.Node parent, java.lang.String childName)
parent
- The parent namechildName
- The name of the children to return
public static IterableNodeList selectNodeList(org.w3c.dom.Node contextNode, java.lang.String path) throws XMLParserException
contextNode
- The context that the path should be used withpath
- The XPath path
XMLParserException
- Thrown if their is a XML problempublic static org.w3c.dom.Node selectSingleNode(org.w3c.dom.Node contextNode, java.lang.String path) throws XMLParserException
contextNode
- The context that the path should be used withpath
- The XPath path
XMLParserException
- Thrown if their is a XML problempublic static javax.xml.parsers.DocumentBuilder createDocBuilder(javax.xml.parsers.DocumentBuilderFactory factory) throws javax.xml.parsers.ParserConfigurationException
factory
- The document builder factory
javax.xml.parsers.ParserConfigurationException
- Thrown if their are any problemspublic static org.w3c.dom.Document parse(java.lang.String contents, java.lang.String schemaName) throws XMLParserException
contents
- The XML StringschemaName
- The schema name, or null if validation is not required
XMLParserException
- Thrown if their was a problem converting the string to a documentpublic static org.w3c.dom.Document parse(java.io.InputStream is, java.lang.String schemaName) throws XMLParserException
is
- The XML InputStreamschemaName
- The schema name, or null if validation is not required
XMLParserException
- Thrown if their was a problem converting the string to a documentpublic static javax.xml.parsers.DocumentBuilderFactory createFactory(java.lang.String schemaName)
schemaName
- The schema name, or null if one should not be used
public static org.w3c.dom.Document parse(java.io.File file, java.lang.String schemaName) throws XMLParserException
file
- The XML fileschemaName
- The schema name, or null if validation is not required
XMLParserException
- Thrown if their was a problem converting the file to a documentpublic static javax.xml.validation.Schema getSchema(java.lang.String name) throws XMLParserException
name
- The name of the schema
XMLParserException
- Thrown if their are any problemspublic static java.lang.String encodeAttributeValue(java.lang.String value)
value
- The value to encode
public static void writeXML(java.io.File file, org.w3c.dom.Document doc) throws java.io.IOException
file
- The file to writedoc
- The XML contents
java.io.IOException
- Thrown if thier is aproblem writing the filepublic java.lang.String quoteXPathQuery(java.lang.String s)
s
- The query
protected java.lang.String getAttribute(org.w3c.dom.Element node, java.lang.String attributeName) throws XMLParserNotFoundException
XMLParserNotFoundException
protected void deleteNode(org.w3c.dom.Element parent, java.lang.String name)
protected org.w3c.dom.Element getElement(org.w3c.dom.Element parent, java.lang.String name)
public static boolean hasNode(org.w3c.dom.Document document, java.lang.String path) throws XMLParserException
document
- The XMLpath
- The node to look for ( via a xpath path)
XMLParserException
- Thrown if their is a parser problem
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |