You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Beat Durrer <bd...@gmail.com> on 2012/04/23 13:46:57 UTC

Re: Make Report PDF

To feed the offtopic-gods:

Anyone ever tried to use a tapestry page with a special fop-template,
which then is fed into FOP?
I guess it would be a nice thing if I were able to capture the page's
output and pipe it into FOP or something. Don't know how, but that
would be cool.

Anyone ever tried that?


Would be cool because I have to add a dynamic PDF output in my project
and reuising XSLT/FOP feels a bit backwards after working with T5 :)


2012/3/21 Lance Java <la...@googlemail.com>:
>> I've just quickly checked the FreeMarker documention about XML
> processing. My impression is that if you have a simpler XML structure and
> output, FreeMarker is a better choice. On the other hand, I'm not sure it
> has support for XPath selectors in the FreeMarker declarative XML
> processing, which is usually the best approach for more complex XML
> structures.
>
> I see reference to using XPath in Freemarker's declaritive approach at the
> bottom of this page
> http://freemarker.sourceforge.net/docs/xgui_declarative_details.htmlalthough
> I can't find any examples
>
> "But in this case don't forge that in XPath expressions (we didn't used any
> in the example) the default XML namespace must be accessed with an explicit
> D: since names without prefix always refer to nodes with no XML namespace
> in XPath. Also note that with the same logic as with imperative XML
> processing, the name of handlers for elements that has no XML namespace is
> N:elementName if (and only if) there is a default XML namespace. However,
> for nodes that are not of type element (such as text nodes), you never use
> the N prefix in the handler name, because those nodes are free of the idea
> of XML namespaces. So for example, the handler for text nodes is always
> just @text."
>
> On Tuesday, 20 March 2012, Thiago H. de Paula Figueiredo <th...@gmail.com>
> wrote:
>> On Tue, 20 Mar 2012 09:28:39 -0300, Lance Java <la...@googlemail.com>
> wrote:
>>
>>>> Actually, XSLT makes sense when the source document is XML already.
>>>
>>> I disagree, both freemarker and XSLT need to parse the XML input into
> some form of DOM object before applying a transformation to it. Do you agree
>>> that XSLT templates are far more verbose than Freemarker templates?
>>
>> No. :) I've just quickly checked the FreeMarker documention about XML
> processing. My impression is that if you have a simpler XML structure and
> output, FreeMarker is a better choice. On the other hand, I'm not sure it
> has support for XPath selectors in the FreeMarker declarative XML
> processing, which is usually the best approach for more complex XML
> structures.
>>
>>>> Sorry, Lance, my flame war detector failed to detect it in this thread.
>>>
>>> Sorry for the inconvenience. :P
>>>
>>> I'm not trying to start a flame war here.
>>
>> I haven't seen any here too, but I just wanted to continue the joke. :)
>>
>>> It just seems that people blindly
>>> often choose XSLT for XML transformations without considering freemarker.
>>
>> Agreed. The more options known, the better the choice.
>>
>>> In this thread, trsvax mentions using JAXB to convert java objects to XML
>>> so that they can be passed to XSLT which parses them into DOM objects.
> Why not just pass the java objects to freemarker and avoid XML all together?
>>
>> I thought the Java to XML part was strange too, unless the declarative
> way is better for the described scenario. Maybe that's the case, as the
> technology used to generate PDF is FO, which is XML-based, but then I'm
> talking about something I barely know . . .
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
>> Owner, Ars Machina Tecnologia da Informação Ltda.
>> http://www.arsmachina.com.br
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Make Report PDF

Posted by Lance Java <la...@googlemail.com>.
I have thought of a way of doing this which only involves a couple of
internal classes.

1. Create a new event response type (lets call is FopPdf)
   public class FopPdf {
      private RenderCommand fopRenderCommand;
      private String fileName;
   }

2. Create a FopPdfComponentEventResultProcessor which does the following:
2a. Use an instance of RenderCommandComponentEventResultProcessor to
convert the RenderCommand to XML (FOP)
2b. Use apache FOP to create the PDF binary and construct a StreamResponse.
2c. Use StreamResponseResultProcessor to push the StreamResponse to the
HTTPResponse

3. In your AppModule, register the FopPdfComponentEventResultProcessor to
handle responses of type FopPdf

4. Return FopPdf from a page's onActivate() or from a component's event
handler method.

Re: Make Report PDF

Posted by "Joost Schouten (mailing lists)" <jo...@jsportal.com>.
I actually added an event handler to my page (could easily be a mixin) that returns the page as a pdf. I did somewhat cheat but it does work nicely. I use a HttpClient to request the same page again (with the sessionid so all session state is correct). From there on you have the exact xhtml you can use to generate your pdf (I use flying saucer) or whatever else you wish to do.

Hope it helps,
Joost


On Apr 23, 2012, at 2:12 PM, Lance Java wrote:

> Funny you should mention this, I actually had a quick try at doing this
> myself but I got a bit stuck... here's what I learned.
> 
> 1. I was trying to use this technique
> http://wiki.apache.org/tapestry/Tapestry5HowToGetAnHTMLStringFromARenderCommandParameterto
> specify a FOP parameter to a Page (or Component) in a tml template.
> 
> 2. From what I can see, there are two ways to return a StreamResponse
> 2a. Return a StreamResponse from the onActivate() method of a page
> 2b. Return a StreamResponse from an event handler method fired by a
> <t:eventlink />
> 
> 3. Unfortunately, you can not use the method suggested in option 1 for
> cases 2a or 2b because tapestry does not initialize or run the page render
> sequence when a StreamResponse is returned in either of these two cases.
> 
> 4. I came to the conclusion that I would probably need to initialize the
> PageRenderQueue myself which would likely involve the use of internal
> tapestry classes.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Make Report PDF

