jvanzyl     01/08/28 09:33:46

  Modified:    src/java/org/apache/turbine Turbine.java
                        TurbineConstants.java
               src/java/org/apache/turbine/services/pull
                        TurbinePullService.java
               src/java/org/apache/turbine/services/template
                        TurbineTemplateService.java
  Log:
  - add some logic to take the application root from the web.xml file.
    if the parameter doesn't exists, traditional behaviour is employed.
  
    these few changes allow the sample app to work as it always has,
    but allows development from a CVS layout.
  
  Revision  Changes    Path
  1.2       +49 -2     jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
  
  Index: Turbine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Turbine.java      2001/08/16 05:08:28     1.1
  +++ Turbine.java      2001/08/28 16:33:46     1.2
  @@ -116,9 +116,11 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Frank Y. Kim</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rafal Krzewski</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
  - * @version $Id: Turbine.java,v 1.1 2001/08/16 05:08:28 jvanzyl Exp $
  + * @version $Id: Turbine.java,v 1.2 2001/08/28 16:33:46 jvanzyl Exp $
    */
  -public class Turbine extends HttpServlet
  +public class Turbine 
  +    extends HttpServlet
  +    implements TurbineConstants
   {
       /**
        * Name of path info parameter used to indicate the redirected stage of
  @@ -149,6 +151,8 @@
        */
       private static boolean firstDoGet = true;
   
  +    private static String applicationRoot;
  +
       /**
        * This init method will load the default resources from a
        * properties file.
  @@ -174,6 +178,17 @@
   
               try
               {
  +                // Set the application root. This defaults to the webapp
  +                // context if not otherwise set. This is to allow 2.1 apps
  +                // to be developed from CVS. This feature will carry over
  +                // into 3.0.
  +                applicationRoot = config.getInitParameter(APPLICATION_ROOT);
  +                
  +                if (applicationRoot == null || applicationRoot.equals("webContext"))
  +                {
  +                    applicationRoot = config.getServletContext().getRealPath("");
  +                }                    
  +                
                   // Initalize TurbineServices and init bootstrap services
                   TurbineServices services =
                       (TurbineServices) TurbineServices.getInstance();
  @@ -644,4 +659,36 @@
                       reallyScrewedNow.getMessage(), reallyScrewedNow );
           }
       }
  +
  +    /**
  +     * Get the application root for this Turbine webapp. This
  +     * concept was started in 3.0 and will allow an app to be
  +     * developed from a standard CVS layout. With a simple
  +     * switch the app will work fully within the servlet
  +     * container for deployment.
  +     *
  +     * @return String applicationRoot
  +     */
  +    public static String getApplicationRoot()
  +    {
  +        return applicationRoot;
  +    }        
  +    
  +    /**
  +     * Used to get the real path of configuration and resource
  +     * information. This can be used by an app being
  +     * developed in a standard CVS layout.
  +     *
  +     * @param String path
  +     * @param String path translated to the application root
  +     */
  +    public static String getRealPath(String path)
  +    {
  +        if (path.startsWith("/"))
  +        {
  +            path = path.substring(1);
  +        }
  +        
  +        return applicationRoot + "/" + path;
  +    }        
   }
  
  
  
  1.2       +2 -0      
jakarta-turbine-2/src/java/org/apache/turbine/TurbineConstants.java
  
  Index: TurbineConstants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/TurbineConstants.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbineConstants.java     2001/08/16 05:08:28     1.1
  +++ TurbineConstants.java     2001/08/28 16:33:46     1.2
  @@ -274,4 +274,6 @@
        * Default document type.
        */
       public static final String DEFAULT_DOCUMENT_TYPE = "default.doctype";
  +
  +    public static final String APPLICATION_ROOT = "applicationRoot";
   }
  
  
  
  1.2       +3 -6      
jakarta-turbine-2/src/java/org/apache/turbine/services/pull/TurbinePullService.java
  
  Index: TurbinePullService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/pull/TurbinePullService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbinePullService.java   2001/08/16 05:09:11     1.1
  +++ TurbinePullService.java   2001/08/28 16:33:46     1.2
  @@ -59,12 +59,10 @@
   import java.util.List;
   import java.util.Properties;
   import java.util.Vector;
  -
   import org.apache.velocity.VelocityContext;
   import org.apache.velocity.context.Context;
  -
  +import org.apache.turbine.Turbine;
   import org.apache.turbine.om.security.User;
  -
   import org.apache.turbine.services.InitializationException;
   import org.apache.turbine.services.TurbineBaseService;
   import org.apache.turbine.services.TurbineServices;
  @@ -73,7 +71,6 @@
   import org.apache.turbine.services.resources.ResourceService;
   import org.apache.turbine.services.resources.TurbineResources;
   import org.apache.turbine.services.servlet.TurbineServlet;
  -
   import org.apache.turbine.util.Log;
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.ServletUtils;
  @@ -147,7 +144,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sean Legassick</a>
  - * @version $Id: TurbinePullService.java,v 1.1 2001/08/16 05:09:11 jvanzyl Exp $
  + * @version $Id: TurbinePullService.java,v 1.2 2001/08/28 16:33:46 jvanzyl Exp $
    */
   public class TurbinePullService extends TurbineBaseService 
       implements PullService
  @@ -287,7 +284,7 @@
            * for it to initialize correctly.
            */
            absolutePathToResourcesDirectory = 
  -            TurbineServlet.getRealPath(resourcesDirectory);
  +            Turbine.getRealPath(resourcesDirectory);
       
           /*
            * Should we refresh the tool box on a per
  
  
  
  1.2       +2 -3      
jakarta-turbine-2/src/java/org/apache/turbine/services/template/TurbineTemplateService.java
  
  Index: TurbineTemplateService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/template/TurbineTemplateService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbineTemplateService.java       2001/08/16 05:09:23     1.1
  +++ TurbineTemplateService.java       2001/08/28 16:33:46     1.2
  @@ -110,7 +110,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ilkka Priha</a>
  - * @version $Id: TurbineTemplateService.java,v 1.1 2001/08/16 05:09:23 jvanzyl Exp $
  + * @version $Id: TurbineTemplateService.java,v 1.2 2001/08/28 16:33:46 jvanzyl Exp $
    */
   public class TurbineTemplateService extends TurbineBaseService
       implements TemplateService
  @@ -720,8 +720,7 @@
       
           /* Let the template engine service to check its existance. */
           TemplateEngineService tes = getTemplateEngineService(template);
  -        if ((tes == null) ||
  -            !tes.templateExists(path.toString()))
  +        if ((tes == null) || !tes.templateExists(path.toString()))
           {
               throw new Exception(
                   "Screen template '" + template + "' not found");
  
  
  

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

Reply via email to