Re: [C3] Sting template, passing argument to method

2012-10-05 Thread Francesco Chicchiriccò
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 MapString, 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.

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.

Regards.

-- 
Francesco Chicchiriccò

ASF Member, Apache Cocoon PMC and Apache Syncope PPMC Member
http://people.apache.org/~ilgrosso/


-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org



Re: [C3] Sting template, passing argument to method

2012-10-05 Thread André Juffer

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 MapString, 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.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat   | WWW: www.strubiocat.oulu.fi
Triacle Biocomputing | WWW: www.triacle-bc.com

-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org



Re: [C3] Sting template, passing argument to method

2012-10-05 Thread gelo1234
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.juf...@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 MapString, 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.juf...@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.orgusers-unsubscr...@cocoon.apache.org
 For additional commands, e-mail: users-h...@cocoon.apache.org




Re: [C3] Sting template, passing argument to method

2012-10-05 Thread Francesco Chicchiriccò
On 05/10/2012 10:59, gelo1234 wrote:

 Is there any reasonable benefit from using ST in transform layer ? I
 tend to believe that C2/C3 authors overly favor ST templates in the
 whole C architecture. Does it stem from the mere fact that ST is
 deadly simple/fast to compute (transform data) while being very
 general-purpose ? Or is there any other reason ? In my opinion ST is
 pretty exotic, i mean it is neither any valid standard, nor seen in
 any favorable (Java EE) technology stack.

 As this case shows, its not a valid engine for general-purpose problems.
 Im not giving here the alternatives yet, because i would like to hear
 first the reasons behind choosing ST as a preferable template engine
 in C2/C3.

AFAIK, ST is not preferred, it's barely the only one available so far
in C3.

And I don't remember ST to be available at all in C2.1 and C2.2.
C2.1 and C.2.2 have instead a wider range of supported template engines,
including JX (my favorite) [1] [2].

If you'd like to port JX (or any other templating engine) to C3, your
contribution is more than welcome.

Best regards.

[1] http://cocoon.apache.org/2.2/blocks/template/1.0/976_1_1.html
[2] http://cocoon.apache.org/2.2/blocks/template/1.0/1012_1_1.html

 2012/10/5 Francesco Chicchiriccò ilgro...@apache.org
 mailto:ilgro...@apache.org

 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 MapString,
 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.

 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.

 Regards.

-- 
Francesco Chicchiriccò

ASF Member, Apache Cocoon PMC and Apache Syncope PPMC Member
http://people.apache.org/~ilgrosso/



Re: [C3] Sting template, passing argument to method

2012-10-05 Thread André Juffer
I got this problem solved. As the DTO holds the requested information as 
a Map, I added one method that returns a SetMap.EntryString, String.


With ST it is easy to iterate:

tribc:socials
 $statistics.socialEventParticipation: { entry |
   tribc:social
 tribc:name$entry.key$/tribc:name
 tribc:number$entry.value$/tribc:number
   /tribc:social
 }$
/tribc:socials


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 MapString, 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.

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.

Regards.




--
Andre H. Juffer  | Phone: +358-8-553 1161
Biocenter Oulu and   | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat   | WWW: www.strubiocat.oulu.fi
Triacle Biocomputing | WWW: www.triacle-bc.com

-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org



Re: [C3] Sting template, passing argument to method

2012-10-05 Thread André Juffer

On 10/05/2012 12:05 PM, gelo1234 wrote:


Andre,

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


I use ST to create the initial XML from a DTO returned by a REST 
resource ('EventResource'), like


...
MapString, Object map = new HashMapString, Object();
EventStatisticsDTO dto = eventFacade_.getStatistics(eventId);
map.put(statistics, dto);
return URLResponseBuilder.newInstance(
servlet:tribc-evt:/event-statistics. + format, map
).build();


The tribc-evt:/event-statistics calls upon the sitemap.
Depending on 'format' (either 'xml' or 'json'), I leave the XML as it 
is, or I transform the XML to JSON using XSL.


Best,
André




Greetings,
Greg

2012/10/5 André Juffer andre.juf...@oulu.fi mailto:andre.juf...@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 MapString,
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
tel:%2B358-8-553%201161
Biocenter Oulu and   | Fax: +358-8-553-1141
tel:%2B358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
mailto:andre.juf...@oulu.fi
University of Oulu, Finland  | WWW:
www.biochem.oulu.fi/__Biocomputing/
http://www.biochem.oulu.fi/Biocomputing/
StruBioCat   | WWW: www.strubiocat.oulu.fi
http://www.strubiocat.oulu.fi
Triacle Biocomputing | WWW: www.triacle-bc.com
http://www.triacle-bc.com

--__--__-
To unsubscribe, e-mail: users-unsubscribe@cocoon.__apache.org
mailto:users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org
mailto:users-h...@cocoon.apache.org





--
Andre H. Juffer  | Phone: +358-8-553 1161
Biocenter Oulu and   | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: 

RE: [C3] Sting template, passing argument to method

2012-10-05 Thread Robby Pelssers
Lol... you beat me to giving the solution.  It's indeed dead simple.  And 
Franscesco is right about ST only supporting javabeans style access.  I had a 
similar issue in the past passing javascript objects from flowscript to 
jxtemplate generator.

So I ended up extending the native JS Object with some methods like values() 
and keys() which are iterable.  And of course a Map has the same methods 
enabling you to get an enumerable of keys/ values or entries.

http://robbypelssers.blogspot.nl/2010/10/creating-higher-order-functions-in.html


Robby
-Original Message-
From: André Juffer [mailto:andre.juf...@oulu.fi] 
Sent: Friday, October 05, 2012 11:15 AM
To: users@cocoon.apache.org
Subject: Re: [C3] Sting template, passing argument to method

I got this problem solved. As the DTO holds the requested information as a Map, 
I added one method that returns a SetMap.EntryString, String.

With ST it is easy to iterate:

tribc:socials
  $statistics.socialEventParticipation: { entry |
tribc:social
  tribc:name$entry.key$/tribc:name
  tribc:number$entry.value$/tribc:number
/tribc:social
  }$
/tribc:socials


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 MapString, 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.

 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.

 Regards.



-- 
Andre H. Juffer  | Phone: +358-8-553 1161
Biocenter Oulu and   | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat   | WWW: www.strubiocat.oulu.fi
Triacle Biocomputing | WWW: www.triacle-bc.com

-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org



[C3] Sting template, passing argument to method

2012-10-04 Thread André Juffer

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 MapString, 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.

--
Andre H. Juffer  | Phone: +358-8-553 1161
Biocenter Oulu and   | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat   | WWW: www.strubiocat.oulu.fi
Triacle Biocomputing | WWW: www.triacle-bc.com

-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org