Posted by Lance Java <la...@googlemail.com>.
Funny you should mention this, I actually had a quick try at doing this
myself but I got a bit stuck... here's what I learned.

1. I was trying to use this technique
http://wiki.apache.org/tapestry/Tapestry5HowToGetAnHTMLStringFromARenderCommandParameterto
specify a FOP parameter to a Page (or Component) in a tml template.

2. From what I can see, there are two ways to return a StreamResponse
2a. Return a StreamResponse from the onActivate() method of a page
2b. Return a StreamResponse from an event handler method fired by a
<t:eventlink />

3. Unfortunately, you can not use the method suggested in option 1 for
cases 2a or 2b because tapestry does not initialize or run the page render
sequence when a StreamResponse is returned in either of these two cases.

4. I came to the conclusion that I would probably need to initialize the
PageRenderQueue myself which would likely involve the use of internal
tapestry classes.

Re: Make Report PDF

Posted by Beat Durrer <bd...@gmail.com>.
To answer my own question:

Yes, someone already did write a servlet filter which feeds all the
underlying servlets/filters into FOP and sends a PDF back to the
browser.
All I need to write is a page with FOP tags on it.
freemarker and XSLT can go back standing in the corner now if you ask me :D

http://permalink.gmane.org/gmane.text.xml.fop.user/24097




2012/4/23 Beat Durrer <bd...@gmail.com>:
> To feed the offtopic-gods:
>
> Anyone ever tried to use a tapestry page with a special fop-template,
> which then is fed into FOP?
> I guess it would be a nice thing if I were able to capture the page's
> output and pipe it into FOP or something. Don't know how, but that
> would be cool.
>
> Anyone ever tried that?
>
>
> Would be cool because I have to add a dynamic PDF output in my project
> and reuising XSLT/FOP feels a bit backwards after working with T5 :)
>
>
> 2012/3/21 Lance Java <la...@googlemail.com>:
>>> I've just quickly checked the FreeMarker documention about XML
>> processing. My impression is that if you have a simpler XML structure and
>> output, FreeMarker is a better choice. On the other hand, I'm not sure it
>> has support for XPath selectors in the FreeMarker declarative XML
>> processing, which is usually the best approach for more complex XML
>> structures.
>>
>> I see reference to using XPath in Freemarker's declaritive approach at the
>> bottom of this page
>> http://freemarker.sourceforge.net/docs/xgui_declarative_details.htmlalthough
>> I can't find any examples
>>
>> "But in this case don't forge that in XPath expressions (we didn't used any
>> in the example) the default XML namespace must be accessed with an explicit
>> D: since names without prefix always refer to nodes with no XML namespace
>> in XPath. Also note that with the same logic as with imperative XML
>> processing, the name of handlers for elements that has no XML namespace is
>> N:elementName if (and only if) there is a default XML namespace. However,
>> for nodes that are not of type element (such as text nodes), you never use
>> the N prefix in the handler name, because those nodes are free of the idea
>> of XML namespaces. So for example, the handler for text nodes is always
>> just @text."
>>
>> On Tuesday, 20 March 2012, Thiago H. de Paula Figueiredo <th...@gmail.com>
>> wrote:
>>> On Tue, 20 Mar 2012 09:28:39 -0300, Lance Java <la...@googlemail.com>
>> wrote:
>>>
>>>>> Actually, XSLT makes sense when the source document is XML already.
>>>>
>>>> I disagree, both freemarker and XSLT need to parse the XML input into
>> some form of DOM object before applying a transformation to it. Do you agree
>>>> that XSLT templates are far more verbose than Freemarker templates?
>>>
>>> No. :) I've just quickly checked the FreeMarker documention about XML
>> processing. My impression is that if you have a simpler XML structure and
>> output, FreeMarker is a better choice. On the other hand, I'm not sure it
>> has support for XPath selectors in the FreeMarker declarative XML
>> processing, which is usually the best approach for more complex XML
>> structures.
>>>
>>>>> Sorry, Lance, my flame war detector failed to detect it in this thread.
>>>>
>>>> Sorry for the inconvenience. :P
>>>>
>>>> I'm not trying to start a flame war here.
>>>
>>> I haven't seen any here too, but I just wanted to continue the joke. :)
>>>
>>>> It just seems that people blindly
>>>> often choose XSLT for XML transformations without considering freemarker.
>>>
>>> Agreed. The more options known, the better the choice.
>>>
>>>> In this thread, trsvax mentions using JAXB to convert java objects to XML
>>>> so that they can be passed to XSLT which parses them into DOM objects.
>> Why not just pass the java objects to freemarker and avoid XML all together?
>>>
>>> I thought the Java to XML part was strange too, unless the declarative
>> way is better for the described scenario. Maybe that's the case, as the
>> technology used to generate PDF is FO, which is XML-based, but then I'm
>> talking about something I barely know . . .
>>>
>>> --
>>> Thiago H. de Paula Figueiredo
>>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>>> Owner, Ars Machina Tecnologia da Informação Ltda.
>>> http://www.arsmachina.com.br
>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org