You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/08/26 11:09:57 UTC

cvs commit: jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/util/jsp JspActionEvent.java

henning     2003/08/26 02:09:57

  Added:       proposals/henning/jsp-tags README.gabriel README.henning
               proposals/henning/jsp-tags/src/java/org/apache/turbine/modules/actions
                        JspAction.java
               proposals/henning/jsp-tags/src/java/org/apache/turbine/modules/screens
                        JspScreen.java
               proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp
                        TurbineJsp.java
               proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags
                        BodyAttributesTag.java BodyTag.java HeadTag.java
                        NavigationTag.java ScreenTag.java
                        TemplateLinkTag.java
               proposals/henning/jsp-tags/src/java/org/apache/turbine/util/jsp
                        JspActionEvent.java
  Log:
  The JSP Tags code as sent to me by Gabriel Moreno <ga...@itcsoluciones.com>
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/README.gabriel
  
  Index: README.gabriel
  ===================================================================
  Return-Path: <ga...@itcsoluciones.com>
  Subject: Re: jsp template problem
  From: Gabriel Moreno <ga...@itcsoluciones.com>
  To: hps@intermeta.de
  Message-Id: <10...@vandal.intra.itcsoluciones.com>
  
  Henning,
  Here is the JSP patch I sent a while ago for using Context in JSP
  templates. The tags are included there.
  
  Thanks,
  Gabriel
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/README.henning
  
  Index: README.henning
  ===================================================================
  Extended JSP Support / JSP Tags for Turbine
  ===========================================
  
  From a first glance, this code needs quite some work. It tries a
  frankensteinian combination of Jsp Pages with a Velocity Context which
  doesn't work out too well. The JspAction, JspActionEvent, the
  JspScreen classes and the patches to the JspService are unlikely to go
  into Turbine in this shape.
  
  The Tag lib in o.a.t.services.jsp.tags seems to be able to compile
  without these classes but this needs looking and documenting from
  someone who is familiar with JSP and taglibs. This is included mainly
  so that the code doesn't get lost again.  
  
  The whole code is at Turbine 2.1 level and needs some reworking,
  especially for the TemplateLinkTag
  
  If you want to use the Jsp View with Turbine and willing to work on
  this, please do and contact us at turbine-dev@jakarta.apache.org 
  
  	-- Henning Schmiedehausen, 2003-08-26
  
  
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/modules/actions/JspAction.java
  
  Index: JspAction.java
  ===================================================================
  package org.apache.turbine.modules.actions;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.turbine.modules.screens.TemplateScreen;
  import org.apache.turbine.services.jsp.TurbineJsp;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.jsp.JspActionEvent;
  import org.apache.velocity.context.Context;
  
  /**
   * This class provides a convenience methods for Jsp Actions
   * to use. Since this class is abstract, it should only be extended
   * and not used directly.
   *
   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   * @author <a href="mailto:gabrielm@itcsoluciones.com">Gabriel A. Moreno</a>
   * @version $Id: JspAction.java,v 1.1 2003/08/26 09:09:56 henning Exp $
   */
  public abstract class JspAction extends JspActionEvent
  {
      /**
       * You SHOULD NOT override this method and implement it in your
       * action.
       *
       * @param data Turbine information.
       * @exception Exception, a generic exception.
       */
      public void doPerform(RunData data)
          throws Exception
      {
          doPerform(data, getContext(data));
      }
  
      /**
       * You SHOULD override this method and implement it in your
       * action.
       *
       * @param data Turbine information.
       * @param context Context for web pages.
       * @exception Exception, a generic exception.
       */
      public abstract void doPerform(RunData data,
                                     Context context)
          throws Exception;
  
      /**
       * Sets up the context and then calls super.perform(); thus,
       * subclasses don't have to worry about getting a context
       * themselves!
       *
       * @param data Turbine information.
       * @exception Exception, a generic exception.
       */
      protected void perform(RunData data)
          throws Exception
      {
          super.perform(data);
      }
  
      /**
       * This method is used when you want to short circuit an Action
       * and change the template that will be executed next.
       *
       * @param data Turbine information.
       * @param template The template that will be executed next.
       */
      public void setTemplate(RunData data,
                              String template)
      {
          TemplateScreen.setTemplate(data, template);
      }
  
      /**
       * Return the Context needed by Jsp.
       *
       * @param RunData data
       * @return Context, a context for web pages.
       */
      protected Context getContext(RunData data)
      {
          return TurbineJsp.getContext(data);
      }
  }
  
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/modules/screens/JspScreen.java
  
  Index: JspScreen.java
  ===================================================================
  package org.apache.turbine.modules.screens;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ecs.ConcreteElement;
  import org.apache.turbine.services.jsp.JspService;
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.services.template.TurbineTemplate;
  import org.apache.turbine.util.RunData;
  import org.apache.velocity.context.Context;
  import org.apache.turbine.services.jsp.TurbineJsp;
  
  /**
   * Jsp Screen with support for conext. The buildTemplate() assumes the
   * template parameter has been set in the RunData object.  This provides
   * the ability to execute several templates from one Screen.
   *
   * <p>
   *
   * If you need more specific behavior in your application, extend this
   * class and override the doBuildTemplate() method.
   *
   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
   * @author <a href="mailto:gabrielm@itcsoluciones.com">Gabriel A. Moreno</a>
   * @version $Id: JspScreen.java,v 1.1 2003/08/26 09:09:56 henning Exp $
   */
  public class JspScreen extends BaseJspScreen {
      
      /**
       * Jsp Screens extending this class should overide this
       * method to perform any particular business logic and add
       * information to the context.
       *
       * @param data Turbine information.
       * @param context Context for web pages.
       * @exception Exception, a generic exception.
       */
      protected void doBuildTemplate( RunData data,
                                      Context context )
          throws Exception
      {
      }
  
      /**
       * Needs to be implemented to make TemplateScreen like us.  The
       * actual method that you should override is the one with the
       * context in the parameter list.
       *
       * @param data Turbine information.
       * @exception Exception, a generic exception.
       */
      protected void doBuildTemplate( RunData data )
          throws Exception
      {
          doBuildTemplate(data, TurbineJsp.getContext(data));
      }
  
      /**
       * Return the Context needed which can then be used in the Jsp template
       *
       * @param data Turbine information.
       * @return A Context.
       */
      public static Context getContext(RunData data)
      {
          return TurbineJsp.getContext(data);
      }
     
  }
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/TurbineJsp.java
  
  Index: TurbineJsp.java
  ===================================================================
  package org.apache.turbine.services.jsp;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.OutputStream;
  import java.io.Writer;
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.util.RunData;
  import org.apache.velocity.context.Context;
  
  /**
   * This is a simple static accessor to common Jsp tasks such as
   * getting an instance of a context as well as handling a request for
   * processing a template.
   *
   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
   * @author <a href="mailto:jvanzyl@periapt.com.com">Jason van Zyl</a>
   * @author <a href="mailto:gabrielm@itcsoluciones.com">Gabriel A. Moreno</a>
   * @version $Id: TurbineJsp.java,v 1.1 2003/08/26 09:09:57 henning Exp $
   */
  public abstract class TurbineJsp
  {
      /**
       * Utility method for accessing the service
       * implementation
       *
       * @return a JspService implementation instance
       */
      protected static JspService getService()
      {
          return (JspService)TurbineServices
              .getInstance().getService(JspService.SERVICE_NAME);
      }
  
      /**
       * This returns a Context that can be used in the Jsp template
       * once you have populated it with information that the template
       * will know about.
       *
       * @param data A Turbine RunData.
       * @return A Context.
       */
      public static Context getContext(RunData data)
      {
          return getService().getContext(data);
      }
  
      /**
       * This method returns a blank Context object.
       *
       * @return A WebContext.
       */
      public static Context getContext()
      {
          return getService().getContext();
      }
  
  }
  
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags/BodyAttributesTag.java
  
  Index: BodyAttributesTag.java
  ===================================================================
  package org.apache.turbine.services.jsp.tags;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.IOException;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  /**
   * Supporting class for the bodyAttributes tag.
   * Sends the contents of the a screen's body tag's attributes
   * parameter to the output stream.  If the screen did not set
   * the attributes parameter, a default may be used if specified
   * in this tag.  Example usage:
   * &lt;body &lt;x:bodyAttributes default='onLoad="jsfunc()"' /&gt;&gt;
   *
   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
   */
  public class BodyAttributesTag extends TagSupport 
  {
      /** 
       * The default body tag attributes, if none is specified in the screen. 
       */
      private String def;
      
      /** 
       * The setter for the default body tag attributes. 
       */
      public void setDefault(String def)
      {
          this.def = def;
      }
      
      /**
       * Method called when the tag is encountered to send attributes to the
       * output stream
       *
       * @return SKIP_BODY, as it is intended to be a single tag.
       */
      public int doStartTag() throws JspException 
      {
          String bodyAttributes = (String)pageContext
              .getAttribute(BodyTag.ATTRIBUTES, PageContext.REQUEST_SCOPE);
          try 
          {
              if (bodyAttributes != null)
              {
                  pageContext.getOut().print(bodyAttributes);
              }
              else
              {
                  pageContext.getOut().print(def);
              }
          }
          catch(java.io.IOException ex) 
          {
              throw new JspException(ex.getMessage());
          }
          return SKIP_BODY;
      }
  }
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags/BodyTag.java
  
  Index: BodyTag.java
  ===================================================================
  package org.apache.turbine.services.jsp.tags;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  /**
   * Supporting class for the body tag.
   * Tags that surround the screen content that will replace the 
   * &lt;x:screen section="body" /&gt; tag in a layout template.
   * An optional attributes parameter can be used to set the value
   * of the &lt;x:bodyAttributes /&gt;, which can also be in the
   * layout.
   * Example usage:
   * &lt;x:body attributes='onLoad="jsfunc()"'&gt;
   * some html content
   * &lt;/x:body&gt;
   *
   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
   */
  public class BodyTag extends TagSupport 
  {
      static final String ATTRIBUTES = "_body_tag_attributes_";
      
      /**
       * attributes parameter can be used to add screen specific attribute values
       * to the &lt;body&gt; tag.
       */
      private String attributes;
  
      /** 
       * The setter for body tag attributes relevant to the screen containing
       * this tag. 
       */
      public void setAttributes(String attributes) 
      {
          pageContext.setAttribute(ATTRIBUTES, attributes, 
              PageContext.REQUEST_SCOPE);
          this.attributes = attributes;
      }
      
      /**
       * Method called when the tag is encountered.  If the layout is in
       * the body section, the contents between the body tags are executed.
       * Otherwise they are skipped.
       *
       * @return EVAL_BODY_INCLUDE, if the section has been set to body
       * or SKIP_BODY, if this section is not active.
       */
      public int doStartTag() throws JspException 
      {
          boolean isActive = ScreenTag.BODY.equals(
              pageContext.getAttribute(ScreenTag.SECTION_KEY, 
                  PageContext.REQUEST_SCOPE) );
          if (isActive)
          {
               return EVAL_BODY_INCLUDE;
          }
          return SKIP_BODY;
      }
      
      /**
       * Method called when the end tag is encountered; it does nothing.  
       *
       * @return EVAL_PAGE
       */
      public int doEndTag() throws JspException 
      {
          return EVAL_PAGE;
      }
  }
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags/HeadTag.java
  
  Index: HeadTag.java
  ===================================================================
  package org.apache.turbine.services.jsp.tags;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  /**
   * Supporting class for the head tag.
   * Tags that surround the screen content that will replace the 
   * &lt;x:screen section="head" /&gt; tag in a layout template.
   * Example usage:
   * &lt;x:head&gt;&lt;title&gt;Login&lt;/title&gt;&lt;/x:head&gt;
   *
   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
   */
  public class HeadTag extends TagSupport 
  {
      /**
       * Method called when the start tag is encountered.  If the layout is 
       * in the head section, the contents between the head tags are executed.
       * Otherwise they are skipped.
       *
       * @return EVAL_BODY_INCLUDE, if the section has been set to body
       * or SKIP_BODY, if this section is not active.
       */
  	public int doStartTag() throws JspException 
      {
          boolean isActive = ScreenTag.HEAD.equals(
              pageContext.getAttribute(ScreenTag.SECTION_KEY, 
                  PageContext.REQUEST_SCOPE) );
          if (isActive)
          {
  		     return EVAL_BODY_INCLUDE;
          }
          return SKIP_BODY;
  	}
      
      /**
       * Method called when the end tag is encountered; it does nothing.  
       *
       * @return EVAL_PAGE
       */
  	public int doEndTag() throws JspException 
      {
  		return EVAL_PAGE;
  	}
  }
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags/NavigationTag.java
  
  Index: NavigationTag.java
  ===================================================================
  package org.apache.turbine.services.jsp.tags;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.IOException;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  import org.apache.turbine.modules.NavigationLoader;
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.services.jsp.JspService;
  import org.apache.turbine.services.template.TemplateService;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.template.TemplateInfo;
  
  /**
   * Supporting class for the bodyAttributes tag.
   * Sends the contents of the a screen's body tag's attributes
   * parameter to the output stream.  If the screen did not set
   * the attributes parameter, a default may be used if specified
   * in this tag.  Example usage:
   * &lt;body &lt;x:bodyAttributes default='onLoad="jsfunc()"' /&gt;&gt;
   *
   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
   */
  public class NavigationTag extends TagSupport 
  {
      /**
       * template parameter defines the template whose contents will replace
       * this tag in the layout.
       */
      private String template;
  
      /** 
       * The setter for template parameter
       */
      public void setTemplate(String template) 
      {
          this.template = template;
      }
  
      /**
       * Method called when the tag is encountered to send the navigation
       * template's contents to the output stream
       *
       * @return SKIP_BODY, as it is intended to be a single tag.
       */
      public int doStartTag() throws JspException 
      {
          RunData data = (RunData)pageContext
                  .getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);    
          data.getTemplateInfo().setNavigationTemplate(template);
          String module = null;
          try
          {  
              pageContext.getOut().flush();
              module = ((TemplateService)TurbineServices.getInstance().getService(
              TemplateService.SERVICE_NAME)).getNavigationName(template);
              NavigationLoader.getInstance().exec(data, module);
          }
          catch (Exception e)
          {
              String message = "Error processing navigation template:" +
                  template + " using module: " + module;
              Log.error(message, e);
              try
              {
                  data.getOut().print("Error processing navigation template: " 
                      + template + " using module: " + module);
              }
              catch(java.io.IOException ioe) {}    
          }
          return SKIP_BODY;
      }
  }
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags/ScreenTag.java
  
  Index: ScreenTag.java
  ===================================================================
  package org.apache.turbine.services.jsp.tags;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.IOException;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  import org.apache.turbine.modules.ScreenLoader;
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.services.jsp.JspService;
  import org.apache.turbine.services.template.TemplateService;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.template.TemplateInfo;
  
  /**
   * Supporting class for the screen tag.
   * Sends the content between the screen's body or head tags to the 
   * output stream.  The decision to output the head or body contents 
   * is decided by the section parameter.  Example usage:
   * &lt;x:screen section="head" /&gt;
   *
   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
   */
  public class ScreenTag extends TagSupport 
  {
      /**
       * section attribute. Valid values are head or body.
       */
      private String section;
      /**
       * contextRelevant attribute. Meant to allow the Screen
       * java code to be skipped in the event the content is static.
       * Not working and have not decided whether to make it work or
       * remove the functionality.
       */
      private boolean staticContent;    
      /**
       * Key used to prevent the templates Screen module from executing
       * multiple times while evaluating the layout.
       */
      private static final String FLAG = "_screen_executed_";
  
      /**
       * Key used to access the section parameter in the request.
       */
      static final String SECTION_KEY = "_layout_section_";
      /**
       * One of the valid values for the section parameter
       */
      static final String BODY = "body";
      /**
       * One of the valid values for the section parameter
       */
      static final String HEAD = "head";
      
      /**
       * setter for the section parameter
       */
      public void setSection(String section) 
      {
          pageContext.setAttribute(SECTION_KEY, section, 
              PageContext.REQUEST_SCOPE);
          this.section = section;
      }
      
      /**
       * setter for the staticContent parameter
       */
      public void setStaticContent(boolean staticContent) 
      {
          this.staticContent = staticContent;
      }
  
      /**
       * Method called when the tag is encountered to send attributes to the
       * output stream
       *
       * @return SKIP_BODY, as it is intended to be a single tag.
       */
      public int doStartTag() throws JspException 
      {
          RunData data = (RunData)pageContext
                  .getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);    
          
          String module = null;
          String template = null;
          Boolean flag = (Boolean)pageContext
                  .getAttribute(FLAG, PageContext.REQUEST_SCOPE);
          JspService jsp = (JspService) TurbineServices.getInstance()
              .getService(JspService.SERVICE_NAME);
          try
          {  
              pageContext.getOut().flush();
              template = data.getTemplateInfo().getScreenTemplate();
              
              if ( staticContent || (flag != null && flag.booleanValue()) ) 
              {
                  jsp.handleRequest(data, "/screens/" + template, false);
              }
              else
              {
                  module = ((TemplateService)TurbineServices.getInstance().getService(
                  TemplateService.SERVICE_NAME)).getScreenName(template);
                  ScreenLoader.getInstance().exec(data, module);
                  pageContext.setAttribute(FLAG, 
                      Boolean.TRUE, PageContext.REQUEST_SCOPE);
              }
          }
          catch (Exception e)
          {
              String message = "Error processing screen template:" +
                  template + " using module: " + module;
              Log.error(message, e);
              try
              {
                  data.getOut().print("Error processing screen template: " 
                      + template + " using module: " + module);
              }
              catch(java.io.IOException ioe) {}    
          }
          return SKIP_BODY;
      }
  }
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/services/jsp/tags/TemplateLinkTag.java
  
  Index: TemplateLinkTag.java
  ===================================================================
  package org.apache.turbine.services.jsp.tags;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.IOException;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  import org.apache.turbine.services.jsp.JspService;
  import org.apache.turbine.util.DynamicURI;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.template.TemplateLink;
  
  /**
    * Supporting class for the TemplateLink tag.
    * Uses the TemplateLink class to construct a URI
    *
    * @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
    */
  public class TemplateLinkTag extends TagSupport
  {
       /**
        * template parameter defines the template to set
        * mandatory parameter
        */
       private String template;
  
       /**
        * The setter for template parameter
        */
       public void setTemplate(String template)
       {
           this.template = template;
       }
  
       /**
        * action parameter defines the action to set
        * optional parameter
        */
       private String action;
  
       /**
        * The setter for screen parameter
        */
       public void setAction(String action)
       {
           this.action = action;
       }
  
       public int doStartTag() throws JspException
       {
           RunData data = 
               (RunData)pageContext.getAttribute(JspService.RUNDATA, 
                                                 PageContext.REQUEST_SCOPE);
  
           TemplateLink link = new TemplateLink( data );
           DynamicURI uri = link.setPage( template );
           if ( action != null ) uri = uri.setAction( action );
  
           try
           {
               if (uri != null) {
                   pageContext.getOut().print(uri.toString());
               }
           }
           catch (Exception e)
           {
               String message = 
                   "Error processing TemplateLink-tag, parameter: template='"
                   + template + "', action='" +action +"'";
               Log.error(message, e);
               try
               {
                   data.getOut().print( message );
               }
               catch(java.io.IOException ioe) {}
           }
  
           return EVAL_BODY_INCLUDE;
       }
  
  }
  
  
  
  
  1.1                  jakarta-turbine-2/proposals/henning/jsp-tags/src/java/org/apache/turbine/util/jsp/JspActionEvent.java
  
  Index: JspActionEvent.java
  ===================================================================
  package org.apache.turbine.util.jsp;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.lang.reflect.Method;
  import java.util.Enumeration;
  import org.apache.turbine.modules.ActionEvent;
  import org.apache.turbine.services.jsp.TurbineJsp;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.RunData;
  import org.apache.velocity.context.Context;
  
  /**
   * In order to use Context in Jsp templates your Action's should
   * extend this class instead of extending the ActionEvent class.  The
   * difference between this class and the ActionEvent class is that
   * this class will first attempt to execute one of your doMethod's
   * with a constructor like this:
   *
   * <p>doEvent(RunData data, Context context)
   *
   * <p>It gets the context from the TemplateInfo.getTemplateContext()
   * method. If it can't find a method like that, then it will try to
   * execute the method without the Context in it.
   *
   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   * @author <a href="mailto:gabrielm@itcsoluciones.com">Gabriel A. Moreno</a>
   * @version $Id: JspActionEvent.java,v 1.1 2003/08/26 09:09:57 henning Exp $
   */
  public abstract class JspActionEvent extends ActionEvent
  {
      /**
       * You need to implement this in your classes that extend this
       * class.
       *
       * @param data A Turbine RunData object.
       * @exception Exception, a generic exception.
       */
      public abstract void doPerform(RunData data)
          throws Exception;
  
      /**
       * This overrides the default Action.perform() to execute the
       * doEvent() method.  If that fails, then it will execute the
       * doPerform() method instead.
       *
       * @param data A Turbine RunData object.
       * @exception Exception, a generic exception.
       */
      protected void perform(RunData data)
          throws Exception
      {
          try
          {
              executeEvents(data, TurbineJsp.getContext(data));
          }
          catch (NoSuchMethodException e)
          {
              doPerform(data);
          }
      }
  
      /**
       * This method should be called to execute the event based system.
       *
       * @param data A Turbine RunData object.
       * @param context Jsp context information.
       * @exception Exception, a generic exception.
       */
      public void executeEvents(RunData data, Context context) throws Exception
      {
          // Name of the button.
          String theButton = null;
  
          // ParameterParser.
          ParameterParser pp = data.getParameters();
  
          String button = pp.convert(BUTTON);
  
          // Loop through and find the button.
          for (Enumeration e = pp.keys() ; e.hasMoreElements() ;)
          {
              String key = (String) e.nextElement();
              if (key.startsWith(button))
              {
                  theButton = formatString(key);
                  break;
              }
          }
  
          if (theButton == null)
              throw new NoSuchMethodException("ActionEvent: The button was null");
  
          try
          {
              // The arguments to the method to find.
              Class[] classes = new Class[2];
              classes[0] = RunData.class;
              classes[1] = Context.class;
  
              // The arguments to pass to the method to execute.
              Object[] args = new Object[2];
  
              Method method = getClass().getMethod(theButton, classes);
              args[0] = data;
              args[1] = context;
              method.invoke(this, args);
          }
          catch (NoSuchMethodException nsme)
          {
              // Attempt to execut things the old way..
              super.executeEvents(data);
          }
      }
  }