Java Code Examples for org.xml.sax.helpers.XMLFilterImpl#setContentHandler()

The following examples show how to use org.xml.sax.helpers.XMLFilterImpl#setContentHandler() . 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: DomHandlerEx.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
ResultImpl() {
    try {
        DocumentBuilderFactory factory = XmlFactory.createDocumentBuilderFactory(false); // safe - only used for BI
        s2d = new SAX2DOMEx(factory);
    } catch (ParserConfigurationException e) {
        throw new AssertionError(e);    // impossible
    }

    XMLFilterImpl f = new XMLFilterImpl() {
        @Override
        public void setDocumentLocator(Locator locator) {
            super.setDocumentLocator(locator);
            location = new LocatorImpl(locator);
        }
    };
    f.setContentHandler(s2d);

    setHandler(f);
}
 
Example 2
Source File: DomHandlerEx.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
ResultImpl() {
    try {
        DocumentBuilderFactory factory = XmlFactory.createDocumentBuilderFactory(false); // safe - only used for BI
        s2d = new SAX2DOMEx(factory);
    } catch (ParserConfigurationException e) {
        throw new AssertionError(e);    // impossible
    }

    XMLFilterImpl f = new XMLFilterImpl() {
        @Override
        public void setDocumentLocator(Locator locator) {
            super.setDocumentLocator(locator);
            location = new LocatorImpl(locator);
        }
    };
    f.setContentHandler(s2d);

    setHandler(f);
}
 
Example 3
Source File: DomHandlerEx.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
ResultImpl() {
    try {
        DocumentBuilderFactory factory = XmlFactory.createDocumentBuilderFactory(false); // safe - only used for BI
        s2d = new SAX2DOMEx(factory);
    } catch (ParserConfigurationException e) {
        throw new AssertionError(e);    // impossible
    }

    XMLFilterImpl f = new XMLFilterImpl() {
        @Override
        public void setDocumentLocator(Locator locator) {
            super.setDocumentLocator(locator);
            location = new LocatorImpl(locator);
        }
    };
    f.setContentHandler(s2d);

    setHandler(f);
}
 
Example 4
Source File: DOMForest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a {@link ContentHandler} to feed SAX events into.
 *
 * <p>
 * The client of this class can feed SAX events into the handler
 * to parse a document into this DOM forest.
 *
 * This version requires that the DOM object to be created and registered
 * to the map beforehand.
 */
private ContentHandler getParserHandler( Document dom ) {
    ContentHandler handler = new DOMBuilder(dom,locatorTable,outerMostBindings);
    handler = new WhitespaceStripper(handler,errorReceiver,entityResolver);
    handler = new VersionChecker(handler,errorReceiver,entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);

    if(errorReceiver!=null)
        f.setErrorHandler(errorReceiver);
    if(entityResolver!=null)
        f.setEntityResolver(entityResolver);

    return f;
}
 
Example 5
Source File: DOMForest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a {@link ContentHandler} to feed SAX events into.
 *
 * <p>
 * The client of this class can feed SAX events into the handler
 * to parse a document into this DOM forest.
 *
 * This version requires that the DOM object to be created and registered
 * to the map beforehand.
 */
private ContentHandler getParserHandler( Document dom ) {
    ContentHandler handler = new DOMBuilder(dom,locatorTable,outerMostBindings);
    handler = new WhitespaceStripper(handler,errorReceiver,entityResolver);
    handler = new VersionChecker(handler,errorReceiver,entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);

    if(errorReceiver!=null)
        f.setErrorHandler(errorReceiver);
    if(entityResolver!=null)
        f.setEntityResolver(entityResolver);

    return f;
}
 
Example 6
Source File: AbstractXmlValidator.java    From iaf with Apache License 2.0 6 votes vote down vote up
public String validate(Object input, IPipeLineSession session, String logPrefix, ValidatorHandler validatorHandler, XMLFilterImpl filter, ValidationContext context) throws XmlValidatorException, PipeRunException, ConfigurationException {

		if (filter != null) {
			// If a filter is present, connect its output to the context.contentHandler.
			// It is assumed that the filter input is already properly connected.
			filter.setContentHandler(context.getContentHandler());
			filter.setErrorHandler(context.getErrorHandler());
		} else {
			validatorHandler.setContentHandler(context.getContentHandler());
		}
		validatorHandler.setErrorHandler(context.getErrorHandler());

		InputSource is = getInputSource(Message.asMessage(input));

		return validate(is, validatorHandler, session, context);
	}
 
