• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18 /*
19  * $Id: ElemFallback.java 468643 2006-10-28 06:56:03Z minchau $
20  */
21 package org.apache.xalan.templates;
22 
23 import javax.xml.transform.TransformerException;
24 
25 import org.apache.xalan.transformer.TransformerImpl;
26 
27 /**
28  * Implement xsl:fallback.
29  * <pre>
30  * <!ELEMENT xsl:fallback %template;>
31  * <!ATTLIST xsl:fallback %space-att;>
32  * </pre>
33  * @see <a href="http://www.w3.org/TR/xslt#fallback">fallback in XSLT Specification</a>
34  * @xsl.usage advanced
35  */
36 public class ElemFallback extends ElemTemplateElement
37 {
38     static final long serialVersionUID = 1782962139867340703L;
39 
40   /**
41    * Get an int constant identifying the type of element.
42    * @see org.apache.xalan.templates.Constants
43    *
44    * @return The token ID for this element
45    */
getXSLToken()46   public int getXSLToken()
47   {
48     return Constants.ELEMNAME_FALLBACK;
49   }
50 
51   /**
52    * Return the node name.
53    *
54    * @return The Element's name
55    */
getNodeName()56   public String getNodeName()
57   {
58     return Constants.ELEMNAME_FALLBACK_STRING;
59   }
60 
61   /**
62    * This is the normal call when xsl:fallback is instantiated.
63    * In accordance with the XSLT 1.0 Recommendation, chapter 15,
64    * "Normally, instantiating an xsl:fallback element does nothing."
65    *
66    * @param transformer non-null reference to the the current transform-time state.
67    *
68    * @throws TransformerException
69    */
execute( TransformerImpl transformer)70   public void execute(
71           TransformerImpl transformer)
72             throws TransformerException
73   {
74   }
75 
76   /**
77    * Execute the fallback elements.  This must be explicitly called to
78    * instantiate the content of an xsl:fallback element.
79    * When an XSLT transformer performs fallback for an instruction
80    * element, if the instruction element has one or more xsl:fallback
81    * children, then the content of each of the xsl:fallback children
82    * must be instantiated in sequence; otherwise, an error must
83    * be signaled. The content of an xsl:fallback element is a template.
84    *
85    * @param transformer non-null reference to the the current transform-time state.
86    *
87    * @throws TransformerException
88    */
executeFallback( TransformerImpl transformer)89   public void executeFallback(
90           TransformerImpl transformer)
91             throws TransformerException
92   {
93 
94     int parentElemType = m_parentNode.getXSLToken();
95     if (Constants.ELEMNAME_EXTENSIONCALL == parentElemType
96         || Constants.ELEMNAME_UNDEFINED == parentElemType)
97     {
98 
99       transformer.executeChildTemplates(this, true);
100 
101     }
102     else
103     {
104 
105       // Should never happen
106       System.out.println(
107         "Error!  parent of xsl:fallback must be an extension or unknown element!");
108     }
109   }
110 }
111