You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Wong, RYM (Richard) " <R....@rl.ac.uk> on 2004/10/15 13:05:26 UTC

Velocity

Hi,

I cannot find out whether VTL is case sensitive or not in the on-line
reference manual.

e.g. Are the reference variables $var  and $VaR regarded as the same
variable?

Richard

***********************************************************************
Richard Wong
Atlas Centre
Rutherford Appleton Laboratory
Oxfordshire
United Kingdom
OX11 0QX

Telephone: 01235-446075
Email:  r.y.m.wong@rl.ac.uk
***********************************************************************
The contents of this email are sent in confidence for the use of the
intended recipient only. If you are not one of the intended recipients do
not take action on it or show it to anyone else, but return this email to
the sender and delete your copy of it.



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


escape double quotes

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Clifton,

> An un-related question...
I changed the subject.  ;)

> How do you escape double quotes? I'm trying to use #set
> ($var="\"MyValue\"") but $var ends up with \"MyValue\" instead of
> "MyValue". When I try it without the backslashes I get parse errors.
There are several ways.

1. If the "MyValue" part is not a reference (which I doubt), you can
use single quote.
  #set($var = '"MyValue"')

2. You can create a variable just for rendering double quotes. 
Assuming $value has "MyValue" in it.
  #set($Q = '"')
  #set($var = "${Q}$value${Q}")

3. You can use the EscapeTool.  Again, assuming $value has "MyValue"
in it.  And $esc has EscapeTool in it.
  #set($var = "${esc.q}$value${esc.q}")
cf. http://wiki.apache.org/jakarta-velocity/EscapeTool

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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


Re: Giving up on Velocity there hope after all

Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Wow,

Thank you all for suggesting DVSL. So far I have managed to replicate 
all of my existing functionality implemented on Anakia with DVSL. The 
code is a LOT cleaner and simpler too. I'm really digging this stuff so 
far. Maybe there's hope for Velocity after all. Things are looking a lot 
better. Thanx.

Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
2101 Embassy Drive
Lancaster, PA  17603

Phone:  717-295-7977 ext. 621
Fax:  717-295-7683
ccc@icsaward.com
ccraig@gbg.com



Tim Colson wrote:

>>As an alternative to Anakia, you can use DVSL for xml transformation.
>>    http://jakarta.apache.org/velocity/dvsl/index.html
>>    
>>
>I'll second that. I've had good luck with DVSL. 
>
>-Timo
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>  
>

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


RE: Giving up on Velocity

Posted by Tim Colson <tc...@cisco.com>.
> As an alternative to Anakia, you can use DVSL for xml transformation.
>     http://jakarta.apache.org/velocity/dvsl/index.html
I'll second that. I've had good luck with DVSL. 

-Timo


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


Re: Giving up on Velocity

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Clifton,

> #macro( expandIfNodeExists $node $templateStr)
>     #if( $node )
>         $!templateStr
>     #end
> #end

## snip

> And then when it encounters another constraint definition in another 
> table element things fall apart. I'd get this:
>    rateunit varchar constraint valid_values check rateunit 
> #if($sltAtr.get(0) .getValue() =='exclude') not #else #end in ("hour",
>    "year"),
At first glance, it looks like you could use the RenderTool.  (My first
glance also says, "I think there's a better way to do this...".  ;))
    http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/RenderTool.html
## But I don't know how to set tools in Anakia.  :(

As an alternative to Anakia, you can use DVSL for xml transformation.
    http://jakarta.apache.org/velocity/dvsl/index.html

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


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


Re: Giving up on Velocity

Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Further info:

The whole big idea is to take input as follows:
    <database>
        <table name="testtable">
            <pk name="id"/>
            <col name="id" type="int"/>
            <col name="compositekey1" type="int"/>
            <col name="compositekey2" type="dec" size="9" scale="3"/>
            <col name="compositekey3" type="varchar" size="10"/>
            <col name="uniquekey" type="varchar" size="30"/>
            <col name="nonnullval" type="varchar" size="30" allownull="no"/>
            <col name="nonnullval2" type="varchar" size="30" allownull="no">
                <default>DEFAULT VALUE</default>
            </col>
            <col name="nullableval" type="varchar" allownull="yes"/>
            <col name="constrained_col" type="varchar">
                <constraint name="simple_constraint">
                    <values select="exclude">
                        <val>hum</val>
                        <val>de</val>
                        <val>dum</val>
                    </values>
                </constraint>
            </col>
            <unique-key cols="compositekey1,compositekey2,compositekey3"/>
            <unique-key cols="uniquekey"/>
        </table>
    </database>

And create some SQL similar to the following:

