Re: Parsing of numeric values

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Tuesday, September 15, 2009, 11:45:54 PM, wkbutler wrote:

> Daniel Dekany wrote:
>> 
>> Tuesday, September 15, 2009, 3:46:17 PM, wkbutler wrote:
>> I don't know... it's not enough concrete for me to form an opinion.
>> The part that is a bit suspicious for me, that if the numerical output
>> generated by the 1st order macros meant to be treated as numbers by
>> the 2nd order macros, then why are they in human-audience format? I
>> mean, FM can output in computer-audience numerical format as well.
>> 
>
> Good question - consider the case of subtotals and grand totals. Grand
> totals operate on subtotals, subtotals operate on 'raw' data. Both are
> products for the user.  You allude to another possible solution though,
> which is to store both formats; I would rather avoid that, but it may be the
> easiest approach.

In principle you don't generate the grand totals from the formatted
output of the subtotals. You just generate them from the
presentation-independent data that represents the subtotals.
Extracting data from formatted output is quite difficult in general
(since that output is optimized for human brains, not for computer
programs), and thus avoided whenever possible.

Of course, building presentation-independent data structures is not
something FM is often used for, since it generates text, not Java
objects and like. But, there are some exceptions, when FM generates
XML or JSON, which are not about presentation but describing
structured "data", and still are text.

> Daniel Dekany wrote:
>> 
>>> Do I need to revert my dataset to a Map<String, Object>, or is there
>>> another
>>> way to inject custom utilities?
>> 
>> There is a way (as far as using a global variable instead of
>> data-model variable is fine for you). Use something like this instead
>> of the myTemplate.process(root, out) call:
>> 
>>   Environment env = myTemplate.createProcessingEnvironment(root, out);
>>   env.setGlobalVariable("util",
>>       env.getObjectWrapper().wrap(new DataUtil()));
>>   env.process();
>> 
>
> Perfect - I will try that. Thank you -

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.