Java Code Examples for com.sun.org.apache.xml.internal.utils.StopParseException

The following examples show how to use com.sun.org.apache.xml.internal.utils.StopParseException. These examples are extracted from open source projects. 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
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Get the stylesheet specification(s) associated via the xml-stylesheet
 * processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with
 * the document document specified in the source parameter, and that match
 * the given criteria.
 *
 * @param source The XML source document.
 * @param media The media attribute to be matched. May be null, in which
 * case the prefered templates will be used (i.e. alternate = no).
 * @param title The value of the title attribute to match. May be null.
 * @param charset The value of the charset attribute to match. May be null.
 * @return A Source object suitable for passing to the TransformerFactory.
 * @throws TransformerConfigurationException
 */
@Override
public Source  getAssociatedStylesheet(Source source, String media,
                                      String title, String charset)
    throws TransformerConfigurationException {

    String baseId;
    XMLReader reader = null;
    InputSource isource;

    /**
     * Fix for bugzilla bug 24187
     */
    StylesheetPIHandler _stylesheetPIHandler = new StylesheetPIHandler(null,media,title,charset);

    try {

        if (source instanceof DOMSource ) {
            final DOMSource domsrc = (DOMSource) source;
            baseId = domsrc.getSystemId();
            final org.w3c.dom.Node node = domsrc.getNode();
            final DOM2SAX dom2sax = new DOM2SAX(node);

            _stylesheetPIHandler.setBaseId(baseId);

            dom2sax.setContentHandler( _stylesheetPIHandler);
            dom2sax.parse();
        } else {
            if (source instanceof SAXSource) {
                reader = ((SAXSource)source).getXMLReader();
            }
            isource = SAXSource.sourceToInputSource(source);
            baseId = isource.getSystemId();

            if (reader == null) {
                reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
                        !_isNotSecureProcessing);
            }

            _stylesheetPIHandler.setBaseId(baseId);
            reader.setContentHandler(_stylesheetPIHandler);
            reader.parse(isource);

        }

        if (_uriResolver != null ) {
            _stylesheetPIHandler.setURIResolver(_uriResolver);
        }

    } catch (StopParseException e ) {
      // startElement encountered so do not parse further
    } catch (org.xml.sax.SAXException se) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", se);
    } catch (IOException ioe ) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", ioe);
    }

     return _stylesheetPIHandler.getAssociatedStylesheet();

}
 
Example 2
Source Project: JDKSourceCode1.8   Source File: TransformerFactoryImpl.java    License: MIT License 4 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Get the stylesheet specification(s) associated via the xml-stylesheet
 * processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with
 * the document document specified in the source parameter, and that match
 * the given criteria.
 *
 * @param source The XML source document.
 * @param media The media attribute to be matched. May be null, in which
 * case the prefered templates will be used (i.e. alternate = no).
 * @param title The value of the title attribute to match. May be null.
 * @param charset The value of the charset attribute to match. May be null.
 * @return A Source object suitable for passing to the TransformerFactory.
 * @throws TransformerConfigurationException
 */
@Override
public Source  getAssociatedStylesheet(Source source, String media,
                                      String title, String charset)
    throws TransformerConfigurationException {

    String baseId;
    XMLReader reader = null;
    InputSource isource;

    /**
     * Fix for bugzilla bug 24187
     */
    StylesheetPIHandler _stylesheetPIHandler = new StylesheetPIHandler(null,media,title,charset);

    try {

        if (source instanceof DOMSource ) {
            final DOMSource domsrc = (DOMSource) source;
            baseId = domsrc.getSystemId();
            final org.w3c.dom.Node node = domsrc.getNode();
            final DOM2SAX dom2sax = new DOM2SAX(node);

            _stylesheetPIHandler.setBaseId(baseId);

            dom2sax.setContentHandler( _stylesheetPIHandler);
            dom2sax.parse();
        } else {
            if (source instanceof SAXSource) {
                reader = ((SAXSource)source).getXMLReader();
            }
            isource = SAXSource.sourceToInputSource(source);
            baseId = isource.getSystemId();

            if (reader == null) {
                reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
                        !_isNotSecureProcessing);
            }

            _stylesheetPIHandler.setBaseId(baseId);
            reader.setContentHandler(_stylesheetPIHandler);
            reader.parse(isource);

        }

        if (_uriResolver != null ) {
            _stylesheetPIHandler.setURIResolver(_uriResolver);
        }

    } catch (StopParseException e ) {
      // startElement encountered so do not parse further
    } catch (org.xml.sax.SAXException se) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", se);
    } catch (IOException ioe ) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", ioe);
    }

     return _stylesheetPIHandler.getAssociatedStylesheet();

}
 
