KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > ElemFallback


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: ElemFallback.java,v 1.17 2004/02/16 20:32:33 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.transformer.TransformerImpl;
24
25 /**
26  * Implement xsl:fallback.
27  * <pre>
28  * <!ELEMENT xsl:fallback %template;>
29  * <!ATTLIST xsl:fallback %space-att;>
30  * </pre>
31  * @see <a HREF="http://www.w3.org/TR/xslt#fallback">fallback in XSLT Specification</a>
32  * @xsl.usage advanced
33  */

34 public class ElemFallback extends ElemTemplateElement
35 {
36
37   /**
38    * Get an int constant identifying the type of element.
39    * @see org.apache.xalan.templates.Constants
40    *
41    * @return The token ID for this element
42    */

43   public int getXSLToken()
44   {
45     return Constants.ELEMNAME_FALLBACK;
46   }
47
48   /**
49    * Return the node name.
50    *
51    * @return The Element's name
52    */

53   public String JavaDoc getNodeName()
54   {
55     return Constants.ELEMNAME_FALLBACK_STRING;
56   }
57
58   /**
59    * This is the normal call when xsl:fallback is instantiated.
60    * In accordance with the XSLT 1.0 Recommendation, chapter 15,
61    * "Normally, instantiating an xsl:fallback element does nothing."
62    *
63    * @param transformer non-null reference to the the current transform-time state.
64    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
65    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
66    *
67    * @throws TransformerException
68    */

69   public void execute(
70           TransformerImpl transformer)
71             throws TransformerException JavaDoc
72   {
73   }
74
75   /**
76    * Execute the fallback elements. This must be explicitly called to
77    * instantiate the content of an xsl:fallback element.
78    * When an XSLT transformer performs fallback for an instruction
79    * element, if the instruction element has one or more xsl:fallback
80    * children, then the content of each of the xsl:fallback children
81    * must be instantiated in sequence; otherwise, an error must
82    * be signaled. The content of an xsl:fallback element is a template.
83    *
84    * @param transformer non-null reference to the the current transform-time state.
85    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
86    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
87    *
88    * @throws TransformerException
89    */

90   public void executeFallback(
91           TransformerImpl transformer)
92             throws TransformerException JavaDoc
93   {
94
95     int parentElemType = m_parentNode.getXSLToken();
96     if (Constants.ELEMNAME_EXTENSIONCALL == parentElemType
97         || Constants.ELEMNAME_UNDEFINED == parentElemType)
98     {
99
100       if (TransformerImpl.S_DEBUG)
101         transformer.getTraceManager().fireTraceEvent(this);
102
103       transformer.executeChildTemplates(this, true);
104
105       if (TransformerImpl.S_DEBUG)
106         transformer.getTraceManager().fireTraceEndEvent(this);
107     }
108     else
109     {
110
111       // Should never happen
112
System.out.println(
113         "Error! parent of xsl:fallback must be an extension or unknown element!");
114     }
115   }
116 }
117
Popular Tags