You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Graeme Knight <gr...@gmail.com> on 2008/12/09 04:05:35 UTC

IMG SRC URL in iframe - part 2.

Hi.

I recently had a question which I put to the forum here:

http://www.nabble.com/IMG-SRC-URL-in-iframe.-td20805408.html Generating IMG
SRC to replace CIDs. 

I believe I have found the answer (thanks to Ernesto's help) which I would
like some verification of if possible (not sure if it needs a wiki page):

Here's the solution:

1) In my application I create a new shared resource:

    @Override
    protected void init()
    {
        getSharedResources().add( "cidImageResource", new CIDImageResource()
);
        mountSharedResource( "/imageStuff", "cidImageResource" );
    }

2) My CIDImageResource class is a subclass of DynamicImageResource.

    It has a single important implementation of a method in it: byte[]
getImageData().

    This method will be passed a filename as a parameter. This filename is
the image file we wish to render and is known by its attachment on 
url-to-cid-image-resource?filename=image.png . Note that 'image.png' is the
name of a file that has previously been serialized onto the file system and
replaces the CID in the HTML email that we are rendering.

3) There is a magic class that I have that loads the HTML email data from
the filesystem and parses out the CIDs, replacing the
SRC="CID:sdkfhsakhfskdfh13213123" with the correct URL to the correct file.
This URL is gotten in the following way:

First we get the following:

            ResourceReference ref = new ResourceReference(
"cidImageResource" );

            RequestCycle requestCycle = getRequestCycle();

We then loop around all our known CID references in the HTML email and call
the following:

           String contentFileName = UserDefaults.resolveUserHomePath(
userName ) + uploadData.getUploadFileName();

           ValueMap parameters = new ValueMap();
           parameters.put( "filename", contentFileName );

          String link = requestCycle.urlFor( resourceReference, parameters
).toString();

Once we have the link to the file, we replace the correct "CID:". We do this
numerous times for the entire HTML email.

4) The HTML email is rendered in an iframe.

See my previous post, which I got working, and sets the innerHTML on the
iframe: 
http://www.nabble.com/Populate-IFRAME-innerHTML-on-AJAX-load-of-panel.-td20887803.html
iframe innerHTML post. 

The shared resource (cidImageResource) that I created in the application is
then called repeatedly during rendering of the iframe, and the image byte
data is returned to the browser and rendered correctly in place of the CIDs.

Does this sound about right? I hope this may be useful to someone else if it
is!

All the best, Graeme.
-- 
View this message in context: http://www.nabble.com/IMG-SRC-URL-in-iframe---part-2.-tp20907919p20907919.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: IMG SRC URL in iframe - part 2.

Posted by Graeme Knight <gr...@gmail.com>.
Hi Ernesto,

Certainly the way you suggested makes a lot of sense to me. It is a nice
resource that can just receive the requests and process based resolution of
the SRC attribute - given that the content if the iframe is populated after
the body has been rendered and really Wicket is not doing any processing
from a component point of view. 

Thanks again, Graeme.


