src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java
author joehw
Wed, 04 Oct 2017 10:54:18 -0700
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 47359 e1a6c0168741
permissions -rw-r--r--
8187593: Cleanup: removing SecuritySupport files Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 42247
diff changeset
     2
 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Sep 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     8
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
    25
import com.sun.org.apache.xalan.internal.XalanConstants;
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
    26
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.dtm.DTM;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    30
import java.io.ByteArrayOutputStream;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    31
import java.io.File;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    32
import java.io.FileOutputStream;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    33
import java.io.IOException;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    34
import java.io.InputStream;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    35
import java.net.URL;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
    36
import java.util.ArrayList;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    37
import java.util.Collections;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    38
import java.util.Date;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    39
import java.util.Enumeration;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    40
import java.util.HashMap;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    41
import java.util.Map;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
    42
import java.util.Objects;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    43
import java.util.Properties;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    44
import java.util.Vector;
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
    45
import java.util.jar.Attributes;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    46
import java.util.jar.JarEntry;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    47
import java.util.jar.JarOutputStream;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    48
import java.util.jar.Manifest;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    49
import javax.xml.XMLConstants;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
    50
import javax.xml.catalog.CatalogFeatures;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
    51
import jdk.xml.internal.JdkXmlFeatures;
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
    52
import jdk.xml.internal.JdkXmlUtils;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    53
import jdk.xml.internal.SecuritySupport;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import org.xml.sax.XMLReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @author G. Todd Miller
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * @author John Howard (johnh@schemasoft.com)
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
public final class XSLTC {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    // A reference to the main stylesheet parser object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    private Parser _parser;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    // A reference to an external XMLReader (SAX parser) passed to us
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    private XMLReader _reader = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    // A reference to an external SourceLoader (for use with include/import)
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private SourceLoader _loader = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    // A reference to the stylesheet being compiled.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    private Stylesheet _stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    // Counters used by various classes to generate unique names.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    // private int _variableSerial     = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    private int _modeSerial         = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    private int _stylesheetSerial   = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    private int _stepPatternSerial  = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    private int _helperClassSerial  = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    private int _attributeSetSerial = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    private int[] _numberFieldIndexes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    // Name index tables
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    private int       _nextGType;  // Next available element type
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    private Vector    _namesIndex; // Index of all registered QNames
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    91
    private Map<String, Integer> _elements;   // Map of all registered elements
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    92
    private Map<String, Integer> _attributes; // Map of all registered attributes
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    // Namespace index tables
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    private int       _nextNSType; // Next available namespace type
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    private Vector    _namespaceIndex; // Index of all registered namespaces
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    97
    private Map<String, Integer> _namespaces; // Map of all registered namespaces
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    98
    private Map<String, Integer> _namespacePrefixes;// Map of all registered namespace prefixes
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    // All literal text in the stylesheet
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   102
    private ArrayList<StringBuilder> m_characterData;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    // These define the various methods for outputting the translet
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    public static final int JAR_OUTPUT         = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    public static final int BYTEARRAY_OUTPUT   = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    public static final int CLASSLOADER_OUTPUT = 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    public static final int BYTEARRAY_AND_FILE_OUTPUT = 4;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    public static final int BYTEARRAY_AND_JAR_OUTPUT  = 5;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    // Compiler options (passed from command line or XSLTC client)
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    private boolean _debug = false;      // -x
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    private String  _jarFileName = null; // -j <jar-file-name>
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    private String  _className = null;   // -o <class-name>
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33349
diff changeset
   116
    private String  _packageName = "die.verwandlung"; // override with -p <package-name>
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    private File    _destDir = null;     // -d <directory-name>
46175
52634f4b683b 8186208: closed/javax/xml/jaxp/transform/cr6657673/CR6657673Test.java: test result: Error. failed to clean up files after test
joehw
parents: 45853
diff changeset
   118
    private int     _outputType = BYTEARRAY_OUTPUT; // by default
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   120
    private ArrayList<ByteArrayOutputStream>  _classes;
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   121
    private ArrayList<JavaClass>  _bcelClasses;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    private boolean _callsNodeset = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    private boolean _multiDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    private boolean _hasIdCall = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * Set to true if template inlining is requested. Template
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * inlining used to be the default, but we have found that
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * Hotspots does a better job with shorter methods, so the
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     * default is *not* to inline now.
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    private boolean _templateInlining = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
     * State of the secure processing feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    private boolean _isSecureProcessing = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   139
    private boolean _useServicesMechanism = true;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   140
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    /**
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   142
     * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   143
     */
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   144
    private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   145
     /**
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   146
     * protocols allowed for external DTD references in source file and/or stylesheet.
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   147
     */
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   148
    private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   149
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   150
    private XMLSecurityManager _xmlSecurityManager;
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   151
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   152
    private final JdkXmlFeatures _xmlFeatures;
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   153
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   154
    /**
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   155
    *  Extension function class loader variables
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   156
    */
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   157
39909
00e4298ae168 8162598: XSLTC transformer swallows empty namespace declaration which is needed to undeclare default namespace
clanger
parents: 39907
diff changeset
   158
    /* Class loader reference that will be used for external extension functions loading */
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   159
    private ClassLoader _extensionClassLoader;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   160
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   161
    /**
39909
00e4298ae168 8162598: XSLTC transformer swallows empty namespace declaration which is needed to undeclare default namespace
clanger
parents: 39907
diff changeset
   162
    *  HashMap with the loaded classes
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   163
    */
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   164
    private final Map<String, Class<?>> _externalExtensionFunctions;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   165
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   166
    /**
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   167
     * Catalog features
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   168
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   169
    CatalogFeatures _catalogFeatures;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   170
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   171
    /**
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   172
     * CDATA chunk size
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   173
     */
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   174
    int _cdataChunkSize;
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   175
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   176
    /**
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     * XSLTC compiler constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     */
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   179
    public XSLTC(boolean useServicesMechanism, JdkXmlFeatures featureManager) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   180
        _parser = new Parser(this, useServicesMechanism);
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   181
        _xmlFeatures = featureManager;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   182
        _extensionClassLoader = null;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   183
        _externalExtensionFunctions = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * Set the state of the secure processing feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    public void setSecureProcessing(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
        _isSecureProcessing = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * Return the state of the secure processing feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    public boolean isSecureProcessing() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
        return _isSecureProcessing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   199
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   200
     * Return the state of the services mechanism feature.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   201
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   202
    public boolean useServicesMechnism() {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   203
        return _useServicesMechanism;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   204
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   205
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   206
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   207
     * Set the state of the services mechanism feature.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   208
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   209
    public void setServicesMechnism(boolean flag) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   210
        _useServicesMechanism = flag;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   211
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   213
     /**
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   214
     * Return the value of the specified feature
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   215
     * @param name name of the feature
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   216
     * @return true if the feature is enabled, false otherwise
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   217
     */
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   218
    public boolean getFeature(JdkXmlFeatures.XmlFeature name) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   219
        return _xmlFeatures.getFeature(name);
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   220
    }
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 20968
diff changeset
   221
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    /**
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   223
     * Return allowed protocols for accessing external stylesheet.
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   224
     * @param name the name of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   225
     * @return the value of the property
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   226
     */
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   227
    public Object getProperty(String name) {
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   228
        if (name.equals(XMLConstants.ACCESS_EXTERNAL_STYLESHEET)) {
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   229
            return _accessExternalStylesheet;
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   230
        }
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   231
        else if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   232
            return _accessExternalDTD;
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   233
        } else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   234
            return _xmlSecurityManager;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   235
        } else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   236
            return _extensionClassLoader;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   237
        } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   238
            return _catalogFeatures;
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   239
        } else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   240
            return _cdataChunkSize;
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   241
        }
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   242
        return null;
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   243
    }
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   244
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   245
    /**
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   246
     * Set allowed protocols for accessing external stylesheet.
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   247
     * @param name the name of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   248
     * @param value the value of the property
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   249
     */
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   250
    public void setProperty(String name, Object value) {
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   251
        if (name.equals(XMLConstants.ACCESS_EXTERNAL_STYLESHEET)) {
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   252
            _accessExternalStylesheet = (String)value;
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   253
        }
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   254
        else if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   255
            _accessExternalDTD = (String)value;
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   256
        } else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 17534
