Java Code Examples for org.xml.sax.XMLReader#setDTDHandler()

The following examples show how to use org.xml.sax.XMLReader#setDTDHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAXParser.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 2
Source File: SAXParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 3
Source File: SAXParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 4
Source File: SAXParser.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 5
Source File: SAXParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 6
Source File: SAXParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 7
Source File: SAXParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 8
Source File: SAXParser.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 9
Source File: SAXParser.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 10
Source File: SAXParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 11
Source File: SAXParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 12
Source File: TestSAXEncoder.java    From exificient with MIT License 5 votes vote down vote up
@Override
public void encodeTo(InputStream xmlInput, OutputStream exiOutput)
		throws Exception {
	// XML reader
	XMLReader xmlReader = getXMLReader();

	exiResult.setOutputStream(exiOutput);

	// set EXI as content & lexical handler
	// EXIResult saxResult = new EXIResult(exiOutput, ef);
	xmlReader.setContentHandler(exiResult.getHandler());

	// set LexicalHandler
	xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler",
			exiResult.getLexicalHandler());
	// set DeclHandler
	xmlReader.setProperty(
			"http://xml.org/sax/properties/declaration-handler",
			exiResult.getLexicalHandler());
	// set DTD handler
	xmlReader.setDTDHandler((DTDHandler) exiResult.getHandler());

	if (isFragment) {
		xmlInput = updateInputStreamToFragment(xmlInput);
		xmlReader = updateXMLReaderToFragment(xmlReader);
	}

	xmlReader.parse(new InputSource(xmlInput));
}
 
Example 13
Source File: DOMBuilder.java    From exificient with MIT License 5 votes vote down vote up
public Document parse(InputStream is, boolean exiBodyOnly)
		throws EXIException {
	try {
		// create SAX to DOM Handlers
		SaxToDomHandler s2dHandler = new SaxToDomHandler(domImplementation,
				false);

		XMLReader reader = new SAXFactory(factory).createEXIReader();
		// EXI Features
		reader.setFeature(Constants.W3C_EXI_FEATURE_BODY_ONLY, exiBodyOnly);
		// SAX Features
		reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
				true);
		reader.setProperty("http://xml.org/sax/properties/lexical-handler",
				s2dHandler);
		reader.setProperty(
				"http://xml.org/sax/properties/declaration-handler",
				s2dHandler);
		reader.setContentHandler(s2dHandler);
		reader.setDTDHandler(s2dHandler);

		reader.parse(new InputSource(is));

		// return document;
		return s2dHandler.getDocument();
	} catch (Exception e) {
		throw new EXIException(e);
	}
}
 
Example 14
Source File: MutableXMLStreamBuffer.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
Example 15
Source File: MutableXMLStreamBuffer.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
Example 16
Source File: MutableXMLStreamBuffer.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
Example 17
Source File: MutableXMLStreamBuffer.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
Example 18
Source File: MutableXMLStreamBuffer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
Example 19
Source File: MutableXMLStreamBuffer.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
Example 20
Source File: MutableXMLStreamBuffer.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}