Home | History | Annotate | Download | only in templates
      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: ElemUnknown.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 /**
     29  * Implement an unknown element
     30  * @xsl.usage advanced
     31  */
     32 public class ElemUnknown extends ElemLiteralResult
     33 {
     34     static final long serialVersionUID = -4573981712648730168L;
     35 
     36   /**
     37    * Get an int constant identifying the type of element.
     38    * @see org.apache.xalan.templates.Constants
     39    *
     40    *@return The token ID for this element
     41    */
     42   public int getXSLToken()
     43   {
     44     return Constants.ELEMNAME_UNDEFINED;
     45   }
     46 
     47   /**
     48    * Execute the fallbacks when an extension is not available.
     49    *
     50    * @param transformer non-null reference to the the current transform-time state.
     51    *
     52    * @throws TransformerException
     53    */
     54   private void executeFallbacks(
     55           TransformerImpl transformer)
     56             throws TransformerException
     57   {
     58     for (ElemTemplateElement child = m_firstChild; child != null;
     59              child = child.m_nextSibling)
     60     {
     61       if (child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
     62       {
     63         try
     64         {
     65           transformer.pushElemTemplateElement(child);
     66           ((ElemFallback) child).executeFallback(transformer);
     67         }
     68         finally
     69         {
     70           transformer.popElemTemplateElement();
     71         }
     72       }
     73     }
     74 
     75   }
     76 
     77   /**
     78    * Return true if this extension element has a <xsl:fallback> child element.
     79    *
     80    * @return true if this extension element has a <xsl:fallback> child element.
     81    */
     82   private boolean hasFallbackChildren()
     83   {
     84     for (ElemTemplateElement child = m_firstChild; child != null;
     85              child = child.m_nextSibling)
     86     {
     87       if (child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
     88         return true;
     89     }
     90 
     91     return false;
     92   }
     93 
     94 
     95   /**
     96    * Execute an unknown element.
     97    * Execute fallback if fallback child exists or do nothing
     98    *
     99    * @param transformer non-null reference to the the current transform-time state.
    100    *
    101    * @throws TransformerException
    102    */
    103   public void execute(TransformerImpl transformer)
    104             throws TransformerException
    105   {
    106 
    107 
    108 	try {
    109 
    110 		if (hasFallbackChildren()) {
    111 			executeFallbacks(transformer);
    112 		} else {
    113 			// do nothing
    114 		}
    115 
    116 	} catch (TransformerException e) {
    117 		transformer.getErrorListener().fatalError(e);
    118 	}
    119   }
    120 
    121 }
    122