Quoting Cezar Totth ([EMAIL PROTECTED]):
> That's why I'm asking again all template-engine developers on this list
> if it isnt the time to share opinion and try to set some sort of
> standard to allow:
> - Template inter-operability - making switching from one template
> engine to another easier for application developer.
> Or even interoperability betwen template engines, like
> including one template using JSP in another template
> using webmacro, and BOTH sharing the same
> variable/name/object space...
I vote for this. You're not going to achieve it within a template,
but there's no reason why the template can't sport a standard interface.
Something like this:
/**
* Level 1 compliant systems provide a mechanism to extract
* this standard representation of the template
*/
public interface Renderer {
String evaluate() throws TemplateException;
void write(Writer out) throws IOException, TemplateException;
}
/**
* Level 2 compliant systems provide this interface as their
* mechanism for getting a Renderer
*/
public interface Template {
Renderer render(Object templateData);
String evaluate(Object templateData) throws TemplateException;
void write(Writer out, Object templateData)
throws IOException, TemplateException;
}
The second of these interfaces is taken almost directly from
WebMacro's Macro interface. I added the Renderer interface because
some implementors may find it easier to create an adapter class
rather than support the WebMacro-like Template/Macro interface.
It could be extended to include other basic things, such as how
to construct a compiled template from an IO stream, etc., but
each additional step will make the interface more difficult for
some implementors to support.
Let's call that "Level 3" and at least settle on the basics before
progressing.
You could then separate the use of a template from its construction
in your servlet code--enabling you to switch between template
systems, or use more than one system in the same application.
You'd have to rewrite your template HTML, and that's a much more
difficult thing to standardize.
The different template systems have widely divergent template
syntax. WebMacro, for example, does not use XML tags, preferring
a simpler and less obfuscated syntax:
> - More powerfull features lacking now in most template systems
> (including JSP) like:
> - Mapping betwen input form fields and setXXX() calls
WebMacro will have this soon. It's on the 1.0 feature list, and
we're at 0.89 now:
http://webmacro.org
> - exception handling within templates.
Not a good idea. Exception handling is a programming issue. The logic
portion of your application should have done all the necessary
computation (causing exceptions to be raised, if any) before the
template is invoked.
A page designer should not have to deal with the possibility that
the contract for a template has been violated.
The right thing to do is invoke a different template on exception,
rather than buildig exception logic into the template.
WebMacro allows the Java code to select which template to execute, based
on any condition you like--including Java's excellen exception handling.
Java is an excellent programming language. Trying to duplicate its
power in a template script language (even Java-like JSP) is a
mistake.
Use Java for programming. Use templates for rendering.
> - automatic internationalisation (like choosing a template source
> depending on user's language prefferences)
WebMacro allows you to write the template selection code yourself. As
aframework, it essentially provides a default implementation of
everything, and allows you to override or replace anything.
> - output diverting...
WebMacro's template system is not tied to the servlet code. You can
use it independently.
> - Output stream buffering - allowing:
> - adding response headers during/after template processing
> (e.g. Content-Length)
> - a more sophisticated exception handling, like dispatching
> the response to a different resource, when something
> goes wrong, even output has been written
WebMacro already does both of these.
> - easy-to-use formatting for dates, numbers, other objects...
Another thing coming for 1.0; there will be default filters, which you
will be able to replace with your own. Not just for dates, but for
anything.
WebMacro can be downloaded and used free:
http://webmacro.org
Justin
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html