KickJava   Java API By Example, From Geeks To Geeks.

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


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: ProcessorStylesheetElement.java,v 1.13 2004/02/11 18:15:51 minchau Exp $
18  */

19 package org.apache.xalan.processor;
20
21 import javax.xml.transform.TransformerConfigurationException JavaDoc;
22 import javax.xml.transform.TransformerException JavaDoc;
23
24 import org.apache.xalan.templates.Stylesheet;
25 import org.apache.xalan.templates.StylesheetComposed;
26 import org.apache.xalan.templates.StylesheetRoot;
27
28 import org.xml.sax.Attributes JavaDoc;
29
30 /**
31  * TransformerFactory for xsl:stylesheet or xsl:transform markup.
32  * @see <a HREF="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
33  * @see <a HREF="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a>
34  */

35 class ProcessorStylesheetElement extends XSLTElementProcessor
36 {
37
38   /**
39    * Receive notification of the start of an strip-space element.
40    *
41    * @param handler The calling StylesheetHandler/TemplatesBuilder.
42    * @param uri The Namespace URI, or the empty string if the
43    * element has no Namespace URI or if Namespace
44    * processing is not being performed.
45    * @param localName The local name (without prefix), or the
46    * empty string if Namespace processing is not being
47    * performed.
48    * @param rawName The raw XML 1.0 name (with prefix), or the
49    * empty string if raw names are not available.
50    * @param attributes The attributes attached to the element. If
51    * there are no attributes, it shall be an empty
52    * Attributes object.
53    */

54   public void startElement(
55           StylesheetHandler handler, String JavaDoc uri, String JavaDoc localName, String JavaDoc rawName, Attributes JavaDoc attributes)
56             throws org.xml.sax.SAXException JavaDoc
57   {
58
59         super.startElement(handler, uri, localName, rawName, attributes);
60     try
61     {
62       int stylesheetType = handler.getStylesheetType();
63       Stylesheet stylesheet;
64
65       if (stylesheetType == StylesheetHandler.STYPE_ROOT)
66       {
67         try
68         {
69           stylesheet = new StylesheetRoot(handler.getSchema(), handler.getStylesheetProcessor().getErrorListener());
70         }
71         catch(TransformerConfigurationException JavaDoc tfe)
72         {
73           throw new TransformerException JavaDoc(tfe);
74         }
75       }
76       else
77       {
78         Stylesheet parent = handler.getStylesheet();
79
80         if (stylesheetType == StylesheetHandler.STYPE_IMPORT)
81         {
82           StylesheetComposed sc = new StylesheetComposed(parent);
83
84           parent.setImport(sc);
85
86           stylesheet = sc;
87         }
88         else
89         {
90           stylesheet = new Stylesheet(parent);
91
92           parent.setInclude(stylesheet);
93         }
94       }
95
96       stylesheet.setDOMBackPointer(handler.getOriginatingNode());
97       stylesheet.setLocaterInfo(handler.getLocator());
98
99       stylesheet.setPrefixes(handler.getNamespaceSupport());
100       handler.pushStylesheet(stylesheet);
101       setPropertiesFromAttributes(handler, rawName, attributes,
102                                   handler.getStylesheet());
103       handler.pushElemTemplateElement(handler.getStylesheet());
104     }
105     catch(TransformerException JavaDoc te)
106     {
107       throw new org.xml.sax.SAXException JavaDoc(te);
108     }
109   }
110
111   /**
112    * Receive notification of the end of an element.
113    *
114    * @param name The element type name.
115    * @param attributes The specified or defaulted attributes.
116    *
117    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
118    * @param uri The Namespace URI, or an empty string.
119    * @param localName The local name (without prefix), or empty string if not namespace processing.
120    * @param rawName The qualified name (with prefix).
121    */

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