You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tim Colson <hs...@happysearch.com> on 2001/03/19 03:14:10 UTC

List Archives & template path

1) Is there a FAQ and/or mailing list archive that I can have a look
through?

2) I realize my mileage may vary since I'm using Velocity with JBUILDER
and Tomcat -
but anyone have a clue to give me as to where the Velocity runtime is
attempting to read in template files from? Can I specify an absolute
windows path? If so - uh - stupid question, but how? I've tried all sorts
of methods without any luck. 

BTW - I can write a file into my templates directory from the servlet I'm
working on using the following code. However, a few lines lower when I try
to read in a .vm file from the same directory path - I get a
ResourceNotFound Exception.

    try {
      FileOutputStream fout =  new FileOutputStream("templates" +
File.separator + "whereami2.out");
      PrintStream myOutput = new PrintStream(fout);
      myOutput.println("Hello There!");
    }
    catch (IOException e) {
      out.println("Error opening file: " + e);
    }

Thanks folks!
Tim Colson




Re: List Archives & template path

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tim Colson wrote:

> 2) I realize my mileage may vary since I'm using Velocity with JBUILDER
> and Tomcat -

I use it that way often...

> but anyone have a clue to give me as to where the Velocity runtime is
> attempting to read in template files from? Can I specify an absolute
> windows path? If so - uh - stupid question, but how? I've tried all sorts
> of methods without any luck.

Yes.  In is the 'current directory' by default, and can be specified
precisely via the properties file.  Read the bit in the developers guide
about properties, and look at the examples.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: List Archives & template path

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/18/01 6:14 PM, "Tim Colson" <hs...@happysearch.com> wrote:

> 1) Is there a FAQ and/or mailing list archive that I can have a look
> through?

There are links to the mailing list archive on the same page where you
learned how to subscribe! At the very top of the page.

> 2) I realize my mileage may vary since I'm using Velocity with JBUILDER
> and Tomcat -
> but anyone have a clue to give me as to where the Velocity runtime is
> attempting to read in template files from? Can I specify an absolute
> windows path? If so - uh - stupid question, but how? I've tried all sorts
> of methods without any luck.
> 
> BTW - I can write a file into my templates directory from the servlet I'm
> working on using the following code. However, a few lines lower when I try
> to read in a .vm file from the same directory path - I get a
> ResourceNotFound Exception.
> 
> try {
> FileOutputStream fout =  new FileOutputStream("templates" +
> File.separator + "whereami2.out");
> PrintStream myOutput = new PrintStream(fout);
> myOutput.println("Hello There!");
> }
> catch (IOException e) {
> out.println("Error opening file: " + e);
> }

eh?

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


Re: List Archives & template path

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
All done.  Thanks.


Tim Colson wrote:
> 
> On Sun, 18 Mar 2001, Tim Colson wrote:
> > 1) Is there a FAQ and/or mailing list archive that I can have a look
> > through?
> Haven't heard back on this one yet - but did manage to find this archive:
> http://marc.theaimsgroup.com/
> 
> > 2) where is the Velocity runtime is attempting to read in templates
> Gier replied:
> > In is the 'current directory' by default, and can be specified
> > precisely via the properties file.  Read the bit in the developers guide
> > about properties, and look at the examples.
> 
> Read the guide a third time. I think perhaps the "Fundamental Pattern"
> code example in the docs is missing a crucial line - Velocity.init();
> 
> After adding the init (which is mentioned in the other examples, but not
> the fundamental one) - my template loads and runs swimmingly. :-)
> 
> Another note - seems that I needed to import two more classes to make
> things happy (again, these aren't noted in the Fundamental Pattern)
> 
> import org.apache.velocity.app.Velocity;
> import org.apache.velocity.Template;
> 
> Thanks!
> Timothy

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

RE: Substring function

Posted by Huy Do <hu...@tramada.com>.
This is cool. I'll now go and change the turbine torque templates for
postgresql
so i can generate my first peers app.

Thanks alot for the rapid replies.

Huy

-----Original Message-----
From: gmj@mta4.srv.hcvlny.cv.net [mailto:gmj@mta4.srv.hcvlny.cv.net]On
Behalf Of Geir Magnusson Jr.
Sent: Tuesday, 20 March 2001 2:11 PM
To: velocity-user@jakarta.apache.org
Subject: Re: Substring function


Huy Do wrote:
>
> Hi,
>
> i'm new to velocity and I was wondering if there was
> a substring function built into velocity. I think this
> would be useful as it is directly related to the presentation
> of strings on a template.

I saw jon responded, but I may be able to provide a little discussion in
addition to his correct but terse suggestion :)

The upshot of what Jon was saying is that in Velocity, Strings from the
context are regular java String classes.  Also, strings you create w/in
the template are also String objects.  All the methods apply.

So you can do things like

#set($foo = "Bar" )
$foo.substring(0,1)

and the output is

B

or other string functions work :

#set($bar = "12345")
#set($len = $bar.length() - 1)
#foreach($i in [0..$len] )
$bar.charAt($i)
#end

which would produce
1
2
3
4
5

geir

--
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/


Re: Substring function

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Huy Do wrote:
> 
> Hi,
> 
> i'm new to velocity and I was wondering if there was
> a substring function built into velocity. I think this
> would be useful as it is directly related to the presentation
> of strings on a template.

I saw jon responded, but I may be able to provide a little discussion in
addition to his correct but terse suggestion :)

The upshot of what Jon was saying is that in Velocity, Strings from the
context are regular java String classes.  Also, strings you create w/in
the template are also String objects.  All the methods apply.

So you can do things like

#set($foo = "Bar" )
$foo.substring(0,1)

