commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [Jelly] Testing if a file exists (elegantly)
Date Wed, 13 Nov 2002 13:26:18 GMT
From: "Vincent Massol" <vmassol@octo.com>
> Hi JellyMen (no offence intended!),

:-)

How about 'Jellies' as an affectionate term for people who do Jelly :)


> While writing some Maven plugins, I've noticed that a very task is to
> check for the existence of a file or directory. All jelly scripts I have
> seen are you doing this way:
>
>   <available file="${maven.war.webxml}"
>     property="maven.cactus.webxml.exists"/>
>
>   <j:if test="${maven.cactus.webxml.exists}">
> [...]
>
> Which forces to create a temporary variable and is bit lengthy to
> write...

Agreed.

> I'm quite sure there is a more elegant solution in Jelly but I can't
> find it. Can someone help?
>
> I'd like something like:
>
> <j:if test="exist ${maven.war.webxml}">
> [...]
>
> Is that possible? :-)

I'm sure it is, though it'd require a Jexl change.

I actually went for a different tack; to create a new tag.

<util:available file="${maven.war.webxml}">
    ...
</util:available>

The tag can take either a File object (which is auto-coerced from a String)
or can take a URI attribute, which can be a full file based URL or a URI
relative to the current Jelly script. To do proper context-aware URI
processing requires a Tag which is the main reason I went this route; also
we get nice type-coersion too..

<util:available uri="foo.xml">
    ...
</util:available>

<util:available uri="file://blah/whatever/foo.xml">
    ...
</util:available>

This is all available in the latest Jelly snapshot.


Going forward, another approach could be to add some helper objects to the
context so that function libraries can be available via variable names. e.g.

public class MyHelperClass {

    public boolean someCheck(Object someArgument, int x) {
        return true;
    }

    ...
}

Then to use these methods...

    <j:useBean var="helper" class="com.acme.MyHelperClass"/>
    ...
   <j:if test="${helper.someCheck(foo, 12)}">
        ...

James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message