reiern70 wrote:
> 
> Hi Graeme,
> Yes more or less... As I said I do no longer  have access to the code I
> wrote (it was for a project on my previous Job)  but as far as I remember
> all I did was:
> 
> 1-mount a resource for servicing files (I suppose I did the same way you
> are
> doing it;-)
> 2-"generate" HTML code asking for those files.
> 
> Maybe part 1) can also be solved by:
> 
> 1- having on the same page containing your HTML a wicket component, maybe
> the same iframe you are using, implementing IResourceListener and, instead
> of having a global resource use, that component to stream back your
> images.
> 2- or using a servlet.
> 
> I really don't know which of these would be the best solution in terms of
> efficiency and use of resources...
> 
> Best,
> 
> Ernesto
> 
> On Tue, Dec 9, 2008 at 3:20 PM, Graeme Knight <gr...@gmail.com>
> wrote:
> 
>>
>> Ernesto - similar to what you did?
>>
>>
>> Graeme Knight wrote:
>> >
>> > Hi.
>> >
>> > I recently had a question which I put to the forum here:
>> >
>> >  http://www.nabble.com/IMG-SRC-URL-in-iframe.-td20805408.html
>> Generating
>> > IMG SRC to replace CIDs.
>> >
>> > I believe I have found the answer (thanks to Ernesto's help) which I
>> would
>> > like some verification of if possible (not sure if it needs a wiki
>> page):
>> >
>> > Here's the solution:
>> >
>> > 1) In my application I create a new shared resource:
>> >
>> >     @Override
>> >     protected void init()
>> >     {
>> >         getSharedResources().add( "cidImageResource", new
>> > CIDImageResource() );
>> >         mountSharedResource( "/imageStuff", "cidImageResource" );
>> >     }
>> >
>> > 2) My CIDImageResource class is a subclass of DynamicImageResource.
>> >
>> >     It has a single important implementation of a method in it: byte[]
>> > getImageData().
>> >
>> >     This method will be passed a filename as a parameter. This filename
>> is
>> > the image file we wish to render and is known by its attachment on
>> > url-to-cid-image-resource?filename=image.png . Note that 'image.png' is
>> > the name of a file that has previously been serialized onto the file
>> > system and replaces the CID in the HTML email that we are rendering.
>> >
>> > 3) There is a magic class that I have that loads the HTML email data
>> from
>> > the filesystem and parses out the CIDs, replacing the
>> > SRC="CID:sdkfhsakhfskdfh13213123" with the correct URL to the correct
>> > file. This URL is gotten in the following way:
>> >
>> > First we get the following:
>> >
>> >             ResourceReference ref = new ResourceReference(
>> > "cidImageResource" );
>> >
>> >             RequestCycle requestCycle = getRequestCycle();
>> >
>> > We then loop around all our known CID references in the HTML email and
>> > call the following:
>> >
>> >            String contentFileName = UserDefaults.resolveUserHomePath(
>> > userName ) + uploadData.getUploadFileName();
>> >
>> >            ValueMap parameters = new ValueMap();
>> >            parameters.put( "filename", contentFileName );
>> >
>> >           String link = requestCycle.urlFor( resourceReference,
>> parameters
>> > ).toString();
>> >
>> > Once we have the link to the file, we replace the correct "CID:". We do
>> > this numerous times for the entire HTML email.
>> >
>> > 4) The HTML email is rendered in an iframe.
>> >
>> > See my previous post, which I got working, and sets the innerHTML on
>> the
>> > iframe:
>> >
>> http://www.nabble.com/Populate-IFRAME-innerHTML-on-AJAX-load-of-panel.-td20887803.html
>> > iframe innerHTML post.
>> >
>> > The shared resource (cidImageResource) that I created in the
>> application
>> > is then called repeatedly during rendering of the iframe, and the image
>> > byte data is returned to the browser and rendered correctly in place of
>> > the CIDs.
>> >
>> > Does this sound about right? I hope this may be useful to someone else
>> if
>> > it is!
>> >
>> > All the best, Graeme.
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/IMG-SRC-URL-in-iframe---part-2.-tp20907919p20915492.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/IMG-SRC-URL-in-iframe---part-2.-tp20907919p20920083.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: IMG SRC URL in iframe - part 2.

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi Graeme,
Yes more or less... As I said I do no longer  have access to the code I
wrote (it was for a project on my previous Job)  but as far as I remember
all I did was:

1-mount a resource for servicing files (I suppose I did the same way you are
doing it;-)
2-"generate" HTML code asking for those files.

Maybe part 1) can also be solved by:

1- having on the same page containing your HTML a wicket component, maybe
the same iframe you are using, implementing IResourceListener and, instead
of having a global resource use, that component to stream back your images.
2- or using a servlet.

I really don't know which of these would be the best solution in terms of
efficiency and use of resources...

Best,

Ernesto

On Tue, Dec 9, 2008 at 3:20 PM, Graeme Knight <gr...@gmail.com> wrote:

