You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Peter Nabbefeld <Pe...@gmx.de> on 2004/08/01 14:27:08 UTC

[Jelly/Jexl] How to add two int values?

Hi,

I'm trying to write a Jelly script for Maven. I've tried "${x + y}" and 
"${x} + ${y}" as the value argument, both don't work for me. I don't 
know, if this is a problem with the archaic versions, Maven uses (e.g. 
ant 1.5.3), or if it is a problem with Jelly/Jexl. If it is a solved 
problem, please give me the right syntax, so I can file a bug for Maven.

Kind regards

Peter Nabbefeld


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Jelly/Jexl] How to add two int values?

Posted by Paul Libbrecht <pa...@activemath.org>.
I agree sometimes casting is surprising in jexl and jelly... making 
this clear would be a strong contribution for the maturity of both.
When I get stuck with these, I solve it using another annoyance: the 
minus sign.

It's as simple as that: ${x+y-0} will always be a number or throw if x 
or y cannot be made to a number.
Do note that "null" may be made into "0", I fear.

paul


Le 1 août 04, à 14:27, Peter Nabbefeld a écrit :
> I'm trying to write a Jelly script for Maven. I've tried "${x + y}" 
> and "${x} + ${y}" as the value argument, both don't work for me. I 
> don't know, if this is a problem with the archaic versions, Maven uses 
> (e.g. ant 1.5.3), or if it is a problem with Jelly/Jexl. If it is a 
> solved problem, please give me the right syntax, so I can file a bug 
> for Maven.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Jelly/Jexl] How to add two int values?

Posted by Peter Nabbefeld <Pe...@gmx.de>.
Dion Gillard schrieb:

> This works for me:
> 
>   result is '${1 + 2}'
>   <set var="x" value="3"/>
>   <set var="y" value="4"/>
>   result is '${x + y}'
> 
> Can you simplify your example?
> 
Thank You!

Your example worked for me, too, so I can now look, why the other 
doesn't work. Most important for me, that I've an example for the 
correct syntax, and now I know it *must* work - I've a better chance to 
fix it now.

Thank You for Your help!

Peter



> On Sun, 01 Aug 2004 15:13:10 +0200, Peter Nabbefeld
> <pe...@gmx.de> wrote:
> 
>>I've asked to add two int values. Here's some of the code (I've tried
>>different versions - without success):
>>
>><j:forEach var="line" items="${pluginIncludeTags}">
>>   <echo>line = ${line}</echo>
>>   <j:set var="_cpos" value="${line.indexOf(':')}"/>
>>   <!-- j:invokeStatic var="_cpos" className="java.lang.Integer"
>>method="parseInt">
>>     <j:arg type="java.lang.String" value="${line.indexOf(':')}"/>
>>   </j:invokeStatic -->
>>   <!-- j:set var="_pos"
>>value="${java.lang.Integer.parseInt(line.substring(0, _cpos))}"/ -->
>>   <j:invokeStatic var="_pos" className="java.lang.Integer"
>>method="parseInt">
>>     <j:arg type="java.lang.String" value="${line.substring(0, _cpos)}"/>
>>   </j:invokeStatic>
>>   <j:set var="_lineDir" value="${line.substring(_cpos, _cpos + _pos)}"/>
>>   <!-- j:invoke var="_lineDir" method="substring" on="${line}">
>>     <j:arg type="int" value="${_cpos)}"/>
>>     <j:arg type="int"><j:expr value="_cpos + _pos"/></j:arg>
>>   </j:invoke -->
>>
>>Peter
>>
>>Dion Gillard schrieb:
>>
>>
>>
>>
>>>What types are x and y?
>>>
>>>On Sun, 01 Aug 2004 14:27:08 +0200, Peter Nabbefeld
>>><pe...@gmx.de> wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>I'm trying to write a Jelly script for Maven. I've tried "${x + y}" and
>>>>"${x} + ${y}" as the value argument, both don't work for me. I don't
>>>>know, if this is a problem with the archaic versions, Maven uses (e.g.
>>>>ant 1.5.3), or if it is a problem with Jelly/Jexl. If it is a solved
>>>>problem, please give me the right syntax, so I can file a bug for Maven.
>>>>
>>>>Kind regards
>>>>
>>>>Peter Nabbefeld
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Jelly/Jexl] How to add two int values?

Posted by Dion Gillard <di...@gmail.com>.
This works for me:

  result is '${1 + 2}'
  <set var="x" value="3"/>
  <set var="y" value="4"/>
  result is '${x + y}'

Can you simplify your example?