Example 7
Source File: TestBeansFilter.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test method for the filter.
 *
 * @exception Exception
 *                test failed
 */
@Test
public void testFilter() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final TransformerHandler th = ((SAXTransformerFactory) tf)
            .newTransformerHandler();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final Result result = new StreamResult(out);
    th.setResult(result);
    final SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    spf.setNamespaceAware(true);
    spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    final SAXParser parser = spf.newSAXParser();
    final XMLFilterImpl filter = new BeansFilter(parser.getXMLReader());
    filter.setContentHandler(th);
    final InputStream in =
        new FileInputStream("../org.jvoicexml.config/src/test/resources/config/test-implementation.xml");
    final InputSource input = new InputSource(in);
    filter.parse(input);
    final String str = out.toString();
    Assert.assertTrue("classpath should be removed",
            str.indexOf("classpath") < 0);
    Assert.assertTrue("repository should be removed",
            str.indexOf("repository") < 0);
}
 
Example 8
Source File: DOMForest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a {@link ContentHandler} to feed SAX events into.
 *
 * <p>
 * The client of this class can feed SAX events into the handler
 * to parse a document into this DOM forest.
 *
 * This version requires that the DOM object to be created and registered
 * to the map beforehand.
 */
private ContentHandler getParserHandler( Document dom ) {
    ContentHandler handler = new DOMBuilder(dom,locatorTable,outerMostBindings);
    handler = new WhitespaceStripper(handler,errorReceiver,entityResolver);
    handler = new VersionChecker(handler,errorReceiver,entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);

    if(errorReceiver!=null)
        f.setErrorHandler(errorReceiver);
    if(entityResolver!=null)
        f.setEntityResolver(entityResolver);

    return f;
}
 
Example 9
Source File: DOMForest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 10
Source File: DOMForest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 11
Source File: DOMForest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 12
Source File: DOMForest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 13
Source File: DOMForest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 14
Source File: DOMForest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 15
Source File: DOMForest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
     * <p/>
     * This version requires that the DOM object to be created and registered
     * to the map beforehand.
     */
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
    XMLReader reader = parserFactory.newSAXParser().getXMLReader();
    DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
    try {
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
    } catch(SAXException e) {
        errorReceiver.debug(e.getMessage());
    }

    ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
    handler = new VersionChecker(handler, errorReceiver, entityResolver);

    // insert the reference finder so that
    // included/imported schemas will be also parsed
    XMLFilterImpl f = logic.createExternalReferenceFinder(this);
    f.setContentHandler(handler);
    if (errorReceiver != null)
        f.setErrorHandler(errorReceiver);
    f.setEntityResolver(entityResolver);

    reader.setContentHandler(f);
    if (errorReceiver != null)
        reader.setErrorHandler(errorReceiver);
    reader.setEntityResolver(entityResolver);
    return reader;
}
 
Example 16
Source File: ModelLoader.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Wraps the specified content handler by a filter.
 * It is little awkward to use a helper implementation class like XMLFilterImpl
 * as the method parameter, but this simplifies the code.
 */
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
    filter.setContentHandler(handler);
    return filter;
}
 
Example 17
Source File: ModelLoader.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Wraps the specified content handler by a filter.
 * It is little awkward to use a helper implementation class like XMLFilterImpl
 * as the method parameter, but this simplifies the code.
 */
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
    filter.setContentHandler(handler);
    return filter;
}
 
Example 18
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Wraps the specified content handler by a filter.
 * It is little awkward to use a helper implementation class like XMLFilterImpl
 * as the method parameter, but this simplifies the code.
 */
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
    filter.setContentHandler(handler);
    return filter;
}
 
Example 19
Source File: ModelLoader.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Wraps the specified content handler by a filter.
 * It is little awkward to use a helper implementation class like XMLFilterImpl
 * as the method parameter, but this simplifies the code.
 */
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
    filter.setContentHandler(handler);
    return filter;
}
 
Example 20
Source File: ModelLoader.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Wraps the specified content handler by a filter.
 * It is little awkward to use a helper implementation class like XMLFilterImpl
 * as the method parameter, but this simplifies the code.
 */
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
    filter.setContentHandler(handler);
    return filter;
}