>
> Ernesto - similar to what you did?
>
>
> Graeme Knight wrote:
> >
> > Hi.
> >
> > I recently had a question which I put to the forum here:
> >
> >  http://www.nabble.com/IMG-SRC-URL-in-iframe.-td20805408.html Generating
> > IMG SRC to replace CIDs.
> >
> > I believe I have found the answer (thanks to Ernesto's help) which I
> would
> > like some verification of if possible (not sure if it needs a wiki page):
> >
> > Here's the solution:
> >
> > 1) In my application I create a new shared resource:
> >
> >     @Override
> >     protected void init()
> >     {
> >         getSharedResources().add( "cidImageResource", new
> > CIDImageResource() );
> >         mountSharedResource( "/imageStuff", "cidImageResource" );
> >     }
> >
> > 2) My CIDImageResource class is a subclass of DynamicImageResource.
> >
> >     It has a single important implementation of a method in it: byte[]
> > getImageData().
> >
> >     This method will be passed a filename as a parameter. This filename
> is
> > the image file we wish to render and is known by its attachment on
> > url-to-cid-image-resource?filename=image.png . Note that 'image.png' is
> > the name of a file that has previously been serialized onto the file
> > system and replaces the CID in the HTML email that we are rendering.
> >
> > 3) There is a magic class that I have that loads the HTML email data from
> > the filesystem and parses out the CIDs, replacing the
> > SRC="CID:sdkfhsakhfskdfh13213123" with the correct URL to the correct
> > file. This URL is gotten in the following way:
> >
> > First we get the following:
> >
> >             ResourceReference ref = new ResourceReference(
> > "cidImageResource" );
> >
> >             RequestCycle requestCycle = getRequestCycle();
> >
> > We then loop around all our known CID references in the HTML email and
> > call the following:
> >
> >            String contentFileName = UserDefaults.resolveUserHomePath(
> > userName ) + uploadData.getUploadFileName();
> >
> >            ValueMap parameters = new ValueMap();
> >            parameters.put( "filename", contentFileName );
> >
> >           String link = requestCycle.urlFor( resourceReference,
> parameters
> > ).toString();
> >
> > Once we have the link to the file, we replace the correct "CID:". We do
> > this numerous times for the entire HTML email.
> >
> > 4) The HTML email is rendered in an iframe.
> >
> > See my previous post, which I got working, and sets the innerHTML on the
> > iframe:
> >
> http://www.nabble.com/Populate-IFRAME-innerHTML-on-AJAX-load-of-panel.-td20887803.html
> > iframe innerHTML post.
> >
> > The shared resource (cidImageResource) that I created in the application
> > is then called repeatedly during rendering of the iframe, and the image
> > byte data is returned to the browser and rendered correctly in place of
> > the CIDs.
> >
> > Does this sound about right? I hope this may be useful to someone else if
> > it is!
> >
> > All the best, Graeme.
> >
>
> --
> View this message in context:
> http://www.nabble.com/IMG-SRC-URL-in-iframe---part-2.-tp20907919p20915492.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: IMG SRC URL in iframe - part 2.

Posted by Graeme Knight <gr...@gmail.com>.
Ernesto - similar to what you did?


Graeme Knight wrote:
> 
> Hi.
> 
> I recently had a question which I put to the forum here:
> 
>  http://www.nabble.com/IMG-SRC-URL-in-iframe.-td20805408.html Generating
> IMG SRC to replace CIDs. 
> 
> I believe I have found the answer (thanks to Ernesto's help) which I would
> like some verification of if possible (not sure if it needs a wiki page):
> 
> Here's the solution:
> 
> 1) In my application I create a new shared resource:
> 
>     @Override
>     protected void init()
>     {
>         getSharedResources().add( "cidImageResource", new
> CIDImageResource() );
>         mountSharedResource( "/imageStuff", "cidImageResource" );
>     }
> 
> 2) My CIDImageResource class is a subclass of DynamicImageResource.
> 
>     It has a single important implementation of a method in it: byte[]
> getImageData().
> 
>     This method will be passed a filename as a parameter. This filename is
> the image file we wish to render and is known by its attachment on 
> url-to-cid-image-resource?filename=image.png . Note that 'image.png' is
> the name of a file that has previously been serialized onto the file
> system and replaces the CID in the HTML email that we are rendering.
> 
> 3) There is a magic class that I have that loads the HTML email data from
> the filesystem and parses out the CIDs, replacing the
> SRC="CID:sdkfhsakhfskdfh13213123" with the correct URL to the correct
> file. This URL is gotten in the following way:
> 
> First we get the following:
> 
>             ResourceReference ref = new ResourceReference(
> "cidImageResource" );
> 
>             RequestCycle requestCycle = getRequestCycle();
> 
> We then loop around all our known CID references in the HTML email and
> call the following:
> 
>            String contentFileName = UserDefaults.resolveUserHomePath(
> userName ) + uploadData.getUploadFileName();
> 
>            ValueMap parameters = new ValueMap();
>            parameters.put( "filename", contentFileName );
> 
>           String link = requestCycle.urlFor( resourceReference, parameters
> ).toString();
> 
> Once we have the link to the file, we replace the correct "CID:". We do
> this numerous times for the entire HTML email.
> 
> 4) The HTML email is rendered in an iframe.
> 
> See my previous post, which I got working, and sets the innerHTML on the
> iframe: 
> http://www.nabble.com/Populate-IFRAME-innerHTML-on-AJAX-load-of-panel.-td20887803.html
> iframe innerHTML post. 
> 
> The shared resource (cidImageResource) that I created in the application
> is then called repeatedly during rendering of the iframe, and the image
> byte data is returned to the browser and rendered correctly in place of
> the CIDs.
> 
> Does this sound about right? I hope this may be useful to someone else if
> it is!
> 
> All the best, Graeme.
> 

-- 
View this message in context: http://www.nabble.com/IMG-SRC-URL-in-iframe---part-2.-tp20907919p20915492.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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