FileDocCategorySizeDatePackage
ParserUtils.javaAPI DocApache Tomcat 6.0.148764Fri Jul 20 04:20:32 BST 2007org.apache.jasper.xmlparser

ParserUtils

public 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.
author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
static ErrorHandler
errorHandler
An error handler for use when parsing XML documents.
static EntityResolver
entityResolver
An entity resolver for use when parsing XML documents.
public static boolean
validating
Constructors Summary
Methods Summary
protected TreeNodeconvert(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.

param
parent The parent TreeNode (if any) for the new TreeNode
param
node The XML document Node to be converted


        // 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 TreeNodeparseXMLDocument(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.

param
uri URI of the XML document being parsed
param
is Input source containing the deployment descriptor
exception
JasperException if an input/output error occurs
exception
JasperException if a parsing error occurs



    // --------------------------------------------------------- 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 TreeNodeparseXMLDocument(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.

param
uri URI of the XML document being parsed
param
is Input stream containing the deployment descriptor
exception
JasperException if an input/output error occurs
exception
JasperException if a parsing error occurs


        return (parseXMLDocument(uri, new InputSource(is)));