Home | History | Annotate | Download | only in processor
      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: ProcessorExsltFuncResult.java 468640 2006-10-28 06:53:53Z minchau $
     20  */
     21 package org.apache.xalan.processor;
     22 
     23 import org.apache.xalan.templates.ElemExsltFuncResult;
     24 import org.apache.xalan.templates.ElemExsltFunction;
     25 import org.apache.xalan.templates.ElemParam;
     26 import org.apache.xalan.templates.ElemTemplateElement;
     27 import org.apache.xalan.templates.ElemVariable;
     28 
     29 import org.xml.sax.Attributes;
     30 import org.xml.sax.SAXException;
     31 
     32 /**
     33  * This class processes parse events for an exslt func:result element.
     34  * @xsl.usage internal
     35  */
     36 public class ProcessorExsltFuncResult extends ProcessorTemplateElem
     37 {
     38     static final long serialVersionUID = 6451230911473482423L;
     39 
     40   /**
     41    * Verify that the func:result element does not appear within a variable,
     42    * parameter, or another func:result, and that it belongs to a func:function
     43    * element.
     44    */
     45   public void startElement(
     46           StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
     47             throws SAXException
     48   {
     49     String msg = "";
     50 
     51     super.startElement(handler, uri, localName, rawName, attributes);
     52     ElemTemplateElement ancestor = handler.getElemTemplateElement().getParentElem();
     53     while (ancestor != null && !(ancestor instanceof ElemExsltFunction))
     54     {
     55       if (ancestor instanceof ElemVariable
     56           || ancestor instanceof ElemParam
     57           || ancestor instanceof ElemExsltFuncResult)
     58       {
     59         msg = "func:result cannot appear within a variable, parameter, or another func:result.";
     60         handler.error(msg, new SAXException(msg));
     61       }
     62       ancestor = ancestor.getParentElem();
     63     }
     64     if (ancestor == null)
     65     {
     66       msg = "func:result must appear in a func:function element";
     67       handler.error(msg, new SAXException(msg));
     68     }
     69   }
     70 }
     71