001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: ProcessorExsltFuncResult.java 468640 2006-10-28 06:53:53Z minchau $
020     */
021    package org.apache.xalan.processor;
022    
023    import org.apache.xalan.templates.ElemExsltFuncResult;
024    import org.apache.xalan.templates.ElemExsltFunction;
025    import org.apache.xalan.templates.ElemParam;
026    import org.apache.xalan.templates.ElemTemplateElement;
027    import org.apache.xalan.templates.ElemVariable;
028    
029    import org.xml.sax.Attributes;
030    import org.xml.sax.SAXException;
031    
032    /**
033     * This class processes parse events for an exslt func:result element.
034     * @xsl.usage internal
035     */
036    public class ProcessorExsltFuncResult extends ProcessorTemplateElem
037    {
038        static final long serialVersionUID = 6451230911473482423L;
039      
040      /**
041       * Verify that the func:result element does not appear within a variable,
042       * parameter, or another func:result, and that it belongs to a func:function 
043       * element.
044       */
045      public void startElement(
046              StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
047                throws SAXException
048      {
049        String msg = "";
050    
051        super.startElement(handler, uri, localName, rawName, attributes);
052        ElemTemplateElement ancestor = handler.getElemTemplateElement().getParentElem();
053        while (ancestor != null && !(ancestor instanceof ElemExsltFunction))
054        {
055          if (ancestor instanceof ElemVariable 
056              || ancestor instanceof ElemParam
057              || ancestor instanceof ElemExsltFuncResult)
058          {
059            msg = "func:result cannot appear within a variable, parameter, or another func:result.";
060            handler.error(msg, new SAXException(msg));
061          }
062          ancestor = ancestor.getParentElem();
063        }
064        if (ancestor == null)
065        {
066          msg = "func:result must appear in a func:function element";
067          handler.error(msg, new SAXException(msg));
068        }
069      }
070    }