Example 3
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Get the stylesheet specification(s) associated via the xml-stylesheet
 * processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with
 * the document document specified in the source parameter, and that match
 * the given criteria.
 *
 * @param source The XML source document.
 * @param media The media attribute to be matched. May be null, in which
 * case the prefered templates will be used (i.e. alternate = no).
 * @param title The value of the title attribute to match. May be null.
 * @param charset The value of the charset attribute to match. May be null.
 * @return A Source object suitable for passing to the TransformerFactory.
 * @throws TransformerConfigurationException
 */
@Override
public Source  getAssociatedStylesheet(Source source, String media,
                                      String title, String charset)
    throws TransformerConfigurationException {

    String baseId;
    XMLReader reader = null;
    InputSource isource;

    /**
     * Fix for bugzilla bug 24187
     */
    StylesheetPIHandler _stylesheetPIHandler = new StylesheetPIHandler(null,media,title,charset);

    try {

        if (source instanceof DOMSource ) {
            final DOMSource domsrc = (DOMSource) source;
            baseId = domsrc.getSystemId();
            final org.w3c.dom.Node node = domsrc.getNode();
            final DOM2SAX dom2sax = new DOM2SAX(node);

            _stylesheetPIHandler.setBaseId(baseId);

            dom2sax.setContentHandler( _stylesheetPIHandler);
            dom2sax.parse();
        } else {
            if (source instanceof SAXSource) {
                reader = ((SAXSource)source).getXMLReader();
            }
            isource = SAXSource.sourceToInputSource(source);
            baseId = isource.getSystemId();

            if (reader == null) {
                reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
                        !_isNotSecureProcessing);
            }

            _stylesheetPIHandler.setBaseId(baseId);
            reader.setContentHandler(_stylesheetPIHandler);
            reader.parse(isource);

        }

        if (_uriResolver != null ) {
            _stylesheetPIHandler.setURIResolver(_uriResolver);
        }

    } catch (StopParseException e ) {
      // startElement encountered so do not parse further
    } catch (org.xml.sax.SAXException se) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", se);
    } catch (IOException ioe ) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", ioe);
    }

     return _stylesheetPIHandler.getAssociatedStylesheet();

}
 
Example 4
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Get the stylesheet specification(s) associated via the xml-stylesheet
 * processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with
 * the document document specified in the source parameter, and that match
 * the given criteria.
 *
 * @param source The XML source document.
 * @param media The media attribute to be matched. May be null, in which
 * case the prefered templates will be used (i.e. alternate = no).
 * @param title The value of the title attribute to match. May be null.
 * @param charset The value of the charset attribute to match. May be null.
 * @return A Source object suitable for passing to the TransformerFactory.
 * @throws TransformerConfigurationException
 */
@Override
public Source  getAssociatedStylesheet(Source source, String media,
                                      String title, String charset)
    throws TransformerConfigurationException {

    String baseId;
    XMLReader reader = null;
    InputSource isource;

    /**
     * Fix for bugzilla bug 24187
     */
    StylesheetPIHandler _stylesheetPIHandler = new StylesheetPIHandler(null,media,title,charset);

    try {

        if (source instanceof DOMSource ) {
            final DOMSource domsrc = (DOMSource) source;
            baseId = domsrc.getSystemId();
            final org.w3c.dom.Node node = domsrc.getNode();
            final DOM2SAX dom2sax = new DOM2SAX(node);

            _stylesheetPIHandler.setBaseId(baseId);

            dom2sax.setContentHandler( _stylesheetPIHandler);
            dom2sax.parse();
        } else {
            if (source instanceof SAXSource) {
                reader = ((SAXSource)source).getXMLReader();
            }
            isource = SAXSource.sourceToInputSource(source);
            baseId = isource.getSystemId();

            if (reader == null) {
                reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
                        !_isNotSecureProcessing);
            }

            _stylesheetPIHandler.setBaseId(baseId);
            reader.setContentHandler(_stylesheetPIHandler);
            reader.parse(isource);

        }

        if (_uriResolver != null ) {
            _stylesheetPIHandler.setURIResolver(_uriResolver);
        }

    } catch (StopParseException e ) {
      // startElement encountered so do not parse further
    } catch (org.xml.sax.SAXException se) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", se);
    } catch (IOException ioe ) {
        throw new TransformerConfigurationException(
            "getAssociatedStylesheets failed", ioe);
    }

     return _stylesheetPIHandler.getAssociatedStylesheet();

}