Return-Path: Delivered-To: apmail-jakarta-turbine-dev-archive@jakarta.apache.org Received: (qmail 74191 invoked by uid 500); 1 Apr 2001 06:13:01 -0000 Mailing-List: contact turbine-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: turbine-dev@jakarta.apache.org Delivered-To: mailing list turbine-dev@jakarta.apache.org Received: (qmail 74180 invoked by uid 500); 1 Apr 2001 06:13:01 -0000 Delivered-To: apmail-jakarta-turbine-cvs@apache.org Date: 1 Apr 2001 06:13:01 -0000 Message-ID: <20010401061301.74176.qmail@apache.org> From: jvanzyl@apache.org To: jakarta-turbine-cvs@apache.org Subject: cvs commit: jakarta-turbine/src/java/org/apache/turbine/services/webmacro TurbineWebMacroService.java jvanzyl 01/03/31 22:13:01 Modified: src/java/org/apache/turbine Turbine.java src/java/org/apache/turbine/modules/actions/sessionvalidator DefaultSessionValidator.java TemplateSecureSessionValidator.java TemplateSessionValidator.java src/java/org/apache/turbine/modules/layouts DefaultLayout.java FreeMarkerLayout.java VelocityECSLayout.java src/java/org/apache/turbine/modules/pages TemplatePage.java src/java/org/apache/turbine/services/jsp TurbineJspService.java src/java/org/apache/turbine/services/template TemplateEngineService.java TemplateService.java TurbineTemplate.java TurbineTemplateService.java src/java/org/apache/turbine/services/velocity TurbineVelocityService.java src/java/org/apache/turbine/services/webmacro TurbineWebMacroService.java Log: - changes to the template services to allow multiple template engines to run at the same time. - cleaned up some other classes as i was tracing the path of the template through the system. Revision Changes Path 1.52 +23 -20 jakarta-turbine/src/java/org/apache/turbine/Turbine.java Index: Turbine.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/Turbine.java,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- Turbine.java 2001/03/22 23:20:48 1.51 +++ Turbine.java 2001/04/01 06:12:56 1.52 @@ -83,6 +83,7 @@ import org.apache.turbine.services.TurbineServices; import org.apache.turbine.services.resources.TurbineResources; import org.apache.turbine.services.logging.LoggingService; +import org.apache.turbine.services.template.TurbineTemplate; /** * Turbine is the main servlet for the entire system. It is final @@ -114,7 +115,7 @@ * @author John D. McNally * @author Frank Y. Kim * @author Rafal Krzewski - * @version $Id: Turbine.java,v 1.51 2001/03/22 23:20:48 rafal Exp $ + * @version $Id: Turbine.java,v 1.52 2001/04/01 06:12:56 jvanzyl Exp $ */ public class Turbine extends HttpServlet { @@ -254,11 +255,9 @@ } // Get the instance of the Session Validator. - SessionValidator sessionValidator = - (SessionValidator)ActionLoader - .getInstance() - .getInstance(TurbineResources - .getString("action.sessionvalidator") ); + SessionValidator sessionValidator = (SessionValidator)ActionLoader + .getInstance().getInstance(TurbineResources.getString( + "action.sessionvalidator")); // if this is the redirected stage of the initial request, check that // the session is now not new. If it is not, then redirect back to the @@ -327,8 +326,11 @@ // as the session is new take this opportunity to set the session // timeout if specified in TR.properties int timeout = TurbineResources.getInt("session.timeout", -1); + if (timeout != -1) + { data.getSession().setMaxInactiveInterval(timeout); + } data.getResponse().sendRedirect( duri.toString() ); return; @@ -385,20 +387,16 @@ // screen other than Login, you need to change that within // TurbineResources.properties...screen.homepage; or, you // can specify your own SessionValidator action. - ActionLoader.getInstance() - .exec( data, - TurbineResources - .getString("action.sessionvalidator") ); + ActionLoader.getInstance().exec( + data,TurbineResources.getString("action.sessionvalidator") ); // Put the Access Control List into the RunData object, so // it is easily available to modules. It is also placed // into the session for serialization. Modules can null // out the ACL to force it to be rebuilt based on more // information. - ActionLoader.getInstance() - .exec(data, - TurbineResources - .getString("action.accesscontroller")); + ActionLoader.getInstance().exec( + data,TurbineResources.getString("action.accesscontroller")); // Start the execution phase. DefaultPage will execute the // appropriate action as well as get the Layout from the @@ -411,17 +409,22 @@ // security purposes. You should really never need more // than just the default page. If you do, add logic to // DefaultPage to do what you want. - PageLoader.getInstance() - .exec(data, - TurbineResources - .getString("page.default")); + + String defaultPage = TurbineTemplate.getDefaultPageName(data); + + if (defaultPage == null) + { + defaultPage = TurbineResources.getString("page.default"); + } + + PageLoader.getInstance().exec(data, defaultPage); // If a module has set data.acl = null, remove acl from // the session. if ( data.getACL() == null ) { - data.getSession() - .removeValue(AccessControlList.SESSION_KEY); + data.getSession().removeValue( + AccessControlList.SESSION_KEY); } try 1.7 +5 -3 jakarta-turbine/src/java/org/apache/turbine/modules/actions/sessionvalidator/DefaultSessionValidator.java Index: DefaultSessionValidator.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/actions/sessionvalidator/DefaultSessionValidator.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DefaultSessionValidator.java 2001/03/06 04:50:43 1.6 +++ DefaultSessionValidator.java 2001/04/01 06:12:56 1.7 @@ -82,7 +82,7 @@ * Turbine servlet. * * @author Dave Bryson - * @version $Id: DefaultSessionValidator.java,v 1.6 2001/03/06 04:50:43 chrise Exp $ + * @version $Id: DefaultSessionValidator.java,v 1.7 2001/04/01 06:12:56 jvanzyl Exp $ */ public class DefaultSessionValidator extends SessionValidator { @@ -92,9 +92,11 @@ * @param data Turbine information. * @exception Exception, a generic exception. */ - public void doPerform( RunData data ) - throws Exception + public void doPerform( RunData data ) throws Exception { + /* + * Pull user from session. + */ data.populate(); // Make sure the User object exists in the Session and that 1.6 +46 -23 jakarta-turbine/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSecureSessionValidator.java Index: TemplateSecureSessionValidator.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSecureSessionValidator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TemplateSecureSessionValidator.java 2001/03/06 04:50:44 1.5 +++ TemplateSecureSessionValidator.java 2001/04/01 06:12:57 1.6 @@ -81,7 +81,7 @@ * * @author John D. McNally * @author Dave Bryson - * @version $Id: TemplateSecureSessionValidator.java,v 1.5 2001/03/06 04:50:44 chrise Exp $ + * @version $Id: TemplateSecureSessionValidator.java,v 1.6 2001/04/01 06:12:57 jvanzyl Exp $ */ public class TemplateSecureSessionValidator extends SessionValidator { @@ -91,48 +91,69 @@ * @param data Turbine information. * @exception Exception, a generic exception. */ - public void doPerform( RunData data ) - throws Exception + public void doPerform( RunData data ) throws Exception { + /* + * Pull user from session. + */ data.populate(); - // this is the secure sessionvalidator, so user must be logged in. + /* + * This is the secure sessionvalidator, so user must be logged in. + */ if ( (data.getUser() == null) || (! data.getUser().hasLoggedIn()) ) { - // only set the message if nothing else has already set it - // (e.g. the LogoutUser action) + /* + * Only set the message if nothing else has already set it + * (e.g. the LogoutUser action). + */ if (data.getMessage() == null) + { data.setMessage(TurbineResources.getString("login.message")); - // set the screen template to the login page + } + + /* + * Set the screen template to the login page. + */ data.getTemplateInfo().setScreenTemplate( - TurbineResources.getString("template.login") ); - // we're not doing any actions buddy! (except action.login which - // will have been performed already) + TurbineResources.getString("template.login") ); + + /* + * We're not doing any actions buddy! (except action.login which + * will have been performed already) + */ data.setAction(null); } - // make sure we have some way to return a response - if ( !data.hasScreen() && - data.getTemplateInfo().getScreenTemplate() == null ) + /* + * Make sure we have some way to return a response. + */ + if ( !data.hasScreen() && + data.getTemplateInfo().getScreenTemplate() == null ) { String template = TurbineResources.getString("template.homepage"); + if (template != null) { data.getTemplateInfo().setScreenTemplate(template); } else { - data.setScreen( TurbineResources - .getString("screen.homepage") ); + data.setScreen(TurbineResources.getString("screen.homepage")); } } - // the session_access_counter can be placed as a hidden field in - // forms. This can be used to prevent a user from using the - // browsers back button and submitting stale data. - // FIXME!! a template needs to be written to use this with templates. + + /* + * The session_access_counter can be placed as a hidden field in + * forms. This can be used to prevent a user from using the + * browsers back button and submitting stale data. + * FIXME!! a template needs to be written to use this with templates. + */ else if ( data.getParameters().containsKey("_session_access_counter") ) { - // See comments in screens.error.InvalidState. + /* + * See comments in screens.error.InvalidState. + */ if ( data.getParameters().getInt("_session_access_counter") < (((Integer)data.getUser().getTemp("_session_access_counter")).intValue()-1) ) { @@ -140,6 +161,7 @@ { data.getTemplateInfo().setScreenTemplate( TurbineResources.getString("template.invalidstate") ); + data.getUser().setTemp( "prev_template", data.getTemplateInfo().getScreenTemplate() ); } @@ -153,13 +175,14 @@ } } - // we do not want to allow both a screen and template parameter. - // The template parameter is dominant. + /* + * We do not want to allow both a screen and template parameter. + * The template parameter is dominant. + */ if ( data.getTemplateInfo().getScreenTemplate() != null ) { data.setScreen(null); } - } /** 1.4 +8 -6 jakarta-turbine/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSessionValidator.java Index: TemplateSessionValidator.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSessionValidator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TemplateSessionValidator.java 2001/03/06 04:50:44 1.3 +++ TemplateSessionValidator.java 2001/04/01 06:12:57 1.4 @@ -72,7 +72,7 @@ * * @author John D. McNally * @author Dave Bryson - * @version $Id: TemplateSessionValidator.java,v 1.3 2001/03/06 04:50:44 chrise Exp $ + * @version $Id: TemplateSessionValidator.java,v 1.4 2001/04/01 06:12:57 jvanzyl Exp $ */ public class TemplateSessionValidator extends SessionValidator { @@ -82,9 +82,11 @@ * @param data Turbine information. * @exception Exception, a generic exception. */ - public void doPerform( RunData data ) - throws Exception + public void doPerform( RunData data ) throws Exception { + /* + * Pull user from session. + */ data.populate(); // The user may have not logged in, so create a "guest" user. @@ -96,17 +98,17 @@ // make sure we have some way to return a response if ( !data.hasScreen() && - data.getTemplateInfo().getScreenTemplate() == null ) + data.getTemplateInfo().getScreenTemplate() == null ) { String template = TurbineResources.getString("template.homepage"); + if (template != null) { data.getTemplateInfo().setScreenTemplate(template); } else { - data.setScreen( TurbineResources - .getString("screen.homepage") ); + data.setScreen(TurbineResources.getString("screen.homepage")); } } // the session_access_counter can be placed as a hidden field in 1.4 +18 -13 jakarta-turbine/src/java/org/apache/turbine/modules/layouts/DefaultLayout.java Index: DefaultLayout.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/layouts/DefaultLayout.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DefaultLayout.java 2001/03/06 04:50:45 1.3 +++ DefaultLayout.java 2001/04/01 06:12:57 1.4 @@ -71,7 +71,7 @@ * This is an example Layout module that is executed by default. * * @author Dave Bryson - * @version $Id: DefaultLayout.java,v 1.3 2001/03/06 04:50:45 chrise Exp $ + * @version $Id: DefaultLayout.java,v 1.4 2001/04/01 06:12:57 jvanzyl Exp $ */ public class DefaultLayout extends Layout { @@ -81,45 +81,50 @@ * @param data Turbine information. * @exception Exception, a generic exception. */ - public void doBuild( RunData data ) - throws Exception + public void doBuild( RunData data ) throws Exception { // Execute the Top Navigation portion for this Layout. ConcreteElement topNav = NavigationLoader.getInstance().eval ( data, "DefaultTopNavigation" ); + if ( topNav != null) + { data.getPage().getBody().addElement( topNav ); + } // If an Action has defined a message, attempt to display it // here. if ( data.getMessage() != null ) { - data.getPage().getBody() - .addElement(new P()) - .addElement( - new Font().setColor(HtmlColor.red) - .addElement(data.getMessageAsHTML())); + data.getPage().getBody().addElement(new P()) + .addElement(new Font().setColor(HtmlColor.red) + .addElement(data.getMessageAsHTML())); } // Now execute the Screen portion of the page. - ConcreteElement screen = ScreenLoader.getInstance().eval ( data, data.getScreen() ); + ConcreteElement screen = ScreenLoader.getInstance() + .eval(data, data.getScreen()); + if (screen != null) + { data.getPage().getBody().addElement( screen ); + } // The screen should have attempted to set a Title for itself, // otherwise, a default title is set. - data.getPage().getTitle() - .addElement( data.getTitle() ); + data.getPage().getTitle().addElement(data.getTitle()); // The screen should have attempted to set a Body bgcolor for // itself, otherwise, a default body bgcolor is set. - data.getPage().getBody() - .setBgColor(HtmlColor.white); + data.getPage().getBody().setBgColor(HtmlColor.white); // Execute the Bottom Navigation portion for this Layout. ConcreteElement bottomNav = NavigationLoader.getInstance().eval ( data, "DefaultBottomNavigation" ); + if ( bottomNav != null) + { data.getPage().getBody().addElement( bottomNav ); + } } } 1.4 +9 -5 jakarta-turbine/src/java/org/apache/turbine/modules/layouts/FreeMarkerLayout.java Index: FreeMarkerLayout.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/layouts/FreeMarkerLayout.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- FreeMarkerLayout.java 2001/03/06 04:50:45 1.3 +++ FreeMarkerLayout.java 2001/04/01 06:12:57 1.4 @@ -71,7 +71,7 @@ * This is a sample FreeMarker Layout module * * @author Dave Bryson - * @version $Id: FreeMarkerLayout.java,v 1.3 2001/03/06 04:50:45 chrise Exp $ + * @version $Id: FreeMarkerLayout.java,v 1.4 2001/04/01 06:12:57 jvanzyl Exp $ */ public class FreeMarkerLayout extends Layout { @@ -91,8 +91,11 @@ // Execute the Top Navigation portion for this Layout. ConcreteElement topNav = ScreenLoader.getInstance().eval ( data, "FreeMarkerScreen" ); + if ( topNav != null) + { data.getPage().getBody().addElement( topNav ); + } // If an Action has defined a message, attempt to display it // here. @@ -114,19 +117,20 @@ // The screen should have attempted to set a Title for itself, // otherwise, a default title is set. - data.getPage().getTitle() - .addElement( data.getTitle() ); + data.getPage().getTitle().addElement(data.getTitle()); // The screen should have attempted to set a Body bgcolor for // itself, otherwise, a default body bgcolor is set. - data.getPage().getBody() - .setBgColor(HtmlColor.white); + data.getPage().getBody().setBgColor(HtmlColor.white); // Execute the Bottom Navigation portion for this Layout. params.add("template", "navigations/default_bottom.html"); ConcreteElement bottomNav = ScreenLoader.getInstance().eval ( data, "FreeMarkerScreen" ); + if ( bottomNav != null) + { data.getPage().getBody().addElement( bottomNav ); + } } } 1.7 +9 -5 jakarta-turbine/src/java/org/apache/turbine/modules/layouts/VelocityECSLayout.java Index: VelocityECSLayout.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/layouts/VelocityECSLayout.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- VelocityECSLayout.java 2001/03/06 22:40:33 1.6 +++ VelocityECSLayout.java 2001/04/01 06:12:57 1.7 @@ -78,7 +78,7 @@ * * @author John D. McNally * @author Dave Bryson - * @version $Id: VelocityECSLayout.java,v 1.6 2001/03/06 22:40:33 chrise Exp $ + * @version $Id: VelocityECSLayout.java,v 1.7 2001/04/01 06:12:57 jvanzyl Exp $ */ public class VelocityECSLayout extends Layout { @@ -88,11 +88,11 @@ * @param data Turbine information. * @exception Exception, a generic exception. */ - public void doBuild( RunData data ) - throws Exception + public void doBuild( RunData data ) throws Exception { /* Get the context needed by Velocity. */ Context context = TurbineVelocity.getContext( data ); + /* Screen results. */ String returnValue = ""; @@ -102,8 +102,11 @@ */ ConcreteElement results = ScreenLoader.getInstance() .eval(data, data.getScreen()); + if (results != null) + { returnValue = results.toString(); + } /* Variable for the screen in the layout template. */ context.put("screen_placeholder", returnValue); @@ -123,7 +126,8 @@ * Finally, generate the layout template and add it to the * body of the Document in the RunData. */ - data.getPage().getBody() - .addElement(TurbineVelocity.handleRequest(context, "layouts" + templateName)); + data.getPage().getBody().addElement( + TurbineVelocity.handleRequest( + context, "layouts" + templateName)); } } 1.12 +17 -8 jakarta-turbine/src/java/org/apache/turbine/modules/pages/TemplatePage.java Index: TemplatePage.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/pages/TemplatePage.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TemplatePage.java 2001/03/06 04:50:46 1.11 +++ TemplatePage.java 2001/04/01 06:12:58 1.12 @@ -114,7 +114,7 @@ * * @author John D. McNally * @author Dave Bryson - * @version $Id: TemplatePage.java,v 1.11 2001/03/06 04:50:46 chrise Exp $ + * @version $Id: TemplatePage.java,v 1.12 2001/04/01 06:12:58 jvanzyl Exp $ */ public class TemplatePage extends DefaultPage { @@ -127,20 +127,30 @@ */ protected void doBuildAfterAction(RunData data) throws Exception { - // Either template or screen should be guaranteed by the SessionValidator - // It is occasionally better to specify the screen instead of template - // in cases where multiple Screens map to one template. The template - // is hardcoded into the Screen in this instance. In this case this - // action is skipped. + /* + * Either template or screen should be guaranteed by the SessionValidator + * It is occasionally better to specify the screen instead of template + * in cases where multiple Screens map to one template. The template + * is hardcoded into the Screen in this instance. In this case this + * action is skipped. + */ if (!data.hasScreen()) { + /* + * This is effectively getting the "template" parameter + * from the parameter parser in rundata. This is coming + * from the request for a template. + */ String template = data.getTemplateInfo().getScreenTemplate(); - // Get the layout template and the correct Screen. + /* + * Get the layout template and the correct Screen. + */ String layoutTemplate = TurbineTemplate.getLayoutTemplateName(template); data.getTemplateInfo().setLayoutTemplate(layoutTemplate); String screen = TurbineTemplate.getScreenName(template); + if (screen == null) { throw new Exception("Screen could not be determined. \n" + @@ -151,5 +161,4 @@ data.setScreen(screen); } } - } 1.12 +7 -5 jakarta-turbine/src/java/org/apache/turbine/services/jsp/TurbineJspService.java Index: TurbineJspService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/jsp/TurbineJspService.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TurbineJspService.java 2001/03/31 16:01:07 1.11 +++ TurbineJspService.java 2001/04/01 06:12:59 1.12 @@ -72,7 +72,7 @@ import org.apache.turbine.services.InitializationException; import org.apache.turbine.services.TurbineBaseService; import org.apache.turbine.services.servlet.TurbineServlet; -import org.apache.turbine.services.template.TemplateEngineService; +import org.apache.turbine.services.template.BaseTemplateEngineService; import org.apache.turbine.services.template.TurbineTemplate; import org.apache.velocity.runtime.configuration.Configuration; @@ -83,9 +83,10 @@ * * @author John D. McNally * @author Jason van Zyl + * @author Daniel Rall */ -public class TurbineJspService extends TurbineBaseService - implements JspService, TemplateEngineService +public class TurbineJspService extends BaseTemplateEngineService + implements JspService { /** The base path prepended to filenames given in arguments */ private String[] paths; @@ -101,11 +102,12 @@ /** * Called during Turbine.init() */ - public void init() throws InitializationException + public void init(RunData data) throws InitializationException { try { initJsp(); + registerConfiguration("jsp"); setInit(true); } catch (Exception e) @@ -113,7 +115,7 @@ throw new InitializationException( "TurbineJspService failed to initialize", e); } - } + } /** * Adds some convenience objects to the request. For example an instance 1.2 +36 -3 jakarta-turbine/src/java/org/apache/turbine/services/template/TemplateEngineService.java Index: TemplateEngineService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/template/TemplateEngineService.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TemplateEngineService.java 2001/03/27 18:55:50 1.1 +++ TemplateEngineService.java 2001/04/01 06:12:59 1.2 @@ -54,17 +54,50 @@ * . */ +import java.util.Hashtable; + /** * This is the interface that all template engine services * must adhere to. This include Velocity, WebMacro, FreeMarker * and the JSP service. * * @author Jason van Zyl - * @version $Id: TemplateEngineService.java,v 1.1 2001/03/27 18:55:50 jvanzyl Exp $ + * @author Daniel Rall + * @version $Id: TemplateEngineService.java,v 1.2 2001/04/01 06:12:59 jvanzyl Exp $ */ public interface TemplateEngineService { + public static final String TEMPLATE_EXTENSIONS = "template.extension"; + public static final String DEFAULT_PAGE = "default.page"; + public static final String DEFAULT_SCREEN = "default.screen"; + public static final String DEFAULT_LAYOUT = "default.layout"; + public static final String DEFAULT_NAVIGATION = "default.navigation"; + public static final String DEFAULT_ERROR_SCREEN = "default.error.screen"; + public static final String DEFAULT_LAYOUT_TEMPLATE = "default.layout.template"; + /** + * Return the configuration of the template engine in + * the form of a Hashtable. + */ + public Hashtable getTemplateEngineServiceConfiguration(); + + /** + * Initializes file extension associations and registers with the + * template service. + * + * @param defaultExt The default file extension association to use + * in case of properties file misconfiguration. + */ + public void registerConfiguration(String defaultExt); + + /** + * Supplies the file extension to key this engine in {@link + * org.apache.turbine.services.template.TemplateService}'s + * registry with. + */ + public String[] getAssociatedFileExtensions(); + + /** * Use the specific template engine to determine whether * a given template exists. This allows Turbine the TemplateService * to delegate the search for a template to the template @@ -73,8 +106,8 @@ * template engine with respect to retrieving templates * from arbitrary sources. * - * @param String template - * @return boolean + * @param template The name of the template to check the existance of. + * @return Whether the specified template exists. */ public boolean templateExists(String template); } 1.7 +28 -7 jakarta-turbine/src/java/org/apache/turbine/services/template/TemplateService.java Index: TemplateService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/template/TemplateService.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TemplateService.java 2001/03/31 16:02:29 1.6 +++ TemplateService.java 2001/04/01 06:12:59 1.7 @@ -54,9 +54,10 @@ * . */ -// Turbine stuff. -import org.apache.turbine.services.*; +import org.apache.turbine.util.RunData; +import org.apache.turbine.services.Service; + /** * This service provides a method for mapping templates to their * appropriate Screens or Navigations. It also allows templates to @@ -65,10 +66,9 @@ * properties file. * * @author John D. McNally - * @version $Id: TemplateService.java,v 1.6 2001/03/31 16:02:29 jvanzyl Exp $ + * @version $Id: TemplateService.java,v 1.7 2001/04/01 06:12:59 jvanzyl Exp $ */ -public interface TemplateService - extends Service +public interface TemplateService extends Service { /** * The key under which this service is stored in TurbineServices. @@ -122,7 +122,7 @@ */ public String getDefaultExtension(); - /** + /** * Get the Screen template given in the properties file. * * @return A String which is the value of the TemplateService @@ -146,8 +146,29 @@ */ public String getDefaultLayoutTemplate(); + /** + * Translates the supplied template paths into their Turbine-canonical + * equivalent (probably absolute paths). + */ public String[] translateTemplatePaths(String[] templatePaths); + + /** + * Delegates to the appropriate {@link + * org.apache.turbine.services.template.TemplateEngineService} to + * check the existance of the specified template. + * + * @param template The template to check for the existance of. + * @param templatePaths The paths to check for the template. + */ public boolean templateExists(String template, String[] templatePaths); + + /** + * Registers the provided template engine for use by the + * TemplateService. + * + * @param service The TemplateEngineService to register. + */ public void registerTemplateEngineService(TemplateEngineService service); - + + public String getDefaultPageName(RunData data); } 1.6 +9 -3 jakarta-turbine/src/java/org/apache/turbine/services/template/TurbineTemplate.java Index: TurbineTemplate.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/template/TurbineTemplate.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TurbineTemplate.java 2001/03/31 16:02:29 1.5 +++ TurbineTemplate.java 2001/04/01 06:12:59 1.6 @@ -54,15 +54,16 @@ * . */ -// Turbine stuff. -import org.apache.turbine.services.*; +import org.apache.turbine.util.RunData; +import org.apache.turbine.services.TurbineServices; + /** * This is a simple static accessor to common TemplateService tasks such as * getting a Screen that is associated with a screen template. * * @author John D. McNally - * @version $Id: TurbineTemplate.java,v 1.5 2001/03/31 16:02:29 jvanzyl Exp $ + * @version $Id: TurbineTemplate.java,v 1.6 2001/04/01 06:12:59 jvanzyl Exp $ */ public abstract class TurbineTemplate { @@ -186,5 +187,10 @@ public static final boolean templateExists(String template, String[] templatePaths) { return getService().templateExists(template, templatePaths); + } + + public static final String getDefaultPageName(RunData data) + { + return getService().getDefaultPageName(data); } } 1.23 +104 -60 jakarta-turbine/src/java/org/apache/turbine/services/template/TurbineTemplateService.java Index: TurbineTemplateService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/template/TurbineTemplateService.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- TurbineTemplateService.java 2001/03/31 16:02:30 1.22 +++ TurbineTemplateService.java 2001/04/01 06:12:59 1.23 @@ -54,17 +54,23 @@ * . */ +import java.io.File; + import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Stack; import java.util.StringTokenizer; -import java.io.File; - import org.apache.turbine.modules.NavigationLoader; import org.apache.turbine.modules.ScreenLoader; + import org.apache.turbine.util.Log; +import org.apache.turbine.util.RunData; + import org.apache.turbine.services.TurbineBaseService; import org.apache.turbine.services.TurbineServices; import org.apache.turbine.services.InitializationException; @@ -110,11 +116,17 @@ * @author John D. McNally * @author Dave Bryson * @author Jason van Zyl - * @version $Id: TurbineTemplateService.java,v 1.22 2001/03/31 16:02:30 jvanzyl Exp $ + * @version $Id: TurbineTemplateService.java,v 1.23 2001/04/01 06:12:59 jvanzyl Exp $ */ public class TurbineTemplateService extends TurbineBaseService implements TemplateService { + /** + * The default file extension used as a registry key when a + * template's file extension cannot be determined. + */ + private static final String NO_FILE_EXT = ""; + /** * The hashtable used to cache Screen names. */ @@ -161,24 +173,26 @@ private String defaultScreen; /** - * The template engine that will be used to test whether - * a given template exists. You will notice that this - * service implements the TemplateEngineService: this - * will remain until all the template engines implement - * this interface. Right now only the Velocity service - * implements this interface. The upshot of this is - * that Velocity can locate templates within the capability - * of Velocity and its resource loaders, the other template - * engines are stuck with the file based template hierarchy. + * The mappings of template file extensions to {@link + * org.apache.turbine.services.template.TemplateEngineService} + * implementations. Implementing template engines can locate + * templates within the capability of any resource loaders they + * may posses, and other template engines are stuck with file + * based template hierarchy only. */ - private TemplateEngineService templateEngineService; + private Hashtable templateEngineRegistry; + + public TurbineTemplateService() + { + templateEngineRegistry = new Hashtable(); + } /** * Called the first time the Service is used. * * @exception InitializationException */ - public void init() throws InitializationException + public void init(RunData data) throws InitializationException { try { @@ -222,35 +236,21 @@ screenCache = new Hashtable((int) (1.25*screenSize) + 1); templateCache = new Hashtable((int) (1.25*templateSize) + 1); } - - /* - * The extension that is added to layout templates. - */ - extension = config.getString("default.extension", "vm"); - - /* - * The default navigation module. - */ - defaultNavigation = config.getString( - "default.navigation", "TemplateNavigation"); - - /* - * The default screen. - */ - defaultScreen = config.getString("default.screen", "TemplateScreen"); + } + + /** + * The {@link org.apache.turbine.services.template.TemplateEngineService} + * associated with the specified template's file extension. + */ + private TemplateEngineService getTemplateEngineService(String template) + { + int dotIndex = template.lastIndexOf('.'); - /* - * The default layout template. - */ - defaultLayoutTemplate = config.getString( - "default.layout.template", "/default." + extension); + String ext = (dotIndex == -1 ? NO_FILE_EXT : template.substring(dotIndex + 1)); - if (defaultLayoutTemplate.indexOf('.') == -1) - { - defaultLayoutTemplate = defaultLayoutTemplate + "." + extension; - } + return (TemplateEngineService) templateEngineRegistry.get(ext); } - + /** * Take a set of template paths and translate them * to the webapp space. This can be used by all @@ -469,7 +469,8 @@ { /* * Check if an extension was included. - * If not, add the default. + * If not, add the default. This shouldn't happen, + * an extension should always be present I think (jvz). */ if ( template.indexOf('.') == -1 ) { @@ -488,7 +489,7 @@ String templateToFind = "screens/" + template; - if (!templateEngineService.templateExists(templateToFind)) + if (!getTemplateEngineService(template).templateExists(templateToFind)) { /* * We should ask the template engine where it @@ -533,7 +534,7 @@ } String[] holder = new String[3]; - holder[0] = getScreenName(pkgs); + holder[0] = getScreenName(pkgs, template); holder[1] = getLayoutTemplateName(paths); holder[2] = template; return holder; @@ -546,7 +547,6 @@ * templateRoot path. */ String pathRoot = null; - String allPaths = ""; String pathSep = System.getProperty("path.separator"); for (int i = 0; i < templatePaths.length; i++) @@ -556,14 +556,8 @@ pathRoot = templatePaths[i]; break; } - allPaths += pathSep + templatePaths[i]; } - if (pathRoot == null) - { - return false; - } - - return true; + return (pathRoot != null); } /** @@ -600,7 +594,7 @@ pkgs[arrayIndex] = pkg.append("Default").toString(); arrayIndex++; } - return getNavigationName(pkgs); + return getNavigationName(pkgs, template); } /** @@ -676,6 +670,14 @@ */ private String getLayoutTemplateName(String[] possiblePaths) { + /* + * Assume at least one path. We should figure out a + * better way to get hold of the engine then having + * to use the template name everytime. + */ + TemplateEngineService tes = + getTemplateEngineService(possiblePaths[0]); + for (int i = 0; i < possiblePaths.length; i++) { /* @@ -683,13 +685,19 @@ * wise because the possiblePaths are coming in * with a prefix of "/". */ - if (templateEngineService.templateExists("layouts" + possiblePaths[i])) + if ( tes.templateExists("layouts" + possiblePaths[i]) ) { return possiblePaths[i]; } } - return defaultLayoutTemplate; + /* + * Now we have to return the default layout for + * the template engine in question. + */ + return (String) tes.getTemplateEngineServiceConfiguration() + .get(TemplateEngineService.DEFAULT_LAYOUT_TEMPLATE); + } /** @@ -699,7 +707,7 @@ * search. * @return A String with the name of the Screen class to use. */ - private String getScreenName( String[] possibleScreens) + private String getScreenName(String[] possibleScreens, String template) { for (int i = 0; i < possibleScreens.length; i++) { @@ -715,7 +723,16 @@ */ } } - return defaultScreen; + + /* + * Need a way to return the template engine default + * screen. + */ + TemplateEngineService tes = getTemplateEngineService(template); + + return (String) tes.getTemplateEngineServiceConfiguration() + .get(TemplateEngineService.DEFAULT_SCREEN); + } @@ -727,7 +744,7 @@ * packages. * @return A String with the name of the Navigation class to use. */ - private String getNavigationName( String[] possibleNavigations) + private String getNavigationName(String[] possibleNavigations, String template) { for (int i = 0; i < possibleNavigations.length; i++) { @@ -743,11 +760,38 @@ */ } } - return defaultNavigation; + + /* + * Need a way to return the template engine default + * navigation. + */ + TemplateEngineService tes = getTemplateEngineService(template); + + return (String) tes.getTemplateEngineServiceConfiguration() + .get(TemplateEngineService.DEFAULT_NAVIGATION); + } public void registerTemplateEngineService(TemplateEngineService service) + { + String[] exts = service.getAssociatedFileExtensions(); + + for (int i = 0; i < exts.length; i++) + { + String ext = exts[i]; + templateEngineRegistry.put(ext, service); + } + } + + /** + * Find the default page module for the given request. + */ + public String getDefaultPageName(RunData data) { - templateEngineService = service; - } + String template = data.getParameters().get("template"); + + return (String) getTemplateEngineService(template) + .getTemplateEngineServiceConfiguration() + .get(TemplateEngineService.DEFAULT_PAGE); + } } 1.40 +9 -10 jakarta-turbine/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java Index: TurbineVelocityService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- TurbineVelocityService.java 2001/03/31 15:55:35 1.39 +++ TurbineVelocityService.java 2001/04/01 06:13:00 1.40 @@ -75,13 +75,12 @@ import org.apache.turbine.util.template.TemplateLink; import org.apache.turbine.util.template.TemplatePageAttributes; -import org.apache.turbine.services.TurbineBaseService; import org.apache.turbine.services.InitializationException; import org.apache.turbine.services.pull.TurbinePull; import org.apache.turbine.services.servlet.TurbineServlet; import org.apache.turbine.services.template.TurbineTemplate; -import org.apache.turbine.services.template.TemplateEngineService; +import org.apache.turbine.services.template.BaseTemplateEngineService; /** * This is a Service that can process Velocity templates from within a @@ -99,10 +98,11 @@ * @author Rafal Krzewski * @author Jason van Zyl * @author Sean Legassick - * @version $Id: TurbineVelocityService.java,v 1.39 2001/03/31 15:55:35 jvanzyl Exp $ + * @author Daniel Rall + * @version $Id: TurbineVelocityService.java,v 1.40 2001/04/01 06:13:00 jvanzyl Exp $ */ -public class TurbineVelocityService extends TurbineBaseService - implements VelocityService,TemplateEngineService +public class TurbineVelocityService extends BaseTemplateEngineService + implements VelocityService { /** * Default encoding to use. This is the default for Velocity, @@ -143,7 +143,7 @@ { } - public void init() throws InitializationException + public void init(RunData data) throws InitializationException { try { @@ -179,12 +179,11 @@ { globalContext = new VelocityContext(); } - - /* + + /* * Register with the template service. */ - TurbineTemplate.registerTemplateEngineService(this); - + registerConfiguration("vm"); setInit(true); } catch (Exception e) 1.29 +13 -14 jakarta-turbine/src/java/org/apache/turbine/services/webmacro/TurbineWebMacroService.java Index: TurbineWebMacroService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/webmacro/TurbineWebMacroService.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- TurbineWebMacroService.java 2001/03/31 15:58:29 1.28 +++ TurbineWebMacroService.java 2001/04/01 06:13:00 1.29 @@ -54,8 +54,6 @@ * . */ -import java.util.Iterator; - import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -83,9 +81,8 @@ import org.apache.turbine.util.webmacro.WebMacroFormatter; import org.apache.turbine.services.InitializationException; -import org.apache.turbine.services.TurbineBaseService; import org.apache.turbine.services.servlet.TurbineServlet; -import org.apache.turbine.services.template.TemplateEngineService; +import org.apache.turbine.services.template.BaseTemplateEngineService; import org.apache.turbine.services.template.TurbineTemplate; import org.apache.velocity.runtime.configuration.Configuration; @@ -116,10 +113,10 @@ * @author Rafal Krzewski * @author Daniel Rall * @author Jason van Zyl - * @version $Id: TurbineWebMacroService.java,v 1.28 2001/03/31 15:58:29 jvanzyl Exp $ + * @version $Id: TurbineWebMacroService.java,v 1.29 2001/04/01 06:13:00 jvanzyl Exp $ */ -public class TurbineWebMacroService extends TurbineBaseService - implements WebMacroService, TemplateEngineService +public class TurbineWebMacroService extends BaseTemplateEngineService + implements WebMacroService { /** * The default encoding used by the WebMacro FastWriter. @@ -132,6 +129,11 @@ protected static final String DEFAULT_ENCODING = "UTF-8"; /** + * A list of template file extensions associated with this service. + */ + private String[] templateFileExtensions; + + /** * The WebMacro engine. */ private WebMacro wm = null; @@ -168,12 +170,13 @@ * * @exception InitializationException Caused by any initialization error. */ - public void init() throws InitializationException + public void init(RunData data) throws InitializationException { try { initWebMacro(); initWebContext(); + registerConfiguration("wm"); setInit(true); } catch (Exception e) @@ -284,7 +287,7 @@ * @param wc The populated context. * @param filename The file name of the template. * @param writer A writer to write the processed template with. - * @throws TurbineException Any exception trown while processing will be +3 * @throws TurbineException Any exception trown while processing will be * wrapped into a TurbineException and rethrown. */ public void handleRequest(WebContext wc, @@ -424,11 +427,7 @@ ("Failed to set up WebMacro templates", e); } - /* - * Register this template engine with the template - * service. - */ - TurbineTemplate.registerTemplateEngineService(this); + registerConfiguration("wm"); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: turbine-dev-help@jakarta.apache.org