< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java

Print this page
rev 959 : 8162598: XSLTC transformer swallows empty namespace declaration which is needed to undeclare default namespace

*** 1,7 **** /* ! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. --- 1,7 ---- /* ! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership.
*** 15,27 **** * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - /* - * $Id: Parser.java,v 1.2.4.1 2005/09/13 12:14:32 pvedula Exp $ - */ package com.sun.org.apache.xalan.internal.xsltc.compiler; import com.sun.java_cup.internal.runtime.Symbol; import com.sun.org.apache.xalan.internal.XalanConstants; --- 15,24 ----
*** 35,52 **** import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Stack; import java.util.StringTokenizer; - import java.util.Vector; import javax.xml.XMLConstants; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; --- 32,49 ---- import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver; import java.io.File; import java.io.IOException; import java.io.StringReader; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Stack; import java.util.StringTokenizer; import javax.xml.XMLConstants; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes;
*** 71,89 **** private static final String XSL = "xsl"; // standard prefix private static final String TRANSLET = "translet"; // extension prefix private Locator _locator = null; ! private XSLTC _xsltc; // Reference to the compiler object. ! private XPathParser _xpathParser; // Reference to the XPath parser. ! private Vector _errors; // Contains all compilation errors ! private Vector _warnings; // Contains all compilation errors private Map<String, String> _instructionClasses; // Maps instructions to classes private Map<String, String[]> _instructionAttrs; // reqd and opt attrs ! private Map<String, QName> _qNames; ! private Map<String, Map> _namespaces; private QName _useAttributeSets; private QName _excludeResultPrefixes; private QName _extensionElementPrefixes; private Map<String, Object> _variableScope; private Stylesheet _currentStylesheet; --- 68,86 ---- private static final String XSL = "xsl"; // standard prefix private static final String TRANSLET = "translet"; // extension prefix private Locator _locator = null; ! private XSLTC _xsltc; // Reference to the compiler object. ! private XPathParser _xpathParser; // Reference to the XPath parser. ! private ArrayList<ErrorMsg> _errors; // Contains all compilation errors ! private ArrayList<ErrorMsg> _warnings; // Contains all compilation warnings private Map<String, String> _instructionClasses; // Maps instructions to classes private Map<String, String[]> _instructionAttrs; // reqd and opt attrs ! private Map<String, QName> _qNames; ! private Map<String, Map<String, QName>> _namespaces; private QName _useAttributeSets; private QName _excludeResultPrefixes; private QName _extensionElementPrefixes; private Map<String, Object> _variableScope; private Stylesheet _currentStylesheet;
*** 111,122 **** _namespaces = new HashMap<>(); _instructionClasses = new HashMap<>(); _instructionAttrs = new HashMap<>(); _variableScope = new HashMap<>(); _template = null; ! _errors = new Vector(); ! _warnings = new Vector(); _symbolTable = new SymbolTable(); _xpathParser = new XPathParser(this); _currentStylesheet = null; _output = null; _root = null; --- 108,119 ---- _namespaces = new HashMap<>(); _instructionClasses = new HashMap<>(); _instructionAttrs = new HashMap<>(); _variableScope = new HashMap<>(); _template = null; ! _errors = new ArrayList<>(); ! _warnings = new ArrayList<>(); _symbolTable = new SymbolTable(); _xpathParser = new XPathParser(this); _currentStylesheet = null; _output = null; _root = null;
*** 137,147 **** } public void setOutput(Output output) { if (_output != null) { if (_output.getImportPrecedence() <= output.getImportPrecedence()) { - String cdata = _output.getCdata(); output.mergeOutput(_output); _output.disable(); _output = output; } else { --- 134,143 ----
*** 170,186 **** } private void addVariableOrParam(VariableBase var) { Object existing = _variableScope.get(var.getName().getStringRep()); if (existing != null) { ! if (existing instanceof Stack) { ! Stack stack = (Stack)existing; stack.push(var); } else if (existing instanceof VariableBase) { ! Stack stack = new Stack(); ! stack.push(existing); stack.push(var); _variableScope.put(var.getName().getStringRep(), stack); } } else { --- 166,183 ---- } private void addVariableOrParam(VariableBase var) { Object existing = _variableScope.get(var.getName().getStringRep()); if (existing != null) { ! if (existing instanceof Stack<?>) { ! @SuppressWarnings("unchecked") ! Stack<VariableBase> stack = (Stack<VariableBase>)existing; stack.push(var); } else if (existing instanceof VariableBase) { ! Stack<VariableBase> stack = new Stack<>(); ! stack.push((VariableBase)existing); stack.push(var); _variableScope.put(var.getName().getStringRep(), stack); } } else {
*** 188,215 **** } } public void removeVariable(QName name) { Object existing = _variableScope.get(name.getStringRep()); ! if (existing instanceof Stack) { ! Stack stack = (Stack)existing; if (!stack.isEmpty()) stack.pop(); if (!stack.isEmpty()) return; } _variableScope.remove(name.getStringRep()); } public VariableBase lookupVariable(QName name) { Object existing = _variableScope.get(name.getStringRep()); if (existing instanceof VariableBase) { ! return((VariableBase)existing); } ! else if (existing instanceof Stack) { ! Stack stack = (Stack)existing; ! return((VariableBase)stack.peek()); } ! return(null); } public void setXSLTC(XSLTC xsltc) { _xsltc = xsltc; } --- 185,213 ---- } } public void removeVariable(QName name) { Object existing = _variableScope.get(name.getStringRep()); ! if (existing instanceof Stack<?>) { ! Stack<?> stack = (Stack<?>)existing; if (!stack.isEmpty()) stack.pop(); if (!stack.isEmpty()) return; } _variableScope.remove(name.getStringRep()); } public VariableBase lookupVariable(QName name) { Object existing = _variableScope.get(name.getStringRep()); if (existing instanceof VariableBase) { ! return (VariableBase)existing; } ! else if (existing instanceof Stack<?>) { ! @SuppressWarnings("unchecked") ! Stack<VariableBase> stack = (Stack<VariableBase>)existing; ! return stack.peek(); } ! return null; } public void setXSLTC(XSLTC xsltc) { _xsltc = xsltc; }
*** 395,408 **** */ public void createAST(Stylesheet stylesheet) { try { if (stylesheet != null) { stylesheet.parseContents(this); - final int precedence = stylesheet.getImportPrecedence(); final Iterator<SyntaxTreeNode> elements = stylesheet.elements(); while (elements.hasNext()) { ! Object child = elements.next(); if (child instanceof Text) { final int l = getLineNumber(); ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_TEXT_NODE_ERR,l,null); reportError(ERROR, err); --- 393,405 ---- */ public void createAST(Stylesheet stylesheet) { try { if (stylesheet != null) { stylesheet.parseContents(this); final Iterator<SyntaxTreeNode> elements = stylesheet.elements(); while (elements.hasNext()) { ! SyntaxTreeNode child = elements.next(); if (child instanceof Text) { final int l = getLineNumber(); ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_TEXT_NODE_ERR,l,null); reportError(ERROR, err);
*** 702,713 **** initAttrTable("processing-instruction", new String[] {"name"}); initAttrTable("namespace-alias", new String[] {"stylesheet-prefix", "result-prefix"}); } - - /** * Initialize the _instructionClasses map, which maps XSL element * names to Java classes in this package. */ private void initStdClasses() { --- 699,708 ----
*** 777,786 **** --- 772,782 ---- } /** * Add primops and base functions to the symbol table. */ + @SuppressWarnings("unused") private void initSymbolTable() { MethodType I_V = new MethodType(Type.Int, Type.Void); MethodType I_R = new MethodType(Type.Int, Type.Real); MethodType I_S = new MethodType(Type.Int, Type.String); MethodType I_D = new MethodType(Type.Int, Type.NodeSet);
*** 969,984 **** public SyntaxTreeNode makeInstance(String uri, String prefix, String local, Attributes attributes) { SyntaxTreeNode node = null; ! QName qname = getQName(uri, prefix, local); String className = _instructionClasses.get(qname.getStringRep()); if (className != null) { try { ! final Class clazz = ObjectFactory.findProviderClass(className, true); node = (SyntaxTreeNode)clazz.newInstance(); node.setQName(qname); node.setParser(this); if (_locator != null) { node.setLineNumber(getLineNumber()); --- 965,980 ---- public SyntaxTreeNode makeInstance(String uri, String prefix, String local, Attributes attributes) { SyntaxTreeNode node = null; ! QName qname = getQName(uri, prefix, local); String className = _instructionClasses.get(qname.getStringRep()); if (className != null) { try { ! final Class<?> clazz = ObjectFactory.findProviderClass(className, true); node = (SyntaxTreeNode)clazz.newInstance(); node.setQName(qname); node.setParser(this); if (_locator != null) { node.setLineNumber(getLineNumber());
*** 1021,1031 **** } // Check if this is an extension of some other XSLT processor else { Stylesheet sheet = _xsltc.getStylesheet(); if ((sheet != null) && (sheet.isExtension(uri))) { ! if (sheet != (SyntaxTreeNode)_parentStack.peek()) { node = new UnsupportedElement(uri, prefix, local, true); UnsupportedElement elem = (UnsupportedElement)node; ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR, getLineNumber(), --- 1017,1027 ---- } // Check if this is an extension of some other XSLT processor else { Stylesheet sheet = _xsltc.getStylesheet(); if ((sheet != null) && (sheet.isExtension(uri))) { ! if (sheet != _parentStack.peek()) { node = new UnsupportedElement(uri, prefix, local, true); UnsupportedElement elem = (UnsupportedElement)node; ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR, getLineNumber(),
*** 1189,1199 **** public void printErrors() { final int size = _errors.size(); if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_ERROR_KEY)); for (int i = 0; i < size; i++) { ! System.err.println(" " + _errors.elementAt(i)); } } } /** --- 1185,1195 ---- public void printErrors() { final int size = _errors.size(); if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_ERROR_KEY)); for (int i = 0; i < size; i++) { ! System.err.println(" " + _errors.get(i)); } } } /**
*** 1202,1212 **** public void printWarnings() { final int size = _warnings.size(); if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_WARNING_KEY)); for (int i = 0; i < size; i++) { ! System.err.println(" " + _warnings.elementAt(i)); } } } /** --- 1198,1208 ---- public void printWarnings() { final int size = _warnings.size(); if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_WARNING_KEY)); for (int i = 0; i < size; i++) { ! System.err.println(" " + _warnings.get(i)); } } } /**
*** 1215,1270 **** public void reportError(final int category, final ErrorMsg error) { switch (category) { case Constants.INTERNAL: // Unexpected internal errors, such as null-ptr exceptions, etc. // Immediately terminates compilation, no translet produced ! _errors.addElement(error); break; case Constants.UNSUPPORTED: // XSLT elements that are not implemented and unsupported ext. // Immediately terminates compilation, no translet produced ! _errors.addElement(error); break; case Constants.FATAL: // Fatal error in the stylesheet input (parsing or content) // Immediately terminates compilation, no translet produced ! _errors.addElement(error); break; case Constants.ERROR: // Other error in the stylesheet input (parsing or content) // Does not terminate compilation, no translet produced ! _errors.addElement(error); break; case Constants.WARNING: // Other error in the stylesheet input (content errors only) // Does not terminate compilation, a translet is produced ! _warnings.addElement(error); break; } } ! public Vector getErrors() { return _errors; } ! public Vector getWarnings() { return _warnings; } /************************ SAX2 ContentHandler INTERFACE *****************/ ! private Stack _parentStack = null; private Map<String, String> _prefixMapping = null; /** * SAX2: Receive notification of the beginning of a document. */ public void startDocument() { _root = null; _target = null; _prefixMapping = null; ! _parentStack = new Stack(); } /** * SAX2: Receive notification of the end of a document. */ --- 1211,1266 ---- public void reportError(final int category, final ErrorMsg error) { switch (category) { case Constants.INTERNAL: // Unexpected internal errors, such as null-ptr exceptions, etc. // Immediately terminates compilation, no translet produced ! _errors.add(error); break; case Constants.UNSUPPORTED: // XSLT elements that are not implemented and unsupported ext. // Immediately terminates compilation, no translet produced ! _errors.add(error); break; case Constants.FATAL: // Fatal error in the stylesheet input (parsing or content) // Immediately terminates compilation, no translet produced ! _errors.add(error); break; case Constants.ERROR: // Other error in the stylesheet input (parsing or content) // Does not terminate compilation, no translet produced ! _errors.add(error); break; case Constants.WARNING: // Other error in the stylesheet input (content errors only) // Does not terminate compilation, a translet is produced ! _warnings.add(error); break; } } ! public ArrayList<ErrorMsg> getErrors() { return _errors; } ! public ArrayList<ErrorMsg> getWarnings() { return _warnings; } /************************ SAX2 ContentHandler INTERFACE *****************/ ! private Stack<SyntaxTreeNode> _parentStack = null; private Map<String, String> _prefixMapping = null; /** * SAX2: Receive notification of the beginning of a document. */ public void startDocument() { _root = null; _target = null; _prefixMapping = null; ! _parentStack = new Stack<>(); } /** * SAX2: Receive notification of the end of a document. */
*** 1316,1326 **** else _rootNamespaceDef = true; _root = element; } else { ! SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek(); parent.addElement(element); element.setParent(parent); } element.setAttributes(new AttributesImpl(attributes)); element.setPrefixMapping(_prefixMapping); --- 1312,1322 ---- else _rootNamespaceDef = true; _root = element; } else { ! SyntaxTreeNode parent = _parentStack.peek(); parent.addElement(element); element.setParent(parent); } element.setAttributes(new AttributesImpl(attributes)); element.setPrefixMapping(_prefixMapping);
*** 1347,1357 **** /** * SAX2: Receive notification of character data. */ public void characters(char[] ch, int start, int length) { String string = new String(ch, start, length); ! SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek(); if (string.length() == 0) return; // If this text occurs within an <xsl:text> element we append it // as-is to the existing text element --- 1343,1353 ---- /** * SAX2: Receive notification of character data. */ public void characters(char[] ch, int start, int length) { String string = new String(ch, start, length); ! SyntaxTreeNode parent = _parentStack.peek(); if (string.length() == 0) return; // If this text occurs within an <xsl:text> element we append it // as-is to the existing text element
< prev index next >