Fwd: [stringtemplate-interest] trouble loading templates from a file

William Surowiec wsurowiec at gmail.com
Wed Jul 12 11:57:38 PDT 2006


I may only have responded to Colin in my last post, so I am enclosing my
reply and an update.

I can move the template file back to the root of the application and
reference it just as template.stg. The cure was Colin's code suggestion (use
a File reader):
            group = new StringTemplateGroup(new
FileReader(templateFileName));


But parsing the file has surfaced a problem. The first '<' encountered
throws:

action parse error in group updates line 3; template context is [update]
line 1:1: unexpected token: getSite
    at org.antlr.stringtemplate.language.ActionParser.primaryExpr(
ActionParser.java:642)

The above message happens when I remove the first '<' from easyAccess (a few
lines down):

group updates;

update (site,auditLogin,auditPassword,customerId,d) ::= <<
<easyAccess dateformat="MM/dd/yyyy">
  <getSite name="$site$">

(The rest removed for this email)

So, another dumb question: how does one use <> as text within a template?

Thanks,

Bill

---------- Forwarded message ----------
From: William Surowiec <wsurowiec at gmail.com>
Date: Jul 12, 2006 2:20 PM
Subject: Re: [stringtemplate-interest] trouble loading templates from a file
To: Colin Bean

On target! The code found the template (and problems of course.)

Many thanks to the community, especially Jose and Colin.

Bill




On 7/12/06, Colin Bean  wrote:
>
> Hi William,
>
> Since you're using a group file, I believe you have to open your group
> file with a FileReader, and pass the FileReader into the
> StringTemplateGroup constructor.  AFIK, just passing a path creates an
> ST group based on a directory, and expects each template to be an .st
> file in that directory (that's why its complaining about update.st).
> Passing a character stream creates an ST group that's actually based
> on your file.
>
> Try something like:
> gFile = new FileReader(templateFileName);
> group = new StringTemplateGroup(gFile);
> stUpdates = group.getInstanceOf("update");
>
> The documentation is a little sparse on this, but if you look under
> "String Template Group Files" in the main documentation, there's an
> example of doing this with a StringReader.
>
> Regards,
> Colin
>
> On 7/12/06, William Surowiec <wsurowiec at gmail.com> wrote:
> > Dumb question: is there any magic to loading templates from a file under
>
> > windows? I have moved the template file to almost all of the usual
> suspect
> > locations (but not, obviously, the right one.) I have tried the root of
> the
> > hard drive, the root of the application (where the application is able
> to
> > find other files), down where the source code lives - all to no avail.
> >
> > The error message  does not complain about finding the file, but loading
> the
> > first template from within the file. At the risk of boring people, here
> is
> > the contents for the template file (two templates are contained within
> the
> > one file):
> >
> > group updates;
> >
> > update (site,auditLogin,auditPassword,customerId,d) ::= <<
> >
> > <easyAccess dateformat="MM/dd/yyyy">
> >   <getSite name="$site$">
> >    <getCustomer login="$auditLogin$" password="$auditPassword$"
> > ip="{null}"><getID result="audituserid"/></getCustomer>
> >    <getUser id="{audituserid}" result="audituser"/>
> >   </getSite>
> >   <startTransaction audituser="{audituser}">
> >     <getSite name="$site$">
> >       <getUser id="$customerId$">
> >       $if(d)$
> >         <getDemographics result="demographics">
> >           $d:changeDemographics()$
> >         <setDemographics props="{demographics}"/>
> >             $endif$
> >        </getUser>
> >     </getSite>
> >     <rollback/>
> >   </startTransaction>
> > </easyAccess>
> >
> > >>
> >
> > changeDemographics (name,value) :: <<
> > <setproperty properties="{demographics}" propname="$name$"
> > propvalue="$value$"/>
> >
> > >>
> >
> >
> > and here is the offending code:
> >
> >         group = new StringTemplateGroup(templateFileName);
> >         stUpdates = group.getInstanceOf("update");
> >
> > The error message says it cannot find update.st .
> >
> > I am using the stringtemplate-2.3b7 jar and the antlr-2.7.6 jar.
> >
> > I am stuck, willing to consider sacrificing a chicken or a virgin, but I
> > live in New York City where one is frowned upon and the other difficult.
>
> >
> > Bill
> >
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060712/8b8d63b3/attachment.html


More information about the stringtemplate-interest mailing list