users@jersey.java.net

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

From: James Strachan <james.strachan_at_gmail.com>
Date: Mon, 17 Aug 2009 09:22:23 +0100

2009/8/17 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>
> 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?

Yes, that would be awesome! Am sure its the same for other template
engines; you tend to resolve the name to something (a URL, stream, JSP
page, template object or whatnot). In Lift's case that would be the
actual template which we can then render in the writeTo method.


> 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.

Yeah - I doubt there's many implementations out there; and I'm sure
they'd all benefit from avoiding multiple lookups

-- 
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/