On Sun, 01 Aug 2004 15:13:10 +0200, Peter Nabbefeld
<pe...@gmx.de> wrote:
> I've asked to add two int values. Here's some of the code (I've tried
> different versions - without success):
> 
> <j:forEach var="line" items="${pluginIncludeTags}">
>    <echo>line = ${line}</echo>
>    <j:set var="_cpos" value="${line.indexOf(':')}"/>
>    <!-- j:invokeStatic var="_cpos" className="java.lang.Integer"
> method="parseInt">
>      <j:arg type="java.lang.String" value="${line.indexOf(':')}"/>
>    </j:invokeStatic -->
>    <!-- j:set var="_pos"
> value="${java.lang.Integer.parseInt(line.substring(0, _cpos))}"/ -->
>    <j:invokeStatic var="_pos" className="java.lang.Integer"
> method="parseInt">
>      <j:arg type="java.lang.String" value="${line.substring(0, _cpos)}"/>
>    </j:invokeStatic>
>    <j:set var="_lineDir" value="${line.substring(_cpos, _cpos + _pos)}"/>
>    <!-- j:invoke var="_lineDir" method="substring" on="${line}">
>      <j:arg type="int" value="${_cpos)}"/>
>      <j:arg type="int"><j:expr value="_cpos + _pos"/></j:arg>
>    </j:invoke -->
> 
> Peter
> 
> Dion Gillard schrieb:
> 
> 
> 
> > What types are x and y?
> >
> > On Sun, 01 Aug 2004 14:27:08 +0200, Peter Nabbefeld
> > <pe...@gmx.de> wrote:
> >
> >>Hi,
> >>
> >>I'm trying to write a Jelly script for Maven. I've tried "${x + y}" and
> >>"${x} + ${y}" as the value argument, both don't work for me. I don't
> >>know, if this is a problem with the archaic versions, Maven uses (e.g.
> >>ant 1.5.3), or if it is a problem with Jelly/Jexl. If it is a solved
> >>problem, please give me the right syntax, so I can file a bug for Maven.
> >>
> >>Kind regards
> >>
> >>Peter Nabbefeld
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
http://www.multitask.com.au/people/dion/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Jelly/Jexl] How to add two int values?

Posted by Peter Nabbefeld <Pe...@gmx.de>.
I've asked to add two int values. Here's some of the code (I've tried 
different versions - without success):

<j:forEach var="line" items="${pluginIncludeTags}">
   <echo>line = ${line}</echo>
   <j:set var="_cpos" value="${line.indexOf(':')}"/>
   <!-- j:invokeStatic var="_cpos" className="java.lang.Integer" 
method="parseInt">
     <j:arg type="java.lang.String" value="${line.indexOf(':')}"/>
   </j:invokeStatic -->
   <!-- j:set var="_pos" 
value="${java.lang.Integer.parseInt(line.substring(0, _cpos))}"/ -->
   <j:invokeStatic var="_pos" className="java.lang.Integer" 
method="parseInt">
     <j:arg type="java.lang.String" value="${line.substring(0, _cpos)}"/>
   </j:invokeStatic>
   <j:set var="_lineDir" value="${line.substring(_cpos, _cpos + _pos)}"/>
   <!-- j:invoke var="_lineDir" method="substring" on="${line}">
     <j:arg type="int" value="${_cpos)}"/>
     <j:arg type="int"><j:expr value="_cpos + _pos"/></j:arg>
   </j:invoke -->

Peter


Dion Gillard schrieb:

> What types are x and y?
> 
> On Sun, 01 Aug 2004 14:27:08 +0200, Peter Nabbefeld
> <pe...@gmx.de> wrote:
> 
>>Hi,
>>
>>I'm trying to write a Jelly script for Maven. I've tried "${x + y}" and
>>"${x} + ${y}" as the value argument, both don't work for me. I don't
>>know, if this is a problem with the archaic versions, Maven uses (e.g.
>>ant 1.5.3), or if it is a problem with Jelly/Jexl. If it is a solved
>>problem, please give me the right syntax, so I can file a bug for Maven.
>>
>>Kind regards
>>
>>Peter Nabbefeld
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Jelly/Jexl] How to add two int values?

Posted by Dion Gillard <di...@gmail.com>.
What types are x and y?

On Sun, 01 Aug 2004 14:27:08 +0200, Peter Nabbefeld
<pe...@gmx.de> wrote:
> 
> Hi,
> 
> I'm trying to write a Jelly script for Maven. I've tried "${x + y}" and
> "${x} + ${y}" as the value argument, both don't work for me. I don't
> know, if this is a problem with the archaic versions, Maven uses (e.g.
> ant 1.5.3), or if it is a problem with Jelly/Jexl. If it is a solved
> problem, please give me the right syntax, so I can file a bug for Maven.
> 
> Kind regards
> 
> Peter Nabbefeld
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
http://www.multitask.com.au/people/dion/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org