All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.xml.parsers.DocumentBuilder Maven / Gradle / Ivy

/*
 * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details (a copy is
 * included at /legal/license.txt).
 * 
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * 
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 */

package javax.xml.parsers;

import java.io.InputStream;
import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;

import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * Defines the API to obtain DOM Document instances from an XML
 * document. Using this class, an application programmer can obtain a
 * {@link Document} from XML.

* * An instance of this class can be obtained from the * {@link DocumentBuilderFactory#newDocumentBuilder()} method. Once * an instance of this class is obtained, XML can be parsed from a * variety of input sources. These input sources are InputStreams * and SAX InputSources.

* * Note that this class reuses several classes from the SAX API. This * does not require that the implementor of the underlying DOM * implementation use a SAX parser to parse XML document into a * Document. It merely requires that the implementation * communicate with the application using these existing APIs. */ public abstract class DocumentBuilder { /** Protected constructor */ protected DocumentBuilder() { } /** * Parse the content of the given InputStream as an XML * document and return a new DOM {@link Document} object. * An IllegalArgumentException is thrown if the * InputStream is null. * * @param is InputStream containing the content to be parsed. * @return Document result of parsing the * InputStream * @exception IOException If any IO errors occur. * @exception SAXException If any parse errors occur. */ public Document parse(InputStream is) throws SAXException, IOException { if (is == null) { throw new IllegalArgumentException("InputStream cannot be null"); } InputSource in = new InputSource(is); return parse(in); } /** * Parse the content of the given input source as an XML document * and return a new DOM {@link Document} object. * An IllegalArgumentException is thrown if the * InputSource is null null. * * @param is InputSource containing the content to be parsed. * @exception IOException If any IO errors occur. * @exception SAXException If any parse errors occur. * @return A new DOM Document object. */ public abstract Document parse(InputSource is) throws SAXException, IOException; /** * Indicates whether or not this parser is configured to * understand namespaces. * * @return true if this parser is configured to understand * namespaces; false otherwise. */ public abstract boolean isNamespaceAware(); /** * Indicates whether or not this parser is configured to * validate XML documents. * * @return true if this parser is configured to validate * XML documents; false otherwise. */ public abstract boolean isValidating(); /** * Specify the {@link EntityResolver} to be used to resolve * entities present in the XML document to be parsed. Setting * this to null will result in the underlying * implementation using it's own default implementation and * behavior. * * @param er The EntityResolver to be used to resolve entities * present in the XML document to be parsed. */ public abstract void setEntityResolver(EntityResolver er); /** * Specify the {@link ErrorHandler} to be used by the parser. * Setting this to null will result in the underlying * implementation using it's own default implementation and * behavior. * * @param eh The ErrorHandler to be used by the parser. */ public abstract void setErrorHandler(ErrorHandler eh); /** * Obtain a new instance of a DOM {@link Document} object * to build a DOM tree with. * * @return A new instance of a DOM Document object. */ public abstract Document newDocument(); /** * Obtain an instance of a {@link DOMImplementation} object. * * @return A new instance of a DOMImplementation. */ public abstract DOMImplementation getDOMImplementation(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy