ParserUtilspublic class ParserUtils extends Object XML parsing utilities for processing web application deployment
descriptor and tag library descriptor files. FIXME - make these
use a separate class loader for the parser to be used. |
Fields Summary |
---|
static ErrorHandler | errorHandlerAn error handler for use when parsing XML documents. | static EntityResolver | entityResolverAn entity resolver for use when parsing XML documents. | public static boolean | validating |
Methods Summary |
---|
protected TreeNode | convert(TreeNode parent, org.w3c.dom.Node node)Create and return a TreeNode that corresponds to the specified Node,
including processing all of the attributes and children nodes.
// Construct a new TreeNode for this node
TreeNode treeNode = new TreeNode(node.getNodeName(), parent);
// Convert all attributes of this node
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
int n = attributes.getLength();
for (int i = 0; i < n; i++) {
Node attribute = attributes.item(i);
treeNode.addAttribute(attribute.getNodeName(),
attribute.getNodeValue());
}
}
// Create and attach all children of this node
NodeList children = node.getChildNodes();
if (children != null) {
int n = children.getLength();
for (int i = 0; i < n; i++) {
Node child = children.item(i);
if (child instanceof Comment)
continue;
if (child instanceof Text) {
String body = ((Text) child).getData();
if (body != null) {
body = body.trim();
if (body.length() > 0)
treeNode.setBody(body);
}
} else {
TreeNode treeChild = convert(treeNode, child);
}
}
}
// Return the completed TreeNode graph
return (treeNode);
| public TreeNode | parseXMLDocument(java.lang.String uri, org.xml.sax.InputSource is)Parse the specified XML document, and return a TreeNode
that corresponds to the root node of the document tree.
// --------------------------------------------------------- Public Methods
Document document = null;
// Perform an XML parse of this document, via JAXP
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(validating);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(entityResolver);
builder.setErrorHandler(errorHandler);
document = builder.parse(is);
} catch (ParserConfigurationException ex) {
throw new JasperException
(Localizer.getMessage("jsp.error.parse.xml", uri), ex);
} catch (SAXParseException ex) {
throw new JasperException
(Localizer.getMessage("jsp.error.parse.xml.line",
uri,
Integer.toString(ex.getLineNumber()),
Integer.toString(ex.getColumnNumber())),
ex);
} catch (SAXException sx) {
throw new JasperException
(Localizer.getMessage("jsp.error.parse.xml", uri), sx);
} catch (IOException io) {
throw new JasperException
(Localizer.getMessage("jsp.error.parse.xml", uri), io);
}
// Convert the resulting document to a graph of TreeNodes
return (convert(null, document.getDocumentElement()));
| public TreeNode | parseXMLDocument(java.lang.String uri, java.io.InputStream is)Parse the specified XML document, and return a TreeNode
that corresponds to the root node of the document tree.
return (parseXMLDocument(uri, new InputSource(is)));
|
|