|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.vizzini.util.xml.XMLUtilities
public class XMLUtilities
Provides convenience methods for XML document handling.
Nested Class Summary | |
---|---|
(package private) class |
XMLUtilities.XMLErrorHandler
Provides an error handler for parsing an XML string. |
Field Summary | |
---|---|
static String |
XML_HEADER
XML header. |
Method Summary | |
---|---|
protected void |
appendAttributes(StringBuffer sb,
Node node)
Append the node's attributes. |
protected boolean |
appendCommentNode(StringBuffer sb,
Comment commentNode,
boolean convertSpecialContent)
Append the comment node. |
protected boolean |
appendTextNode(StringBuffer sb,
Text textNode,
boolean convertSpecialContent)
Append the text node. |
String |
convertAttributesToString(NamedNodeMap attributes)
Append the node's attributes. |
String |
convertSpecialContent(String data)
Convert special contents into the HTML/XML equivalent entity reference. |
String |
convertToHTML(Node parent)
|
String |
convertToString(Node parent)
|
String |
convertToString(Node parent,
boolean isFormatted,
boolean convertSpecialContent)
|
protected boolean |
convertToStringProcessNode(StringBuffer sb,
Node parent,
boolean isFormatted,
boolean convertSpecialContent,
int level)
Process the given node in the asString() flow. |
String |
createNamespacePredicate(String namespace,
String nodeName)
|
String |
format(String tagName,
boolean value)
Format the given XML tag and value. |
String |
format(String tagName,
Date value)
Format the given XML tag and value. |
String |
format(String tagName,
double value)
Format the given XML tag and value. |
String |
format(String tagName,
double value,
int numDigits)
Format the given XML tag and value. |
String |
format(String tagName,
int value)
Format the given XML tag and value. |
String |
format(String tagName,
String value)
Format the given XML tag and value. |
String |
formatDate(Calendar calendar)
|
String |
formatDate(Date date)
|
String |
formatDate(int year,
int month,
int day)
|
String |
formatDecimal(double number,
int numDigits)
Round the given number to the desired number of digits to the right of the decimal point. |
Attr |
getAttribute(Node node,
String attributeName)
Return the attribute of the given name at the given path location below the given node. |
Attr |
getAttribute(Node parent,
String path,
String attributeName)
Return the attribute of the given name at the given path location below the given node. |
String |
getAttributeValue(Node node,
String attributeName)
Return the value of the attribute of the given name at the given path location below the given node. |
String |
getAttributeValue(Node parent,
String path,
String attributeName)
Return the value of the attribute of the given name at the given path location below the given node. |
Node |
getFirstChildNamed(Node parent,
String name)
Return the first child with the given tag name. |
static XMLUtilities |
getInstance()
Return the singleton instance. |
Node |
getNode(Node parent,
String path)
Return the node at the given path location below the given node. |
NodeList |
getNodeList(Node parent,
String path)
Return the nodes at the given path location below the given node. |
String |
getNodeValue(Node parent,
String path)
Return the value of the node at the given path location below the given parent. |
Date |
parseDate(String value)
Return a Date parsed from the given XML formatted string. |
Document |
parseDocument(File file)
Return a validated and parsed XML document from the given file. |
Document |
parseDocument(File file,
boolean isNamespaceAware,
boolean isValidating)
Return an XML document from the given file. |
Document |
parseDocument(Reader reader)
Return a validated and parsed XML document from the given reader. |
Document |
parseDocument(Reader reader,
boolean isNamespaceAware,
boolean isValidating)
Return an XML document from the given reader. |
Document |
parseDocument(String xml)
Return a validated and parsed XML document from the given reader. |
Document |
parseDocument(String xml,
boolean isNamespaceAware,
boolean isValidating)
Return an XML document from the given reader. |
protected void |
prepareNextLine(StringBuffer sb,
int level)
Prepare the next line of the formatted XML string. |
void |
setNodeValue(Node parent,
String path,
String value)
Set the value of the first node at the given path location below the given node. |
void |
setNodeValue(Node parent,
String path,
String value,
boolean convertSpecialContent)
Set the value of the first node at the given path location below the given node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String XML_HEADER
Method Detail |
---|
public static XMLUtilities getInstance()
public String convertAttributesToString(NamedNodeMap attributes)
attributes
- Attributes to convert.
public String convertSpecialContent(String data)
data
- the data to encode
public String convertToHTML(Node parent)
parent
- Parent node (or document).
public String convertToString(Node parent)
parent
- Parent node (or document).
public String convertToString(Node parent, boolean isFormatted, boolean convertSpecialContent)
parent
- Parent node (or document).isFormatted
- Flag indicating if the return string
should be formatted.convertSpecialContent
- Flag indicating whether special content
(&,',&aquot;,<,>) in
Comment nodes should be converted to
HTML.
public String createNamespacePredicate(String namespace, String nodeName)
namespace
- Namespace string.nodeName
- A node name.
public String format(String tagName, int value)
tagName
- Tag name.value
- Node value.
public String format(String tagName, double value)
tagName
- Tag name.value
- Node value.
public String format(String tagName, boolean value)
tagName
- Tag name.value
- Node value.
public String format(String tagName, String value)
tagName
- Tag name.value
- Node value.
public String format(String tagName, Date value)
tagName
- Tag name.value
- Value.
public String format(String tagName, double value, int numDigits)
tagName
- Tag name.value
- Node value.numDigits
-
public String formatDate(Date date)
date
- Date object, typically representing now.
public String formatDate(Calendar calendar)
calendar
- Calendar object, typically representing now.
public String formatDate(int year, int month, int day)
year
- Four digit year.month
- Month number in [1,12].day
- Day of month in [1,28],[1,30] or [1,31] depending on the
month.
public String formatDecimal(double number, int numDigits)
number
- Number to be formatted.numDigits
- Number of digits in the fraction portion of a number
(zero or more).
public Attr getAttribute(Node node, String attributeName)
node
- Node (or document).attributeName
- Attribute name.
public Attr getAttribute(Node parent, String path, String attributeName)
parent
- Parent node (or document).path
- Path to the node of interest; separator is /.attributeName
- Attribute name.
public String getAttributeValue(Node node, String attributeName)
node
- Node (or document).attributeName
- Attribute name.
public String getAttributeValue(Node parent, String path, String attributeName)
parent
- Parent node (or document).path
- Path to the node of interest; separator is /.attributeName
- Attribute name.
public Node getFirstChildNamed(Node parent, String name)
parent
- Parent node (or document).name
- Tag name of the node of interest.
public Node getNode(Node parent, String path)
parent
- Parent node (or document).path
- XPath to the node of interest.
public NodeList getNodeList(Node parent, String path)
parent
- Parent node (or document).path
- XPath to the node of interest.
public String getNodeValue(Node parent, String path)
parent
- Parent node (or document).path
- Path relative to the parent to the node of interest;
separator is /.
public Date parseDate(String value) throws ParseException
Date
parsed from the given XML formatted string.
value
-
ParseException
public Document parseDocument(String xml) throws ParserConfigurationException, IOException, SAXException
xml
- XML source string.
MalformedXMLException
InvalidXMLException
ParserConfigurationException
IOException
SAXException
public Document parseDocument(File file) throws ParserConfigurationException, IOException, SAXException
file
- XML source file.
MalformedXMLException
InvalidXMLException
ParserConfigurationException
IOException
SAXException
public Document parseDocument(Reader reader) throws ParserConfigurationException, IOException, SAXException
reader
- Reader.
MalformedXMLException
InvalidXMLException
ParserConfigurationException
IOException
SAXException
public Document parseDocument(String xml, boolean isNamespaceAware, boolean isValidating) throws ParserConfigurationException, IOException, SAXException
xml
- XML source string.isNamespaceAware
- Flag indicating if the parser is namespace
aware.isValidating
- Flag indicating if the parser should validate.
MalformedXMLException
InvalidXMLException
ParserConfigurationException
IOException
SAXException
public Document parseDocument(File file, boolean isNamespaceAware, boolean isValidating) throws ParserConfigurationException, IOException, SAXException
file
- XML source file.isNamespaceAware
- Flag indicating if the parser is namespace
aware.isValidating
- Flag indicating if the parser should validate.
MalformedXMLException
InvalidXMLException
ParserConfigurationException
IOException
SAXException
public Document parseDocument(Reader reader, boolean isNamespaceAware, boolean isValidating) throws ParserConfigurationException, IOException, SAXException
reader
- Reader.isNamespaceAware
- Flag indicating if the parser is namespace
aware.isValidating
- Flag indicating if the parser should validate.
MalformedXMLException
InvalidXMLException
ParserConfigurationException
IOException
SAXException
public void setNodeValue(Node parent, String path, String value)
parent
- Parent node.path
- Path relative to the parent to the node of interest;
separator is /.value
- Value to set.public void setNodeValue(Node parent, String path, String value, boolean convertSpecialContent)
parent
- Parent node.path
- Path relative to the parent to the node of
interest; separator is /.value
- Value to set.convertSpecialContent
- Flag indicating whether special content
(&,',&aquot;,<,>) in
Comment nodes should be converted to HTML.protected void appendAttributes(StringBuffer sb, Node node)
sb
- String buffer which holds the string being built.node
- Node being processed.protected boolean appendCommentNode(StringBuffer sb, Comment commentNode, boolean convertSpecialContent)
sb
- String buffer which holds the string
being built.commentNode
- Comment node to append.convertSpecialContent
- Flag indicating whether special content
(&,',&aquot;,<,>) in
Comment nodes should be converted to
HTML.
protected boolean appendTextNode(StringBuffer sb, Text textNode, boolean convertSpecialContent)
sb
- String buffer which holds the string
being built.textNode
- Text node to append.convertSpecialContent
- Flag indicating whether special content
(&,',&aquot;,<,>) in
Comment nodes should be converted to
HTML.
protected boolean convertToStringProcessNode(StringBuffer sb, Node parent, boolean isFormatted, boolean convertSpecialContent, int level)
asString()
flow.
sb
- String buffer which holds the string
being built.parent
- Parent node being processed.isFormatted
- Flag indicating if the return string
should be formatted.convertSpecialContent
- Flag indicating whether special content
(&,',&aquot;,<,>) in
Comment nodes should be converted to
HTML.level
- Level in the node hierarchy.
protected void prepareNextLine(StringBuffer sb, int level)
sb
- String buffer which holds the string being built.level
- Level in the node hierarchy.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2007 Vizzini.org. All Rights Reserved. | 2007.12.25.03.00.02 |