Interesting. I used to do the same thing. Then I came up with
an idea one step further -- I use a StringTokenizer object to
scan for $$ in the HTML file. If the token returned starts with
"com.", then I assume the token is a class name and check to see
if it is an instance of Templet (an interface with a
"String getHTML(HttpServletRequest)" method). If it is, I create
an instance of the object, and call getHTML.

I also check for tokens that start with "req." and replace the
following string with the value of "getParameter(req)".

Now rather than having a bunch of "replace" method calls in my
Servlets, I have one parser than can call any class specified
in the HTML file or replace any token with a parameter of the
HTTP request.

Of course, this is starting to remind me of SSI and JSP...

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Carlos Amengual
Sent: Sunday, May 16, 1999 12:07 PM
To: [EMAIL PROTECTED]
Subject: Re: HTML Tags


Raphael Gillett wrote:
>
> Hello everyone,
>
> I agree wholeheartedly with Luther's aim of reducing
> unnecessary, tedious & errorprone typing.
>
> Jon's ECS solution does not achieve that goal, because
> it involves a lot of extra typing (e.g. many out.println
> statements are simply replaced with many addElements).
> Of course ECS is useful for other purposes.
>
> Luther has identified a much-needed feature that
> would benefit us all.

Rather than introducing here-documents and similar syntax in Java to
produce HTML, I prefer to follow a model with separation of code and
HTML. You write your HTML, then read it with the code, manipulate it
programmatically, and output the result.

I have a DocParser interface that includes these two methods:

 public void setParameter(String widgetname, String propname, String
propvalue);

 public void setParameter(String widgetname, int offset, String
propname, String propvalue);

(Thinking now, maybe setParameter is not the best name, but is what I
have now). The first method allows to set the value [propvalue] of an
attribute called [propvalue] of the [widgetname] tag. The second version
includes an offset to locate a tag relative to another one (for example
an anchor), as this avoids having to deal with non-standard tags, but is
dangerous when you modify the HTML file with an editor and inadvertently
introduce additional tags.

I have an "HtmlDocParser" class that implements the interface for HTML,
and you can do for example:

  document.setParameter("message", "value", msg);

My code is not opensource, but there's a free package called HtmlScreen
that does a similar thing.


Carlos

___________________________________________________________________________
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

___________________________________________________________________________
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

Reply via email to