and the output is

B

or other string functions work :

#set($bar = "12345")
#set($len = $bar.length() - 1)
#foreach($i in [0..$len] )
$bar.charAt($i)
#end

which would produce
1
2
3
4
5

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Substring function

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/19/01 5:28 PM, "Huy Do" <hu...@tramada.com> wrote:

> Hi,
> 
> i'm new to velocity and I was wondering if there was
> a substring function built into velocity. I think this
> would be useful as it is directly related to the presentation
> of strings on a template.
> 
> Thanks
> 
> Huy

context.put ("foo", new String());

template:

$foo.substring()

-jon


Substring function

Posted by Huy Do <hu...@tramada.com>.
Hi,

i'm new to velocity and I was wondering if there was
a substring function built into velocity. I think this
would be useful as it is directly related to the presentation
of strings on a template.

Thanks

Huy

Re: List Archives & template path

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Magnus ?or Torfason wrote:
> 
> > > import org.apache.velocity.app.Velocity;
> > > import org.apache.velocity.Template;
> >
> > Will update that too, although the "Fundamental Pattern" was meant to
> > show the pattern, not do a tutorial on using non-JDK classes :)  But
> > good catch - if people need that, it will be there...
> 
> Isn't this more about telling people which packages Velocity and Template
> are in.
> 
> I know how to use non-JDK classes, but did not know that Velocity was in
> org.apache.velocity.app.

Just to be clear : 

I apologize if I came across as snippy or sarcastic.  What I meant was
that when I wrote that,  in my head was meant to be more of a 'model' of
how it worked, rather than working code.  The reason is that there are
slightly different init approaches for applications vs servlets, so I
did the details later on in the document.

Again, sorry if that came across wrong.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: List Archives & template path

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Magnus ?or Torfason wrote:
> 
> > > import org.apache.velocity.app.Velocity;
> > > import org.apache.velocity.Template;
> >
> > Will update that too, although the "Fundamental Pattern" was meant to
> > show the pattern, not do a tutorial on using non-JDK classes :)  But
> > good catch - if people need that, it will be there...
> 
> Isn't this more about telling people which packages Velocity and Template
> are in.

Well, initially it was just to show the basic pattern - but I realize
since people need it, it's important. 

And if you look - it's there now :)

geir 
-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

RE: List Archives & template path

Posted by Magnus ?or Torfason <ma...@handtolvur.is>.
> > import org.apache.velocity.app.Velocity;
> > import org.apache.velocity.Template;
>
> Will update that too, although the "Fundamental Pattern" was meant to
> show the pattern, not do a tutorial on using non-JDK classes :)  But
> good catch - if people need that, it will be there...

Isn't this more about telling people which packages Velocity and Template
are in.

I know how to use non-JDK classes, but did not know that Velocity was in
org.apache.velocity.app.

magnus

> geir


Re: List Archives & template path

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tim Colson wrote:
> 
> On Sun, 18 Mar 2001, Tim Colson wrote:
> > 1) Is there a FAQ and/or mailing list archive that I can have a look
> > through?
> Haven't heard back on this one yet - but did manage to find this archive:
> http://marc.theaimsgroup.com/

Also 

http://www.mail-archive.com/

> 
> > 2) where is the Velocity runtime is attempting to read in templates
> Gier replied:
> > In is the 'current directory' by default, and can be specified
> > precisely via the properties file.  Read the bit in the developers guide
> > about properties, and look at the examples.
> 
> Read the guide a third time. I think perhaps the "Fundamental Pattern"
> code example in the docs is missing a crucial line - Velocity.init();

Yikes! Sorry.  Fixing right now :)

> After adding the init (which is mentioned in the other examples, but not
> the fundamental one) - my template loads and runs swimmingly. :-)
> 
> Another note - seems that I needed to import two more classes to make
> things happy (again, these aren't noted in the Fundamental Pattern)
> 
> import org.apache.velocity.app.Velocity;
> import org.apache.velocity.Template;

Will update that too, although the "Fundamental Pattern" was meant to
show the pattern, not do a tutorial on using non-JDK classes :)  But
good catch - if people need that, it will be there...

geir


-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: List Archives & template path

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/19/01 9:35 AM, "Tim Colson" <hs...@happysearch.com> wrote:

> 
> On Sun, 18 Mar 2001, Tim Colson wrote:
>> 1) Is there a FAQ and/or mailing list archive that I can have a look
>> through?
> Haven't heard back on this one yet - but did manage to find this archive:
> http://marc.theaimsgroup.com/

Tim, I responded to you:

"There are links to the mailing list archive on the same page where you
learned how to subscribe! At the very top of the page."

-jon


Re: List Archives & template path

Posted by Tim Colson <hs...@happysearch.com>.
On Sun, 18 Mar 2001, Tim Colson wrote:
> 1) Is there a FAQ and/or mailing list archive that I can have a look
> through?
Haven't heard back on this one yet - but did manage to find this archive:
http://marc.theaimsgroup.com/

> 2) where is the Velocity runtime is attempting to read in templates
Gier replied:
> In is the 'current directory' by default, and can be specified
> precisely via the properties file.  Read the bit in the developers guide
> about properties, and look at the examples.

Read the guide a third time. I think perhaps the "Fundamental Pattern"
code example in the docs is missing a crucial line - Velocity.init(); 

After adding the init (which is mentioned in the other examples, but not
the fundamental one) - my template loads and runs swimmingly. :-)

Another note - seems that I needed to import two more classes to make
things happy (again, these aren't noted in the Fundamental Pattern)

import org.apache.velocity.app.Velocity;
import org.apache.velocity.Template;

Thanks!
Timothy