jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12458 d601e4bba306
child 17534 21dc0b2762da
permissions -rw-r--r--
6657673: Issues with JAXP Reviewed-by: alanb, lancea, ahgross, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: Parser.java,v 1.2.4.1 2005/09/13 12:14:32 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.io.File;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import java.io.StringReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import java.util.Dictionary;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import java.util.Hashtable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import java.util.Properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import java.util.Stack;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import java.util.StringTokenizer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.java_cup.internal.runtime.Symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import javax.xml.XMLConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import javax.xml.parsers.ParserConfigurationException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import javax.xml.parsers.SAXParser;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import javax.xml.parsers.SAXParserFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    47
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    48
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import org.xml.sax.Attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import org.xml.sax.helpers.AttributesImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import org.xml.sax.Locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import org.xml.sax.SAXParseException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
import org.xml.sax.XMLReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @author G. Todd Miller
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * @author Erwin Bolwidt <ejb@klomp.org>
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
public class Parser implements Constants, ContentHandler {
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    private static final String XSL = "xsl";            // standard prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    private static final String TRANSLET = "translet"; // extension prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    private Locator _locator = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    private XSLTC _xsltc;             // Reference to the compiler object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private XPathParser _xpathParser; // Reference to the XPath parser.
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    private Vector _errors;           // Contains all compilation errors
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    private Vector _warnings;         // Contains all compilation errors
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    private Hashtable   _instructionClasses; // Maps instructions to classes
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    private Hashtable   _instructionAttrs;;  // reqd and opt attrs
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    private Hashtable   _qNames;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    private Hashtable   _namespaces;
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    private QName       _useAttributeSets;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    private QName       _excludeResultPrefixes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    private QName       _extensionElementPrefixes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    private Hashtable   _variableScope;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    private Stylesheet  _currentStylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    private SymbolTable _symbolTable; // Maps QNames to syntax-tree nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    private Output      _output;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    private Template    _template;    // Reference to the template being parsed.
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    private boolean     _rootNamespaceDef; // Used for validity check
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    private SyntaxTreeNode _root;
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    private String _target;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    private int _currentImportPrecedence;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    98
    private boolean _useServicesMechanism = true;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    99
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   100
    public Parser(XSLTC xsltc, boolean useServicesMechanism) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        _xsltc = xsltc;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   102
        _useServicesMechanism = useServicesMechanism;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    public void init() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        _qNames              = new Hashtable(512);
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        _namespaces          = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        _instructionClasses  = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        _instructionAttrs    = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        _variableScope       = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        _template            = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        _errors              = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        _warnings            = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
        _symbolTable         = new SymbolTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        _xpathParser         = new XPathParser(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        _currentStylesheet   = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
        _output              = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        _root                = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
        _rootNamespaceDef    = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        _currentImportPrecedence = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        initStdClasses();
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        initInstructionAttrs();
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        initExtClasses();
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        initSymbolTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        _useAttributeSets =
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            getQName(XSLT_URI, XSL, "use-attribute-sets");
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
        _excludeResultPrefixes =
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            getQName(XSLT_URI, XSL, "exclude-result-prefixes");
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
        _extensionElementPrefixes =
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
            getQName(XSLT_URI, XSL, "extension-element-prefixes");
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    public void setOutput(Output output) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        if (_output != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            if (_output.getImportPrecedence() <= output.getImportPrecedence()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                String cdata = _output.getCdata();
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                output.mergeOutput(_output);
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                _output.disable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                _output = output;
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                output.disable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            _output = output;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    public Output getOutput() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        return _output;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    public Properties getOutputProperties() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        return getTopLevelStylesheet().getOutputProperties();
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    public void addVariable(Variable var) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        addVariableOrParam(var);
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    public void addParameter(Param param) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
        addVariableOrParam(param);
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
    private void addVariableOrParam(VariableBase var) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        Object existing = _variableScope.get(var.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        if (existing != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
            if (existing instanceof Stack) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                Stack stack = (Stack)existing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
                stack.push(var);
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
            else if (existing instanceof VariableBase) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
                Stack stack = new Stack();
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
                stack.push(existing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
                stack.push(var);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
                _variableScope.put(var.getName(), stack);
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            _variableScope.put(var.getName(), var);
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
    public void removeVariable(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
        Object existing = _variableScope.get(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        if (existing instanceof Stack) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            Stack stack = (Stack)existing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            if (!stack.isEmpty()) stack.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
            if (!stack.isEmpty()) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        _variableScope.remove(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    public VariableBase lookupVariable(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        Object existing = _variableScope.get(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
        if (existing instanceof VariableBase) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
            return((VariableBase)existing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        else if (existing instanceof Stack) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            Stack stack = (Stack)existing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
            return((VariableBase)stack.peek());
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        return(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    public void setXSLTC(XSLTC xsltc) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        _xsltc = xsltc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    public XSLTC getXSLTC() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
        return _xsltc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    public int getCurrentImportPrecedence() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        return _currentImportPrecedence;
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    public int getNextImportPrecedence() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
        return ++_currentImportPrecedence;
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    public void setCurrentStylesheet(Stylesheet stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        _currentStylesheet = stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
    public Stylesheet getCurrentStylesheet() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        return _currentStylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    public Stylesheet getTopLevelStylesheet() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        return _xsltc.getStylesheet();
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    public QName getQNameSafe(final String stringRep) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
        // parse and retrieve namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        final int colon = stringRep.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        if (colon != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            final String prefix = stringRep.substring(0, colon);
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
            final String localname = stringRep.substring(colon + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            String namespace = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            // Get the namespace uri from the symbol table
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
            if (prefix.equals(XMLNS_PREFIX) == false) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                namespace = _symbolTable.lookupNamespace(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                if (namespace == null) namespace = EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
            return getQName(namespace, prefix, localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
            final String uri = stringRep.equals(XMLNS_PREFIX) ? null
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                : _symbolTable.lookupNamespace(EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            return getQName(uri, null, stringRep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
    public QName getQName(final String stringRep) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        return getQName(stringRep, true, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    public QName getQNameIgnoreDefaultNs(final String stringRep) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        return getQName(stringRep, true, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    public QName getQName(final String stringRep, boolean reportError) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        return getQName(stringRep, reportError, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    private QName getQName(final String stringRep, boolean reportError,
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        boolean ignoreDefaultNs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        // parse and retrieve namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        final int colon = stringRep.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        if (colon != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            final String prefix = stringRep.substring(0, colon);
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
            final String localname = stringRep.substring(colon + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
            String namespace = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
            // Get the namespace uri from the symbol table
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
            if (prefix.equals(XMLNS_PREFIX) == false) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
                namespace = _symbolTable.lookupNamespace(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
                if (namespace == null && reportError) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
                    final int line = getLineNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
                    ErrorMsg err = new ErrorMsg(ErrorMsg.NAMESPACE_UNDEF_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
                                                line, prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                    reportError(ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
            return getQName(namespace, prefix, localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
            if (stringRep.equals(XMLNS_PREFIX)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                ignoreDefaultNs = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
            final String defURI = ignoreDefaultNs ? null
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                                  : _symbolTable.lookupNamespace(EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
            return getQName(defURI, null, stringRep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
    public QName getQName(String namespace, String prefix, String localname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        if (namespace == null || namespace.equals(EMPTYSTRING)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
            QName name = (QName)_qNames.get(localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            if (name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
                name = new QName(null, prefix, localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
                _qNames.put(localname, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
            return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
            Dictionary space = (Dictionary)_namespaces.get(namespace);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   314
            String lexicalQName =
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   315
                       (prefix == null || prefix.length() == 0)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   316
                            ? localname
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   317
                            : (prefix + ':' + localname);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   318
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            if (space == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                final QName name = new QName(namespace, prefix, localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
                _namespaces.put(namespace, space = new Hashtable());
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   322
                space.put(lexicalQName, name);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            else {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   326
                QName name = (QName)space.get(lexicalQName);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
                if (name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
                    name = new QName(namespace, prefix, localname);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   329
                    space.put(lexicalQName, name);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    public QName getQName(String scope, String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        return getQName(scope + name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
    public QName getQName(QName scope, QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
        return getQName(scope.toString() + name.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
    public QName getUseAttributeSets() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        return _useAttributeSets;
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
    public QName getExtensionElementPrefixes() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        return _extensionElementPrefixes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    public QName getExcludeResultPrefixes() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
        return _excludeResultPrefixes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
     * Create an instance of the <code>Stylesheet</code> class,
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
     * and then parse, typecheck and compile the instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * Must be called after <code>parse()</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
    public Stylesheet makeStylesheet(SyntaxTreeNode element)
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        throws CompilerException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
            Stylesheet stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
            if (element instanceof Stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
                stylesheet = (Stylesheet)element;
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
                stylesheet = new Stylesheet();
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
                stylesheet.setSimplified();
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
                stylesheet.addElement(element);
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
                stylesheet.setAttributes((AttributesImpl) element.getAttributes());
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
                // Map the default NS if not already defined
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                if (element.lookupNamespace(EMPTYSTRING) == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                    element.addPrefixMapping(EMPTYSTRING, EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
            stylesheet.setParser(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
            return stylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        catch (ClassCastException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
            ErrorMsg err = new ErrorMsg(ErrorMsg.NOT_STYLESHEET_ERR, element);
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
            throw new CompilerException(err.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
     * Instanciates a SAX2 parser and generate the AST from the input.
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    public void createAST(Stylesheet stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
            if (stylesheet != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
                stylesheet.parseContents(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
                final int precedence = stylesheet.getImportPrecedence();
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
                final Enumeration elements = stylesheet.elements();
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                while (elements.hasMoreElements()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
                    Object child = elements.nextElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
                    if (child instanceof Text) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
                        final int l = getLineNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
                        ErrorMsg err =
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
                            new ErrorMsg(ErrorMsg.ILLEGAL_TEXT_NODE_ERR,l,null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
                        reportError(ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
                if (!errorsFound()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
                    stylesheet.typeCheck(_symbolTable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        catch (TypeCheckError e) {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   413
            reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
     * Parses a stylesheet and builds the internal abstract syntax tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
     * @param reader A SAX2 SAXReader (parser)
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
     * @param input A SAX2 InputSource can be passed to a SAX reader
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
     * @return The root of the abstract syntax tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
    public SyntaxTreeNode parse(XMLReader reader, InputSource input) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
            // Parse the input document and build the abstract syntax tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            reader.setContentHandler(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            reader.parse(input);
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            // Find the start of the stylesheet within the tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
            return (SyntaxTreeNode)getStylesheet(_root);
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        catch (IOException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
            if (_xsltc.debug()) e.printStackTrace();
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   433
            reportError(ERROR,new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        catch (SAXException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
            Throwable ex = e.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
            if (_xsltc.debug()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
                e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
                if (ex != null) ex.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
            }
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   441
            reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
        catch (CompilerException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
            if (_xsltc.debug()) e.printStackTrace();
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   445
            reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
        catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
            if (_xsltc.debug()) e.printStackTrace();
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   449
            reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
     * Parses a stylesheet and builds the internal abstract syntax tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
     * @param input A SAX2 InputSource can be passed to a SAX reader
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
     * @return The root of the abstract syntax tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
    public SyntaxTreeNode parse(InputSource input) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
            // Create a SAX parser and get the XMLReader object it uses
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   462
            final SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
            if (_xsltc.isSecureProcessing()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
                try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
                    factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
                catch (SAXException e) {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
                factory.setFeature(Constants.NAMESPACE_FEATURE,true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
            catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
                factory.setNamespaceAware(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
            final SAXParser parser = factory.newSAXParser();
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
            final XMLReader reader = parser.getXMLReader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
            return(parse(reader, input));
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
        catch (ParserConfigurationException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
            ErrorMsg err = new ErrorMsg(ErrorMsg.SAX_PARSER_CONFIG_ERR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
            reportError(ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
        catch (SAXParseException e){
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
            reportError(ERROR, new ErrorMsg(e.getMessage(),e.getLineNumber()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
        catch (SAXException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            reportError(ERROR, new ErrorMsg(e.getMessage()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
    public SyntaxTreeNode getDocumentRoot() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
        return _root;
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
    private String _PImedia = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
    private String _PItitle = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
    private String _PIcharset = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
     * Set the parameters to use to locate the correct <?xml-stylesheet ...?>
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
     * processing instruction in the case where the input document is an
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
     * XML document with one or more references to a stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
     * @param media The media attribute to be matched. May be null, in which
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
     * case the prefered templates will be used (i.e. alternate = no).
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
     * @param title The value of the title attribute to match. May be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
     * @param charset The value of the charset attribute to match. May be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
    protected void setPIParameters(String media, String title, String charset) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
        _PImedia = media;
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
        _PItitle = title;
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
        _PIcharset = charset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
     * Extracts the DOM for the stylesheet. In the case of an embedded
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
     * stylesheet, it extracts the DOM subtree corresponding to the
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
     * embedded stylesheet that has an 'id' attribute whose value is the
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
     * same as the value declared in the <?xml-stylesheet...?> processing
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
     * instruction (P.I.). In the xml-stylesheet P.I. the value is labeled
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
     * as the 'href' data of the P.I. The extracted DOM representing the
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
     * stylesheet is returned as an Element object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
    private SyntaxTreeNode getStylesheet(SyntaxTreeNode root)
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
        throws CompilerException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
        // Assume that this is a pure XSL stylesheet if there is not
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
        // <?xml-stylesheet ....?> processing instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
        if (_target == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
            if (!_rootNamespaceDef) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
                ErrorMsg msg = new ErrorMsg(ErrorMsg.MISSING_XSLT_URI_ERR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
                throw new CompilerException(msg.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
            return(root);
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
        // Find the xsl:stylesheet or xsl:transform with this reference
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
        if (_target.charAt(0) == '#') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
            SyntaxTreeNode element = findStylesheet(root, _target.substring(1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
            if (element == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                ErrorMsg msg = new ErrorMsg(ErrorMsg.MISSING_XSLT_TARGET_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
                                            _target, root);
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                throw new CompilerException(msg.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
            return(element);
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
            return(loadExternalStylesheet(_target));
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
     * Find a Stylesheet element with a specific ID attribute value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
     * This method is used to find a Stylesheet node that is referred
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
     * in a <?xml-stylesheet ... ?> processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
    private SyntaxTreeNode findStylesheet(SyntaxTreeNode root, String href) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
        if (root == null) return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
        if (root instanceof Stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
            String id = root.getAttribute("id");
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
            if (id.equals(href)) return root;
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
        Vector children = root.getContents();
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
        if (children != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
            final int count = children.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
            for (int i = 0; i < count; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                SyntaxTreeNode child = (SyntaxTreeNode)children.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
                SyntaxTreeNode node = findStylesheet(child, href);
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
                if (node != null) return node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
     * For embedded stylesheets: Load an external file with stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
    private SyntaxTreeNode loadExternalStylesheet(String location)
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
        throws CompilerException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
        InputSource source;
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
        // Check if the location is URL or a local file
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
        if ((new File(location)).exists())
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
            source = new InputSource("file:"+location);
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
            source = new InputSource(location);
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
        SyntaxTreeNode external = (SyntaxTreeNode)parse(source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
        return(external);
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
    private void initAttrTable(String elementName, String[] attrs) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
        _instructionAttrs.put(getQName(XSLT_URI, XSL, elementName),
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
                                attrs);
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
    private void initInstructionAttrs() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
        initAttrTable("template",
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
            new String[] {"match", "name", "priority", "mode"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
        initAttrTable("stylesheet",
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
            new String[] {"id", "version", "extension-element-prefixes",
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
                "exclude-result-prefixes"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        initAttrTable("transform",
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
            new String[] {"id", "version", "extension-element-prefixes",
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
                "exclude-result-prefixes"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
        initAttrTable("text", new String[] {"disable-output-escaping"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        initAttrTable("if", new String[] {"test"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
        initAttrTable("choose", new String[] {});
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
        initAttrTable("when", new String[] {"test"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
        initAttrTable("otherwise", new String[] {});
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        initAttrTable("for-each", new String[] {"select"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
        initAttrTable("message", new String[] {"terminate"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
        initAttrTable("number",
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
            new String[] {"level", "count", "from", "value", "format", "lang",
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
                "letter-value", "grouping-separator", "grouping-size"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
                initAttrTable("comment", new String[] {});
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
        initAttrTable("copy", new String[] {"use-attribute-sets"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
        initAttrTable("copy-of", new String[] {"select"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
        initAttrTable("param", new String[] {"name", "select"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
        initAttrTable("with-param", new String[] {"name", "select"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
        initAttrTable("variable", new String[] {"name", "select"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
        initAttrTable("output",
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
            new String[] {"method", "version", "encoding",
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
                "omit-xml-declaration", "standalone", "doctype-public",
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
                "doctype-system", "cdata-section-elements", "indent",
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
                "media-type"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
        initAttrTable("sort",
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
           new String[] {"select", "order", "case-order", "lang", "data-type"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
        initAttrTable("key", new String[] {"name", "match", "use"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
        initAttrTable("fallback", new String[] {});
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
        initAttrTable("attribute", new String[] {"name", "namespace"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
        initAttrTable("attribute-set",
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
            new String[] {"name", "use-attribute-sets"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
        initAttrTable("value-of",
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
            new String[] {"select", "disable-output-escaping"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
        initAttrTable("element",
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
            new String[] {"name", "namespace", "use-attribute-sets"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
        initAttrTable("call-template", new String[] {"name"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
        initAttrTable("apply-templates", new String[] {"select", "mode"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
        initAttrTable("apply-imports", new String[] {});
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
        initAttrTable("decimal-format",
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
            new String[] {"name", "decimal-separator", "grouping-separator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
                "infinity", "minus-sign", "NaN", "percent", "per-mille",
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
                "zero-digit", "digit", "pattern-separator"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
        initAttrTable("import", new String[] {"href"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
        initAttrTable("include", new String[] {"href"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
        initAttrTable("strip-space", new String[] {"elements"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
        initAttrTable("preserve-space", new String[] {"elements"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        initAttrTable("processing-instruction", new String[] {"name"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        initAttrTable("namespace-alias",
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
           new String[] {"stylesheet-prefix", "result-prefix"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
     * Initialize the _instructionClasses Hashtable, which maps XSL element
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
     * names to Java classes in this package.
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
    private void initStdClasses() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
        initStdClass("template", "Template");
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        initStdClass("stylesheet", "Stylesheet");
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        initStdClass("transform", "Stylesheet");
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        initStdClass("text", "Text");
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        initStdClass("if", "If");
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
        initStdClass("choose", "Choose");
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
        initStdClass("when", "When");
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        initStdClass("otherwise", "Otherwise");
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        initStdClass("for-each", "ForEach");
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
        initStdClass("message", "Message");
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
        initStdClass("number", "Number");
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
        initStdClass("comment", "Comment");
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        initStdClass("copy", "Copy");
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
        initStdClass("copy-of", "CopyOf");
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
        initStdClass("param", "Param");
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
        initStdClass("with-param", "WithParam");
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        initStdClass("variable", "Variable");
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
        initStdClass("output", "Output");
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
        initStdClass("sort", "Sort");
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
        initStdClass("key", "Key");
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
        initStdClass("fallback", "Fallback");
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
        initStdClass("attribute", "XslAttribute");
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
        initStdClass("attribute-set", "AttributeSet");
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
        initStdClass("value-of", "ValueOf");
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
        initStdClass("element", "XslElement");
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
        initStdClass("call-template", "CallTemplate");
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
        initStdClass("apply-templates", "ApplyTemplates");
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
        initStdClass("apply-imports", "ApplyImports");
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
        initStdClass("decimal-format", "DecimalFormatting");
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
        initStdClass("import", "Import");
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
        initStdClass("include", "Include");
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
        initStdClass("strip-space", "Whitespace");
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
        initStdClass("preserve-space", "Whitespace");
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
        initStdClass("processing-instruction", "ProcessingInstruction");
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
        initStdClass("namespace-alias", "NamespaceAlias");
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
    private void initStdClass(String elementName, String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        _instructionClasses.put(getQName(XSLT_URI, XSL, elementName),
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
                                COMPILER_PACKAGE + '.' + className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
    public boolean elementSupported(String namespace, String localName) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
        return(_instructionClasses.get(getQName(namespace, XSL, localName)) != null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
    public boolean functionSupported(String fname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
        return(_symbolTable.lookupPrimop(fname) != null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
    private void initExtClasses() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
        initExtClass("output", "TransletOutput");
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
        initExtClass(REDIRECT_URI, "write", "TransletOutput");
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
    private void initExtClass(String elementName, String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
        _instructionClasses.put(getQName(TRANSLET_URI, TRANSLET, elementName),
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
                                COMPILER_PACKAGE + '.' + className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
    private void initExtClass(String namespace, String elementName, String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
        _instructionClasses.put(getQName(namespace, TRANSLET, elementName),
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
                                COMPILER_PACKAGE + '.' + className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
     * Add primops and base functions to the symbol table.
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
    private void initSymbolTable() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
        MethodType I_V  = new MethodType(Type.Int, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
        MethodType I_R  = new MethodType(Type.Int, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
        MethodType I_S  = new MethodType(Type.Int, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
        MethodType I_D  = new MethodType(Type.Int, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
        MethodType R_I  = new MethodType(Type.Real, Type.Int);
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
        MethodType R_V  = new MethodType(Type.Real, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
        MethodType R_R  = new MethodType(Type.Real, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
        MethodType R_D  = new MethodType(Type.Real, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
        MethodType R_O  = new MethodType(Type.Real, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
        MethodType I_I  = new MethodType(Type.Int, Type.Int);
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
        MethodType D_O  = new MethodType(Type.NodeSet, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
        MethodType D_V  = new MethodType(Type.NodeSet, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
        MethodType D_S  = new MethodType(Type.NodeSet, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
        MethodType D_D  = new MethodType(Type.NodeSet, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
        MethodType A_V  = new MethodType(Type.Node, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
        MethodType S_V  = new MethodType(Type.String, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
        MethodType S_S  = new MethodType(Type.String, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
        MethodType S_A  = new MethodType(Type.String, Type.Node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
        MethodType S_D  = new MethodType(Type.String, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
        MethodType S_O  = new MethodType(Type.String, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
        MethodType B_O  = new MethodType(Type.Boolean, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
        MethodType B_V  = new MethodType(Type.Boolean, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
        MethodType B_B  = new MethodType(Type.Boolean, Type.Boolean);
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
        MethodType B_S  = new MethodType(Type.Boolean, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
        MethodType D_X  = new MethodType(Type.NodeSet, Type.Object);
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
        MethodType R_RR = new MethodType(Type.Real, Type.Real, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        MethodType I_II = new MethodType(Type.Int, Type.Int, Type.Int);
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
        MethodType B_RR = new MethodType(Type.Boolean, Type.Real, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
        MethodType B_II = new MethodType(Type.Boolean, Type.Int, Type.Int);
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
        MethodType S_SS = new MethodType(Type.String, Type.String, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
        MethodType S_DS = new MethodType(Type.String, Type.Real, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
        MethodType S_SR = new MethodType(Type.String, Type.String, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
        MethodType O_SO = new MethodType(Type.Reference, Type.String, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
        MethodType D_SS =
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
            new MethodType(Type.NodeSet, Type.String, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
        MethodType D_SD =
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
            new MethodType(Type.NodeSet, Type.String, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
        MethodType B_BB =
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
            new MethodType(Type.Boolean, Type.Boolean, Type.Boolean);
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
        MethodType B_SS =
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
            new MethodType(Type.Boolean, Type.String, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
        MethodType S_SD =
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
            new MethodType(Type.String, Type.String, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
        MethodType S_DSS =
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
            new MethodType(Type.String, Type.Real, Type.String, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
        MethodType S_SRR =
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
            new MethodType(Type.String, Type.String, Type.Real, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
        MethodType S_SSS =
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
            new MethodType(Type.String, Type.String, Type.String, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
         * Standard functions: implemented but not in this table concat().
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
         * When adding a new function make sure to uncomment
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
         * the corresponding line in <tt>FunctionAvailableCall</tt>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
        // The following functions are inlined
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
        _symbolTable.addPrimop("current", A_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
        _symbolTable.addPrimop("last", I_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
        _symbolTable.addPrimop("position", I_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
        _symbolTable.addPrimop("true", B_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
        _symbolTable.addPrimop("false", B_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
        _symbolTable.addPrimop("not", B_B);
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        _symbolTable.addPrimop("name", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
        _symbolTable.addPrimop("name", S_A);
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
        _symbolTable.addPrimop("generate-id", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        _symbolTable.addPrimop("generate-id", S_A);
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
        _symbolTable.addPrimop("ceiling", R_R);
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
        _symbolTable.addPrimop("floor", R_R);
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
        _symbolTable.addPrimop("round", R_R);
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
        _symbolTable.addPrimop("contains", B_SS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
        _symbolTable.addPrimop("number", R_O);
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
        _symbolTable.addPrimop("number", R_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
        _symbolTable.addPrimop("boolean", B_O);
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
        _symbolTable.addPrimop("string", S_O);
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
        _symbolTable.addPrimop("string", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
        _symbolTable.addPrimop("translate", S_SSS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
        _symbolTable.addPrimop("string-length", I_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
        _symbolTable.addPrimop("string-length", I_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
        _symbolTable.addPrimop("starts-with", B_SS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
        _symbolTable.addPrimop("format-number", S_DS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
        _symbolTable.addPrimop("format-number", S_DSS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
        _symbolTable.addPrimop("unparsed-entity-uri", S_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
        _symbolTable.addPrimop("key", D_SS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
        _symbolTable.addPrimop("key", D_SD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
        _symbolTable.addPrimop("id", D_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
        _symbolTable.addPrimop("id", D_D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
        _symbolTable.addPrimop("namespace-uri", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
        _symbolTable.addPrimop("function-available", B_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
        _symbolTable.addPrimop("element-available", B_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
        _symbolTable.addPrimop("document", D_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
        _symbolTable.addPrimop("document", D_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
        // The following functions are implemented in the basis library
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
        _symbolTable.addPrimop("count", I_D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        _symbolTable.addPrimop("sum", R_D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
        _symbolTable.addPrimop("local-name", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
        _symbolTable.addPrimop("local-name", S_D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
        _symbolTable.addPrimop("namespace-uri", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
        _symbolTable.addPrimop("namespace-uri", S_D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
        _symbolTable.addPrimop("substring", S_SR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
        _symbolTable.addPrimop("substring", S_SRR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
        _symbolTable.addPrimop("substring-after", S_SS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
        _symbolTable.addPrimop("substring-before", S_SS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
        _symbolTable.addPrimop("normalize-space", S_V);
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
        _symbolTable.addPrimop("normalize-space", S_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
        _symbolTable.addPrimop("system-property", S_S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
        // Extensions
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
        _symbolTable.addPrimop("nodeset", D_O);
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
        _symbolTable.addPrimop("objectType", S_O);
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
        _symbolTable.addPrimop("cast", O_SO);
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
        // Operators +, -, *, /, % defined on real types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
        _symbolTable.addPrimop("+", R_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
        _symbolTable.addPrimop("-", R_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
        _symbolTable.addPrimop("*", R_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
        _symbolTable.addPrimop("/", R_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
        _symbolTable.addPrimop("%", R_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
        // Operators +, -, * defined on integer types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
        // Operators / and % are not  defined on integers (may cause exception)
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
        _symbolTable.addPrimop("+", I_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
        _symbolTable.addPrimop("-", I_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
        _symbolTable.addPrimop("*", I_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
         // Operators <, <= >, >= defined on real types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
        _symbolTable.addPrimop("<",  B_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
        _symbolTable.addPrimop("<=", B_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
        _symbolTable.addPrimop(">",  B_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
        _symbolTable.addPrimop(">=", B_RR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
        // Operators <, <= >, >= defined on int types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
        _symbolTable.addPrimop("<",  B_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
        _symbolTable.addPrimop("<=", B_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
        _symbolTable.addPrimop(">",  B_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
        _symbolTable.addPrimop(">=", B_II);
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
        // Operators <, <= >, >= defined on boolean types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
        _symbolTable.addPrimop("<",  B_BB);
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
        _symbolTable.addPrimop("<=", B_BB);
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
        _symbolTable.addPrimop(">",  B_BB);
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
        _symbolTable.addPrimop(">=", B_BB);
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
        // Operators 'and' and 'or'.
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
        _symbolTable.addPrimop("or", B_BB);
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
        _symbolTable.addPrimop("and", B_BB);
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
        // Unary minus.
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
        _symbolTable.addPrimop("u-", R_R);
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
        _symbolTable.addPrimop("u-", I_I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
    public SymbolTable getSymbolTable() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
        return _symbolTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
    public Template getTemplate() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
        return _template;
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
    public void setTemplate(Template template) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
        _template = template;
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
    private int _templateIndex = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
    public int getTemplateIndex() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
        return(_templateIndex++);
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
     * Creates a new node in the abstract syntax tree. This node can be
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
     *  o) a supported XSLT 1.0 element
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
     *  o) an unsupported XSLT element (post 1.0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
     *  o) a supported XSLT extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
     *  o) an unsupported XSLT extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
     *  o) a literal result element (not an XSLT element and not an extension)
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
     * Unsupported elements do not directly generate an error. We have to wait
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
     * until we have received all child elements of an unsupported element to
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
     * see if any <xsl:fallback> elements exist.
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
    private boolean versionIsOne = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
    public SyntaxTreeNode makeInstance(String uri, String prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
        String local, Attributes attributes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        SyntaxTreeNode node = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
        QName  qname = getQName(uri, prefix, local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
        String className = (String)_instructionClasses.get(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        if (className != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
            try {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   931
                final Class clazz = ObjectFactory.findProviderClass(className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
                node = (SyntaxTreeNode)clazz.newInstance();
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
                node.setQName(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
                node.setParser(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
                if (_locator != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
                    node.setLineNumber(getLineNumber());
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
                if (node instanceof Stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
                    _xsltc.setStylesheet((Stylesheet)node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
                checkForSuperfluousAttributes(node, attributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
            catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
                ErrorMsg err = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
                reportError(ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
            catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
                ErrorMsg err = new ErrorMsg(ErrorMsg.INTERNAL_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
                                            e.getMessage(), node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
                reportError(FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
            if (uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
                // Check if the element belongs in our namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
                if (uri.equals(XSLT_URI)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
                    node = new UnsupportedElement(uri, prefix, local, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
                    UnsupportedElement element = (UnsupportedElement)node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
                    ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_XSL_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
                                                getLineNumber(),local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
                    element.setErrorMessage(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
                    if (versionIsOne) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
                        reportError(UNSUPPORTED,msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
                // Check if this is an XSLTC extension element
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
                else if (uri.equals(TRANSLET_URI)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
                    node = new UnsupportedElement(uri, prefix, local, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
                    UnsupportedElement element = (UnsupportedElement)node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
                    ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
                                                getLineNumber(),local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
                    element.setErrorMessage(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
                // Check if this is an extension of some other XSLT processor
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
                    Stylesheet sheet = _xsltc.getStylesheet();
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
                    if ((sheet != null) && (sheet.isExtension(uri))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
                        if (sheet != (SyntaxTreeNode)_parentStack.peek()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
                            node = new UnsupportedElement(uri, prefix, local, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
                            UnsupportedElement elem = (UnsupportedElement)node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
                            ErrorMsg msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
                                new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
                                             getLineNumber(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
                                             prefix+":"+local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
                            elem.setErrorMessage(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
                        }
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
            if (node == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
                node = new LiteralElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
                node.setLineNumber(getLineNumber());
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
        if ((node != null) && (node instanceof LiteralElement)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
            ((LiteralElement)node).setQName(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
        return(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
     * checks the list of attributes against a list of allowed attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
     * for a particular element node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
    private void checkForSuperfluousAttributes(SyntaxTreeNode node,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
        Attributes attrs)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
        QName qname = node.getQName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
        boolean isStylesheet = (node instanceof Stylesheet);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
        String[] legal = (String[]) _instructionAttrs.get(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
        if (versionIsOne && legal != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
            int j;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
            final int n = attrs.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
                final String attrQName = attrs.getQName(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
                if (isStylesheet && attrQName.equals("version")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
                    versionIsOne = attrs.getValue(i).equals("1.0");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
                // Ignore if special or if it has a prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
                if (attrQName.startsWith("xml") ||
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
                    attrQName.indexOf(':') > 0) continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
                for (j = 0; j < legal.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
                    if (attrQName.equalsIgnoreCase(legal[j])) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
                if (j == legal.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
                    final ErrorMsg err =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
                        new ErrorMsg(ErrorMsg.ILLEGAL_ATTRIBUTE_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
                                attrQName, node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
                    // Workaround for the TCK failure ErrorListener.errorTests.error001..
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
                    err.setWarningError(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
                    reportError(WARNING, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
     * Parse an XPath expression:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
     *  @param parent - XSL element where the expression occured
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
     *  @param exp    - textual representation of the expression
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
    public Expression parseExpression(SyntaxTreeNode parent, String exp) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
        return (Expression)parseTopLevel(parent, "<EXPRESSION>"+exp, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
     * Parse an XPath expression:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
     *  @param parent - XSL element where the expression occured
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
     *  @param attr   - name of this element's attribute to get expression from
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
     *  @param def    - default expression (if the attribute was not found)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
    public Expression parseExpression(SyntaxTreeNode parent,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
                                      String attr, String def) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
        // Get the textual representation of the expression (if any)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
        String exp = parent.getAttribute(attr);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
        // Use the default expression if none was found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
        if ((exp.length() == 0) && (def != null)) exp = def;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
        // Invoke the XPath parser
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
        return (Expression)parseTopLevel(parent, "<EXPRESSION>"+exp, exp);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
     * Parse an XPath pattern:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
     *  @param parent  - XSL element where the pattern occured
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
     *  @param pattern - textual representation of the pattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
    public Pattern parsePattern(SyntaxTreeNode parent, String pattern) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
        return (Pattern)parseTopLevel(parent, "<PATTERN>"+pattern, pattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
     * Parse an XPath pattern:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
     *  @param parent - XSL element where the pattern occured
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
     *  @param attr   - name of this element's attribute to get pattern from
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
     *  @param def    - default pattern (if the attribute was not found)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
    public Pattern parsePattern(SyntaxTreeNode parent,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
                                String attr, String def) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
        // Get the textual representation of the pattern (if any)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
        String pattern = parent.getAttribute(attr);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
        // Use the default pattern if none was found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
        if ((pattern.length() == 0) && (def != null)) pattern = def;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
        // Invoke the XPath parser
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
        return (Pattern)parseTopLevel(parent, "<PATTERN>"+pattern, pattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
     * Parse an XPath expression or pattern using the generated XPathParser
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
     * The method will return a Dummy node if the XPath parser fails.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
    private SyntaxTreeNode parseTopLevel(SyntaxTreeNode parent, String text,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
                                         String expression) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
        int line = getLineNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
            _xpathParser.setScanner(new XPathLexer(new StringReader(text)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
            Symbol result = _xpathParser.parse(expression, line);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
            if (result != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
                final SyntaxTreeNode node = (SyntaxTreeNode)result.value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
                if (node != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
                    node.setParser(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
                    node.setParent(parent);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
                    node.setLineNumber(line);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
// System.out.println("e = " + text + " " + node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
                    return node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
            reportError(ERROR, new ErrorMsg(ErrorMsg.XPATH_PARSER_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
                                            expression, parent));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
        catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
            if (_xsltc.debug()) e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
            reportError(ERROR, new ErrorMsg(ErrorMsg.XPATH_PARSER_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
                                            expression, parent));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
        // Return a dummy pattern (which is an expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
        SyntaxTreeNode.Dummy.setParser(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
        return SyntaxTreeNode.Dummy;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
    /************************ ERROR HANDLING SECTION ************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
     * Returns true if there were any errors during compilation
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
    public boolean errorsFound() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
        return _errors.size() > 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
     * Prints all compile-time errors
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
    public void printErrors() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
        final int size = _errors.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
        if (size > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
            System.err.println(new ErrorMsg(ErrorMsg.COMPILER_ERROR_KEY));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
            for (int i = 0; i < size; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
                System.err.println("  " + _errors.elementAt(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
     * Prints all compile-time warnings
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
    public void printWarnings() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
        final int size = _warnings.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
        if (size > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
            System.err.println(new ErrorMsg(ErrorMsg.COMPILER_WARNING_KEY));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
            for (int i = 0; i < size; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
                System.err.println("  " + _warnings.elementAt(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
     * Common error/warning message handler
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
    public void reportError(final int category, final ErrorMsg error) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
        switch (category) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
        case Constants.INTERNAL:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
            // Unexpected internal errors, such as null-ptr exceptions, etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
            // Immediately terminates compilation, no translet produced
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
            _errors.addElement(error);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
        case Constants.UNSUPPORTED:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
            // XSLT elements that are not implemented and unsupported ext.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
            // Immediately terminates compilation, no translet produced
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
            _errors.addElement(error);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
        case Constants.FATAL:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
            // Fatal error in the stylesheet input (parsing or content)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
            // Immediately terminates compilation, no translet produced
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
            _errors.addElement(error);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
        case Constants.ERROR:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
            // Other error in the stylesheet input (parsing or content)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
            // Does not terminate compilation, no translet produced
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
            _errors.addElement(error);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
        case Constants.WARNING:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
            // Other error in the stylesheet input (content errors only)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
            // Does not terminate compilation, a translet is produced
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
            _warnings.addElement(error);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
    public Vector getErrors() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
        return _errors;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
    public Vector getWarnings() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
        return _warnings;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
    /************************ SAX2 ContentHandler INTERFACE *****************/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
    private Stack _parentStack = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
    private Hashtable _prefixMapping = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
     * SAX2: Receive notification of the beginning of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
    public void startDocument() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
        _root = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
        _target = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
        _prefixMapping = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
        _parentStack = new Stack();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
     * SAX2: Receive notification of the end of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
    public void endDocument() { }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
     * SAX2: Begin the scope of a prefix-URI Namespace mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
     *       This has to be passed on to the symbol table!
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
    public void startPrefixMapping(String prefix, String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
        if (_prefixMapping == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
            _prefixMapping = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
        _prefixMapping.put(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
     * SAX2: End the scope of a prefix-URI Namespace mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
     *       This has to be passed on to the symbol table!
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
    public void endPrefixMapping(String prefix) { }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
     * SAX2: Receive notification of the beginning of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
     *       The parser may re-use the attribute list that we're passed so
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
     *       we clone the attributes in our own Attributes implementation
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
    public void startElement(String uri, String localname,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
                             String qname, Attributes attributes)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
        throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
        final int col = qname.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
        final String prefix = (col == -1) ? null : qname.substring(0, col);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
        SyntaxTreeNode element = makeInstance(uri, prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
                                        localname, attributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
        if (element == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
            ErrorMsg err = new ErrorMsg(ErrorMsg.ELEMENT_PARSE_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
                                        prefix+':'+localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
            throw new SAXException(err.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
        // If this is the root element of the XML document we need to make sure
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
        // that it contains a definition of the XSL namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
        if (_root == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
            if ((_prefixMapping == null) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
                (_prefixMapping.containsValue(Constants.XSLT_URI) == false))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
                _rootNamespaceDef = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
                _rootNamespaceDef = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
            _root = element;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
            SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
            parent.addElement(element);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
            element.setParent(parent);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
        element.setAttributes(new AttributesImpl(attributes));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
        element.setPrefixMapping(_prefixMapping);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
        if (element instanceof Stylesheet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
            // Extension elements and excluded elements have to be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
            // handled at this point in order to correctly generate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
            // Fallback elements from <xsl:fallback>s.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
            getSymbolTable().setCurrentNode(element);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1285
            ((Stylesheet)element).declareExtensionPrefixes(this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
        _prefixMapping = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
        _parentStack.push(element);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
     * SAX2: Receive notification of the end of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
    public void endElement(String uri, String localname, String qname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
        _parentStack.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
     * SAX2: Receive notification of character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
    public void characters(char[] ch, int start, int length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
        String string = new String(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
        SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
        if (string.length() == 0) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
        // If this text occurs within an <xsl:text> element we append it
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
        // as-is to the existing text element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
        if (parent instanceof Text) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
            ((Text)parent).setText(string);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
        // Ignore text nodes that occur directly under <xsl:stylesheet>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
        if (parent instanceof Stylesheet) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
        SyntaxTreeNode bro = parent.lastChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
        if ((bro != null) && (bro instanceof Text)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
            Text text = (Text)bro;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
            if (!text.isTextElement()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
                if ((length > 1) || ( ((int)ch[0]) < 0x100)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
                    text.setText(string);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
                    return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
        // Add it as a regular text node otherwise
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
        parent.addElement(new Text(string));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
    private String getTokenValue(String token) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
        final int start = token.indexOf('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
        final int stop = token.lastIndexOf('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
        return token.substring(start+1, stop);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
     * SAX2: Receive notification of a processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
     *       These require special handling for stylesheet PIs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
    public void processingInstruction(String name, String value) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
        // We only handle the <?xml-stylesheet ...?> PI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
        if ((_target == null) && (name.equals("xml-stylesheet"))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
            String href = null;    // URI of stylesheet found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
            String media = null;   // Media of stylesheet found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
            String title = null;   // Title of stylesheet found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
            String charset = null; // Charset of stylesheet found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
            // Get the attributes from the processing instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
            StringTokenizer tokens = new StringTokenizer(value);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
            while (tokens.hasMoreElements()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
                String token = (String)tokens.nextElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
                if (token.startsWith("href"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
                    href = getTokenValue(token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
                else if (token.startsWith("media"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
                    media = getTokenValue(token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
                else if (token.startsWith("title"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
                    title = getTokenValue(token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
                else if (token.startsWith("charset"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
                    charset = getTokenValue(token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
            // Set the target to this PI's href if the parameters are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
            // null or match the corresponding attributes of this PI.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
            if ( ((_PImedia == null) || (_PImedia.equals(media))) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
                 ((_PItitle == null) || (_PImedia.equals(title))) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
                 ((_PIcharset == null) || (_PImedia.equals(charset))) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
                _target = href;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
     * IGNORED - all ignorable whitespace is ignored
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
    public void ignorableWhitespace(char[] ch, int start, int length) { }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
     * IGNORED - we do not have to do anything with skipped entities
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
    public void skippedEntity(String name) { }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
     * Store the document locator to later retrieve line numbers of all
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
     * elements from the stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
    public void setDocumentLocator(Locator locator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
        _locator = locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
     * Get the line number, or zero
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
     * if there is no _locator.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
    private int getLineNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
        int line = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
        if (_locator != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
                line = _locator.getLineNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
        return line;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
}