diff changeset
   257
            _xmlSecurityManager = (XMLSecurityManager)value;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   258
        } else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   259
            _extensionClassLoader = (ClassLoader) value;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   260
            /* Clear the external extension functions HashMap if extension class
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   261
               loader was changed */
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   262
            _externalExtensionFunctions.clear();
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   263
        } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   264
            _catalogFeatures = (CatalogFeatures)value;
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   265
        } else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   266
            _cdataChunkSize = Integer.parseInt((String)value);
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   267
        }
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   268
    }
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   269
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   270
    /**
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
     * Only for user by the internal TrAX implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
    public Parser getParser() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        return _parser;
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
     * Only for user by the internal TrAX implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    public void setOutputType(int type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        _outputType = type;
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
     * Only for user by the internal TrAX implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
    public Properties getOutputProperties() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        return _parser.getOutputProperties();
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     * Initializes the compiler to compile a new stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
    public void init() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        _reader = null;
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   297
        _classes = new ArrayList<>();
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   298
        _bcelClasses = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   301
    private void setExternalExtensionFunctions(String name, Class<?> clazz) {
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   302
        if (_isSecureProcessing && clazz != null && !_externalExtensionFunctions.containsKey(name)) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   303
            _externalExtensionFunctions.put(name, clazz);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   304
        }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   305
    }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   306
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   307
    /*
39909
00e4298ae168 8162598: XSLTC transformer swallows empty namespace declaration which is needed to undeclare default namespace
clanger
parents: 39907
diff changeset
   308
     * Function loads an external extension function.
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   309
     * The filtering of function types (external,internal) takes place in FunctionCall class
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   310
     *
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   311
     */
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   312
    Class loadExternalFunction(String name) throws ClassNotFoundException {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   313
        Class loaded = null;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   314
        //Check if the function is not loaded already
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   315
        if (_externalExtensionFunctions.containsKey(name)) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   316
            loaded = _externalExtensionFunctions.get(name);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   317
        } else if (_extensionClassLoader != null) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   318
            loaded = Class.forName(name, true, _extensionClassLoader);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   319
            setExternalExtensionFunctions(name, loaded);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   320
        }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   321
        if (loaded == null) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   322
            throw new ClassNotFoundException(name);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   323
        }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   324
        //Return loaded class
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   325
        return (Class) loaded;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   326
    }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   327
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   328
    /*
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   329
     * Returns unmodifiable view of HashMap with loaded external extension
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   330
     * functions - will be needed for the TransformerImpl
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   331
    */
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   332
    public Map<String, Class<?>> getExternalExtensionFunctions() {
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   333
        return Collections.unmodifiableMap(_externalExtensionFunctions);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   334
    }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   335
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     * Initializes the compiler to produce a new translet
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    private void reset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        _nextGType      = DTM.NTYPES;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   341
        _elements       = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   342
        _attributes     = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   343
        _namespaces     = new HashMap<>();
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 42247
diff changeset
   344
        _namespaces.put("", _nextNSType);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        _namesIndex     = new Vector(128);
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        _namespaceIndex = new Vector(32);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   347
        _namespacePrefixes = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        _stylesheet     = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        _parser.init();
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        //_variableSerial     = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        _modeSerial         = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
        _stylesheetSerial   = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
        _stepPatternSerial  = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
        _helperClassSerial  = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        _attributeSetSerial = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        _multiDocument      = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        _hasIdCall          = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
        _numberFieldIndexes = new int[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
            -1,         // LEVEL_SINGLE
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
            -1,         // LEVEL_MULTIPLE
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
            -1          // LEVEL_ANY
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        };
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   363
        _externalExtensionFunctions.clear();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
     * Defines an external SourceLoader to provide the compiler with documents
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
     * referenced in xsl:include/import
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
     * @param loader The SourceLoader to use for include/import
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
    public void setSourceLoader(SourceLoader loader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        _loader = loader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
     * Set a flag indicating if templates are to be inlined or not. The
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
     * default is to do inlining, but this causes problems when the
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
     * stylesheets have a large number of templates (e.g. branch targets
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
     * exceeding 64K or a length of a method exceeding 64K).
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    public void setTemplateInlining(boolean templateInlining) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        _templateInlining = templateInlining;
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   384
     /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   385
     * Return the state of the template inlining feature.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   386
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   387
    public boolean getTemplateInlining() {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   388
        return _templateInlining;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   389
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
     * Set the parameters to use to locate the correct <?xml-stylesheet ...?>
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
     * processing instruction in the case where the input document to the
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
     * compiler (and parser) is an XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
     * @param media The media attribute to be matched. May be null, in which
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
     * case the prefered templates will be used (i.e. alternate = no).
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
     * @param title The value of the title attribute to match. May be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
     * @param charset The value of the charset attribute to match. May be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
    public void setPIParameters(String media, String title, String charset) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        _parser.setPIParameters(media, title, charset);
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
     * Compiles an XSL stylesheet pointed to by a URL
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
     * @param url An URL containing the input XSL stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
    public boolean compile(URL url) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
            // Open input stream from URL and wrap inside InputSource
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
            final InputStream stream = url.openStream();
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
            final InputSource input = new InputSource(stream);
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
            input.setSystemId(url.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
            return compile(input, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
        catch (IOException e) {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   417
            _parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
     * Compiles an XSL stylesheet pointed to by a URL
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
     * @param url An URL containing the input XSL stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
     * @param name The name to assign to the translet class
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
    public boolean compile(URL url, String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
            // Open input stream from URL and wrap inside InputSource
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
            final InputStream stream = url.openStream();
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
            final InputSource input = new InputSource(stream);
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
            input.setSystemId(url.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
            return compile(input, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        catch (IOException e) {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   436
            _parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
     * Compiles an XSL stylesheet passed in through an InputStream
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
     * @param stream An InputStream that will pass in the stylesheet contents
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
     * @param name The name of the translet class to generate
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
     * @return 'true' if the compilation was successful
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
    public boolean compile(InputStream stream, String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        final InputSource input = new InputSource(stream);
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
        input.setSystemId(name); // We have nothing else!!!
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        return compile(input, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
     * Compiles an XSL stylesheet passed in through an InputStream
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
     * @param input An InputSource that will pass in the stylesheet contents
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
     * @param name The name of the translet class to generate - can be null
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
     * @return 'true' if the compilation was successful
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
    public boolean compile(InputSource input, String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
            // Reset globals in case we're called by compile(Vector v);
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
            reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
            // The systemId may not be set, so we'll have to check the URL
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
            String systemId = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
            if (input != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
                systemId = input.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
            // Set the translet class name if not already set
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
            if (_className == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
                if (name != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
                    setClassName(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
                else if (systemId != null && !systemId.equals("")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
                    setClassName(Util.baseName(systemId));
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                // Ensure we have a non-empty class name at this point
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
                if (_className == null || _className.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
                    setClassName("GregorSamsa"); // default translet name
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
            // Get the root node of the abstract syntax tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
            SyntaxTreeNode element = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
            if (_reader == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
                element = _parser.parse(input);
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
                element = _parser.parse(_reader, input);
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
            // Compile the translet - this is where the work is done!
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
            if ((!_parser.errorsFound()) && (element != null)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
                // Create a Stylesheet element from the root node
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
                _stylesheet = _parser.makeStylesheet(element);
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
                _stylesheet.setSourceLoader(_loader);
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
                _stylesheet.setSystemId(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
                _stylesheet.setParentStylesheet(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
                _stylesheet.setTemplateInlining(_templateInlining);
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
                _parser.setCurrentStylesheet(_stylesheet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
                // Create AST under the Stylesheet element (parse & type-check)
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
                _parser.createAST(_stylesheet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
            // Generate the bytecodes and output the translet class(es)
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
            if ((!_parser.errorsFound()) && (_stylesheet != null)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
                _stylesheet.setCallsNodeset(_callsNodeset);
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
                _stylesheet.setMultiDocument(_multiDocument);
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
                _stylesheet.setHasIdCall(_hasIdCall);
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
                // Class synchronization is needed for BCEL
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
                synchronized (getClass()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
                    _stylesheet.translate();
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
        catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
            /*if (_debug)*/ e.printStackTrace();
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   521
            _parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
        catch (Error e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
            if (_debug) e.printStackTrace();
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   525
            _parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
        finally {
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
            _reader = null; // reset this here to be sure it is not re-used
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
        return !_parser.errorsFound();
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
     * Compiles a set of stylesheets pointed to by a Vector of URLs
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
     * @param stylesheets A Vector containing URLs pointing to the stylesheets
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
     * @return 'true' if the compilation was successful
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
    public boolean compile(Vector stylesheets) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
        // Get the number of stylesheets (ie. URLs) in the vector
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
        final int count = stylesheets.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
        // Return straight away if the vector is empty
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
        if (count == 0) return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
        // Special handling needed if the URL count is one, becuase the
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
        // _className global must not be reset if it was set explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
        if (count == 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
            final Object url = stylesheets.firstElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
            if (url instanceof URL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
                return compile((URL)url);
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
            // Traverse all elements in the vector and compile
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
            final Enumeration urls = stylesheets.elements();
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
            while (urls.hasMoreElements()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
                _className = null; // reset, so that new name will be computed
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
                final Object url = urls.nextElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
                if (url instanceof URL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
                    if (!compile((URL)url)) return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
     * Returns an array of bytecode arrays generated by a compilation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
     * @return JVM bytecodes that represent translet class definition
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
    public byte[][] getBytecodes() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
        final int count = _classes.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
        final byte[][] result = new byte[count][1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
        for (int i = 0; i < count; i++)
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   576
            result[i] = _classes.get(i).toByteArray();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
        return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
     * Compiles a stylesheet pointed to by a URL. The result is put in a
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
     * set of byte arrays. One byte array for each generated class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
     * @param name The name of the translet class to generate
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
     * @param input An InputSource that will pass in the stylesheet contents
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
     * @param outputType The output type
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
     * @return JVM bytecodes that represent translet class definition
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    public byte[][] compile(String name, InputSource input, int outputType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
        _outputType = outputType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
        if (compile(input, name))
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
            return getBytecodes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
     * Compiles a stylesheet pointed to by a URL. The result is put in a
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
     * set of byte arrays. One byte array for each generated class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
     * @param name The name of the translet class to generate
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
     * @param input An InputSource that will pass in the stylesheet contents
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
     * @return JVM bytecodes that represent translet class definition
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
    public byte[][] compile(String name, InputSource input) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
        return compile(name, input, BYTEARRAY_OUTPUT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
     * Set the XMLReader to use for parsing the next input stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
     * @param reader XMLReader (SAX2 parser) to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
    public void setXMLReader(XMLReader reader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        _reader = reader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
     * Get the XMLReader to use for parsing the next input stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
    public XMLReader getXMLReader() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
        return _reader ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
    /**
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   623
     * Get a list of all compile error messages
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   624
     * @return A List containing all compile error messages
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
     */
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   626
    public ArrayList<ErrorMsg> getErrors() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
        return _parser.getErrors();
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
    /**
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   631
     * Get a list of all compile warning messages
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   632
     * @return A List containing all compile error messages
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
     */
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   634
    public ArrayList<ErrorMsg> getWarnings() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
        return _parser.getWarnings();
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
     * Print all compile error messages to standard output
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
    public void printErrors() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
        _parser.printErrors();
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
     * Print all compile warning messages to standard output
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
    public void printWarnings() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
        _parser.printWarnings();
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
     * This method is called by the XPathParser when it encounters a call
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
     * to the document() function. Affects the DOM used by the translet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
    protected void setMultiDocument(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
        _multiDocument = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
    public boolean isMultiDocument() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        return _multiDocument;
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
     * This method is called by the XPathParser when it encounters a call
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
     * to the nodeset() extension function. Implies multi document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
    protected void setCallsNodeset(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        if (flag) setMultiDocument(flag);
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        _callsNodeset = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
    public boolean callsNodeset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        return _callsNodeset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
    protected void setHasIdCall(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        _hasIdCall = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
    public boolean hasIdCall() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        return _hasIdCall;
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
     * Set the class name for the generated translet. This class name is
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
     * overridden if multiple stylesheets are compiled in one go using the
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
     * compile(Vector urls) method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
     * @param className The name to assign to the translet class
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
    public void setClassName(String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
        final String base  = Util.baseName(className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
        final String noext = Util.noExtName(base);
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
        String name  = Util.toJavaName(noext);
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
        if (_packageName == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
            _className = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
            _className = _packageName + '.' + name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
     * Get the class name for the generated translet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
    public String getClassName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
        return _className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
     * Convert for Java class name of local system file name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
     * (Replace '.' with '/' on UNIX and replace '.' by '\' on Windows/DOS.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
    private String classFileName(final String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
        return className.replace('.', File.separatorChar) + ".class";
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
     * Generate an output File object to send the translet to
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
    private File getOutputFile(String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
        if (_destDir != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
            return new File(_destDir, classFileName(className));
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
            return new File(classFileName(className));
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
     * Set the destination directory for the translet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
     * The current working directory will be used by default.
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    public boolean setDestDirectory(String dstDirName) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
        final File dir = new File(dstDirName);
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
   733
        if (SecuritySupport.doesFileExist(dir) || dir.mkdirs()) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
            _destDir = dir;
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
            _destDir = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
     * Set an optional package name for the translet and auxiliary classes
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
    public void setPackageName(String packageName) {
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33349
diff changeset
   747
        _packageName = Objects.requireNonNull(packageName);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
        if (_className != null) setClassName(_className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
     * Set the name of an optional JAR-file to dump the translet and
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
     * auxiliary classes to
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
    public void setJarFileName(String jarFileName) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
        final String JAR_EXT = ".jar";
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
        if (jarFileName.endsWith(JAR_EXT))
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
            _jarFileName = jarFileName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
            _jarFileName = jarFileName + JAR_EXT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        _outputType = JAR_OUTPUT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
    public String getJarFileName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
        return _jarFileName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
     * Set the top-level stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
    public void setStylesheet(Stylesheet stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
        if (_stylesheet == null) _stylesheet = stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
     * Returns the top-level stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
    public Stylesheet getStylesheet() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
        return _stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
     * Registers an attribute and gives it a type so that it can be mapped to
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
     * DOM attribute types at run-time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
    public int registerAttribute(QName name) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   787
        Integer code = _attributes.get(name.toString());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
        if (code == null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   789
            code = _nextGType++;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
            _attributes.put(name.toString(), code);
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
            final String uri = name.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
            final String local = "@"+name.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
            if ((uri != null) && (!uri.equals("")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
                _namesIndex.addElement(uri+":"+local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
                _namesIndex.addElement(local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
            if (name.getLocalPart().equals("*")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
                registerNamespace(name.getNamespace());
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
        return code.intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
     * Registers an element and gives it a type so that it can be mapped to
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
     * DOM element types at run-time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
    public int registerElement(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
        // Register element (full QName)
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   810
        Integer code = _elements.get(name.toString());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
        if (code == null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   812
            _elements.put(name.toString(), code = _nextGType++);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
            _namesIndex.addElement(name.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
        if (name.getLocalPart().equals("*")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
            registerNamespace(name.getNamespace());
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
        return code.intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
     /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
      * Registers a namespace prefix and gives it a type so that it can be mapped to
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
      * DOM namespace types at run-time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
      */
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
    public int registerNamespacePrefix(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   828
    Integer code = _namespacePrefixes.get(name.toString());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
    if (code == null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   830
        code = _nextGType++;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
        _namespacePrefixes.put(name.toString(), code);
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        final String uri = name.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
        if ((uri != null) && (!uri.equals(""))){
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
            // namespace::ext2:ped2 will be made empty in TypedNamespaceIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
            _namesIndex.addElement("?");
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
        } else{
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
           _namesIndex.addElement("?"+name.getLocalPart());
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
    return code.intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
     * Registers a namespace and gives it a type so that it can be mapped to
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
     * DOM namespace types at run-time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
    public int registerNamespace(String namespaceURI) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   848
        Integer code = _namespaces.get(namespaceURI);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
        if (code == null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   850
            code = _nextNSType++;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
            _namespaces.put(namespaceURI,code);
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
            _namespaceIndex.addElement(namespaceURI);
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
        }
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 42247
diff changeset
   854
        return code;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
    public int nextModeSerial() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
        return _modeSerial++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
    public int nextStylesheetSerial() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
        return _stylesheetSerial++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
    public int nextStepPatternSerial() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
        return _stepPatternSerial++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
    public int[] getNumberFieldIndexes() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
        return _numberFieldIndexes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
    public int nextHelperClassSerial() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
        return _helperClassSerial++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
    public int nextAttributeSetSerial() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
        return _attributeSetSerial++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
    public Vector getNamesIndex() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
        return _namesIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
    public Vector getNamespaceIndex() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
        return _namespaceIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
     * Returns a unique name for every helper class needed to
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
     * execute a translet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
    public String getHelperClassName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
        return getClassName() + '$' + _helperClassSerial++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
    public void dumpClass(JavaClass clazz) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
46175
52634f4b683b 8186208: closed/javax/xml/jaxp/transform/cr6657673/CR6657673Test.java: test result: Error. failed to clean up files after test
joehw
parents: 45853
diff changeset
   899
        if (_outputType == BYTEARRAY_AND_FILE_OUTPUT)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
            File outFile = getOutputFile(clazz.getClassName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
            String parentDir = outFile.getParent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
            if (parentDir != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
                File parentFile = new File(parentDir);
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
   905
                if (!SecuritySupport.doesFileExist(parentFile))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
                    parentFile.mkdirs();
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
            switch (_outputType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
            case JAR_OUTPUT:
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   913
                _bcelClasses.add(clazz);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
            case BYTEARRAY_OUTPUT:
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
            case BYTEARRAY_AND_FILE_OUTPUT:
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
            case BYTEARRAY_AND_JAR_OUTPUT:
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
            case CLASSLOADER_OUTPUT:
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
                ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
                clazz.dump(out);
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   921
                _classes.add(out);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
                if (_outputType == BYTEARRAY_AND_FILE_OUTPUT)
46175
52634f4b683b 8186208: closed/javax/xml/jaxp/transform/cr6657673/CR6657673Test.java: test result: Error. failed to clean up files after test
joehw
parents: 45853
diff changeset
   924
                  clazz.dump(getOutputFile(clazz.getClassName()));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
                else if (_outputType == BYTEARRAY_AND_JAR_OUTPUT)
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   926
                  _bcelClasses.add(clazz);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
        catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
            e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
     * File separators are converted to forward slashes for ZIP files.
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
    private String entryName(File f) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
        return f.getName().replace(File.separatorChar, '/');
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
     * Generate output JAR-file and packages
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
    public void outputToJar() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
        // create the manifest
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
        final Manifest manifest = new Manifest();
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
        final java.util.jar.Attributes atrs = manifest.getMainAttributes();
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   950
        atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.2");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   952
        final Map<String, Attributes> map = manifest.getEntries();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
        // create manifest
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
        final String now = (new Date()).toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
        final java.util.jar.Attributes.Name dateAttr =
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
            new java.util.jar.Attributes.Name("Date");
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
        final File jarFile = new File(_destDir, _jarFileName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
        final JarOutputStream jos =
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
            new JarOutputStream(new FileOutputStream(jarFile), manifest);
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   961
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   962
        for (JavaClass clazz : _bcelClasses) {
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   963
            final String className = clazz.getClassName().replace('.', '/');
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   964
            final java.util.jar.Attributes attr = new java.util.jar.Attributes();
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   965
            attr.put(dateAttr, now);
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   966
            map.put(className + ".class", attr);
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39909
diff changeset
   967
            jos.putNextEntry(new JarEntry(className + ".class"));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
            final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
            clazz.dump(out); // dump() closes it's output stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
            out.writeTo(jos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
        jos.close();
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
     * Turn debugging messages on/off
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
    public void setDebug(boolean debug) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
        _debug = debug;
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
     * Get current debugging message setting
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
    public boolean debug() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
        return _debug;
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
     * Retrieve a string representation of the character data to be stored
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
     * in the translet as a <code>char[]</code>.  There may be more than
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
     * one such array required.
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
     * @param index The index of the <code>char[]</code>.  Zero-based.
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
     * @return String The character data to be stored in the corresponding
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
     *               <code>char[]</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
    public String getCharacterData(int index) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
   999
        return (m_characterData.get(index)).toString();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
     * Get the number of char[] arrays, thus far, that will be created to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
     * store literal text in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
    public int getCharacterDataCount() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
        return (m_characterData != null) ? m_characterData.size() : 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
     * Add literal text to char arrays that will be used to store character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
     * data in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
     * @param newData String data to be added to char arrays.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
     *                Pre-condition:  <code>newData.length() &le; 21845</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
     * @return int offset at which character data will be stored
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
    public int addCharacterData(String newData) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1018
        StringBuilder currData;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
        if (m_characterData == null) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1020
            m_characterData = new ArrayList<>();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1021
            currData = new StringBuilder();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1022
            m_characterData.add(currData);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
        } else {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1024
            currData = m_characterData.get(m_characterData.size()-1);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
        // Character data could take up to three-times as much space when
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
        // written to the class file as UTF-8.  The maximum size for a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
        // constant is 65535/3.  If we exceed that,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
        // (We really should use some "bin packing".)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
        if (newData.length() + currData.length() > 21845) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1032
            currData = new StringBuilder();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 36520
diff changeset
  1033
            m_characterData.add(currData);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
        int newDataOffset = currData.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
        currData.append(newData);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
        return newDataOffset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
}