CREATE TABLE testtable id int,
   compositekey1 int,
   compositekey2 dec(9, 3),
   compositekey3 varchar(10),
   uniquekey varchar(30),
   nonnullval varchar(30) NOT NULL,
   nonnullval2 varchar(30) DEFAULT 'DEFAULT VALUE' NOT NULL,
   nullableval varchar NULL,
   constrained_col varchar constraint simple_constraint check 
constrained_col not in ("hum",
   "de",
   "dum");

 It almost works but as I include multiple table elements in my XML it 
falls apart. Like in my prior email a subsequent table element:

        <table name="employee">
            <pk name="id"/>
            <col name="id" type="int"/>
            <col name="salaried" type="boolean"/>
            <col name="rateamt" type="dec" size="9" scale="4"/>
            <col name="rateunit" type="varchar">
                <doc>Determines the frequency that rateamt is paid.</doc>
                <constraint name="valid_values">
                    <values>
                        <val>hour</val>
                        <val>year</val>
                    </values>
                </constraint>
            </col>
            <col name="grade" type="varchar"/>
            <col name="title" type="varchar"/>
            <related table="user" how="onetoone">
                <match><onpks/></match>
            </related>
        </table>

...produces the following output:

CREATE TABLE employee id int,
   salaried boolean,
   rateamt dec(9, 4),
   rateunit varchar constraint valid_values check rateunit 
#if($sltAtr.get(0) .getValue() =='exclude') not #else #end in ("hour",
   "year"),
   grade varchar,
   title varchar;

I'm frustrated because as I look back on what I've created it looks less 
like a template and more like a programmed procedure. I blame myself for 
my lack of experience and lack of understanding Velocity. However I was 
hoping that this approach would be something I could hit the ground 
running with. Given time I'm sure I'd accept Velocity's syntax (had a 
similar experience with Ant). Just feeling frustrated.

Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
2101 Embassy Drive
Lancaster, PA  17603

Phone:  717-295-7977 ext. 621
Fax:  717-295-7683
ccc@icsaward.com
ccraig@gbg.com



Shinobu Kawai wrote:

>Hi Clifton,
>
>  
>
>>I've had it. I'm trying my best but I can't get Velocity/Anakia to
>>properly convert my XML to SQL. The code is starting to smell and it
>>just doesn't feel quite right. I'm ready to hang up my efforts and call
>>it quits. I can't see why something as simple as expanding a constraint
>>list like this:
>>               <constraint name="simple_constraint">
>>                   <values select="exclude">
>>                       <val>hum</val>
>>                       <val>de</val>
>>                       <val>dum</val>
>>                   </values>
>>               </constraint>
>>
>>would take code that looks like this:
>>    
>>
>## snip
>
>  
>
>>And even that doesn't work.
>>    
>>
>Can you explain what output you want, and what you are actually getting?
>
>Best regards,
>-- Shinobu Kawai
>
>  
>

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


Re: Giving up on Velocity

Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Shinobu,

Sorry for airing my frustrations. I'm just having a lot of trouble 
adjusting to Velocity. Anyhowz, My prior snippet listed here:

#macro( expandIfNodeExists $node $templateStr)
    #if( $node )
        $!templateStr
    #end
#end

#macro( defineConstraints $col )
    #set ($colName = $col.getAttributeValue("name"))
    #set ( $constraint = $col.selectNodes("constraint") )
    #set ($constraintName = $constraint.selectNodes("@name").get(0))
    #if( $constraint.selectNodes("values") && 
$constraint.selectNodes("values").selectNodes("val") )
        #expandIfNodeExists($constraintName "constraint 
$constraintName.getValue()")
        #set ($list='')
        #foreach ($validVal in 
$constraint.selectNodes("values").selectNodes("val"))
            #set($qte = '"')
            #if($list=='')
                #set($list = "$qte$validVal.getText()$qte")
            #else
                #set($list = "$!list,$qte$validVal.getText()$qte")
            #end
        #end
        check $!colName
        #set ( $sltAtr = $constraint.selectNodes("values/@select") )
        #set ( $tmpltStr = "#if($sltAtr.get(0).getValue()=='exclude') 
not #else #end" )
        #expandIfNodeExists($sltAtr $tmpltStr)
        in ( $!list )
    #end
#end

 appeared to work as it would produce results like this when it 
encountered the 1st table element:

   constrained_col varchar constraint simple_constraint check 
constrained_col not in ("hum",
   "de",
   "dum");

And then when it encounters another constraint definition in another 
table element things fall apart. I'd get this:
   rateunit varchar constraint valid_values check rateunit 
#if($sltAtr.get(0) .getValue() =='exclude') not #else #end in ("hour",
   "year"),

