Nops. For that kind of thing I am using a different approach.
I have what I call a DbCursor class that works as an iterator
over a ResultSet (it is not an Iterator implementation but
another kind of iterator, since forward only ResultSets with
nested ResultSets or BLOBs make implementing an Iterator over
them really hard or impossible.)
At each iteration over the DbCursor one can access data using
an instance of a DbCursorData class, which main methods are
something like:
public final Object get(String i_colName); // this is the one for
templates
public final Object get(int i_colIndex);
this allows the use of a template syntax like:
$rowdata.colname
To help formatting stuff, the DbCursor allows to apply filters
(formatters) to all or some of its columns. Those filters
basically convert the column value obtained from the ResultSet
wrapped by the DbCursor (using a getObject(colName) call) into
a formatted String.
For this kind of stuff, I just use a filter that escapes the
value. A simplistic version of the formatting method would be
something like this:
String format(Object obj)
{ return (null == obj) ? "" : escape(obj.toString());
}
Simplistic because you also have to consider BLOBs and other
"special" column types. In my implementation I just have
different filters for the special data types and a take care
of nested datasets (supported) by wrapping it with a DbCursor.
BTW, I even support nested datasets by using a (Velocity)
template. Their XML definition looks something like this:
<sql name="groupedProd" db="prodDb" maxrows="20">
SELECT * FROM prodgroup_tbl ORDER BY catorder
<sql name="p">
SELECT * FROM product_view
WHERE prodgroupid=$parent.prodgroupid
ORDER BY catorder
</sql>
</sql>
This allows nested datasets in databases that do not support
them. And I can use nested iterations for them in Velocity.
Is this interesting for anyone else?
Have fun,
Paulo Gaspar
> -----Original Message-----
> From: Jose Alberto Fernandez [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 05, 2001 00:11
>
>
> How does that work for method invocations:
>
> ... $myObject.getResultset().getColumn("NAME") ...
>
> can a context approach dothe escaping for method calls?
>
> Jose Alberto
>
> > -----Original Message-----
> > From: Paulo Gaspar [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, April 04, 2001 2:05 PM
> > To: [EMAIL PROTECTED]
> > Subject: RE: [PROPOSAL] InsertionListener
> >
> >
> > Jose,
> >
> >
> > Could a wrapper around the objects you are placing at the
> > context be a solution?
> >
> > Since Velocity can use a class with a get() method like:
> >
> > class MyWrapper
> > { private Object theWrappedObject;
> >
> > public MyWrapper(Object anObjectToWrap)
> > { super();
> > theWrappedObject = anObjectToWrap;
> > ...
> > }
> >
> > public Object get(String name)
> > {
> > ...
> > }
> > }
> >
> > calling
> > get("somevalue")
> >
> > for an in-template
> > $escapedObject.somevalue
> >
> >
> > The wrapper class could use some introspection in the get()
> > method (in a similar way to what Velocity usually does) in
> > order to introspect the wrapped object, get the value for
> > its "somevalue" property, convert it into a string and
> > escape it, giving it back to Velocity.
> >
> > So, you would place the objects which have values to escape
> > using something like:
> > myContext.put("escapedObject", new MyWrapper(myOriginalObject));
> >
> > Of course that, if ALL your objects need to be escaped, you
> > could also derive a new version of context that does just that.
> >
> >
> > For escaping simple values, like in
> > $simple
> > you can just convert them to an escaped String just when putting
> > them in the context, with some method like:
> > String escapeObject(Object obj)
> > { return (null == obj) ? "" : escape(obj.toString());
> > }
> >
> > and then
> > myContext.put("simple", MyUtils.escapeObject(simpleObject));
> >
> >
> > Of course that you could create a VelocityContext descendent with
> > new methods like:
> > public void putSimple(String name, Object value)
> >
> > that would make this last simple escaping and then use the
> > inherited put(), and like
> > public void putWrap(String name, Object value)
> >
> > that would do the wrapping thing I first talked about.
> >
> >
> > And, of course, you are still in trouble if you use things like:
> > $more.levels.toget.it
> >
> > But if these cases are just 10% of the thing, you might allow
> > them to go like:
> > $tool.escape($more.levels.toget.it)
> >
> > =:o)
> >
> >
> > All this looks simpler to me than tell the template engine when
> > to behave different (although an listener/escaper could be passed
> > through the context).
> >
> >
> > Have fun,
> >
> > Paulo Gaspar
> >
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>