I did some research on something similar for my Buccoo project.
Although I haven't blogged about it yet, my method it may be of some
use to you.

For Buccoo I wanted all the dynamic Tapestry output to be well formed
XML. It is my understanding that components add their own HTML code at
different stages (like links to stylesheets and javascript for the
form validation) that I can't directly modify (or really want to). To
get the final output in XML no matter what, I had to decorate the page
response in the AppModule, render the page and then convert it to the
output I wanted.

You could stop at the render page part and stream the output to the
text file you wanted.

I'm filtering the pages I want converted using the content type, but
you can use the page name etc. You would not need the TagsoupService I
injected in my code below.

You may also want to look at Tapestry 5's source for the
PageResponseRenderer's renderPageResponse method.

    public static PageResponseRenderer decoratePageResponseRenderer(
        @InjectService("PageMarkupRenderer") final PageMarkupRenderer
markupRenderer,
        @InjectService("MarkupWriterFactory") final
MarkupWriterFactory markupWriterFactory,
        @InjectService("MetaDataLocator") final MetaDataLocator metaDataLocator,
        @InjectService("TagsoupService") final TagsoupService tagsoupService,
        final Object delegate)
    {
        return new PageResponseRenderer()
        {
            public void renderPageResponse(Page page, Response
response) throws IOException
            {
                ComponentResources pageResources =
page.getRootComponent().getComponentResources();

                String contentTypeString =
metaDataLocator.findMeta(TapestryConstants.RESPONSE_CONTENT_TYPE,

pageResources);
                ContentType contentType = new ContentType(contentTypeString);

                // Make sure there's always a charset specified.

                String encoding = contentType.getParameter(CHARSET);
                if (encoding == null)
                {
                  encoding =
metaDataLocator.findMeta(TapestryConstants.RESPONSE_ENCODING,
pageResources);
                  contentType.setParameter(CHARSET, encoding);
                }

                MarkupWriter writer = markupWriterFactory.newMarkupWriter();
                markupRenderer.renderPageMarkup(page, writer);

                String finalContentType = contentType.toString();
                finalContentType =
finalContentType.replace("application/xhtml+xml", "text/html");

                PrintWriter pw = response.getPrintWriter(finalContentType);


                if (contentTypeString.equals("application/xhtml+xml")) {
                  StringWriter sw = new StringWriter();
                  PrintWriter spw = new PrintWriter(sw);
                  writer.toMarkup(spw);
                  spw.flush();
                  spw.close();
                  pw.print(tagsoupService.asXML(sw.toString()));
                } else if (contentTypeString.equals("text/xml")) {
                  StringWriter sw = new StringWriter();
                  PrintWriter spw = new PrintWriter(sw);
                  writer.toMarkup(spw);
                  spw.flush();
                  spw.close();
                  pw.print("<?xml version=\"1.0\" encoding=\"UTF-8\"
?>\r\n" + sw.toString());
                } else {
                  writer.toMarkup(pw);
                }
                pw.flush();
            }
        };
    }


On Dec 3, 2007 2:11 PM, Josh Canfield <[EMAIL PROTECTED]> wrote:
> I've done something like what you are asking in order to generate email
> messages. It's not pretty, and not well supported but it can be done...
>
> Here is the guts of the process:
>
> protected String getHtml(String page, String[] context, EmailContext
> emailContext) {
>         Request request = _requestGlobals.getRequest();
>         Response response = _requestGlobals.getResponse();
>         // response wrapper stores everything written into a buffer
>         EmailResponse emailResponse = new
> EmailResponse(_requestGlobals.getHTTPServletResponse());
>         _requestGlobals.store(request, emailResponse);
>         // email context contains some parameters passed into the rendered
> page
>         request.getSession(true).setAttribute("emailContext", emailContext);
>         // pageRenderRequestHandler clears the environment... remember
> things to put back later (fragile)...
>         Heartbeat heartbeat = _environment.peek(Heartbeat.class);
>         FormSupport formSupport = _environment.peek(FormSupport.class);
>         try {
>             _pageRenderRequestHandler.handle(page, context);
>             return emailResponse.toString();
>         } catch (Exception e) {
>             _log.warn("Failed to send video external " + e.getMessage());
>         } finally {
>             // Hope no other env vars are stored :(
>             _environment.push(Heartbeat.class, heartbeat);
>             _environment.push(FormSupport.class, formSupport);
>
>             // Always restore the response
>             _requestGlobals.store(request, response);
>             request.getSession(true).setAttribute("emailContext", null);
>         }
>         return null;
>     }
> This code is used to generate the html version of all email messages sent by
> thedailytube.com
>
> Hope that helps,
> Josh
>
>
>
>
> On Dec 3, 2007 8:41 AM, patrick whalen <[EMAIL PROTECTED]> wrote:
>
> >
> > Could anyone give me any pointers or directions on how to stream the html
> > output that Tapestry generates out to a text file, which would be stored
> > in
> > a specific directory outside the Tapestry project?
> >
> > I would also like to be able to do the same with assets such as css and
> > javascript files, though this would be less important, and more of a
> > convenience.
> >
> > Any hints and suggestions are appreciated.
> >
> > Thanks much.    patrick
> > --
> > View this message in context:
> > http://www.nabble.com/T5---Stream-source-output-to-text-file-tf4937616.html#a14133292
> > Sent from the Tapestry - User mailing list archive at 
> > Nabble.com<http://nabble.com/>
> > .
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> --
> TheDailyTube.com. Sign up and get the best new videos on the internet
> delivered fresh to your inbox.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to