You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Vincent Massol <vm...@octo.com> on 2002/11/12 23:51:27 UTC

[Jelly] Testing if a file exists (elegantly)

Hi JellyMen (no offence intended!),

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

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? :-)

Thanks
-Vincent


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Jelly] Testing if a file exists (elegantly)

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Vincent Massol" <vm...@octo.com>
> Hum... thinking a bit more about it, it doesn't really help for the
> following case:
>
>     <available file="${maven.war.webxml}"
>         property="maven.cactus.webxml.exists"/>
>
>     <j:choose>
>       <j:when test="${maven.cactus.webxml.exists}">
>         <j:set var="webxml" value="${maven.war.webxml}"/>
>       </j:when>
>       <j:otherwise>
>         <j:set var="webxml" value="${maven.cactus.emptywebxml}"/>
>       </j:otherwise>
>     </j:choose>
>
> How would you go about writing this? Using the helper you mentioned?
>
> Anyway, don't worry, I can live with <available> for now! :-)

Having a helper might well be easier. Though you could write the above like
this...

<j:set var="webxml" value="${maven.cactus.emptywebxml}"/>
<util:available file="${maven.war.webxml}">
    <j:set var="webxml" value="${maven.war.webxml}"/>
</util:available>

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Jelly] Testing if a file exists (elegantly)

Posted by Vincent Massol <vm...@octo.com>.
Hum... thinking a bit more about it, it doesn't really help for the
following case:

    <available file="${maven.war.webxml}"
        property="maven.cactus.webxml.exists"/>

    <j:choose>
      <j:when test="${maven.cactus.webxml.exists}">
        <j:set var="webxml" value="${maven.war.webxml}"/>
      </j:when>
      <j:otherwise>
        <j:set var="webxml" value="${maven.cactus.emptywebxml}"/>
      </j:otherwise>
    </j:choose>

How would you go about writing this? Using the helper you mentioned?

Anyway, don't worry, I can live with <available> for now! :-)

Thanks
-Vincent


> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@octo.com]
> Sent: 13 November 2002 14:58
> To: 'Jakarta Commons Developers List'
> Subject: RE: [Jelly] Testing if a file exists (elegantly)
> 
> 
> 
> > -----Original Message-----
> > From: James Strachan [mailto:james_strachan@yahoo.co.uk]
> > Sent: 13 November 2002 13:26
> > To: Jakarta Commons Developers List
> > Subject: Re: [Jelly] Testing if a file exists (elegantly)
> >
> > From: "Vincent Massol" <vm...@octo.com>
> > > Hi JellyMen (no offence intended!),
> >
> > :-)
> >
> > How about 'Jellies' as an affectionate term for people who do Jelly
:)
> 
> ok for Jellies ;-)
> 
> [snip]
> 
> > I actually went for a different tack; to create a new tag.
> >
> > <util:available file="${maven.war.webxml}">
> >     ...
> > </util:available>
> >
> 
> Great! That's perfect. Thanks a lot. I'm going to update the Cactus
> plugin to use that.
> 
> [snip]
> 
> -Vincent
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Jelly] Testing if a file exists (elegantly)

Posted by Vincent Massol <vm...@octo.com>.

> -----Original Message-----
> From: James Strachan [mailto:james_strachan@yahoo.co.uk]
> Sent: 13 November 2002 13:26
> To: Jakarta Commons Developers List
> Subject: Re: [Jelly] Testing if a file exists (elegantly)
> 
> From: "Vincent Massol" <vm...@octo.com>
> > Hi JellyMen (no offence intended!),
> 
> :-)
> 
> How about 'Jellies' as an affectionate term for people who do Jelly :)

ok for Jellies ;-)

[snip]

> I actually went for a different tack; to create a new tag.
> 
> <util:available file="${maven.war.webxml}">
>     ...
> </util:available>
> 

Great! That's perfect. Thanks a lot. I'm going to update the Cactus
plugin to use that.

[snip]

-Vincent


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Jelly] Testing if a file exists (elegantly)

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Vincent Massol" <vm...@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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>