T5: Email-Component to send me current web page

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

T5: Email-Component to send me current web page

Michael Capper
Hi,

I was wondering how to properly write a component for our site, which is supposed to appear on any page, and enables the user to mail the current content of the page he is viewing.

We've got our MailService up and running. Now I've been trying two ways of getting to the HTML source of the last page's source.
One being by javascript, submitting all the current content when clicking on the email-icon. Is supposed to capture the current state of our site, which can be changed a bit by javascript while using it (Dragging a series of images around etc). It also tries to embedd the current images and cut the hrefs out, which seems to work alright in FF, not IE.

The other is by an Action-Link on the email-icon, the onAction method then fiddles around with the Request and lets a Handler render the request into a ResponseWrapper (exposing the byte[] of the Response). This also gives me the HTML source, and would be usable per se, but it throws an Exception when popping an environment.

From what I've read, it's difficult to more or less properly style the html in an email, as if Safari/FF/IE weren't hell enough... I am thinking about copying all the .css-data into the header of the html-part of the mail.

The Images i either want to embed in the html, or with the multipart/inline mime type. Well, it barely works, but it is still ugly.

Any recommondations on this topic for me?

Thanks for your time,
Michael
Reply | Threaded
Open this post in threaded view
|

Re: T5: Email-Component to send me current web page

Michael Capper
Michael Capper wrote
The other is by an Action-Link on the email-icon, the onAction method then fiddles around with the Request and lets a Handler render the request into a ResponseWrapper (exposing the byte[] of the Response). This also gives me the HTML source, and would be usable per se, but it throws an Exception when popping an environment.

The exception is:


09-09-04 14:46:48,597 [ERROR] org.apache.tapestry5.services.TapestryModule.RequestExceptionHandler (DefaultRequestExceptionHandler:62) Processing of request failed with uncaught exception: java.util.NoSuchElementException
java.util.NoSuchElementException
        at java.util.LinkedList.remove(LinkedList.java:788)
        at java.util.LinkedList.removeFirst(LinkedList.java:134)
        at org.apache.tapestry5.internal.services.EnvironmentImpl.pop(EnvironmentImpl.java:91)
        at $Environment_123850a00de.pop($Environment_123850a00de.java)
        at $Environment_123850a0068.pop($Environment_123850a0068.java)
        at $ComponentRequestHandler_123850a0096.handleComponentEvent($ComponentRequestHandler_123850a0096.java)
...snip
        at de.avetana.patientenakte.services.AppModule$1.service(AppModule.java:107)


We can continue normally as long as we don't make this exception visible, but still, obviously something is wrong. The action handler which messes around with the PageRenderRequestHandler is:

        @Inject
        private TypeCoercer typeCoercer;

        @InjectPage
        private EmailPostPage emailPostPage;

        //Inject more...

        @OnEvent(component = "prepareEmail")
        public EmailPostPage onPrepareEmail()
        {
                Request request = requestGlobals.getRequest();
                Response response = requestGlobals.getResponse();
                String encoding = requestGlobals.getHTTPServletRequest().getCharacterEncoding();
                ResponseWrapper responseWrapper = new ResponseWrapper(response,
                        encoding); //implements Response, exposes content
                requestGlobals.storeRequestResponse(request, responseWrapper);

                Component page = componentResources.getPage();
                Object data = new Object(); //try to get the context by reflection
                try
                {
                        Method onpassivate = page.getClass().getMethod("onPassivate");
                        data = onpassivate.invoke(page);
                }
                catch (NoSuchMethodException e1)
                {
                        Debug.debug("OK, no activation context.");
                }
                catch (Exception e) //shortened for mailinglist
                {
                        e.printStackTrace();
                }

                PageRenderRequestParameters parameters = new PageRenderRequestParameters(
                        componentResources.getPageName(), new ArrayEventContext(
                                typeCoercer, data));
                try
                {
                        pageRenderRequestHandler.handle(parameters);
                        requestGlobals.storeRequestResponse(request, response);
                }
                catch (IOException e)
                {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                currentASO.setEmailContentRaw(responseWrapper.getContent());
                emailForwardPage.setRawContent(responseWrapper.getContent());
                emailPostPage.setData(responseWrapper.getContent());
                return emailPostPage;
        }