Maybe I'll have a look tomorrow and see where I muffed it up. Thanks for 
all of your replies.

Kind Regards,
Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
2101 Embassy Drive
Lancaster, PA  17603

Phone:  717-295-7977 ext. 621
Fax:  717-295-7683
ccc@icsaward.com
ccraig@gbg.com



Shinobu Kawai wrote:

>Hi Clifton,
>
>  
>
>>I've had it. I'm trying my best but I can't get Velocity/Anakia to
>>properly convert my XML to SQL. The code is starting to smell and it
>>just doesn't feel quite right. I'm ready to hang up my efforts and call
>>it quits. I can't see why something as simple as expanding a constraint
>>list like this:
>>               <constraint name="simple_constraint">
>>                   <values select="exclude">
>>                       <val>hum</val>
>>                       <val>de</val>
>>                       <val>dum</val>
>>                   </values>
>>               </constraint>
>>
>>would take code that looks like this:
>>    
>>
>## snip
>
>  
>
>>And even that doesn't work.
>>    
>>
>Can you explain what output you want, and what you are actually getting?
>
>Best regards,
>-- Shinobu Kawai
>
>  
>

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


Re: Giving up on Velocity

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Clifton,

> I've had it. I'm trying my best but I can't get Velocity/Anakia to
> properly convert my XML to SQL. The code is starting to smell and it
> just doesn't feel quite right. I'm ready to hang up my efforts and call
> it quits. I can't see why something as simple as expanding a constraint
> list like this:
>                <constraint name="simple_constraint">
>                    <values select="exclude">
>                        <val>hum</val>
>                        <val>de</val>
>                        <val>dum</val>
>                    </values>
>                </constraint>
> 
> would take code that looks like this:
## snip

> And even that doesn't work.
Can you explain what output you want, and what you are actually getting?

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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


Giving up on Velocity

Posted by "Clifton C. Craig" <cc...@icsaward.com>.
I've had it. I'm trying my best but I can't get Velocity/Anakia to 
properly convert my XML to SQL. The code is starting to smell and it 
just doesn't feel quite right. I'm ready to hang up my efforts and call 
it quits. I can't see why something as simple as expanding a constraint 
list like this:
                <constraint name="simple_constraint">
                    <values select="exclude">
                        <val>hum</val>
                        <val>de</val>
                        <val>dum</val>
                    </values>
                </constraint>

would take code that looks like this:
#macro( expandIfNodeExists $node $templateStr)
    #if( $node )
        $!templateStr
    #end
#end

#macro( defineConstraints $col )
    #set ($colName = $col.getAttributeValue("name"))
    #set ( $constraint = $col.selectNodes("constraint") )
    #set ($constraintName = $constraint.selectNodes("@name").get(0))
    #if( $constraint.selectNodes("values") && 
$constraint.selectNodes("values").selectNodes("val") )
        #expandIfNodeExists($constraintName "constraint 
$constraintName.getValue()")
        #set ($list='')
        #foreach ($validVal in 
$constraint.selectNodes("values").selectNodes("val"))
            #set($qte = '"')
            #if($list=='')
                #set($list = "$qte$validVal.getText()$qte")
            #else
                #set($list = "$!list,$qte$validVal.getText()$qte")
            #end
        #end
        check $!colName
        #set ( $sltAtr = $constraint.selectNodes("values/@select") )
        #set ( $tmpltStr = "#if($sltAtr.get(0).getValue()=='exclude') 
not #else #end" )
        #expandIfNodeExists($sltAtr $tmpltStr)
        in ( $!list )
    #end
#end

And even that doesn't work. I know it probably not the technology at 
fault and it's just me. However, I feel like I've been slowed to a stop 
(if not a backward sprint) using Anakia. I thought it was the perfect 
fit at first but now I can't get past the clumsiness of doing anything 
sophisticated with it. If anyone can see where I'm coming from, please 
chime in and lend a hand. Otherwise, I'm stumped and I give up.

Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
2101 Embassy Drive
Lancaster, PA  17603

Phone:  717-295-7977 ext. 621
Fax:  717-295-7683
ccc@icsaward.com
ccraig@gbg.com



Clifton C. Craig wrote:

