Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet#setMultiDocument()

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet#setMultiDocument() . 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: TemplatesHandlerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuffer errorMessage = new StringBuffer();
            Vector errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.elementAt(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 2
Source File: TemplatesHandlerImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuilder errorMessage = new StringBuilder();
            ArrayList<ErrorMsg> errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.get(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 3
Source File: TemplatesHandlerImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuffer errorMessage = new StringBuffer();
            Vector errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.elementAt(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 4
Source File: TemplatesHandlerImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuilder errorMessage = new StringBuilder();
            ArrayList<ErrorMsg> errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.get(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 5
Source File: TemplatesHandlerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuilder errorMessage = new StringBuilder();
            ArrayList<ErrorMsg> errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.get(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 6
Source File: TemplatesHandlerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuilder errorMessage = new StringBuilder();
            ArrayList<ErrorMsg> errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.get(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 7
Source File: TemplatesHandlerImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null || (_useCatalog &&
                    _catalogFeatures.get(CatalogFeatures.Feature.FILES) != null)) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuilder errorMessage = new StringBuilder();
            ArrayList<ErrorMsg> errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.get(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 8
Source File: TemplatesHandlerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null || (_useCatalog &&
                    _catalogFeatures.get(CatalogFeatures.Feature.FILES) != null)) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuilder errorMessage = new StringBuilder();
            ArrayList<ErrorMsg> errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.get(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 9
Source File: TemplatesHandlerImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuffer errorMessage = new StringBuffer();
            Vector errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.elementAt(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 10
Source File: TemplatesHandlerImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuffer errorMessage = new StringBuffer();
            Vector errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.elementAt(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}
 
Example 11
Source File: TemplatesHandlerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Just forward SAX2 event to parser object.
 */
public void endDocument() throws SAXException {
    _parser.endDocument();

    // create the templates
    try {
        XSLTC xsltc = _parser.getXSLTC();

        // Set the translet class name if not already set
        String transletName;
        if (_systemId != null) {
            transletName = Util.baseName(_systemId);
        }
        else {
            transletName = (String)_tfactory.getAttribute("translet-name");
        }
        xsltc.setClassName(transletName);

        // Get java-legal class name from XSLTC module
        transletName = xsltc.getClassName();

        Stylesheet stylesheet = null;
        SyntaxTreeNode root = _parser.getDocumentRoot();

        // Compile the translet - this is where the work is done!
        if (!_parser.errorsFound() && root != null) {
            // Create a Stylesheet element from the root node
            stylesheet = _parser.makeStylesheet(root);
            stylesheet.setSystemId(_systemId);
            stylesheet.setParentStylesheet(null);

            if (xsltc.getTemplateInlining())
               stylesheet.setTemplateInlining(true);
            else
               stylesheet.setTemplateInlining(false);

            // Set a document loader (for xsl:include/import) if defined
            if (_uriResolver != null) {
                stylesheet.setSourceLoader(this);
            }

            _parser.setCurrentStylesheet(stylesheet);

            // Set it as top-level in the XSLTC object
            xsltc.setStylesheet(stylesheet);

            // Create AST under the Stylesheet element
            _parser.createAST(stylesheet);
        }

        // Generate the bytecodes and output the translet class(es)
        if (!_parser.errorsFound() && stylesheet != null) {
            stylesheet.setMultiDocument(xsltc.isMultiDocument());
            stylesheet.setHasIdCall(xsltc.hasIdCall());

            // Class synchronization is needed for BCEL
            synchronized (xsltc.getClass()) {
                stylesheet.translate();
            }
        }

        if (!_parser.errorsFound()) {
            // Check that the transformation went well before returning
            final byte[][] bytecodes = xsltc.getBytecodes();
            if (bytecodes != null) {
                _templates =
                new TemplatesImpl(xsltc.getBytecodes(), transletName,
                    _parser.getOutputProperties(), _indentNumber, _tfactory);

                // Set URIResolver on templates object
                if (_uriResolver != null) {
                    _templates.setURIResolver(_uriResolver);
                }
            }
        }
        else {
            StringBuffer errorMessage = new StringBuffer();
            Vector errors = _parser.getErrors();
            final int count = errors.size();
            for (int i = 0; i < count; i++) {
                if (errorMessage.length() > 0)
                    errorMessage.append('\n');
                errorMessage.append(errors.elementAt(i).toString());
            }
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
        }
    }
    catch (CompilerException e) {
        throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
    }
}