You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jv...@apache.org on 2001/08/09 20:48:51 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/modules/screens Error.java TemplateScreen.java TemplateSecureScreen.java

jvanzyl     01/08/09 11:48:51

  Modified:    src/java/org/apache/turbine/modules Module.java
               src/java/org/apache/turbine/modules/actions
                        TemplateAction.java
               src/java/org/apache/turbine/modules/screens Error.java
                        TemplateScreen.java TemplateSecureScreen.java
  Added:       src/java/org/apache/turbine/modules Error.java
                        SecureModule.java
  Log:
  - almost have the sample app working with a single Module class.
  - removed all the remaining logic in TemplateScreen and moved it
    into the Module class so that we will soon only really need a single
    Module class, and will the Pull model in full effect you will probably
    never need to subclass it either. more to discuss on the list as
    i think actions are now distinct from modules which are used to
    render content and should probably not be refered to as modules.
  
  Revision  Changes    Path
  1.11      +42 -1     jakarta-turbine/src/java/org/apache/turbine/modules/Module.java
  
  Index: Module.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/Module.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Module.java	2001/08/05 21:25:51	1.10
  +++ Module.java	2001/08/09 18:48:51	1.11
  @@ -68,7 +68,7 @@
    * future use is yet to be determined.
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: Module.java,v 1.10 2001/08/05 21:25:51 jvanzyl Exp $
  + * @version $Id: Module.java,v 1.11 2001/08/09 18:48:51 jvanzyl Exp $
    */
   public class Module
   {
  @@ -84,6 +84,7 @@
       protected String doBuild( RunData data )
           throws Exception
       {
  +        doBuildTemplate(data);
           return "";
       }
   
  @@ -113,6 +114,24 @@
           doBuild(data);
       }
   
  +    /**
  +     * This method should be overidden by subclasses that wish to add
  +     * specific business logic.
  +     *
  +     * @param data Turbine information.
  +     * @exception Exception, a generic exception.
  +     */
  +    protected void doBuildTemplate( RunData data, TemplateContext context)
  +        throws Exception
  +    {
  +    }
  +
  +    protected void doBuildTemplate( RunData data )
  +        throws Exception
  +    {
  +        doBuildTemplate(data, getTemplateContext(data));
  +    }
  +
       public static TemplateContext getTemplateContext()
       {
           return TurbinePull.getGlobalContext();
  @@ -184,4 +203,26 @@
           }
           return null;
       }
  +
  +    /**
  +     * This method is used when you want to short circuit a Screen and
  +     * change the template that will be executed next. <b>Note that the current
  +     * context will be applied to the next template that is executed.
  +     * If you want to have the context executed for the next screen,
  +     * to be the same one as the next screen, then you should use the
  +     * TemplateScreen.doRedirect() method.</b>
  +     *
  +     * @param data Turbine information.
  +     * @param template The name of the next template.
  +     * @param deprecated use setTarget(data,template)
  +     */
  +    public static void setTemplate(RunData data, String template)
  +    {
  +        setTarget(data,template);
  +    }
  +
  +    public static void setTarget(RunData data, String template)
  +    {
  +        data.setTarget(template);
  +    }        
   }
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/modules/Error.java
  
  Index: Error.java
  ===================================================================
  package org.apache.turbine.modules;
  
  /* ====================================================================
   * 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.Turbine;
  import org.apache.turbine.RunData;
  import org.apache.turbine.TemplateContext;
  
  /**
   * VelocityErrorScreen screen - directs errors at the velocity
   * error template defined in template.error.
   *
   * @author <a href="mailto:gonzalo.diethelm@sonda.com">Gonzalo Diethelm</a>
   * @version $Id: Error.java,v 1.1 2001/08/09 18:48:51 jvanzyl Exp $
   */
  public class Error 
      extends Module
  {
      /**
       * Implement this to 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,
                                      TemplateContext context )
          throws Exception
      {
          context.put("processingException",data.getStackTraceException().toString());
          context.put("stackTrace", data.getStackTrace());
          String errorTemplate = 
              Turbine.getConfiguration().getString("template.error","/Error.vm");
          setTemplate(data, errorTemplate);
      }
  }
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/modules/SecureModule.java
  
  Index: SecureModule.java
  ===================================================================
  package org.apache.turbine.modules;
  
  /* ====================================================================
   * 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.RunData;
  import org.apache.turbine.TemplateContext;
  
  /**
   * VelocitySecureScreen
   *
   * Always performs a Security Check that you've defined before
   * executing the doBuildtemplate().  You should extend this class and
   * add the specific security check needed.  If you have a number of
   * screens that need to perform the same check, you could make a base
   * screen by extending this class and implementing the isAuthorized().
   * Then each screen that needs to perform the same check could extend
   * your base screen.
   *
   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
   * @version $Id: SecureModule.java,v 1.1 2001/08/09 18:48:51 jvanzyl Exp $
   */
  public abstract class SecureModule
      extends Module
  {
      /**
       * This method overrides the method in WebMacroSiteScreen to
       * perform a security check first.
       *
       * @param data Turbine information.
       * @exception Exception, a generic exception.
       */
      protected void doBuildTemplate( RunData data ) 
          throws Exception
      {
          if (isAuthorized(data))
          {
              doBuildTemplate(data, getTemplateContext(data));
          }
      }
  
      /**
       * Implement this method to perform the security check needed.
       * You should set the template in this method that you want the
       * user to be sent to if they're unauthorized.
       *
       * @param data Turbine information.
       * @return True if the user is authorized to access the screen.
       * @exception Exception, a generic exception.
       */
      protected abstract boolean isAuthorized(RunData data)
          throws Exception;
  }
  
  
  
  1.10      +1 -20     jakarta-turbine/src/java/org/apache/turbine/modules/actions/TemplateAction.java
  
  Index: TemplateAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/actions/TemplateAction.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TemplateAction.java	2001/08/05 16:12:17	1.9
  +++ TemplateAction.java	2001/08/09 18:48:51	1.10
  @@ -77,7 +77,7 @@
    *
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  - * @version $Id: TemplateAction.java,v 1.9 2001/08/05 16:12:17 jvanzyl Exp $
  + * @version $Id: TemplateAction.java,v 1.10 2001/08/09 18:48:51 jvanzyl Exp $
    */
   public abstract class TemplateAction 
       extends ActionEvent
  @@ -175,24 +175,5 @@
               // Attempt to execut things the old way..
               super.executeEvents(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.
  -     * @deprecated use setTarget(data,template)
  -     */
  -    public void setTemplate(RunData data,
  -                            String template)
  -    {
  -        setTarget(data,template);
  -    }
  -
  -    public void setTarget(RunData data, String template)
  -    {
  -        data.setTarget(template);
       }
   }
  
  
  
  1.9       +1 -27     jakarta-turbine/src/java/org/apache/turbine/modules/screens/Error.java
  
  Index: Error.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/screens/Error.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Error.java	2001/07/12 23:42:44	1.8
  +++ Error.java	2001/08/09 18:48:51	1.9
  @@ -54,35 +54,9 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.turbine.Turbine;
  -import org.apache.turbine.RunData;
  -import org.apache.turbine.TemplateContext;
  -
   /**
  - * VelocityErrorScreen screen - directs errors at the velocity
  - * error template defined in template.error.
  - *
  - * @author <a href="mailto:gonzalo.diethelm@sonda.com">Gonzalo Diethelm</a>
  - * @version $Id: Error.java,v 1.8 2001/07/12 23:42:44 jvanzyl Exp $
    */
   public class Error 
  -    extends TemplateScreen
  +    extends org.apache.turbine.modules.Error
   {
  -    /**
  -     * Implement this to 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,
  -                                    TemplateContext context )
  -        throws Exception
  -    {
  -        context.put("processingException",data.getStackTraceException().toString());
  -        context.put("stackTrace", data.getStackTrace());
  -        String errorTemplate = 
  -            Turbine.getConfiguration().getString("template.error","/Error.vm");
  -        setTemplate(data, errorTemplate);
  -    }
   }
  
  
  
  1.21      +1 -115    jakarta-turbine/src/java/org/apache/turbine/modules/screens/TemplateScreen.java
  
  Index: TemplateScreen.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/screens/TemplateScreen.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TemplateScreen.java	2001/08/05 16:12:17	1.20
  +++ TemplateScreen.java	2001/08/09 18:48:51	1.21
  @@ -54,123 +54,9 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.turbine.Turbine;
  -import org.apache.turbine.RunData;
  -import org.apache.turbine.TemplateContext;
  -import org.apache.turbine.modules.Module;
  -import org.apache.fulcrum.template.TurbineTemplate;
  -
   /**
  - * Template Screen.
  - *
  - * Base Template Screens should extend this class and override the
  - * buildTemplate() method.  Users of the particular service can then
  - * override the doBuildTemplate() for any specific pre-processing.
  - * You can also override the doBuild() method in order to add extra
  - * functionality to your system, but you need to make sure to at least
  - * duplicate the existing functionality in order for things to work.
  - * Look at the code for the doBuild() method to get an idea of what is
  - * going on there (it is quite simple really).
  - *
  - * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: TemplateScreen.java,v 1.20 2001/08/05 16:12:17 jvanzyl Exp $
    */
   public class TemplateScreen 
  -    extends Module
  +    extends org.apache.turbine.modules.Module
   {
  -    /**
  -     * This method should be overidden by subclasses that wish to add
  -     * specific business logic.
  -     *
  -     * @param data Turbine information.
  -     * @exception Exception, a generic exception.
  -     */
  -    protected void doBuildTemplate( RunData data, TemplateContext context)
  -        throws Exception
  -    {
  -    }
  -
  -    protected void doBuildTemplate( RunData data )
  -        throws Exception
  -    {
  -        doBuildTemplate(data, getTemplateContext(data));
  -    }
  -
  -
  -    /**
  -     * This method should be implemented by Base template classes.  It
  -     * should contain the specific template service code to generate
  -     * the template.
  -     *
  -     * @param data Turbine information.
  -     * @return A ConcreteElement.
  -     * @exception Exception, a generic exception.
  -     */
  -    public String buildTemplate( RunData data ) 
  -        throws Exception
  -    {
  -        return "";
  -    }
  -
  -    /**
  -     * This method can be overridden to write code that executes when
  -     * the template has been built (called from a finally clause, so
  -     * executes regardless of whether an exception is thrown or not)
  -     */
  -    protected void doPostBuildTemplate( RunData data )
  -    {
  -        // empty
  -    }
  -
  -    /**
  -     * This method is called by the Screenloader to construct the
  -     * Screen.
  -     *
  -     * @param data Turbine information.
  -     * @return A ConcreteElement.
  -     * @exception Exception, a generic exception.
  -     */
  -    protected String doBuild( RunData data )
  -        throws Exception
  -    {
  -        String out = null;
  -
  -        try
  -        {
  -            doBuildTemplate(data);
  -            out = buildTemplate(data);
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -        }
  -        finally
  -        {
  -            doPostBuildTemplate(data);
  -        }
  -
  -        return out;
  -    }
  -
  -    /**
  -     * This method is used when you want to short circuit a Screen and
  -     * change the template that will be executed next. <b>Note that the current
  -     * context will be applied to the next template that is executed.
  -     * If you want to have the context executed for the next screen,
  -     * to be the same one as the next screen, then you should use the
  -     * TemplateScreen.doRedirect() method.</b>
  -     *
  -     * @param data Turbine information.
  -     * @param template The name of the next template.
  -     * @param deprecated use setTarget(data,template)
  -     */
  -    public static void setTemplate(RunData data, String template)
  -    {
  -        setTarget(data,template);
  -    }
  -
  -    public static void setTarget(RunData data, String template)
  -    {
  -        data.setTarget(template);
  -    }        
   }
  
  
  
  1.6       +1 -43     jakarta-turbine/src/java/org/apache/turbine/modules/screens/TemplateSecureScreen.java
  
  Index: TemplateSecureScreen.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/screens/TemplateSecureScreen.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TemplateSecureScreen.java	2001/08/09 06:36:29	1.5
  +++ TemplateSecureScreen.java	2001/08/09 18:48:51	1.6
  @@ -54,51 +54,9 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.turbine.RunData;
  -import org.apache.turbine.TemplateContext;
  -
   /**
  - * VelocitySecureScreen
  - *
  - * Always performs a Security Check that you've defined before
  - * executing the doBuildtemplate().  You should extend this class and
  - * add the specific security check needed.  If you have a number of
  - * screens that need to perform the same check, you could make a base
  - * screen by extending this class and implementing the isAuthorized().
  - * Then each screen that needs to perform the same check could extend
  - * your base screen.
  - *
  - * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: TemplateSecureScreen.java,v 1.5 2001/08/09 06:36:29 jon Exp $
    */
   public abstract class TemplateSecureScreen 
  -    extends TemplateScreen
  +    extends org.apache.turbine.modules.SecureModule
   {
  -    /**
  -     * This method overrides the method in WebMacroSiteScreen to
  -     * perform a security check first.
  -     *
  -     * @param data Turbine information.
  -     * @exception Exception, a generic exception.
  -     */
  -    protected void doBuildTemplate( RunData data ) 
  -        throws Exception
  -    {
  -        if (isAuthorized(data))
  -        {
  -            doBuildTemplate( data, getTemplateContext( data ) );
  -        }
  -    }
  -
  -    /**
  -     * Implement this method to perform the security check needed.
  -     * You should set the template in this method that you want the
  -     * user to be sent to if they're unauthorized.
  -     *
  -     * @param data Turbine information.
  -     * @return True if the user is authorized to access the screen.
  -     * @exception Exception, a generic exception.
  -     */
  -    protected abstract boolean isAuthorized( RunData data )
  -        throws Exception;
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org