2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
* $Id: ProcessorTemplateElem.java,v 1.2 2009/12/10 03:18:35 matthewoliver Exp $
21
package org.apache.xalan.processor;
23
import javax.xml.transform.TransformerException;
25
import org.apache.xalan.res.XSLTErrorResources;
26
import org.apache.xalan.templates.ElemTemplateElement;
28
import org.xml.sax.Attributes;
31
* This class processes parse events for an XSLT template element.
32
* @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
33
* @see <a href="http://www.w3.org/TR/xslt#section-Creating-the-Result-Tree">section-Creating-the-Result-Tree in XSLT Specification</a>
35
public class ProcessorTemplateElem extends XSLTElementProcessor
37
static final long serialVersionUID = 8344994001943407235L;
40
* Receive notification of the start of an element.
42
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
43
* @param uri The Namespace URI, or an empty string.
44
* @param localName The local name (without prefix), or empty string if not namespace processing.
45
* @param rawName The qualified name (with prefix).
46
* @param attributes The specified or defaulted attributes.
48
public void startElement(
49
StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
50
throws org.xml.sax.SAXException
53
super.startElement(handler, uri, localName, rawName, attributes);
56
// ElemTemplateElement parent = handler.getElemTemplateElement();
57
XSLTElementDef def = getElemDef();
58
Class classObject = def.getClassObject();
59
ElemTemplateElement elem = null;
63
elem = (ElemTemplateElement) classObject.newInstance();
65
elem.setDOMBackPointer(handler.getOriginatingNode());
66
elem.setLocaterInfo(handler.getLocator());
67
elem.setPrefixes(handler.getNamespaceSupport());
69
catch (InstantiationException ie)
71
handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, ie);//"Failed creating ElemTemplateElement instance!", ie);
73
catch (IllegalAccessException iae)
75
handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, iae);//"Failed creating ElemTemplateElement instance!", iae);
78
setPropertiesFromAttributes(handler, rawName, attributes, elem);
79
appendAndPush(handler, elem);
81
catch(TransformerException te)
83
throw new org.xml.sax.SAXException(te);
88
* Append the current template element to the current
89
* template element, and then push it onto the current template
92
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
93
* @param elem non-null reference to a the current template element.
95
* @throws org.xml.sax.SAXException Any SAX exception, possibly
96
* wrapping another exception.
98
protected void appendAndPush(
99
StylesheetHandler handler, ElemTemplateElement elem)
100
throws org.xml.sax.SAXException
103
ElemTemplateElement parent = handler.getElemTemplateElement();
104
if(null != parent) // defensive, for better multiple error reporting. -sb
106
parent.appendChild(elem);
107
handler.pushElemTemplateElement(elem);
112
* Receive notification of the end of an element.
114
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
115
* @param uri The Namespace URI, or an empty string.
116
* @param localName The local name (without prefix), or empty string if not namespace processing.
117
* @param rawName The qualified name (with prefix).
119
public void endElement(
120
StylesheetHandler handler, String uri, String localName, String rawName)
121
throws org.xml.sax.SAXException
123
super.endElement(handler, uri, localName, rawName);
124
handler.popElemTemplateElement().setEndLocaterInfo(handler.getLocator());