> An un-related question...
> How do you escape double quotes? I'm trying to use #set 
> ($var="\"MyValue\"") but $var ends up with \"MyValue\" instead of 
> "MyValue". When I try it without the backslashes I get parse errors.
>
> Clifton C. Craig, Software Engineer
> Intelligent Computer Systems -  A Division of GBG
> 2101 Embassy Drive
> Lancaster, PA  17603
>
> Phone:  717-295-7977 ext. 621
> Fax:  717-295-7683
> ccc@icsaward.com
> ccraig@gbg.com
>
>
>
> Clifton C. Craig wrote:
>
>> Hello all. I'm still green with Velocity. I'm wondering what's the 
>> easiest way to test a string for a numeric. For example, I have a 
>> string $myVal that can contain "foo", or "23.2", or "15". I want to 
>> 1st check if it is a numeric and then wrap it with quotes if it is not.
>>
>> Clifton C. Craig, Software Engineer
>> Intelligent Computer Systems -  A Division of GBG
>> 2101 Embassy Drive
>> Lancaster, PA  17603
>>
>> Phone:  717-295-7977 ext. 621
>> Fax:  717-295-7683
>> ccc@icsaward.com
>> ccraig@gbg.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>

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


Re: String Numerical Testing?

Posted by "Clifton C. Craig" <cc...@icsaward.com>.
An un-related question...
How do you escape double quotes? I'm trying to use #set 
($var="\"MyValue\"") but $var ends up with \"MyValue\" instead of 
"MyValue". When I try it without the backslashes I get parse errors.

Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
2101 Embassy Drive
Lancaster, PA  17603

Phone:  717-295-7977 ext. 621
Fax:  717-295-7683
ccc@icsaward.com
ccraig@gbg.com



Clifton C. Craig wrote:

> Hello all. I'm still green with Velocity. I'm wondering what's the 
> easiest way to test a string for a numeric. For example, I have a 
> string $myVal that can contain "foo", or "23.2", or "15". I want to 
> 1st check if it is a numeric and then wrap it with quotes if it is not.
>
> Clifton C. Craig, Software Engineer
> Intelligent Computer Systems -  A Division of GBG
> 2101 Embassy Drive
> Lancaster, PA  17603
>
> Phone:  717-295-7977 ext. 621
> Fax:  717-295-7683
> ccc@icsaward.com
> ccraig@gbg.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>

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


Re: String Numerical Testing?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Clifton,

> Hello all. I'm still green with Velocity. I'm wondering what's the
> easiest way to test a string for a numeric. For example, I have a string
> $myVal that can contain "foo", or "23.2", or "15". I want to 1st check
> if it is a numeric and then wrap it with quotes if it is not.
I would use o.a.c.l.math.NumberUtils as a tool.
   http://jakarta.apache.org/commons/lang/apidocs/org/apache/commons/lang/math/NumberUtils.html#isNumber(java.lang.String)

If it doesn't do what you want, you can always create your own tool.  ;)

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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


String Numerical Testing?

Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Hello all. I'm still green with Velocity. I'm wondering what's the 
easiest way to test a string for a numeric. For example, I have a string 
$myVal that can contain "foo", or "23.2", or "15". I want to 1st check 
if it is a numeric and then wrap it with quotes if it is not.

Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
2101 Embassy Drive
Lancaster, PA  17603

Phone:  717-295-7977 ext. 621
Fax:  717-295-7683
ccc@icsaward.com
ccraig@gbg.com


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


Re: Velocity

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Richard,

> I cannot find out whether VTL is case sensitive or not in the on-line
> reference manual.
Oh my, it's not?

> e.g. Are the reference variables $var  and $VaR regarded as the same
> variable?
They aren't.  So you can say it's case sensitive.  But please read this:
    http://jakarta.apache.org/velocity/user-guide.html#Case%20Substitution

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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


Re: Velocity

Posted by Barbara Baughman <ba...@utdallas.edu>.
It is case sensitive except in the case of get methods, you can make
the first letter after "get" upper or lower case when you use the
shortcut.

public String getLastUpdate()

can be rendered as
   $this.lastUpdate
   $this.LastUpdate
   $this.getLastUpdate().

Note that it is only forgiving of the first letter after "get".

Barbara Baughman
X2157

On Fri, 15 Oct 2004, Mike Kienenberger wrote:

> "Wong, RYM (Richard) " <R....@rl.ac.uk> wrote:
> > Hi,
> >
> > I cannot find out whether VTL is case sensitive or not in the on-line
> > reference manual.
> >
> > e.g. Are the reference variables $var  and $VaR regarded as the same
> > variable?
>
> I'm fairly certain they are case sensitive.
>
> The easiest and most authoratative way to find out is to just try it, of
> course :)
>
> -Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Re: Velocity

Posted by Mike Kienenberger <mk...@alaska.net>.
"Wong, RYM (Richard) " <R....@rl.ac.uk> wrote:
> Hi,
> 
> I cannot find out whether VTL is case sensitive or not in the on-line
> reference manual.
> 
> e.g. Are the reference variables $var  and $VaR regarded as the same
> variable?

I'm fairly certain they are case sensitive.

The easiest and most authoratative way to find out is to just try it, of 
course :)

-Mike

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