henning     2003/03/11 06:33:36

  Modified:    src/java/org/apache/turbine/modules/screens
                        BaseJspScreen.java VelocityDirectScreen.java
                        VelocityErrorScreen.java VelocityScreen.java
                        VelocitySecureScreen.java
  Log:
  - Clean up the "/" handling in all screen classes
  - change hardcoded values for prefix and context variable names to
    Constants
  - Style cleanup, javadoc fixes
  
  Revision  Changes    Path
  1.5       +15 -23    
jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/BaseJspScreen.java
  
  Index: BaseJspScreen.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/BaseJspScreen.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseJspScreen.java        9 Mar 2003 02:41:46 -0000       1.4
  +++ BaseJspScreen.java        11 Mar 2003 14:33:34 -0000      1.5
  @@ -57,14 +57,13 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import org.apache.ecs.ConcreteElement;
  -
  -import org.apache.turbine.services.TurbineServices;
  +import org.apache.commons.lang.StringUtils;
   
  -import org.apache.turbine.services.jsp.JspService;
  +import org.apache.ecs.ConcreteElement;
   
  +import org.apache.turbine.TurbineConstants;
  +import org.apache.turbine.services.jsp.TurbineJsp;
   import org.apache.turbine.services.template.TurbineTemplate;
  -
   import org.apache.turbine.util.RunData;
   
   /**
  @@ -76,11 +75,15 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
    * @version $Id$
    */
  -public class BaseJspScreen extends TemplateScreen
  +public class BaseJspScreen
  +        extends TemplateScreen
   {
       /** Logging */
       private static Log log = LogFactory.getLog(BaseJspScreen.class);
   
  +    /** The prefix for lookup up screen pages */
  +    private String prefix = TurbineConstants.SCREEN_PREFIX + "/";
  +
       /**
        * Method that sets up beans and forward the request to the JSP.
        *
  @@ -91,33 +94,21 @@
       public ConcreteElement buildTemplate(RunData data)
               throws Exception
       {
  -        // set up any data in beans, etc
  -        doBuildTemplate(data);
  -
           String screenTemplate = data.getTemplateInfo().getScreenTemplate();
           // get the name of the JSP we want to use
           String templateName
               = TurbineTemplate.getScreenTemplateName(screenTemplate);
   
           // The Template Service could not find the Screen
  -        if (templateName == null)
  +        if (StringUtils.isEmpty(templateName))
           {
               log.error("Screen " + screenTemplate + " not found!");
               throw new Exception("Could not find screen for " + screenTemplate);
           }
   
  -        // Template service adds the leading slash, but make it sure.
  -        if ((templateName.length() > 0) &&
  -                (templateName.charAt(0) != '/'))
  -        {
  -            templateName = '/' + templateName;
  -        }
  -
           // let service know whether we are using a layout
  -        JspService jsp = (JspService)
  -                TurbineServices.getInstance().getService(JspService.SERVICE_NAME);
  -        jsp.handleRequest(data, "/screens" + templateName,
  -                getLayout(data) == null);
  +        TurbineJsp.handleRequest(data, prefix + templateName,
  +                                 getLayout(data) == null);
   
           return null;
       }
  @@ -128,7 +119,8 @@
        * @param data, the Rundata object
        * @exception Exception, a generic exception.
        */
  -    protected void doBuildTemplate(RunData data) throws Exception
  +    protected void doBuildTemplate(RunData data)
  +        throws Exception
       {
       }
   }
  
  
  
  1.9       +17 -47    
jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocityDirectScreen.java
  
  Index: VelocityDirectScreen.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocityDirectScreen.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- VelocityDirectScreen.java 9 Mar 2003 02:41:46 -0000       1.8
  +++ VelocityDirectScreen.java 11 Mar 2003 14:33:34 -0000      1.9
  @@ -76,15 +76,11 @@
   import org.apache.velocity.context.Context;
   
   /**
  - * Base Velocity Screen.  The buildTemplate() assumes the template
  - * parameter has been set in the RunData object.  This provides the
  - * ability to execute several templates from one Screen.
  - *
  + * VelocityDirectScreen is a screen class which returns its output
  + * directly to the output stream. It can be used if buffering an
  + * output screen isn't possible or the result doesn't fit in the
  + * memory.
    * <p>
  - *
  - * If you need more specific behavior in your application, extend this
  - * class and override the doBuildTemplate() method.
  - *
    * @author <a href="mailto:[EMAIL PROTECTED]">Dave Bryson</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
    * @version $Id$
  @@ -95,6 +91,9 @@
       /** Logging */
       private static Log log = LogFactory.getLog(VelocityDirectScreen.class);
   
  +    /** The prefix for lookup up screen pages */
  +    private String prefix = TurbineConstants.SCREEN_PREFIX + "/";
  +
       /**
        * This builds the Velocity template.
        *
  @@ -105,8 +104,6 @@
       public ConcreteElement buildTemplate(RunData data)
           throws Exception
       {
  -        StringElement output = new StringElement();
  -        String screenData = null;
           Context context = TurbineVelocity.getContext(data);
   
           String screenTemplate = data.getTemplateInfo().getScreenTemplate();
  @@ -114,63 +111,36 @@
               = TurbineTemplate.getScreenTemplateName(screenTemplate);
   
           // The Template Service could not find the Screen
  -        if (templateName == null)
  +        if (StringUtils.isEmpty(templateName))
           {
               log.error("Screen " + screenTemplate + " not found!");
               throw new Exception("Could not find screen for " + screenTemplate);
           }
  -        // Template service adds the leading slash, but make it sure.
  -        if ((templateName.length() > 0) &&
  -                (templateName.charAt(0) != '/'))
  -        {
  -            templateName = '/' + templateName;
  -        }
   
           try
           {
  -            // if a layout has been defined return the results, otherwise
  -            // send the results directly to the output stream.
  -            if (getLayout(data) == null)
  -            {
  -                TurbineVelocity.handleRequest(context,
  -                        "screens" + templateName,
  -                        data.getResponse().getOutputStream());
  -            }
  -            else
  -            {
  -                TurbineVelocity.handleRequest(context,
  -                        "screens" + templateName,
  -                        data.getOut());
  -            }
  +            TurbineVelocity.handleRequest(context,
  +                                          prefix + templateName,
  +                                          data.getOut());
  +
           }
           catch (Exception e)
           {
               // If there is an error, build a $processingException and
               // attempt to call the error.vm template in the screens
               // directory.
  -            context.put ("processingException", e.toString());
  -            context.put ("stackTrace", ExceptionUtils.getStackTrace(e));
  +            context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, 
e.toString());
  +            context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, 
ExceptionUtils.getStackTrace(e));
   
               templateName = Turbine.getConfiguration()
                   .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
                              TurbineConstants.TEMPLATE_ERROR_VM);
   
  -            if ((templateName.length() > 0) &&
  -                (templateName.charAt(0) != '/'))
  -            {
  -                templateName = '/' + templateName;
  -            }
               TurbineVelocity.handleRequest(context,
  -                    "screens" + templateName,
  +                    prefix + templateName,
                       data.getOut());
           }
   
  -        // package the response in an ECS element
  -        if (screenData != null)
  -        {
  -            output.setFilterState(false);
  -            output.addElement(screenData);
  -        }
  -        return output;
  +        return null;
       }
   }
  
  
  
  1.8       +5 -4      
jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocityErrorScreen.java
  
  Index: VelocityErrorScreen.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocityErrorScreen.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- VelocityErrorScreen.java  9 Mar 2003 02:41:46 -0000       1.7
  +++ VelocityErrorScreen.java  11 Mar 2003 14:33:35 -0000      1.8
  @@ -82,9 +82,10 @@
       protected void doBuildTemplate(RunData data, Context context)
               throws Exception
       {
  -        context.put("processingException",
  -                data.getStackTraceException().toString());
  -        context.put("stackTrace", data.getStackTrace());
  +        context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER,
  +                     data.getStackTraceException().toString());
  +        context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER,
  +                     data.getStackTrace());
   
           String errorTemplate = Turbine.getConfiguration()
               .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
  
  
  
  1.8       +21 -27    
jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocityScreen.java
  
  Index: VelocityScreen.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocityScreen.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- VelocityScreen.java       9 Mar 2003 02:41:46 -0000       1.7
  +++ VelocityScreen.java       11 Mar 2003 14:33:35 -0000      1.8
  @@ -95,6 +95,9 @@
       /** Logging */
       private static Log log = LogFactory.getLog(VelocityScreen.class);
   
  +    /** The prefix for lookup up screen pages */
  +    private String prefix = TurbineConstants.SCREEN_PREFIX + "/";
  +
       /**
        * Velocity Screens extending this class should overide this
        * method to perform any particular business logic and add
  @@ -134,28 +137,21 @@
       public ConcreteElement buildTemplate(RunData data)
           throws Exception
       {
  -        StringElement output = null;
           String screenData = null;
  +        
           Context context = TurbineVelocity.getContext(data);
   
           String screenTemplate = data.getTemplateInfo().getScreenTemplate();
           String templateName
               = TurbineTemplate.getScreenTemplateName(screenTemplate);
  -
  +        
           // The Template Service could not find the Screen
  -        if (templateName == null)
  +        if (StringUtils.isEmpty(templateName))
           {
               log.error("Screen " + screenTemplate + " not found!");
               throw new Exception("Could not find screen for " + screenTemplate);
           }
  -
  -        // Template service adds the leading slash, but make it sure.
  -        if ((templateName.length() > 0) &&
  -                (templateName.charAt(0) != '/'))
  -        {
  -            templateName = '/' + templateName;
  -        }
  -
  +        
           try
           {
               // if a layout has been defined return the results, otherwise
  @@ -163,13 +159,13 @@
               if (getLayout(data) == null)
               {
                   TurbineVelocity.handleRequest(context,
  -                        "screens" + templateName,
  +                        prefix + templateName,
                           data.getResponse().getOutputStream());
               }
               else
               {
                   screenData = TurbineVelocity
  -                        .handleRequest(context, "screens" + templateName);
  +                        .handleRequest(context, prefix + templateName);
               }
           }
           catch (Exception e)
  @@ -177,27 +173,23 @@
               // If there is an error, build a $processingException and
               // attempt to call the error.vm template in the screens
               // directory.
  -            context.put ("processingException", e.toString());
  -            context.put ("stackTrace", ExceptionUtils.getStackTrace(e));
  -
  +            context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, 
e.toString());
  +            context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, 
ExceptionUtils.getStackTrace(e));
  +            
               templateName = Turbine.getConfiguration()
                   .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
                              TurbineConstants.TEMPLATE_ERROR_VM);
  -
  -            if ((templateName.length() > 0) &&
  -                    (templateName.charAt(0) != '/'))
  -            {
  -                templateName = '/' + templateName;
  -            }
  +            
               screenData = TurbineVelocity.handleRequest(
  -                    context, "screens" + templateName);
  +                context, prefix + templateName);
           }
  -
  +        
           // package the response in an ECS element
  +        StringElement output = new StringElement();
  +        output.setFilterState(false);
  +
           if (screenData != null)
           {
  -            output = new StringElement();
  -            output.setFilterState(false);
               output.addElement(screenData);
           }
           return output;
  @@ -208,6 +200,8 @@
        *
        * @param data Turbine information.
        * @return A Context.
  +     *
  +     * @deprecated Use TurbineVelocity.getContext(data)
        */
       public static Context getContext(RunData data)
       {
  
  
  
  1.4       +8 -7      
jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocitySecureScreen.java
  
  Index: VelocitySecureScreen.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/screens/VelocitySecureScreen.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VelocitySecureScreen.java 9 Mar 2003 02:41:46 -0000       1.3
  +++ VelocitySecureScreen.java 11 Mar 2003 14:33:35 -0000      1.4
  @@ -54,10 +54,9 @@
    * <http://www.apache.org/>.
    */
   
  -// Turbine
  -
   import org.apache.turbine.services.velocity.TurbineVelocity;
   import org.apache.turbine.util.RunData;
  +
   import org.apache.velocity.context.Context;
   
   /**
  @@ -74,7 +73,8 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Dave Bryson</a>
    * @version $Id$
    */
  -public abstract class VelocitySecureScreen extends VelocityScreen
  +public abstract class VelocitySecureScreen
  +        extends VelocityScreen
   {
       /**
        * Implement this to add information to the context.
  @@ -88,13 +88,14 @@
               throws Exception;
   
       /**
  -     * This method overrides the method in WebMacroSiteScreen to
  +     * This method overrides the method in VelocityScreen to
        * perform a security check first.
        *
        * @param data Turbine information.
        * @exception Exception, a generic exception.
        */
  -    protected void doBuildTemplate(RunData data) throws Exception
  +    protected void doBuildTemplate(RunData data)
  +        throws Exception
       {
           if (isAuthorized(data))
           {
  @@ -106,7 +107,7 @@
        * 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.  See the
  -     * WebMacroSecuritCheck utility.
  +     * VelocitySecurityCheck utility.
        *
        * @param data Turbine information.
        * @return True if the user is authorized to access the screen.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to