jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java
author joehw
Wed, 08 May 2013 23:38:03 -0700
changeset 17534 21dc0b2762da
parent 12458 d601e4bba306
child 20968 dde41f8b7b96
permissions -rw-r--r--
8011653: Upgrade JDK8 to JAXP 1.5 Reviewed-by: alanb, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: TemplatesHandlerImpl.java,v 1.2.4.1 2005/09/06 12:09:03 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.trax;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.XMLConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.transform.Source;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.transform.Templates;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import javax.xml.transform.URIResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import javax.xml.transform.sax.TemplatesHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xalan.internal.xsltc.compiler.CompilerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import org.xml.sax.Locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import org.xml.sax.Attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * Implementation of a JAXP1.1 TemplatesHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
public class TemplatesHandlerImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    implements ContentHandler, TemplatesHandler, SourceLoader
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     * System ID for this stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    private String _systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     * Number of spaces to add for output indentation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    private int _indentNumber;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     * This URIResolver is passed to all Transformers.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    private URIResolver _uriResolver = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     * A reference to the transformer factory that this templates
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * object belongs to.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    private TransformerFactoryImpl _tfactory = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * A reference to XSLTC's parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    private Parser _parser = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     * The created Templates object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    private TemplatesImpl _templates = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * Default constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    protected TemplatesHandlerImpl(int indentNumber,
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        TransformerFactoryImpl tfactory)
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
        _indentNumber = indentNumber;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        _tfactory = tfactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        // Instantiate XSLTC and get reference to parser object
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    98
        XSLTC xsltc = new XSLTC(tfactory.useServicesMechnism());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        if (tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING))
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
            xsltc.setSecureProcessing(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 12458
diff changeset
   102
        xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 12458
diff changeset
   103
                (String)tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET));
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 12458
diff changeset
   104
        xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD,
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 12458
diff changeset
   105
                (String)tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_DTD));
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 12458
diff changeset
   106
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 12458
diff changeset
   107
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   108
        if ("true".equals(tfactory.getAttribute(TransformerFactoryImpl.ENABLE_INLINING)))
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   109
            xsltc.setTemplateInlining(true);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   110
        else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   111
            xsltc.setTemplateInlining(false);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   112
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        _parser = xsltc.getParser();
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     * Implements javax.xml.transform.sax.TemplatesHandler.getSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     * Get the base ID (URI or system ID) from where relative URLs will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
     * resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     * @return The systemID that was set with setSystemId(String id)
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        return _systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * Implements javax.xml.transform.sax.TemplatesHandler.setSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * Get the base ID (URI or system ID) from where relative URLs will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     * @param id Base URI for this stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    public void setSystemId(String id) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        _systemId = id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * Store URIResolver needed for Transformers.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    public void setURIResolver(URIResolver resolver) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        _uriResolver = resolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     * Implements javax.xml.transform.sax.TemplatesHandler.getTemplates()
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     * When a TemplatesHandler object is used as a ContentHandler or
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     * DocumentHandler for the parsing of transformation instructions, it
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * creates a Templates object, which the caller can get once the SAX
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     * events have been completed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * @return The Templates object that was created during the SAX event
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     *         process, or null if no Templates object has been created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    public Templates getTemplates() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        return _templates;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     * This method implements XSLTC's SourceLoader interface. It is used to
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     * @param href The URI of the document to load
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     * @param context The URI of the currently loaded document
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     * @param xsltc The compiler that resuests the document
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     * @return An InputSource with the loaded document
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    public InputSource loadSource(String href, String context, XSLTC xsltc) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
            // A _uriResolver must be set if this method is called
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
            final Source source = _uriResolver.resolve(href, context);
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
            if (source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                return Util.getInputSource(xsltc, source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        catch (TransformerException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
            // Falls through
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    // -- ContentHandler --------------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     * Re-initialize parser and forward SAX2 event.
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    public void startDocument() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        XSLTC xsltc = _parser.getXSLTC();
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        xsltc.init();   // calls _parser.init()
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        xsltc.setOutputType(XSLTC.BYTEARRAY_OUTPUT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
        _parser.startDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    public void endDocument() throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        _parser.endDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
        // create the templates
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            XSLTC xsltc = _parser.getXSLTC();
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
            // Set the translet class name if not already set
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   202
            String transletName;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            if (_systemId != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                transletName = Util.baseName(_systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                transletName = (String)_tfactory.getAttribute("translet-name");
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            xsltc.setClassName(transletName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
            // Get java-legal class name from XSLTC module
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
            transletName = xsltc.getClassName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            Stylesheet stylesheet = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            SyntaxTreeNode root = _parser.getDocumentRoot();
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
            // Compile the translet - this is where the work is done!
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            if (!_parser.errorsFound() && root != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                // Create a Stylesheet element from the root node
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                stylesheet = _parser.makeStylesheet(root);
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                stylesheet.setSystemId(_systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                stylesheet.setParentStylesheet(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   224
                if (xsltc.getTemplateInlining())
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   225
                   stylesheet.setTemplateInlining(true);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   226
                else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   227
                   stylesheet.setTemplateInlining(false);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   228
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                // Set a document loader (for xsl:include/import) if defined
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                if (_uriResolver != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                    stylesheet.setSourceLoader(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                _parser.setCurrentStylesheet(stylesheet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
                // Set it as top-level in the XSLTC object
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
                xsltc.setStylesheet(stylesheet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
                // Create AST under the Stylesheet element
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                _parser.createAST(stylesheet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            // Generate the bytecodes and output the translet class(es)
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            if (!_parser.errorsFound() && stylesheet != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
                stylesheet.setMultiDocument(xsltc.isMultiDocument());
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                stylesheet.setHasIdCall(xsltc.hasIdCall());
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                // Class synchronization is needed for BCEL
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
                synchronized (xsltc.getClass()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                    stylesheet.translate();
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            if (!_parser.errorsFound()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                // Check that the transformation went well before returning
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                final byte[][] bytecodes = xsltc.getBytecodes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                if (bytecodes != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                    _templates =
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                    new TemplatesImpl(xsltc.getBytecodes(), transletName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                        _parser.getOutputProperties(), _indentNumber, _tfactory);
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                    // Set URIResolver on templates object
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                    if (_uriResolver != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                        _templates.setURIResolver(_uriResolver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
                StringBuffer errorMessage = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                Vector errors = _parser.getErrors();
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                final int count = errors.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                for (int i = 0; i < count; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
                    if (errorMessage.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                        errorMessage.append('\n');
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
                    errorMessage.append(errors.elementAt(i).toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
                throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        catch (CompilerException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
            throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    public void startPrefixMapping(String prefix, String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        _parser.startPrefixMapping(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    public void endPrefixMapping(String prefix) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        _parser.endPrefixMapping(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    public void startElement(String uri, String localname, String qname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        Attributes attributes) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        _parser.startElement(uri, localname, qname, attributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    public void endElement(String uri, String localname, String qname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        _parser.endElement(uri, localname, qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
    public void characters(char[] ch, int start, int length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        _parser.characters(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    public void processingInstruction(String name, String value) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        _parser.processingInstruction(name, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    public void ignorableWhitespace(char[] ch, int start, int length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
        _parser.ignorableWhitespace(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     * Just forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    public void skippedEntity(String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        _parser.skippedEntity(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     * Set internal system Id and forward SAX2 event to parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    public void setDocumentLocator(Locator locator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        setSystemId(locator.getSystemId());
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        _parser.setDocumentLocator(locator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
}