<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3603" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Hi Mohamed,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>actually it is the philosophy of StringTemplate that
templates don't do calculations other than what is needed for display. So I
fear it is not the right tool for your task, since you require something which
builds a page model (all data displayed on the generated page) from your
business model (all data the application provides) and something which generates
a visible page from the page model.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>StringTemplate only performs the latter job. If you want to
use ST anyway you need to build something which takes some userdefined
rules/calculations and generates a page model out of the business
model.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>If you prefer a very dirty hack: create an object
like:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>class Calculator implements Map { public String get(String
expr) { return eval(expr); } /* implement dummies for the other operations
*/ }</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Add a calculator to your page model:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>st.setAttribute("calc",new
Calculator());</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Use the calculator in your template:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>$calc.({$a$+$b$})$</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Just to make clear: this is a very very dirty hack and
violates the StringTemplate philosophy in ways which could bring the wrath of
the god(s) of model/view-separation upon you or me and may or may not turn the
one who actually implements the above into an appropriate heap of
dust.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Also Terence might not invite you to dinner
anymore...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Regards,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2>Ron</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=375261409-03082009><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left>
<HR tabIndex=-1>
</DIV>
<DIV dir=ltr align=left><FONT face=Tahoma size=2><B>From:</B>
stringtemplate-interest-bounces@antlr.org
[mailto:stringtemplate-interest-bounces@antlr.org] <B>On Behalf Of </B>Mohamed
Mansour<BR><B>Sent:</B> Friday, July 31, 2009 8:27 PM<BR><B>To:</B> Jim
Idle<BR><B>Cc:</B> stringtemplate-interest@antlr.org<BR><B>Subject:</B> Re:
[stringtemplate-interest] How to use variables inside
formatmodifiers<BR></FONT><BR></DIV>
<DIV></DIV>Hmm, that would be unfortunate. I can't use this kind of approach
then. I am trying to create a generic "Report" where every user can do whatever
they want with it. If they wanted to add 10 to the result to any variable, they
could. But we can't do that with StringTemplate.
<DIV><BR></DIV>
<DIV>I guess that is the limitation of StringTemplate.</DIV>
<DIV><BR></DIV>
<DIV>Isn't there any way I can make it work, like a hack? A user can modify a
variable by appending(adding) a number to it. (simply scenario)</DIV>
<DIV><BR></DIV>
<DIV>Thanks,</DIV>
<DIV><BR></DIV>
<DIV>-- Mohamed Mansour<BR><BR><BR>
<DIV class=gmail_quote>On Fri, Jul 31, 2009 at 2:16 PM, Jim Idle <SPAN
dir=ltr><<A
href="mailto:jimi@temporal-wave.com">jimi@temporal-wave.com</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV text="#000000" bgcolor="#ffffff">
<DIV>
<DIV></DIV>
<DIV class=h5>Mohamed Mansour wrote:
<BLOCKQUOTE type="cite">
<DIV class=gmail_quote>Hello,
<DIV><BR></DIV>
<DIV>I have been using StringTemplate to produce stylized report
files. Some variables need to be formatted someway, for example if I
want to uppercase a variable I do, therefore I setup an attribute
renderer:</DIV>
<DIV><FONT
face="'courier new', monospace">$foo;format="uppercase"$</FONT></DIV>
<DIV><BR></DIV>
<DIV>In my specific case I would need to apply more than one formatter (more
than one attribute renderer for a variable), so I created many attribute
renders and I can process them like:</DIV>
<DIV><FONT
face="'courier new', monospace">$foo;format="uppercase|fixedlength:10:x:R|lowercase"$</FONT>
If you notice a modifer could have parameters ( with colons as seen with
fixedlength)</DIV>
<DIV><BR></DIV>
<DIV>So if $foo is "123aBc" it will return "XXXX123abc", the above works
perfectly fine</DIV>
<DIV><BR></DIV>
<DIV>My main problem is that, some parameters in my format modifiers need to
be ST variables, for example, I would need to add a number:</DIV>
<DIV><FONT
face="'courier new', monospace">$numA;format="calculate:+:$numB$"$</FONT></DIV>
<DIV><BR></DIV>
<DIV>If numA = 10, and numB = 5, the formatter will return15. But my problem
is that, it treats the variables as a string doesn't actually give me the
exact value of the variable.</DIV>
<DIV><BR></DIV>
<DIV>How can I pass variables in the "format"
area?</DIV></DIV></BLOCKQUOTE></DIV></DIV>Calculations need to be performed
before setting the values in the templates otherwise you are breaking the
model/view separation that StringTemplate is as strict about as it can be. In
other words you should not be trying to do this.<BR><BR>The attribute renderer
while powerful, has to be used carefully so that you do not break this
separation as it is kind of a back door (the only way to close it would be to
implement a generic formatting engine and get rid of attribute renderers, but
that is a lot of code bloat of
course.<BR><BR>Jim<BR></DIV><BR>_______________________________________________<BR>stringtemplate-interest
mailing list<BR><A
href="mailto:stringtemplate-interest@antlr.org">stringtemplate-interest@antlr.org</A><BR><A
href="http://www.antlr.org/mailman/listinfo/stringtemplate-interest"
target=_blank>http://www.antlr.org/mailman/listinfo/stringtemplate-interest</A><BR><BR></BLOCKQUOTE></DIV><BR></DIV>
<hr><FONT face="Arial" size="-2">WINCOR NIXDORF International GmbH <br>
Sitz der Gesellschaft: Paderborn <br>
Registergericht Paderborn HRB 3507<br>
Geschäftsführer: Eckard Heidloff (Vorsitzender), Stefan Auerbach, Dr. Jürgen Wunram<br>
Vorsitzender des Aufsichtsrats: Karl-Heinz Stiller <br>
Steuernummer: 339/5884/0020 - Ust-ID Nr.: DE812927716 - WEEE-Reg.-Nr. DE44477193<br>
<br>
Diese E-Mail enthält vertrauliche Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.<br>
<br>
This e-mail may contain confidential information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. <br>
</FONT>
</BODY></HTML>