In Jetspeed we plan to support at least 2 template engines as 
our default implementation: Velocity and JSP.

In order to simplify maintenance, I'd like to write only one 
version of our actions, and not one per templating system, as in
most cases the action code itself is not dependent on the templating
system.

Currently Turbine does not make this very easy because the action
needs to explicitely test against all possible templating context
and set the appropriate values in all the contexts...

In order to improve this behavior, I'd like to implement the 
following scheme:

- Create a template neutral context object (TurbineContext) used 
  by actions for storing template-neutral values that should
  be accesible by the templates
  
- Add to the TemplateInfo class, the following methods :

  void setContext( TurbineContext ctxt );
  
  TurbineContext getContext();
  
- Modify the templating system services (Velocity, WebMacro, etc...)
  in order to use a template engine specific context backed by the
  TurbineContext object.
  
  For example:
  
  public class TurbineVelocityContext extends VelocityContext 
  {
  
    public TurbineContext ctxt = null;

    public TurbineVelocityContext( TurbineContext context )
    {
      this.ctxt = context;
    }
 
    public void put( Object key, Object value)
    {
      if (ctxt!=null) 
      {
        ctxt.put(key,value);
      }
      else
      {
        super.put(key,value);
      }
    }
    
    // idem for get, etc...
  }
  
- Create a generic TemplateAction class

  public class TemplateAction extends Action 
  {
    public abstract void doPerform( RunData data, 
                                    TurbineContext context )
  }
  
  Such a TemplateAction can be used with any templating system
  since any TurbineContext modification is automatically 
  reflected in the template system specific Contexts (and
  vice-versa)


With this scheme, it should also be possible to create a TemplatePage 
class that may work with all the context-based templating system.

What do you think about this idea ? 
Is there an implementation issue that may prevent this from working ?

--
Raphaël Luta - [EMAIL PROTECTED]
Vivendi Universal Networks - Services Manager / Paris


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to