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: ProcessorLRE.java 475981 2006-11-16 23:35:53Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xalan.processor; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.List; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerConfigurationException; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.Constants; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.ElemExtensionCall; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.ElemLiteralResult; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.ElemTemplate; 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.ElemTemplateElement; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.Stylesheet; 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.StylesheetRoot; 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.XMLNSDecl; 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.SAXSourceLocator; 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPath; 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Attributes; 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Locator; 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.helpers.AttributesImpl; 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Processes an XSLT literal-result-element, or something that looks 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * like one. The actual {@link org.apache.xalan.templates.ElemTemplateElement} 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * produced may be a {@link org.apache.xalan.templates.ElemLiteralResult}, 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a {@link org.apache.xalan.templates.StylesheetRoot}, or a 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link org.apache.xalan.templates.ElemExtensionCall}. 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a> 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.apache.xalan.templates.ElemLiteralResult 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class ProcessorLRE extends ProcessorTemplateElem 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static final long serialVersionUID = -1490218021772101404L; 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the start of an element. 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param handler non-null reference to current StylesheetHandler that is constructing the Templates. 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri The Namespace URI, or an empty string. 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name (without prefix), or empty string if not namespace processing. 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param rawName The qualified name (with prefix). 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param attributes The specified or defaulted attributes. 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void startElement( 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplateElement p = handler.getElemTemplateElement(); 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean excludeXSLDecl = false; 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean isLREAsStyleSheet = false; 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == p) 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Literal Result Template as stylesheet. 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor lreProcessor = handler.popProcessor(); 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementProcessor stylesheetProcessor = 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.getProcessorFor(Constants.S_XSLNAMESPACEURL, "stylesheet", 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "xsl:stylesheet"); 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.pushProcessor(lreProcessor); 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stylesheet stylesheet; 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheet = getStylesheetRoot(handler); 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch(TransformerConfigurationException tfe) 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException(tfe); 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // stylesheet.setDOMBackPointer(handler.getOriginatingNode()); 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // ***** Note that we're assigning an empty locator. Is this necessary? 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SAXSourceLocator slocator = new SAXSourceLocator(); 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Locator locator = handler.getLocator(); 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null != locator) 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson slocator.setLineNumber(locator.getLineNumber()); 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson slocator.setColumnNumber(locator.getColumnNumber()); 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson slocator.setPublicId(locator.getPublicId()); 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson slocator.setSystemId(locator.getSystemId()); 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheet.setLocaterInfo(slocator); 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheet.setPrefixes(handler.getNamespaceSupport()); 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.pushStylesheet(stylesheet); 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isLREAsStyleSheet = true; 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson AttributesImpl stylesheetAttrs = new AttributesImpl(); 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson AttributesImpl lreAttrs = new AttributesImpl(); 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int n = attributes.getLength(); 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i = 0; i < n; i++) 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String attrLocalName = attributes.getLocalName(i); 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String attrUri = attributes.getURI(i); 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String value = attributes.getValue(i); 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((null != attrUri) && attrUri.equals(Constants.S_XSLNAMESPACEURL)) 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheetAttrs.addAttribute(null, attrLocalName, attrLocalName, 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attributes.getType(i), 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attributes.getValue(i)); 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if ((attrLocalName.startsWith("xmlns:") || attrLocalName.equals( 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "xmlns")) && value.equals(Constants.S_XSLNAMESPACEURL)) 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // ignore 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson lreAttrs.addAttribute(attrUri, attrLocalName, 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attributes.getQName(i), 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attributes.getType(i), 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attributes.getValue(i)); 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attributes = lreAttrs; 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Set properties from the attributes, but don't throw 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // an error if there is an attribute defined that is not 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // allowed on a stylesheet. 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try{ 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheetProcessor.setPropertiesFromAttributes(handler, "stylesheet", 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheetAttrs, stylesheet); 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (Exception e) 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // This is pretty ugly, but it will have to do for now. 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // This is just trying to append some text specifying that 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // this error came from a missing or invalid XSLT namespace 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // declaration. 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If someone comes up with a better solution, please feel 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // free to contribute it. -mm 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (stylesheet.getDeclaredPrefixes() == null || 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson !declaredXSLNS(stylesheet)) 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(XSLMessages.createWarning(XSLTErrorResources.WG_OLD_XSLT_NS, null)); 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(e); 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.pushElemTemplateElement(stylesheet); 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplate template = new ElemTemplate(); 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (slocator != null) 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson template.setLocaterInfo(slocator); 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson appendAndPush(handler, template); 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH, 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.getStylesheetProcessor().getErrorListener()); 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson template.setMatch(rootMatch); 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // template.setDOMBackPointer(handler.getOriginatingNode()); 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheet.setTemplate(template); 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson p = handler.getElemTemplateElement(); 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson excludeXSLDecl = true; 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLTElementDef def = getElemDef(); 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Class classObject = def.getClassObject(); 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean isExtension = false; 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean isComponentDecl = false; 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean isUnknownTopLevel = false; 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while (null != p) 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("Checking: "+p); 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (p instanceof ElemLiteralResult) 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemLiteralResult parentElem = (ElemLiteralResult) p; 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isExtension = parentElem.containsExtensionElementURI(uri); 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (p instanceof Stylesheet) 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Stylesheet parentElem = (Stylesheet) p; 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isExtension = parentElem.containsExtensionElementURI(uri); 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((false == isExtension) && (null != uri) 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson && (uri.equals(Constants.S_BUILTIN_EXTENSIONS_URL) 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson || uri.equals(Constants.S_BUILTIN_OLD_EXTENSIONS_URL))) 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isComponentDecl = true; 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isUnknownTopLevel = true; 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (isExtension) 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson p = p.getParentElem(); 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplateElement elem = null; 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (isExtension) 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("Creating extension(1): "+uri); 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem = new ElemExtensionCall(); 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (isComponentDecl) 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem = (ElemTemplateElement) classObject.newInstance(); 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (isUnknownTopLevel) 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // TBD: Investigate, not sure about this. -sb 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem = (ElemTemplateElement) classObject.newInstance(); 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem = (ElemTemplateElement) classObject.newInstance(); 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.setDOMBackPointer(handler.getOriginatingNode()); 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.setLocaterInfo(handler.getLocator()); 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.setPrefixes(handler.getNamespaceSupport(), excludeXSLDecl); 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (elem instanceof ElemLiteralResult) 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setNamespace(uri); 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setLocalName(localName); 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setRawName(rawName); 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setIsLiteralResultAsStylesheet( 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isLREAsStyleSheet); 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (InstantiationException ie) 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMLITRSLT, null, ie);//"Failed creating ElemLiteralResult instance!", ie); 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (IllegalAccessException iae) 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMLITRSLT, null, iae);//"Failed creating ElemLiteralResult instance!", iae); 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson setPropertiesFromAttributes(handler, rawName, attributes, elem); 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // bit of a hack here... 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!isExtension && (elem instanceof ElemLiteralResult)) 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson isExtension = 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).containsExtensionElementURI(uri); 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (isExtension) 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("Creating extension(2): "+uri); 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem = new ElemExtensionCall(); 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.setLocaterInfo(handler.getLocator()); 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson elem.setPrefixes(handler.getNamespaceSupport()); 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setNamespace(uri); 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setLocalName(localName); 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((ElemLiteralResult) elem).setRawName(rawName); 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson setPropertiesFromAttributes(handler, rawName, attributes, elem); 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson appendAndPush(handler, elem); 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch(TransformerException te) 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.xml.sax.SAXException(te); 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method could be over-ridden by a class that extends this class. 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param handler non-null reference to current StylesheetHandler that is constructing the Templates. 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return an object that represents the stylesheet element. 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Stylesheet getStylesheetRoot(StylesheetHandler handler) throws TransformerConfigurationException 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StylesheetRoot stylesheet; 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheet = new StylesheetRoot(handler.getSchema(), handler.getStylesheetProcessor().getErrorListener()); 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (handler.getStylesheetProcessor().isSecureProcessing()) 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson stylesheet.setSecureProcessing(true); 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return stylesheet; 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Receive notification of the end of an element. 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param handler non-null reference to current StylesheetHandler that is constructing the Templates. 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri The Namespace URI, or an empty string. 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name (without prefix), or empty string if not namespace processing. 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param rawName The qualified name (with prefix). 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void endElement( 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StylesheetHandler handler, String uri, String localName, String rawName) 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws org.xml.sax.SAXException 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElemTemplateElement elem = handler.getElemTemplateElement(); 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (elem instanceof ElemLiteralResult) 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (((ElemLiteralResult) elem).getIsLiteralResultAsStylesheet()) 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson handler.popStylesheet(); 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super.endElement(handler, uri, localName, rawName); 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean declaredXSLNS(Stylesheet stylesheet) 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson List declaredPrefixes = stylesheet.getDeclaredPrefixes(); 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int n = declaredPrefixes.size(); 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i = 0; i < n; i++) 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XMLNSDecl decl = (XMLNSDecl) declaredPrefixes.get(i); 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(decl.getURI().equals(Constants.S_XSLNAMESPACEURL)) 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return true; 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 370