19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: StylesheetHandler.java 468640 2006-10-28 06:53:53Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xalan.processor; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Stack; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.ErrorListener; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.Source; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.SourceLocator; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.Templates; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerConfigurationException; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.sax.TemplatesHandler; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.extensions.ExpressionVisitor; 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources; 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.Constants; 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.ElemForEach; 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.ElemTemplateElement; 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.Stylesheet; 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.StylesheetRoot; 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.BoolStack; 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.NamespaceSupport2; 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.NodeConsumer; 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.PrefixResolver; 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.SAXSourceLocator; 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.XMLCharacterRecognizer; 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPath; 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.compiler.FunctionTable; 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.Function; 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Node; 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Attributes; 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.InputSource; 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Locator; 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.helpers.DefaultHandler; 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.helpers.NamespaceSupport; 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Initializes and processes a stylesheet via SAX events. 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This class acts as essentially a state machine, maintaining 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a ContentHandler stack, and pushing appropriate content 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * handlers as parse events occur. 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class StylesheetHandler extends DefaultHandler 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson implements TemplatesHandler, PrefixResolver, NodeConsumer 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The function table of XPath and XSLT; 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private FunctionTable m_funcTable = new FunctionTable(); 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The flag for the setting of the optimize feature; 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_optimize = true; 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The flag for the setting of the incremental feature; 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_incremental = false; 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The flag for the setting of the source_location feature; 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_source_location = false; 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Create a StylesheetHandler object, creating a root stylesheet 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * as the target. 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param processor non-null reference to the transformer factory that owns this handler. 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerConfigurationException if a StylesheetRoot 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * can not be constructed for some reason. 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public StylesheetHandler(TransformerFactoryImpl processor) 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerConfigurationException 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Class func = org.apache.xalan.templates.FuncDocument.class; 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_funcTable.installFunction("document", func); 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // func = new org.apache.xalan.templates.FuncKey(); 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // FunctionTable.installFunction("key", func); 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson func = org.apache.xalan.templates.FuncFormatNumb.class; 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_funcTable.installFunction("format-number", func); 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_optimize =((Boolean) processor.getAttribute( 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerFactoryImpl.FEATURE_OPTIMIZE)).booleanValue(); 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_incremental = ((Boolean) processor.getAttribute( 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerFactoryImpl.FEATURE_INCREMENTAL)).booleanValue(); 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_source_location = ((Boolean) processor.getAttribute( 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerFactoryImpl.FEATURE_SOURCE_LOCATION)).booleanValue(); 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // m_schema = new XSLTSchema(); 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson init(processor); 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Do common initialization. 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param processor non-null reference to the transformer factory that owns this handler. 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void init(TransformerFactoryImpl processor) 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetProcessor = processor; 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Set the initial content handler. 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_processors.push(m_schema.getElementProcessor()); 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.pushNewNamespaceSupport(); 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // m_includeStack.push(SystemIDResolver.getAbsoluteURI(this.getBaseIdentifier(), null)); 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // initXPath(processor, null); 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Process an expression string into an XPath. 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Must be public for access by the AVT class. 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param str A non-null reference to a valid or invalid XPath expression string. 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A non-null reference to an XPath object that represents the string argument. 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if the expression can not be processed. 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#section-Expressions">Section 4 Expressions in XSLT Specification</a> 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XPath createXPath(String str, ElemTemplateElement owningTemplate) 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPath xpath = new XPath(str, owningTemplate, this, XPath.SELECT, handler, 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_funcTable); 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Visit the expression, registering namespaces for any extension functions it includes. 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xpath.callVisitors(xpath, new ExpressionVisitor(getStylesheetRoot())); 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return xpath; 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Process an expression string into an XPath. 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param str A non-null reference to a valid or invalid match pattern string. 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A non-null reference to an XPath object that represents the string argument. 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if the pattern can not be processed. 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#patterns">Section 5.2 Patterns in XSLT Specification</a> 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPath createMatchPatternXPath(String str, ElemTemplateElement owningTemplate) 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPath xpath = new XPath(str, owningTemplate, this, XPath.MATCH, handler, 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_funcTable); 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Visit the expression, registering namespaces for any extension functions it includes. 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xpath.callVisitors(xpath, new ExpressionVisitor(getStylesheetRoot())); 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return xpath; 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Given a namespace, get the corrisponding prefix from the current 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * namespace support context. 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param prefix The prefix to look up, which may be an empty string ("") for the default Namespace. 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The associated Namespace URI, or null if the prefix 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is undeclared in this context. 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getNamespaceForPrefix(String prefix) 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return this.getNamespaceSupport().getURI(prefix); 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Given a namespace, get the corrisponding prefix. This is here only 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to support the {@link org.apache.xml.utils.PrefixResolver} interface, 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and will throw an error if invoked on this object. 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param prefix The prefix to look up, which may be an empty string ("") for the default Namespace. 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param context The node context from which to look up the URI. 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The associated Namespace URI, or null if the prefix 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is undeclared in this context. 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getNamespaceForPrefix(String prefix, org.w3c.dom.Node context) 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Don't need to support this here. Return the current URI for the prefix, 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // ignoring the context. 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson assertion(true, "can't process a context node in StylesheetHandler!"); 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Utility function to see if the stack contains the given URL. 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param stack non-null reference to a Stack. 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param url URL string on which an equality test will be performed. 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if the stack contains the url argument. 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean stackContains(Stack stack, String url) 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int n = stack.size(); 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean contains = false; 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i = 0; i < n; i++) 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String url2 = (String) stack.elementAt(i); 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (url2.equals(url)) 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson contains = true; 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return contains; 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Implementation of the TRAX TemplatesBuilder interface. 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When this object is used as a ContentHandler or ContentHandler, it will 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * create a Templates object, which the caller can get once 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the SAX events have been completed. 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The stylesheet object that was created during 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the SAX event process, or null if no stylesheet has 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * been created. 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Author <a href="mailto:scott_boag@lotus.com">Scott Boag</a> 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Templates getTemplates() 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getStylesheetRoot(); 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the base ID (URL or system ID) for the stylesheet 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * created by this builder. This must be set in order to 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * resolve relative URLs in the stylesheet. 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param baseID Base URL for this stylesheet. 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setSystemId(String baseID) 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pushBaseIndentifier(baseID); 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the base ID (URI or system ID) from where relative 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * URLs will be resolved. 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The systemID that was set with {@link #setSystemId}. 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getSystemId() 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return this.getBaseIdentifier(); 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Implementation of the EntityResolver interface. 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Resolve an external entity. 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param publicId The public identifer, or null if none is 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * available. 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param systemId The system identifier provided in the XML 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * document. 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The new input source, or null to require the 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * default behaviour. 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException if the entity can not be resolved. 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public InputSource resolveEntity(String publicId, String systemId) 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getCurrentProcessor().resolveEntity(this, publicId, systemId); 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Implementation of DTDHandler interface. 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of a notation declaration. 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>By default, do nothing. Application writers may override this 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method in a subclass if they wish to keep track of the notations 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * declared in a document.</p> 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param name The notation name. 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param publicId The notation public identifier, or null if not 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * available. 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param systemId The notation system identifier. 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.DTDHandler#notationDecl 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void notationDecl(String name, String publicId, String systemId) 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getCurrentProcessor().notationDecl(this, name, publicId, systemId); 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of an unparsed entity declaration. 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param name The entity name. 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param publicId The entity public identifier, or null if not 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * available. 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param systemId The entity system identifier. 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param notationName The name of the associated notation. 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.DTDHandler#unparsedEntityDecl 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void unparsedEntityDecl(String name, String publicId, 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String systemId, String notationName) 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getCurrentProcessor().unparsedEntityDecl(this, name, publicId, systemId, 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson notationName); 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Given a namespace URI, and a local name or a node type, get the processor 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for the element, or return null if not allowed. 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri The Namespace URI, or an empty string. 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name (without prefix), or empty string if not namespace processing. 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param rawName The qualified name (with prefix). 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A non-null reference to a element processor. 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException if the element is not allowed in the 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * found position in the stylesheet. 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor getProcessorFor( 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String uri, String localName, String rawName) 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor currentProcessor = getCurrentProcessor(); 3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementDef def = currentProcessor.getElemDef(); 3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor elemProcessor = def.getProcessorFor(uri, localName); 3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == elemProcessor 3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson && !(currentProcessor instanceof ProcessorStylesheetDoc) 3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson && ((null == getStylesheet() 3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson || Double.valueOf(getStylesheet().getVersion()).doubleValue() 3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson > Constants.XSLTVERSUPPORTED) 3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ||(!uri.equals(Constants.S_XSLNAMESPACEURL) && 3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson currentProcessor instanceof ProcessorStylesheetElement) 3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson || getElemVersion() > Constants.XSLTVERSUPPORTED 3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson )) 3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elemProcessor = def.getProcessorForUnknown(uri, localName); 3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == elemProcessor) 3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_ALLOWED_IN_POSITION, new Object[]{rawName}),null);//rawName + " is not allowed in this position in the stylesheet!", 3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return elemProcessor; 3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Implementation of ContentHandler interface. 3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //////////////////////////////////////////////////////////////////// 3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive a Locator object for document events. 4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This is called by the parser to push a locator for the 4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stylesheet being parsed. The stack needs to be popped 4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * after the stylesheet has been parsed. We pop in 4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * popStylesheet. 4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param locator A locator for all SAX document events. 4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#setDocumentLocator 4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.Locator 4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setDocumentLocator(Locator locator) 4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("pushing locator for: "+locator.getSystemId()); 4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetLocatorStack.push(new SAXSourceLocator(locator)); 4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The level of the stylesheet we are at. 4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private int m_stylesheetLevel = -1; 4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the beginning of the document. 4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#startDocument 4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void startDocument() throws org.xml.sax.SAXException 4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetLevel++; 4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pushSpaceHandling(false); 4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** m_parsingComplete becomes true when the top-level stylesheet and all 4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * its included/imported stylesheets have been been fully parsed, as an 4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * indication that composition/optimization/compilation can begin. 4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see isStylesheetParsingComplete */ 4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_parsingComplete = false; 4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Test whether the _last_ endDocument() has been processed. 4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This is needed as guidance for stylesheet optimization 4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and compilation engines, which generally don't want to start 4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * until all included and imported stylesheets have been fully 4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * parsed. 4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true iff the complete stylesheet tree has been built. 4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isStylesheetParsingComplete() 4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_parsingComplete; 4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the end of the document. 4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#endDocument 4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void endDocument() throws org.xml.sax.SAXException 4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != getStylesheetRoot()) 4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (0 == m_stylesheetLevel) 4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStylesheetRoot().recompose(); 4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEETROOT, null)); //"Did not find the stylesheet root!"); 4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor elemProcessor = getCurrentProcessor(); 4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != elemProcessor) 4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elemProcessor.startNonText(this); 4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetLevel--; 4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson popSpaceHandling(); 4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // WARNING: This test works only as long as stylesheets are parsed 4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // more or less recursively. If we switch to an iterative "work-list" 4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // model, this will become true prematurely. In that case, 4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // isStylesheetParsingComplete() will have to be adjusted to be aware 4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // of the worklist. 4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_parsingComplete = (m_stylesheetLevel < 0); 4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private java.util.Vector m_prefixMappings = new java.util.Vector(); 4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the start of a Namespace mapping. 5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>By default, do nothing. Application writers may override this 5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method in a subclass to take specific actions at the start of 5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * each element (such as allocating a new tree node or writing 5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * output to a file).</p> 5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param prefix The Namespace prefix being declared. 5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri The Namespace URI mapped to the prefix. 5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#startPrefixMapping 5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void startPrefixMapping(String prefix, String uri) 5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // m_nsSupport.pushContext(); 5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // this.getNamespaceSupport().declarePrefix(prefix, uri); 5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //m_prefixMappings.add(prefix); // JDK 1.2+ only -sc 5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //m_prefixMappings.add(uri); // JDK 1.2+ only -sc 5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_prefixMappings.addElement(prefix); // JDK 1.1.x compat -sc 5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_prefixMappings.addElement(uri); // JDK 1.1.x compat -sc 5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the end of a Namespace mapping. 5299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>By default, do nothing. Application writers may override this 5319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method in a subclass to take specific actions at the start of 5329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * each element (such as allocating a new tree node or writing 5339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * output to a file).</p> 5349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param prefix The Namespace prefix being declared. 5369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#endPrefixMapping 5379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 5399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 5409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException 5429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // m_nsSupport.popContext(); 5459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Flush the characters buffer. 5499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException 5519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private void flushCharacters() throws org.xml.sax.SAXException 5539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor elemProcessor = getCurrentProcessor(); 5569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != elemProcessor) 5589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elemProcessor.startNonText(this); 5599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the start of an element. 5639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri The Namespace URI, or an empty string. 5659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name (without prefix), or empty string if not namespace processing. 5669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param rawName The qualified name (with prefix). 5679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param attributes The specified or defaulted attributes. 5689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException 5709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void startElement( 5729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String uri, String localName, String rawName, Attributes attributes) 5739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 5749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NamespaceSupport nssupport = this.getNamespaceSupport(); 5769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson nssupport.pushContext(); 5779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int n = m_prefixMappings.size(); 5799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i = 0; i < n; i++) 5819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String prefix = (String)m_prefixMappings.elementAt(i++); 5839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String nsURI = (String)m_prefixMappings.elementAt(i); 5849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson nssupport.declarePrefix(prefix, nsURI); 5859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //m_prefixMappings.clear(); // JDK 1.2+ only -sc 5879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_prefixMappings.removeAllElements(); // JDK 1.1.x compat -sc 5889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_elementID++; 5909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // This check is currently done for all elements. We should possibly consider 5929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // limiting this check to xsl:stylesheet elements only since that is all it really 5939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // applies to. Also, it could be bypassed if m_shouldProcess is already true. 5949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // In other words, the next two statements could instead look something like this: 5959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // if (!m_shouldProcess) 5969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // { 5979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // if (localName.equals(Constants.ELEMNAME_STYLESHEET_STRING) && 5989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // url.equals(Constants.S_XSLNAMESPACEURL)) 5999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // { 6009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // checkForFragmentID(attributes); 6019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // if (!m_shouldProcess) 6029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // return; 6039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // } 6049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // else 6059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // return; 6069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // } 6079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // I didn't include this code statement at this time because in practice 6089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // it is a small performance hit and I was waiting to see if its absence 6099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // caused a problem. - GLP 6109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson checkForFragmentID(attributes); 6129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 6149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return; 6159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson flushCharacters(); 6179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pushSpaceHandling(attributes); 6199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor elemProcessor = getProcessorFor(uri, localName, 6219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson rawName); 6229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null != elemProcessor) // defensive, for better multiple error reporting. -sb 6249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.pushProcessor(elemProcessor); 6269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elemProcessor.startElement(this, uri, localName, rawName, attributes); 6279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 6299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_shouldProcess = false; 6319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson popSpaceHandling(); 6329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the end of an element. 6389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri The Namespace URI, or an empty string. 6409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name (without prefix), or empty string if not namespace processing. 6419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param rawName The qualified name (with prefix). 6429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#endElement 6439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 6459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 6469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void endElement(String uri, String localName, String rawName) 6489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 6499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_elementID--; 6529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 6549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return; 6559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((m_elementID + 1) == m_fragmentID) 6579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_shouldProcess = false; 6589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson flushCharacters(); 6609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson popSpaceHandling(); 6629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor p = getCurrentProcessor(); 6649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson p.endElement(this, uri, localName, rawName); 6669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.popProcessor(); 6679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.getNamespaceSupport().popContext(); 6689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of character data inside an element. 6729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param ch The characters. 6749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param start The start position in the character array. 6759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param length The number of characters to use from the 6769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * character array. 6779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#characters 6789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 6809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 6819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void characters(char ch[], int start, int length) 6839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 6849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 6879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return; 6889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor elemProcessor = getCurrentProcessor(); 6909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementDef def = elemProcessor.getElemDef(); 6919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (def.getType() != XSLTElementDef.T_PCDATA) 6939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elemProcessor = def.getProcessorFor(null, "text()"); 6949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == elemProcessor) 6969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If it's whitespace, just ignore it, otherwise flag an error. 6999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!XMLCharacterRecognizer.isWhiteSpace(ch, start, length)) 7009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error( 7019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLMessages.createMessage(XSLTErrorResources.ER_NONWHITESPACE_NOT_ALLOWED_IN_POSITION, null),null);//"Non-whitespace text is not allowed in this position in the stylesheet!", 7029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 7059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elemProcessor.characters(this, ch, start, length); 7069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 7099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of ignorable whitespace in element content. 7109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param ch The whitespace characters. 7129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param start The start position in the character array. 7139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param length The number of characters to use from the 7149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * character array. 7159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#ignorableWhitespace 7169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 7189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 7199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 7209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void ignorableWhitespace(char ch[], int start, int length) 7219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 7229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 7259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return; 7269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getCurrentProcessor().ignorableWhitespace(this, ch, start, length); 7289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 7319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of a processing instruction. 7329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The Parser will invoke this method once for each processing 7349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * instruction found: note that processing instructions may occur 7359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * before or after the main document element.</p> 7369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>A SAX parser should never report an XML declaration (XML 1.0, 7389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * section 2.8) or a text declaration (XML 1.0, section 4.3.1) 7399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * using this method.</p> 7409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>By default, do nothing. Application writers may override this 7429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method in a subclass to take specific actions for each 7439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * processing instruction, such as setting status variables or 7449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * invoking other methods.</p> 7459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param target The processing instruction target. 7479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param data The processing instruction data, or null if 7489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * none is supplied. 7499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#processingInstruction 7509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 7529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 7539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 7549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void processingInstruction(String target, String data) 7559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 7569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 7589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return; 7599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Recreating Scott's kluge: 7619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // A xsl:for-each or xsl:apply-templates may have a special 7629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // PI that tells us not to cache the document. This PI 7639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // should really be namespaced. 7649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // String localName = getLocalName(target); 7659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // String ns = m_stylesheet.getNamespaceFromStack(target); 7669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // 7679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // %REVIEW%: We need a better PI architecture 7689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String prefix="",ns="", localName=target; 7709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int colon=target.indexOf(':'); 7719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(colon>=0) 7729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ns=getNamespaceForPrefix(prefix=target.substring(0,colon)); 7749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson localName=target.substring(colon+1); 7759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 7789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // A xsl:for-each or xsl:apply-templates may have a special 7809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // PI that tells us not to cache the document. This PI 7819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // should really be namespaced... but since the XML Namespaces 7829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // spec never defined namespaces as applying to PI's, and since 7839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // the testcase we're trying to support is inconsistant in whether 7849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // it binds the prefix, I'm going to make this sloppy for 7859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // testing purposes. 7869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if( 7879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "xalan-doc-cache-off".equals(target) || 7889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "xalan:doc-cache-off".equals(target) || 7899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ("doc-cache-off".equals(localName) && 7909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ns.equals("org.apache.xalan.xslt.extensions.Redirect") ) 7919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ) 7929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(!(m_elems.peek() instanceof ElemForEach)) 7949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException 7959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ("xalan:doc-cache-off not allowed here!", 7969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getLocator()); 7979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemForEach elem = (ElemForEach)m_elems.peek(); 7989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.m_doc_cache_off = true; 8009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //System.out.println("JJK***** Recognized <? {"+ns+"}"+prefix+":"+localName+" "+data+"?>"); 8029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch(Exception e) 8059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // JJK: Officially, unknown PIs can just be ignored. 8079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Do we want to issue a warning? 8089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson flushCharacters(); 8129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getCurrentProcessor().processingInstruction(this, target, data); 8139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 8169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of a skipped entity. 8179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>By default, do nothing. Application writers may override this 8199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method in a subclass to take specific actions for each 8209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * processing instruction, such as setting status variables or 8219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * invoking other methods.</p> 8229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param name The name of the skipped entity. 8249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.xml.sax.ContentHandler#processingInstruction 8259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException Any SAX exception, possibly 8279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * wrapping another exception. 8289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 8299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void skippedEntity(String name) throws org.xml.sax.SAXException 8309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 8339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return; 8349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getCurrentProcessor().skippedEntity(this, name); 8369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 8399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Warn the user of an problem. 8409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg An key into the {@link org.apache.xalan.res.XSLTErrorResources} 8429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * table, that is one of the WG_ prefixed definitions. 8439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args An array of arguments for the given warning. 8449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException that wraps a 8469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.TransformerException} if the current 8479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.ErrorListener#warning} 8489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method chooses to flag this condition as an error. 8499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 8509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 8519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void warn(String msg, Object args[]) throws org.xml.sax.SAXException 8529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = XSLMessages.createWarning(msg, args); 8559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = getLocator(); 8569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 8579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 8599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != handler) 8619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.warning(new TransformerException(formattedMsg, locator)); 8629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 8649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 8669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 8709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Assert that a condition is true. If it is not true, throw an error. 8719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param condition false if an error should not be thrown, otherwise true. 8739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg Error message to be passed to the RuntimeException as an 8749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * argument. 8759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws RuntimeException if the condition is not true. 8769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 8779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 8789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private void assertion(boolean condition, String msg) throws RuntimeException 8799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!condition) 8819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new RuntimeException(msg); 8829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 8859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an error, and probably throw an 8869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 8879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg An error message. 8899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param e An error which the SAXException should wrap. 8909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException that wraps a 8929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.TransformerException} if the current 8939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.ErrorListener#error} 8949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method chooses to flag this condition as an error. 8959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 8969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 8979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected void error(String msg, Exception e) 8989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 8999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = getLocator(); 9029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 9039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerException pe; 9049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!(e instanceof TransformerException)) 9069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pe = (null == e) 9089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ? new TransformerException(msg, locator) 9099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson : new TransformerException(msg, locator, e); 9109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 9129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pe = (TransformerException) e; 9139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != handler) 9159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 9179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.error(pe); 9199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 9219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 9239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 9269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(pe); 9279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 9309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an error, and probably throw an 9319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 9329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg A key into the {@link org.apache.xalan.res.XSLTErrorResources} 9349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * table, that is one of the WG_ prefixed definitions. 9359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args An array of arguments for the given warning. 9369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param e An error which the SAXException should wrap. 9379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException that wraps a 9399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.TransformerException} if the current 9409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.ErrorListener#error} 9419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method chooses to flag this condition as an error. 9429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 9439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 9449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected void error(String msg, Object args[], Exception e) 9459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 9469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = XSLMessages.createMessage(msg, args); 9499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(formattedMsg, e); 9519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 9549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of a XSLT processing warning. 9559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param e The warning information encoded as an exception. 9579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException that wraps a 9599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.TransformerException} if the current 9609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.ErrorListener#warning} 9619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method chooses to flag this condition as an error. 9629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 9639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void warning(org.xml.sax.SAXParseException e) 9649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 9659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = e.getMessage(); 9689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = getLocator(); 9699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 9709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 9729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.warning(new TransformerException(formattedMsg, locator)); 9749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 9769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 9789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 9829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of a recoverable XSLT processing error. 9839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param e The error information encoded as an exception. 9859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException that wraps a 9879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.TransformerException} if the current 9889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.ErrorListener#error} 9899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method chooses to flag this condition as an error. 9909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 9919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void error(org.xml.sax.SAXParseException e) 9929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 9939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = e.getMessage(); 9969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = getLocator(); 9979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 9989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 10009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.error(new TransformerException(formattedMsg, locator)); 10029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 10049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 10069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Report a fatal XSLT processing error. 10119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param e The error information encoded as an exception. 10139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException that wraps a 10159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.TransformerException} if the current 10169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link javax.xml.transform.ErrorListener#fatalError} 10179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method chooses to flag this condition as an error. 10189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void fatalError(org.xml.sax.SAXParseException e) 10209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 10219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = e.getMessage(); 10249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = getLocator(); 10259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 10269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 10289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.fatalError(new TransformerException(formattedMsg, locator)); 10309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 10329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 10349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If we have a URL to a XML fragment, this is set 10399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to false until the ID is found. 10409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (warning: I worry that this should be in a stack). 10419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_shouldProcess = true; 10439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If we have a URL to a XML fragment, the value is stored 10469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in this string, and the m_shouldProcess flag is set to 10479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * false until we match an ID with this string. 10489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (warning: I worry that this should be in a stack). 10499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private String m_fragmentIDString; 10519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Keep track of the elementID, so we can tell when 10549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is has completed. This isn't a real ID, but rather 10559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a nesting level. However, it's good enough for 10569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * our purposes. 10579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (warning: I worry that this should be in a stack). 10589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private int m_elementID = 0; 10609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The ID of the fragment that has been found 10639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (warning: I worry that this should be in a stack). 10649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private int m_fragmentID = 0; 10669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Check to see if an ID attribute matched the #id, called 10699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * from startElement. 10709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param attributes The specified or defaulted attributes. 10729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private void checkForFragmentID(Attributes attributes) 10749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_shouldProcess) 10779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((null != attributes) && (null != m_fragmentIDString)) 10799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int n = attributes.getLength(); 10819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i = 0; i < n; i++) 10839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String name = attributes.getQName(i); 10859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (name.equals(Constants.ATTRNAME_ID)) 10879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String val = attributes.getValue(i); 10899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (val.equalsIgnoreCase(m_fragmentIDString)) 10919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_shouldProcess = true; 10939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_fragmentID = m_elementID; 10949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The XSLT TransformerFactory for needed services. 11039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private TransformerFactoryImpl m_stylesheetProcessor; 11059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the XSLT TransformerFactoryImpl for needed services. 11089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * TODO: This method should be renamed. 11099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The TransformerFactoryImpl that owns this handler. 11119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public TransformerFactoryImpl getStylesheetProcessor() 11139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_stylesheetProcessor; 11159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If getStylesheetType returns this value, the current stylesheet 11199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is a root stylesheet. 11209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 11219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final int STYPE_ROOT = 1; 11239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If getStylesheetType returns this value, the current stylesheet 11269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is an included stylesheet. 11279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 11289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final int STYPE_INCLUDE = 2; 11309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If getStylesheetType returns this value, the current stylesheet 11339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is an imported stylesheet. 11349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 11359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final int STYPE_IMPORT = 3; 11379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The current stylesheet type. */ 11399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private int m_stylesheetType = STYPE_ROOT; 11409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the type of stylesheet that should be built 11439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or is being processed. 11449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return one of STYPE_ROOT, STYPE_INCLUDE, or STYPE_IMPORT. 11469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int getStylesheetType() 11489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_stylesheetType; 11509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the type of stylesheet that should be built 11549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or is being processed. 11559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param type Must be one of STYPE_ROOT, STYPE_INCLUDE, or STYPE_IMPORT. 11579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void setStylesheetType(int type) 11599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetType = type; 11619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The stack of stylesheets being processed. 11659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Stack m_stylesheets = new Stack(); 11679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the stylesheet that this handler is constructing. 11709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The current stylesheet that is on top of the stylesheets stack, 11729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or null if no stylesheet is on the stylesheets stack. 11739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stylesheet getStylesheet() 11759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (m_stylesheets.size() == 0) 11779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ? null : (Stylesheet) m_stylesheets.peek(); 11789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the last stylesheet that was popped off the stylesheets stack. 11829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The last popped stylesheet, or null. 11849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stylesheet getLastPoppedStylesheet() 11869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_lastPoppedStylesheet; 11889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the stylesheet root that this handler is constructing. 11929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The root stylesheet of the stylesheets tree. 11949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public StylesheetRoot getStylesheetRoot() 11969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (m_stylesheetRoot != null){ 11989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetRoot.setOptimizer(m_optimize); 11999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetRoot.setIncremental(m_incremental); 12009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetRoot.setSource_location(m_source_location); 12019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_stylesheetRoot; 12039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The root stylesheet of the stylesheets tree. */ 12069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StylesheetRoot m_stylesheetRoot; 12079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The last stylesheet that was popped off the stylesheets stack. */ 12099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stylesheet m_lastPoppedStylesheet; 12109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push the current stylesheet being constructed. If no other stylesheets 12139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * have been pushed onto the stack, assume the argument is a stylesheet 12149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * root, and also set the stylesheet root member. 12159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param s non-null reference to a stylesheet. 12179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void pushStylesheet(Stylesheet s) 12199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (m_stylesheets.size() == 0) 12229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetRoot = (StylesheetRoot) s; 12239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheets.push(s); 12259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop the last stylesheet pushed, and return the stylesheet that this 12299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * handler is constructing, and set the last popped stylesheet member. 12309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Also pop the stylesheet locator stack. 12319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The stylesheet popped off the stack, or the last popped stylesheet. 12339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stylesheet popStylesheet() 12359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // The stylesheetLocatorStack needs to be popped because 12389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // a locator was pushed in for this stylesheet by the SAXparser by calling 12399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // setDocumentLocator(). 12409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_stylesheetLocatorStack.isEmpty()) 12419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_stylesheetLocatorStack.pop(); 12429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!m_stylesheets.isEmpty()) 12449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_lastPoppedStylesheet = (Stylesheet) m_stylesheets.pop(); 12459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Shouldn't this be null if stylesheets is empty? -sb 12479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_lastPoppedStylesheet; 12489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The stack of current processors. 12529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Stack m_processors = new Stack(); 12549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current XSLTElementProcessor at the top of the stack. 12579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Valid XSLTElementProcessor, which should never be null. 12599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor getCurrentProcessor() 12619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (XSLTElementProcessor) m_processors.peek(); 12639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push the current XSLTElementProcessor onto the top of the stack. 12679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param processor non-null reference to the current element processor. 12699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushProcessor(XSLTElementProcessor processor) 12719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_processors.push(processor); 12739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop the current XSLTElementProcessor from the top of the stack. 12779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return the XSLTElementProcessor which was popped. 12789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor popProcessor() 12809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (XSLTElementProcessor) m_processors.pop(); 12829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The root of the XSLT Schema, which tells us how to 12869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * transition content handlers, create elements, etc. 12879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For the moment at least, this can't be static, since 12889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the processors store state. 12899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private XSLTSchema m_schema = new XSLTSchema(); 12919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the root of the XSLT Schema, which tells us how to 12949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * transition content handlers, create elements, etc. 12959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The root XSLT Schema, which should never be null. 12979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 12989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XSLTSchema getSchema() 13009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_schema; 13029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The stack of elements, pushed and popped as events occur. 13069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Stack m_elems = new Stack(); 13089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current ElemTemplateElement at the top of the stack. 13119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Valid ElemTemplateElement, which may be null. 13129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplateElement getElemTemplateElement() 13149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 13179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (ElemTemplateElement) m_elems.peek(); 13199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (java.util.EmptyStackException ese) 13219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 13239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** An increasing number that is used to indicate the order in which this element 13279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * was encountered during the parse of the XSLT tree. 13289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private int m_docOrderCount = 0; 13309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the next m_docOrderCount number and increments the number for future use. 13339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int nextUid() 13359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_docOrderCount++; 13379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push the current XSLTElementProcessor to the top of the stack. As a 13419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * side-effect, set the document order index (simply because this is a 13429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * convenient place to set it). 13439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 13449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param elem Should be a non-null reference to the intended current 13459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * template element. 13469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushElemTemplateElement(ElemTemplateElement elem) 13489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (elem.getUid() == -1) 13519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.setUid(nextUid()); 13529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_elems.push(elem); 13549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current XSLTElementProcessor from the top of the stack. 13589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return the ElemTemplateElement which was popped. 13599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplateElement popElemTemplateElement() 13619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (ElemTemplateElement) m_elems.pop(); 13639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This will act as a stack to keep track of the 13679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * current include base. 13689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stack m_baseIdentifiers = new Stack(); 13709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 13729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push a base identifier onto the base URI stack. 13739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 13749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param baseID The current base identifier for this position in the 13759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stylesheet, which may be a fragment identifier, or which may be null. 13769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#base-uri"> 13779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Section 3.2 Base URI of XSLT specification.</a> 13789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 13799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushBaseIndentifier(String baseID) 13809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != baseID) 13839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int posOfHash = baseID.indexOf('#'); 13859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (posOfHash > -1) 13879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 13889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_fragmentIDString = baseID.substring(posOfHash + 1); 13899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_shouldProcess = false; 13909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 13929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_shouldProcess = true; 13939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 13959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_shouldProcess = true; 13969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 13979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_baseIdentifiers.push(baseID); 13989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 13999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop a base URI from the stack. 14029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return baseIdentifier. 14039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String popBaseIndentifier() 14059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (String) m_baseIdentifiers.pop(); 14079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the base identifier. 14119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 14129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The base identifier of the current stylesheet. 14139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getBaseIdentifier() 14159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Try to get the baseIdentifier from the baseIdentifier's stack, 14189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // which may not be the same thing as the value found in the 14199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // SourceLocators stack. 14209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String base = (String) (m_baseIdentifiers.isEmpty() 14219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ? null : m_baseIdentifiers.peek()); 14229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Otherwise try the stylesheet. 14249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == base) 14259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SourceLocator locator = getLocator(); 14279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson base = (null == locator) ? "" : locator.getSystemId(); 14299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return base; 14329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The top of this stack should contain the currently processed 14369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stylesheet SAX locator object. 14379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Stack m_stylesheetLocatorStack = new Stack(); 14399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current stylesheet Locator object. 14429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 14439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return non-null reference to the current locator object. 14449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public SAXSourceLocator getLocator() 14469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (m_stylesheetLocatorStack.isEmpty()) 14499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = new SAXSourceLocator(); 14519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locator.setSystemId(this.getStylesheetProcessor().getDOMsystemID()); 14539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return locator; 14559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // m_stylesheetLocatorStack.push(locator); 14579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ((SAXSourceLocator) m_stylesheetLocatorStack.peek()); 14609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * A stack of URL hrefs for imported stylesheets. This is 14649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * used to diagnose circular imports. 14659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Stack m_importStack = new Stack(); 14679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * A stack of Source objects obtained from a URIResolver, 14709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for each element in this stack there is a 1-1 correspondence 14719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * with an element in the m_importStack. 14729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Stack m_importSourceStack = new Stack(); 14749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push an import href onto the stylesheet stack. 14779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 14789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param hrefUrl non-null reference to the URL for the current imported 14799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stylesheet. 14809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushImportURL(String hrefUrl) 14829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_importStack.push(hrefUrl); 14849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push the Source of an import href onto the stylesheet stack, 14889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * obtained from a URIResolver, null if there is no URIResolver, 14899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or if that resolver returned null. 14909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 14919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushImportSource(Source sourceFromURIResolver) 14929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 14939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_importSourceStack.push(sourceFromURIResolver); 14949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 14959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 14969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 14979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See if the imported stylesheet stack already contains 14989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the given URL. Used to test for recursive imports. 14999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param hrefUrl non-null reference to a URL string. 15019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if the URL is on the import stack. 15039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean importStackContains(String hrefUrl) 15059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return stackContains(m_importStack, hrefUrl); 15079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop an import href from the stylesheet stack. 15119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return non-null reference to the import URL that was popped. 15139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String popImportURL() 15159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (String) m_importStack.pop(); 15179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String peekImportURL() 15209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (String) m_importStack.peek(); 15229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Source peekSourceFromURIResolver() 15259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (Source) m_importSourceStack.peek(); 15279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop a Source from a user provided URIResolver, corresponding 15319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to the URL popped from the m_importStack. 15329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Source popImportSource() 15349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (Source) m_importSourceStack.pop(); 15369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If this is set to true, we've already warned about using the 15409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * older XSLT namespace URL. 15419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean warnedAboutOldXSLTNamespace = false; 15439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** Stack of NamespaceSupport objects. */ 15459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stack m_nsSupportStack = new Stack(); 15469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push a new NamespaceSupport instance. 15499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushNewNamespaceSupport() 15519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_nsSupportStack.push(new NamespaceSupport2()); 15539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop the current NamespaceSupport object. 15579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void popNamespaceSupport() 15609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_nsSupportStack.pop(); 15629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current NamespaceSupport object. 15669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return a non-null reference to the current NamespaceSupport object, 15689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * which is the top of the namespace support stack. 15699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NamespaceSupport getNamespaceSupport() 15719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (NamespaceSupport) m_nsSupportStack.peek(); 15739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The originating node if the current stylesheet is being created 15779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * from a DOM. 15789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.apache.xml.utils.NodeConsumer 15799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Node m_originatingNode; 15819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the node that is originating the SAX event. 15849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param n Reference to node that originated the current event. 15869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.apache.xml.utils.NodeConsumer 15879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setOriginatingNode(Node n) 15899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 15909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_originatingNode = n; 15919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 15929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 15939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 15949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the node that is originating the SAX event. 15959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 15969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Reference to node that originated the current event. 15979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.apache.xml.utils.NodeConsumer 15989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 15999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getOriginatingNode() 16009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_originatingNode; 16029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 16059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Stack of booleans that are pushed and popped in start/endElement depending 16069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * on the value of xml:space=default/preserve. 16079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 16089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private BoolStack m_spacePreserveStack = new BoolStack(); 16099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 16119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return boolean value from the spacePreserve stack depending on the value 16129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of xml:space=default/preserve. 16139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 16149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if space should be preserved, false otherwise. 16159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 16169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean isSpacePreserve() 16179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_spacePreserveStack.peek(); 16199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 16229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Pop boolean value from the spacePreserve stack. 16239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 16249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void popSpaceHandling() 16259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_spacePreserveStack.pop(); 16279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 16309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push boolean value on to the spacePreserve stack. 16319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 16329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param b true if space should be preserved, false otherwise. 16339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 16349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushSpaceHandling(boolean b) 16359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXParseException 16369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_spacePreserveStack.push(b); 16389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 16419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Push boolean value on to the spacePreserve stack depending on the value 16429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of xml:space=default/preserve. 16439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 16449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param attrs list of attributes that were passed to startElement. 16459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 16469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void pushSpaceHandling(Attributes attrs) 16479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXParseException 16489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String value = attrs.getValue("xml:space"); 16509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == value) 16519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_spacePreserveStack.push(m_spacePreserveStack.peekOrFalse()); 16539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if(value.equals("preserve")) 16559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_spacePreserveStack.push(true); 16579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if(value.equals("default")) 16599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_spacePreserveStack.push(false); 16619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 16639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator locator = getLocator(); 16659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener handler = m_stylesheetProcessor.getErrorListener(); 16669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 16689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.error(new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_ILLEGAL_XMLSPACE_VALUE, null), locator)); //"Illegal value for xml:space", locator)); 16709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (TransformerException te) 16729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXParseException(te.getMessage(), locator, te); 16749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_spacePreserveStack.push(m_spacePreserveStack.peek()); 16769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 16799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private double getElemVersion() 16809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplateElement elem = getElemTemplateElement(); 16829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson double version = -1; 16839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while ((version == -1 || version == Constants.XSLTVERSUPPORTED) && elem != null) 16849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try{ 16869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson version = Double.valueOf(elem.getXmlVersion()).doubleValue(); 16879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (Exception ex) 16899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 16909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson version = -1; 16919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem = elem.getParentElem(); 16939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (version == -1)? Constants.XSLTVERSUPPORTED : version; 16959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 16969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 16979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see PrefixResolver#handlesNullPrefixes() 16989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 16999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean handlesNullPrefixes() { 17009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 17019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 17029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 17039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 17049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Optimization flag 17059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 17069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean getOptimize() { 17079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_optimize; 17089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 17099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 17109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 17119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Incremental flag 17129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 17139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean getIncremental() { 17149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_incremental; 17159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 17169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 17179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 17189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Source Location flag 17199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 17209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean getSource_location() { 17219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_source_location; 17229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 17239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 17249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 17259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 17269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 17279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1728