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