KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > processor > ProcessorTemplateElem


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ProcessorTemplateElem.java,v 1.14 2004/02/11 18:15:51 minchau Exp $
18  */

19 package org.apache.xalan.processor;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.res.XSLTErrorResources;
24 import org.apache.xalan.templates.ElemTemplateElement;
25
26 import org.xml.sax.Attributes JavaDoc;
27
28 /**
29  * This class processes parse events for an XSLT template element.
30  * @see <a HREF="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
31  * @see <a HREF="http://www.w3.org/TR/xslt#section-Creating-the-Result-Tree">section-Creating-the-Result-Tree in XSLT Specification</a>
32  */

33 public class ProcessorTemplateElem extends XSLTElementProcessor
34 {
35
36   /**
37    * Receive notification of the start of an element.
38    *
39    * @param name The element type name.
40    *
41    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
42    * @param uri The Namespace URI, or an empty string.
43    * @param localName The local name (without prefix), or empty string if not namespace processing.
44    * @param rawName The qualified name (with prefix).
45    * @param attributes The specified or defaulted attributes.
46    */

47   public void startElement(
48           StylesheetHandler handler, String JavaDoc uri, String JavaDoc localName, String JavaDoc rawName, Attributes JavaDoc attributes)
49             throws org.xml.sax.SAXException JavaDoc
50   {
51
52     super.startElement(handler, uri, localName, rawName, attributes);
53     try
54     {
55       // ElemTemplateElement parent = handler.getElemTemplateElement();
56
XSLTElementDef def = getElemDef();
57       Class JavaDoc classObject = def.getClassObject();
58       ElemTemplateElement elem = null;
59
60       try
61       {
62         elem = (ElemTemplateElement) classObject.newInstance();
63
64         elem.setDOMBackPointer(handler.getOriginatingNode());
65         elem.setLocaterInfo(handler.getLocator());
66         elem.setPrefixes(handler.getNamespaceSupport());
67       }
68       catch (InstantiationException JavaDoc ie)
69       {
70         handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, ie);//"Failed creating ElemTemplateElement instance!", ie);
71
}
72       catch (IllegalAccessException JavaDoc iae)
73       {
74         handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, iae);//"Failed creating ElemTemplateElement instance!", iae);
75
}
76
77       setPropertiesFromAttributes(handler, rawName, attributes, elem);
78       appendAndPush(handler, elem);
79     }
80     catch(TransformerException JavaDoc te)
81     {
82       throw new org.xml.sax.SAXException JavaDoc(te);
83     }
84   }
85
86   /**
87    * Append the current template element to the current
88    * template element, and then push it onto the current template
89    * element stack.
90    *
91    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
92    * @param elem non-null reference to a the current template element.
93    *
94    * @throws org.xml.sax.SAXException Any SAX exception, possibly
95    * wrapping another exception.
96    */

97   protected void appendAndPush(
98           StylesheetHandler handler, ElemTemplateElement elem)
99             throws org.xml.sax.SAXException JavaDoc
100   {
101
102     ElemTemplateElement parent = handler.getElemTemplateElement();
103     if(null != parent) // defensive, for better multiple error reporting. -sb
104
{
105       parent.appendChild(elem);
106       handler.pushElemTemplateElement(elem);
107     }
108   }
109
110   /**
111    * Receive notification of the end of an element.
112    *
113    * @param name The element type name.
114    * @param attributes The specified or defaulted attributes.
115    *
116    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
117    * @param uri The Namespace URI, or an empty string.
118    * @param localName The local name (without prefix), or empty string if not namespace processing.
119    * @param rawName The qualified name (with prefix).
120    */

121   public void endElement(
122           StylesheetHandler handler, String JavaDoc uri, String JavaDoc localName, String JavaDoc rawName)
123             throws org.xml.sax.SAXException JavaDoc
124   {
125     super.endElement(handler, uri, localName, rawName);
126     handler.popElemTemplateElement().setEndLocaterInfo(handler.getLocator());
127   }
128 }
129
Popular Tags