Example usage for javax.xml.transform.sax SAXTransformerFactory setErrorListener

List of usage examples for javax.xml.transform.sax SAXTransformerFactory setErrorListener

Introduction

In this page you can find the example usage for javax.xml.transform.sax SAXTransformerFactory setErrorListener.

Prototype

public abstract void setErrorListener(ErrorListener listener);

Source Link

Document

Set the error event listener for the TransformerFactory, which is used for the processing of transformation instructions, and not for the transformation itself.

Usage

From source file:org.apache.cocoon.components.xslt.TraxProcessor.java

/**
 * Get the TransformerFactory associated with the given classname. If the
 * class can't be found or the given class doesn't implement the required
 * interface, the default factory is returned.
 *//*from w w w  .  j  a  v  a2 s  .c  o  m*/
private SAXTransformerFactory getTransformerFactory(String factoryName) {
    SAXTransformerFactory _factory;

    if (null == factoryName) {
        _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
    } else {
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            if (loader == null) {
                loader = getClass().getClassLoader();
            }
            _factory = (SAXTransformerFactory) loader.loadClass(factoryName).newInstance();
        } catch (ClassNotFoundException cnfe) {
            getLogger().error("Cannot find the requested TrAX factory '" + factoryName
                    + "'. Using default TrAX Transformer Factory instead.");
            if (m_factory != null)
                return m_factory;
            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
        } catch (ClassCastException cce) {
            getLogger().error("The indicated class '" + factoryName
                    + "' is not a TrAX Transformer Factory. Using default TrAX Transformer Factory instead.");
            if (m_factory != null)
                return m_factory;
            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
        } catch (Exception e) {
            getLogger().error("Error found loading the requested TrAX Transformer Factory '" + factoryName
                    + "'. Using default TrAX Transformer Factory instead.");
            if (m_factory != null)
                return m_factory;
            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
        }
    }

    _factory.setErrorListener(new TraxErrorListener(getLogger(), null));
    _factory.setURIResolver(this);

    // FIXME (SM): implementation-specific parameter passing should be
    // made more extensible.
    if (_factory.getClass().getName().equals("org.apache.xalan.processor.TransformerFactoryImpl")) {
        _factory.setAttribute("http://xml.apache.org/xalan/features/incremental",
                BooleanUtils.toBooleanObject(m_incrementalProcessing));
    }
    // SAXON 8 will not report errors unless version warning is set to false.
    if (_factory.getClass().getName().equals("net.sf.saxon.TransformerFactoryImpl")) {
        _factory.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE);
    }

    return _factory;
}