cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gelo1234 <gelo1...@gmail.com>
Subject Re: [C3] Sting template, passing argument to method
Date Fri, 05 Oct 2012 09:05:26 GMT
Andre,

In my opinion, if you are dealing with XML data, you should turn your eyes
into XSL[T] instead of ST.

Greetings,
Greg

2012/10/5 André Juffer <andre.juffer@oulu.fi>

> On 10/05/2012 09:30 AM, Francesco Chicchiriccò wrote:
>
>> On 04/10/2012 08:53, André Juffer wrote:
>>
>>> Hello,
>>>
>>> I am dealing with the following problem. A REST resource returns an
>>> (DTO) object called statistics (of type Statistics) holding various
>>> properties. With string template, each property can be inserted into
>>> an XML file, like
>>>
>>> <A>$statistics.propertyA$</A>
>>>
>>> where the corresponding method on the Statistics object is
>>> getPropertyA().
>>>
>>> One of the properties requires an argument of type String, where the
>>> actual method signature is getNumberFor(String name). It returns an
>>> int. The name is obtained from a list of names obtained from the
>>> statistics objects as well. The idea is to iterate through the list of
>>> names and return a number (int) for each name.
>>>
>>> Thus, the XML code that I try to complete looks like:
>>> <socials>
>>>    $statistics.names: { name |
>>>      <social>
>>>        <name>$name$</name>
>>>        <number>$statistics.numberFor(**name)$</tribc:number>
>>>      </social>
>>>    }$
>>> </socials>
>>>
>>> The Statistics object holds among other things a Map<String, Integer>
>>> with the requested numbers.
>>>
>>> The line $statistics.numberFor(name)$ is however erroneous. I cannot
>>> pass the current value of name to the method in question.
>>>
>>> My question is now: How to pass a argument to a given method on an
>>> object using string template. The string template website did not give
>>> a clear answer, so maybe it is not even possible, or maybe I just
>>> completely overlooked it.
>>>
>>> Any help is appreciated.
>>>
>>
>> Hi André.
>> I am not an ST expert at all, but I really think there is no support for
>> generic method invocation on ST expressions: the only methods supported
>> seem to ne related to properties, "à la JavaBean".
>>
>
> Yeah, that's what I thought.
>
>
>
>> For your use case, I'd change a bit the application logic by providing a
>> C3 REST controller that would act as a "data conversion proxy" between
>> the sitemap and the actual REST resource you are currently dealing with.
>> In this way you could query the external REST resource from the C3 REST
>> controller body and prepare the data in a format that's suitable for ST.
>>
>
> OK, I'll have a look at this. Alternatively, I may simply add a method to
> the DTO that returns an XML representation of the DTO. With ST, one would
> use then $statistics.asXml$ or something, but it appears that all > and <
> symbols are replaced with &lt; and &gt; which is not what I want of course.
>
> Thanks,
> Andre
>
>
>> Regards.
>>
>>
>
> --
> Andre H. Juffer              | Phone: +358-8-553 1161
> Biocenter Oulu and           | Fax: +358-8-553-1141
> Department of Biochemistry   | Email: andre.juffer@oulu.fi
> University of Oulu, Finland  | WWW: www.biochem.oulu.fi/**Biocomputing/<http://www.biochem.oulu.fi/Biocomputing/>
> StruBioCat                   | WWW: www.strubiocat.oulu.fi
> Triacle Biocomputing         | WWW: www.triacle-bc.com
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.**apache.org<users-unsubscribe@cocoon.apache.org>
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Mime
View raw message