users@jersey.java.net

LiftTemplateProcessor.scala <was> Re: svn commit: r2657 - trunk/jersey/contribs/scala: . jersey-lift/src/main/scala/com/sun/jersey/lift

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 17 Aug 2009 09:43:57 +0200

On Aug 13, 2009, at 12:04 PM, jstrachan_at_dev.java.net wrote:
>
> + // TODO this code actually results in looking up the resource
> twice
> + // once here first then again Lift land
> + // I wonder if there's a better way to do this just once?
> + if (servletContext.getResource(path) == null) {
> + if (servletContext.getResource(path + ".html") == null &&
> + servletContext.getResource(path + ".xhtml") == null) {
> + return null
> }
> }

James, if TemplateProcessor was the following:

   public interface TemplateProcessor<T> {

       T resolve(String name);

       void writeTo(T resolvedObject, Object model, OutputStream out)
throws IOException;
   }

would that help? That way resolve can return something specific to its
implementation and avoid duplication of any work in the writeTo
method. But can modify this interface and maintain source backwards
compatibility, is the following source compatible?

   public interface TypeTemplateProcessor<T> {
       T resolve(String name);

       void writeTo(T resolvedObject, Object model, OutputStream out)
throws IOException;
   }

   public TemplateProcessor extends TypeTemplateProcessor<String> {}


The ResolvedViewable class would also require modification.

public class ResolvedViewable<T> extends Viewable {

     private final TypeTemplateProcessor<T> template;

     /**
      * Create a resolved viewable.
      *
      * @param t the template processor.
      * @param fullyQualifiedName the fully qualified template name
identifying a
      * template.
      * @param model the model.
      */
     public ResolvedViewable(TypeTemplateProcessor<T> tp, T resolved,
Object model) {
         this(t, resolved, model, null);
     }

We can probably break this because it is not likely to be used by
developers.

Paul.