org.xml.sax.XMLFilter Java Examples

The following examples show how to use org.xml.sax.XMLFilter. 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: SmartTransformerFactoryImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #2
Source File: SmartTransformerFactoryImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #3
Source File: SmartTransformerFactoryImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #4
Source File: TransformerFactoryImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #5
Source File: TransformerFactoryImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #6
Source File: SmartTransformerFactoryImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #7
Source File: SmartTransformerFactoryImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #8
Source File: SmartTransformerFactoryImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #9
Source File: TransformerFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #10
Source File: SmartTransformerFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #11
Source File: SmartTransformerFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #12
Source File: TransformerFactoryImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #13
Source File: SmartTransformerFactoryImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #14
Source File: SmartTransformerFactoryImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #15
Source File: TransformerFactoryImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #16
Source File: SmartTransformerFactoryImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #17
Source File: SmartTransformerFactoryImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #18
Source File: SAXTFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unit test for TemplatesHandler setter/getter.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase13() throws Exception {
    String outputFile = USER_DIR + "saxtf013.out";
    String goldFile = GOLDEN_DIR + "saxtf013GF.out";
    try(FileInputStream fis = new FileInputStream(XML_FILE)) {
        // The transformer will use a SAX parser as it's reader.
        XMLReader reader = XMLReaderFactory.createXMLReader();

        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory) TransformerFactory.newInstance();
        TemplatesHandler thandler = saxTFactory.newTemplatesHandler();
        // I have put this as it was complaining about systemid
        thandler.setSystemId("file:///" + USER_DIR);

        reader.setContentHandler(thandler);
        reader.parse(XSLT_FILE);
        XMLFilter filter
                = saxTFactory.newXMLFilter(thandler.getTemplates());
        filter.setParent(reader);

        filter.setContentHandler(new MyContentHandler(outputFile));
        filter.parse(new InputSource(fis));
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
Example #19
Source File: SAXTFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unit test for contentHandler setter/getter.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase12() throws Exception {
    String outputFile = USER_DIR + "saxtf012.out";
    String goldFile = GOLDEN_DIR + "saxtf012GF.out";
    // The transformer will use a SAX parser as it's reader.
    XMLReader reader = XMLReaderFactory.createXMLReader();

    InputSource is = new InputSource(new FileInputStream(XSLT_FILE));
    SAXSource saxSource = new SAXSource();
    saxSource.setInputSource(is);

    SAXTransformerFactory saxTFactory = (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter filter = saxTFactory.newXMLFilter(saxSource);

    filter.setParent(reader);
    filter.setContentHandler(new MyContentHandler(outputFile));

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(XML_FILE));
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
Example #20
Source File: TransformerFactoryImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #21
Source File: SAXTFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unit test for contentHandler setter/getter along reader as handler's
 * parent.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase10() throws Exception {
    String outputFile = USER_DIR + "saxtf010.out";
    String goldFile = GOLDEN_DIR + "saxtf010GF.out";
    // The transformer will use a SAX parser as it's reader.
    XMLReader reader = XMLReaderFactory.createXMLReader();
    SAXTransformerFactory saxTFactory
            = (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter filter =
        saxTFactory.newXMLFilter(new StreamSource(XSLT_FILE));
    filter.setParent(reader);
    filter.setContentHandler(new MyContentHandler(outputFile));

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(XML_FILE));
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
Example #22
Source File: TransformerFactoryImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                throw new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #23
Source File: SmartTransformerFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #24
Source File: SmartTransformerFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #25
Source File: TransformerFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #26
Source File: SmartTransformerFactoryImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
Example #27
Source File: SmartTransformerFactoryImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
Example #28
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a RELAX NG grammar into an annotated grammar.
 */
private Model loadRELAXNG() throws SAXException {

    // build DOM forest
    final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );

    // use JAXP masquerading to validate the input document.
    // DOMForest -> ExtensionBindingChecker -> RNGOM

    XMLReaderCreator xrc = new XMLReaderCreator() {
        public XMLReader createXMLReader() {

            // foreset parser cannot change the receivers while it's working,
            // so we need to have one XMLFilter that works as a buffer
            XMLFilter buffer = new XMLFilterImpl() {
                @Override
                public void parse(InputSource source) throws IOException, SAXException {
                    forest.createParser().parse( source, this, this, this );
                }
            };

            XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
            f.setParent(buffer);

            f.setEntityResolver(opt.entityResolver);

            return f;
        }
    };

    Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );

    return loadRELAXNG(p);

}
 
Example #29
Source File: SAXTFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unit test for contentHandler setter/getter with parent.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase11() throws Exception {
    String outputFile = USER_DIR + "saxtf011.out";
    String goldFile = GOLDEN_DIR + "saxtf011GF.out";
    // The transformer will use a SAX parser as it's reader.
    XMLReader reader = XMLReaderFactory.createXMLReader();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    Document document = docBuilder.parse(new File(XSLT_FILE));
    Node node = (Node)document;
    DOMSource domSource= new DOMSource(node);

    SAXTransformerFactory saxTFactory
            = (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter filter = saxTFactory.newXMLFilter(domSource);

    filter.setParent(reader);
    filter.setContentHandler(new MyContentHandler(outputFile));

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(XML_FILE));
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
Example #30
Source File: XMLFilterProcessor.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Makes a filter from a series of xsltProcessors that applies those 
 * templates in order.
 * @param templateList The series of xsltProcessors used to construct the
 * filter.
 * @throws BuildException If no xsltProcessors are specified.
 */
XMLFilter makeFilter(List<CCGBankTaskTemplates> templateList)
	throws FileNotFoundException,SAXException,
		 TransformerConfigurationException {

	// make templates
	if(templates == null) {
		templates = makeTemplates(taskTemplatesList);
	}
	
	// assemble list of xslt templates into a filter
	XMLFilter currentFilter = null, previousFilter = null;
	for (Templates t : templates) {
		currentFilter = transformerFactory.newXMLFilter(t);
		currentFilter.setErrorHandler(errorHandler);
		
		if(previousFilter == null) { // it's the first one
			currentFilter.setParent(
					XMLReaderFactory.createXMLReader());					
		}
		else {
			currentFilter.setParent(previousFilter);
		}
		
		previousFilter = currentFilter;
	}
	
	if(currentFilter == null ) {
		throw new IllegalArgumentException("no templates specified");
	}
	
	currentFilter.setErrorHandler(errorHandler);
	currentFilter.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
	
	return currentFilter;
}