You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by François Meillet <fm...@meillet.com> on 2010/01/27 14:41:05 UTC

images not under the context root directory

Hi Wicketers,

I have a directory, /xxx/images with uploaded images, which is not under the application context root directory.
How can I serve them as static images ?

I tried the StaticImage class I found in the forum (http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
but it doesn't work for me. It just work if the image files are under the context root directory.

Thanks for your help. 

François 




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


Re: images not under the context root directory

Posted by Riyad Kalla <rk...@gmail.com>.
Good call -- going the intercept-and-stream route is great when you cannot
read from a web-addressable folder, but if you can do that, and can avoid
all that server-side processing by using a direct URL and just let the app
server do it's thing, then +1 on that.

Sounds like you got it going that way.

-R

On Fri, Jan 29, 2010 at 1:25 PM, m j <ms...@gmail.com> wrote:

> Well after my question I started researching and changed my upload folder
> to:
>
> String path = WebApplication.get().getServletContext().getRealPath("");
> Folder uploadFolder = new Folder(path+"/uploads");
>
> I can now reference the files via the url (.../uploads/..), so much simpler
> this way... I suppose this is what I was trying to do from the beginning.
>
> Thanks for the help.
>
>
> On Fri, Jan 29, 2010 at 2:51 PM, Matthew J <ms...@gmail.com> wrote:
>
> > Correct, Glassfish would allow this; however, if I can do it
> > programmatically with ease I would rather do this (as installations may
> > change and I would rather not have the static uri). I assumed Wicket had
> > access to all files in the context root (or what I assume is one, which
> > maybe isn't).
> >
> > I am currently trying the code posted below (MountedImageFactory), though
> I
> > need to alter it to work with all files, and its a little bulky.
> >
> > I am not bound to where I upload, is there a way to upload to a Folder
> that
> > wicket would be able to find easily? I currently make an upload Folder:
> > Folder upload = new Folder("uploads"); I upload to it similar to the
> > wicket-examples.
> >
> >
> > On 29-Jan-10, at 2:39 PM, Riyad Kalla wrote:
> >
> >  ot sure how that mounting rule in glassfish works, it might be
> >> relative to your app root, but it seems it should work and just be
> treated
> >> as a normal path -- in the case of the previous fellow I understood his
> >> situation to be that he *had* to host resources out of a system
> directory
> >> that wasn't web-addressable. I believe in your case they are web
> >> addressable
> >> if that glassfis
> >>
> >
> >
>

Re: images not under the context root directory

Posted by Daniele Dellafiore <il...@gmail.com>.
Hi.
I am facing the same problem: user upload images and I want to access
from wicket.
Of course, user resources are not going to stay under the webapp context.
I would prefer also to put this images wherever I want in the file
system, not under the container folder as well.

I have taken some more decisions:
1. user upload in a user subfolder. So I have a main pictures folder
and then pictures/user1, pictures/user2 and so on.
2. I do not want to use an external servlet or ask apache. Maybe there
are good reason to to that, but I can just think at performance
reasons.

Too get images from a custom folder in wicket I found only one way: to
subclass DynamiImagerResource. I override:

protected byte[] getImageData() {}

and there I can access any folder I want on my filesystem with
standard java API.
I would write almost the same code in a custom servlet. But with a
servlet that serve and image if called, say, to:

localhost:9090/myApp/pictures/user1/pic1

would expose an interface to directly access the image, while all
resource access code stay "in wicket" so I have a security issue. This
is also the reason I can't use the solution François Meillet expose,
even if I find a very nice one if one does not have my privacy issue.

My only problem now is that I can't figure out how to get a nice URL
with DynamicWebResource but is the less important of all requirment.

What is your opinion about that? What are potential problems in using
DynamicImageResource to serve an image that is not dynamic, is just
stored in a user related folder?

-- 
Daniele Dellafiore
http://danieledellafiore.net

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


Re: images not under the context root directory

Posted by m j <ms...@gmail.com>.
Well after my question I started researching and changed my upload folder
to:

String path = WebApplication.get().getServletContext().getRealPath("");
Folder uploadFolder = new Folder(path+"/uploads");

I can now reference the files via the url (.../uploads/..), so much simpler
this way... I suppose this is what I was trying to do from the beginning.

Thanks for the help.


On Fri, Jan 29, 2010 at 2:51 PM, Matthew J <ms...@gmail.com> wrote:

> Correct, Glassfish would allow this; however, if I can do it
> programmatically with ease I would rather do this (as installations may
> change and I would rather not have the static uri). I assumed Wicket had
> access to all files in the context root (or what I assume is one, which
> maybe isn't).
>
> I am currently trying the code posted below (MountedImageFactory), though I
> need to alter it to work with all files, and its a little bulky.
>
> I am not bound to where I upload, is there a way to upload to a Folder that
> wicket would be able to find easily? I currently make an upload Folder:
> Folder upload = new Folder("uploads"); I upload to it similar to the
> wicket-examples.
>
>
> On 29-Jan-10, at 2:39 PM, Riyad Kalla wrote:
>
>  ot sure how that mounting rule in glassfish works, it might be
>> relative to your app root, but it seems it should work and just be treated
>> as a normal path -- in the case of the previous fellow I understood his
>> situation to be that he *had* to host resources out of a system directory
>> that wasn't web-addressable. I believe in your case they are web
>> addressable
>> if that glassfis
>>
>
>

Re: images not under the context root directory

Posted by Matthew J <ms...@gmail.com>.
Correct, Glassfish would allow this; however, if I can do it  
programmatically with ease I would rather do this (as installations  
may change and I would rather not have the static uri). I assumed  
Wicket had access to all files in the context root (or what I assume  
is one, which maybe isn't).

I am currently trying the code posted below (MountedImageFactory),  
though I need to alter it to work with all files, and its a little  
bulky.

I am not bound to where I upload, is there a way to upload to a Folder  
that wicket would be able to find easily? I currently make an upload  
Folder: Folder upload = new Folder("uploads"); I upload to it similar  
to the wicket-examples.

On 29-Jan-10, at 2:39 PM, Riyad Kalla wrote:

> ot sure how that mounting rule in glassfish works, it might be
> relative to your app root, but it seems it should work and just be  
> treated
> as a normal path -- in the case of the previous fellow I understood  
> his
> situation to be that he *had* to host resources out of a system  
> directory
> that wasn't web-addressable. I believe in your case they are web  
> addressable
> if that glassfis


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


Re: images not under the context root directory

Posted by Riyad Kalla <rk...@gmail.com>.
Matthew, this seems like a glassfish question... if you can "mount" local
system dirs in glassfish as web dirs, for example:
alternatedocroot_1 from=/uploads/*
dir=/Users/insane/path/under/netbeans/glassfish/domain1/uploads/Videos

would you access that content using http://www.mysite.com/uploads/*

Again, I'm not sure how that mounting rule in glassfish works, it might be
relative to your app root, but it seems it should work and just be treated
as a normal path -- in the case of the previous fellow I understood his
situation to be that he *had* to host resources out of a system directory
that wasn't web-addressable. I believe in your case they are web addressable
if that glassfish feature mounts them up as such?

-R

On Fri, Jan 29, 2010 at 12:17 PM, Matthew J <ms...@gmail.com> wrote:

> Question, as I am dealing with a similar issue, except I save my file to my
> glassfish directory (ie: glassfish/domains/domain1/uploads/Videos/...). I
> can't seem to find the url though I have tried many different types of
> urls...
>
> For the record
>
> ((WebApplication)WebApplication.get()).getServletContext().getRealPath(newFile.getCanonicalPath())
> returns:
>
> /Users/msj121/NetBeansProjects/WebBuilder/dist/gfdeploy/WebBuilder/WebBuilder-war_war/Applications/Programs/NetBeans/sges-v3/glassfish/domains/domain1/uploads/Videos/...
>
>
> btw, for those using Glassfish you can have urls to physical hard drive
> space even not in the context root by using an alternatedocroot (ie:
> "alternatedocroot_1 from=/uploads/* dir=/").
>
>
> I assume my directory is in the context root and I should be able to find
> it, no?
>
>
> On 29-Jan-10, at 12:47 AM, Ernesto Reinaldo Barreiro wrote:
>
>  Hi Riyad,
>>
>> I didn't get offended by your message... which otherwise raised a very
>> valid
>> issue.
>>
>> Cheers,
>>
>> Ernesto
>>
>> On Thu, Jan 28, 2010 at 5:26 PM, Riyad Kalla <rk...@gmail.com> wrote:
>>
>>  Ernesto,
>>>
>>> Sorry about that -- I didn't mean to imply your impl was back, that was
>>> more
>>> directed at Francois along the lines of "that's a lot of overhead, are
>>> you
>>> sure you need to do that?" -- but now that I understand what his use-case
>>> is
>>> (saw his last reply about /usr/ext/img/<IMAGES HERE>) I get it. I was
>>> thinking they were under /webapp/images.
>>>
>>> I'll go back to sitting in my corner ;)
>>>
>>> -R
>>>
>>> On Wed, Jan 27, 2010 at 9:54 PM, Ernesto Reinaldo Barreiro <
>>> reiern70@gmail.com> wrote:
>>>
>>>  Sure it is overhead but he wanted to serve images from a folder not
>>>> under application
>>>> context root directory... Then, you have to serve them somehow? The
>>>>
>>> options
>>>
>>>> I see are
>>>>
>>>> 1-A dedicated servlet?
>>>> 2-With Wicket... and thats what the code shows... and for sure it can be
>>>> done in a simpler way...
>>>>
>>>> A would try to use 1. As then Wicket would not have to serve the images.
>>>>
>>>> Regards,
>>>>
>>>> Ernesto
>>>>
>>>> On Wed, Jan 27, 2010 at 9:43 PM, Riyad Kalla <rk...@gmail.com> wrote:
>>>>
>>>>  This seems like adding a large amount of overhead to an image-heavy
>>>>>
>>>> site
>>>
>>>> (e.g. image blog or something), I thought I read in Wicket in Action
>>>>>
>>>> that
>>>
>>>> WicketFilter ignored HTTP requests for non-wicket resources now and
>>>>>
>>>> passed
>>>>
>>>>> them through to the underlying server to handle avoiding the need to
>>>>>
>>>> remap
>>>>
>>>>> your wicket URLs to something like /app/* so you could have /images and
>>>>> other resources under root and not have them go through the filter.
>>>>>
>>>>> Is this not the case?
>>>>>
>>>>> On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
>>>>> reiern70@gmail.com> wrote:
>>>>>
>>>>>  Hi Francois,
>>>>>>
>>>>>> Following example works.....
>>>>>>
>>>>>> 1-Create this class anywhere you want need.
>>>>>>
>>>>>> package com.antilia.demo.manager.img;
>>>>>>
>>>>>> import java.io.ByteArrayOutputStream;
>>>>>> import java.io.File;
>>>>>> import java.io.FileInputStream;
>>>>>> import java.io.IOException;
>>>>>> import java.io.InputStream;
>>>>>> import java.io.OutputStream;
>>>>>>
>>>>>> import org.apache.wicket.AttributeModifier;
>>>>>> import org.apache.wicket.markup.html.image.Image;
>>>>>> import
>>>>>>
>>>>> org.apache.wicket.markup.html.image.resource.DynamicImageResource;
>>>>
>>>>> import org.apache.wicket.model.Model;
>>>>>> import org.apache.wicket.protocol.http.WebApplication;
>>>>>> import org.apache.wicket.protocol.http.WebRequestCycle;
>>>>>> import org.apache.wicket.util.file.Folder;
>>>>>>
>>>>>> /**
>>>>>> *
>>>>>> * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>>>>>> *
>>>>>> */
>>>>>> public abstract class MountedImageFactory {
>>>>>>
>>>>>>
>>>>>> static int BUFFER_SIZE = 10*1024;
>>>>>> /**
>>>>>>   * Copies one stream into the other..
>>>>>> * @param is source Stream
>>>>>> * @param os destination Stream
>>>>>> * */
>>>>>> static public void copy(InputStream is, OutputStream os) throws
>>>>>>
>>>>> IOException
>>>>>
>>>>>> {
>>>>>> byte[] buf = new byte[BUFFER_SIZE];
>>>>>> while (true) {
>>>>>> int tam = is.read(buf);
>>>>>> if (tam == -1) {
>>>>>> return;
>>>>>> }
>>>>>> os.write(buf, 0, tam);
>>>>>> }
>>>>>> }
>>>>>> public static  byte[] bytes(InputStream is) throws IOException {
>>>>>> ByteArrayOutputStream out = new ByteArrayOutputStream();
>>>>>> copy(is, out);
>>>>>> return out.toByteArray();
>>>>>> }
>>>>>> private static ImageFromFolderWebResource dynamicResource;
>>>>>> private static class ImageFromFolderWebResource extends
>>>>>> DynamicImageResource {
>>>>>> private static final long serialVersionUID = 1L;
>>>>>>
>>>>>> private File folder;
>>>>>> public ImageFromFolderWebResource(File folder, String mountPoint) {
>>>>>> this.folder = folder;
>>>>>> WebApplication.get().getSharedResources().add(mountPoint, this);
>>>>>> WebApplication.get().mountSharedResource(mountPoint,
>>>>>> "org.apache.wicket.Application/"+mountPoint);
>>>>>> }
>>>>>> @Override
>>>>>> protected byte[] getImageData() {
>>>>>> try {
>>>>>> String name =
>>>>>>
>>>>> WebRequestCycle.get().getRequest().getParameter("name");
>>>
>>>> return bytes(new FileInputStream(new
>>>>>>
>>>>> File(getFolder().getAbsolutePath()
>>>
>>>> +
>>>>
>>>>> System.getProperty("file.separator")+(name))));
>>>>>> } catch (Exception e) {
>>>>>> //TODO: do this properly
>>>>>> return null;
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> public File getFolder() {
>>>>>> return folder;
>>>>>> }
>>>>>> }
>>>>>> /**
>>>>>> * @return Folder from where images will be retrieved.
>>>>>> */
>>>>>> protected abstract Folder getFolder();
>>>>>> /**
>>>>>> * @return the URL to mount the dynamic WEB resource.e.g.
>>>>>> */
>>>>>> protected abstract String getMountPoint();
>>>>>> public Image createImage(String id, final String imageName) {
>>>>>> if(dynamicResource == null)
>>>>>> dynamicResource = new ImageFromFolderWebResource(getFolder(),
>>>>>> getMountPoint());
>>>>>> return new Image(id) {
>>>>>> private static final long serialVersionUID = 1L;
>>>>>>
>>>>>> @Override
>>>>>> protected void onBeforeRender() {
>>>>>> String path = WebRequestCycle.get().getRequest().getURL();
>>>>>> path = path.substring(0, path.indexOf('/'));
>>>>>> add(new AttributeModifier("src",true, new
>>>>>> Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
>>>>>> super.onBeforeRender();
>>>>>> }
>>>>>> };
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> 2- Create a test page.
>>>>>>
>>>>>> import org.apache.wicket.markup.html.WebPage;
>>>>>> import org.apache.wicket.markup.html.image.Image;
>>>>>> import org.apache.wicket.util.file.Folder;
>>>>>>
>>>>>> /**
>>>>>> * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>>>>>> *
>>>>>> */
>>>>>> public class TestPage extends WebPage {
>>>>>>
>>>>>> private static final MountedImageFactory IMAGE_FACTORY = new
>>>>>> MountedImageFactory() {
>>>>>> @Override
>>>>>> protected Folder getFolder() {
>>>>>> return new Folder("C:/temp/images");
>>>>>> }
>>>>>> @Override
>>>>>> protected String getMountPoint() {
>>>>>> return "test";
>>>>>> }
>>>>>> };
>>>>>> /**
>>>>>> *
>>>>>> */
>>>>>> public TestPage() {
>>>>>> Image img = IMAGE_FACTORY.createImage("img", "test.png");
>>>>>> add(img);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> and the HTML markup
>>>>>>
>>>>>> <html xmlns:wicket="org.apache.wicket">
>>>>>> <head></head>
>>>>>> <body>
>>>>>>  <img wicket:id="img" alt="Test"/>
>>>>>> </body>
>>>>>> </html>
>>>>>>
>>>>>> 3- If you place a "test.png" on your "C:/temp/images" then you should
>>>>>>
>>>>> be
>>>>
>>>>> able to see the image when you hit the page.
>>>>>>
>>>>>> Hope you can adapt this to your needs?
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Ernesto
>>>>>>
>>>>>> 2010/1/27 François Meillet <fm...@meillet.com>
>>>>>>
>>>>>>  Thank for yours posts.
>>>>>>> I try the solutions, but  I can't figure out how to serve images as
>>>>>>>
>>>>>> static
>>>>>>
>>>>>>> images.
>>>>>>> F.
>>>>>>>
>>>>>>> Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
>>>>>>>
>>>>>>>  On 01/27/10 15:57, Jonas wrote:
>>>>>>>>
>>>>>>>>> Have you tried the following:
>>>>>>>>>
>>>>>>>>> WebComponent image = new WebComponent("someWicketId");
>>>>>>>>> image.add(new SimpleAttributeModifier("src", "http://
>>>>>>>>>
>>>>>>>> .....jpg"));
>>>
>>>>  add(image);
>>>>>>>>>
>>>>>>>>> with markup
>>>>>>>>>
>>>>>>>>> <img wicket:id="someWicketId" />
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> that should work just fine...
>>>>>>>>>
>>>>>>>>> if you cannot hardcode the image url, you can use the following
>>>>>>>>> instead of SimpleAttributeModifier
>>>>>>>>> image.add(new AttributeModifier("src", true new
>>>>>>>>> AbstractReadOnlyModel<String>() {
>>>>>>>>>   public String getObject() {
>>>>>>>>>       String url = ... (fetch the image url from anywhere
>>>>>>>>>
>>>>>>>> else)
>>>
>>>>        // e.g. '/xxx/yyyy/image893748.png'
>>>>>>>>>       return url;
>>>>>>>>>   }
>>>>>>>>> ));
>>>>>>>>>
>>>>>>>>
>>>>>>>> Or, maybe a bit nicer, encapsulate it into a component and let
>>>>>>>>
>>>>>>> the
>>>
>>>> URI
>>>>>
>>>>>> come from a Model, as usual in Wicket:
>>>>>>>
>>>>>>>>
>>>>>>>> class ExternalImageUri
>>>>>>>> extends WebComponent
>>>>>>>> {
>>>>>>>>     public ExternalImageUri(String id, IModel<String> uri)
>>>>>>>>     {
>>>>>>>>             super(id, uri);
>>>>>>>>             add(new AttributeModifier("src", true, uri));
>>>>>>>>     }
>>>>>>>>
>>>>>>>>     @Override
>>>>>>>>     protected void onComponentTag(ComponentTag tag)
>>>>>>>>     {
>>>>>>>>             super.onComponentTag(tag);
>>>>>>>>             checkComponentTag(tag, "img");
>>>>>>>>     }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> This in the Wiki at
>>>>>>>>
>>>>>>> http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> -- Thomas
>>>>>>>>
>>>>>>>>
>>>>>>>>  2010/1/27 François Meillet<fm...@meillet.com>:
>>>>>>>>>
>>>>>>>>>> Hi Wicketers,
>>>>>>>>>>
>>>>>>>>>> I have a directory, /xxx/images with uploaded images, which is
>>>>>>>>>>
>>>>>>>>> not
>>>>
>>>>> under the application context root directory.
>>>>>>>
>>>>>>>> How can I serve them as static images ?
>>>>>>>>>>
>>>>>>>>>> I tried the StaticImage class I found in the forum (
>>>>>>>>>>
>>>>>>>>> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543
>>>>>>> )
>>>>>>>
>>>>>>>> but it doesn't work for me. It just work if the image files are
>>>>>>>>>>
>>>>>>>>> under
>>>>>
>>>>>> the context root directory.
>>>>>>>
>>>>>>>>
>>>>>>>>>> Thanks for your help.
>>>>>>>>>>
>>>>>>>>>> François
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>
>>>>>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>
>>>>>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>>  -------------------------------------------------------------------
>>>
>>>>  Thomas Kappler                        thomas.kappler@isb-sib.ch
>>>>>>>> Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
>>>>>>>> CMU, rue Michel Servet 1
>>>>>>>> 1211 Geneve 4
>>>>>>>> Switzerland                              http://www.uniprot.org
>>>>>>>>
>>>>>>>>  -------------------------------------------------------------------
>>>
>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>
>>>>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>> François Meillet
>>>>>>> fmtdc@meillet.com
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>
>>>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: images not under the context root directory

Posted by Matthew J <ms...@gmail.com>.
Question, as I am dealing with a similar issue, except I save my file  
to my glassfish directory (ie: glassfish/domains/domain1/uploads/ 
Videos/...). I can't seem to find the url though I have tried many  
different types of urls...

For the record
((WebApplication 
)WebApplication 
.get()).getServletContext().getRealPath(newFile.getCanonicalPath())
returns:
/Users/msj121/NetBeansProjects/WebBuilder/dist/gfdeploy/WebBuilder/ 
WebBuilder-war_war/Applications/Programs/NetBeans/sges-v3/glassfish/ 
domains/domain1/uploads/Videos/...


btw, for those using Glassfish you can have urls to physical hard  
drive space even not in the context root by using an alternatedocroot  
(ie: "alternatedocroot_1 from=/uploads/* dir=/").


I assume my directory is in the context root and I should be able to  
find it, no?

On 29-Jan-10, at 12:47 AM, Ernesto Reinaldo Barreiro wrote:

> Hi Riyad,
>
> I didn't get offended by your message... which otherwise raised a  
> very valid
> issue.
>
> Cheers,
>
> Ernesto
>
> On Thu, Jan 28, 2010 at 5:26 PM, Riyad Kalla <rk...@gmail.com> wrote:
>
>> Ernesto,
>>
>> Sorry about that -- I didn't mean to imply your impl was back, that  
>> was
>> more
>> directed at Francois along the lines of "that's a lot of overhead,  
>> are you
>> sure you need to do that?" -- but now that I understand what his  
>> use-case
>> is
>> (saw his last reply about /usr/ext/img/<IMAGES HERE>) I get it. I was
>> thinking they were under /webapp/images.
>>
>> I'll go back to sitting in my corner ;)
>>
>> -R
>>
>> On Wed, Jan 27, 2010 at 9:54 PM, Ernesto Reinaldo Barreiro <
>> reiern70@gmail.com> wrote:
>>
>>> Sure it is overhead but he wanted to serve images from a folder not
>>> under application
>>> context root directory... Then, you have to serve them somehow? The
>> options
>>> I see are
>>>
>>> 1-A dedicated servlet?
>>> 2-With Wicket... and thats what the code shows... and for sure it  
>>> can be
>>> done in a simpler way...
>>>
>>> A would try to use 1. As then Wicket would not have to serve the  
>>> images.
>>>
>>> Regards,
>>>
>>> Ernesto
>>>
>>> On Wed, Jan 27, 2010 at 9:43 PM, Riyad Kalla <rk...@gmail.com>  
>>> wrote:
>>>
>>>> This seems like adding a large amount of overhead to an image-heavy
>> site
>>>> (e.g. image blog or something), I thought I read in Wicket in  
>>>> Action
>> that
>>>> WicketFilter ignored HTTP requests for non-wicket resources now and
>>> passed
>>>> them through to the underlying server to handle avoiding the need  
>>>> to
>>> remap
>>>> your wicket URLs to something like /app/* so you could have / 
>>>> images and
>>>> other resources under root and not have them go through the filter.
>>>>
>>>> Is this not the case?
>>>>
>>>> On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
>>>> reiern70@gmail.com> wrote:
>>>>
>>>>> Hi Francois,
>>>>>
>>>>> Following example works.....
>>>>>
>>>>> 1-Create this class anywhere you want need.
>>>>>
>>>>> package com.antilia.demo.manager.img;
>>>>>
>>>>> import java.io.ByteArrayOutputStream;
>>>>> import java.io.File;
>>>>> import java.io.FileInputStream;
>>>>> import java.io.IOException;
>>>>> import java.io.InputStream;
>>>>> import java.io.OutputStream;
>>>>>
>>>>> import org.apache.wicket.AttributeModifier;
>>>>> import org.apache.wicket.markup.html.image.Image;
>>>>> import
>>> org.apache.wicket.markup.html.image.resource.DynamicImageResource;
>>>>> import org.apache.wicket.model.Model;
>>>>> import org.apache.wicket.protocol.http.WebApplication;
>>>>> import org.apache.wicket.protocol.http.WebRequestCycle;
>>>>> import org.apache.wicket.util.file.Folder;
>>>>>
>>>>> /**
>>>>> *
>>>>> * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>>>>> *
>>>>> */
>>>>> public abstract class MountedImageFactory {
>>>>>
>>>>>
>>>>> static int BUFFER_SIZE = 10*1024;
>>>>> /**
>>>>>    * Copies one stream into the other..
>>>>> * @param is source Stream
>>>>> * @param os destination Stream
>>>>> * */
>>>>> static public void copy(InputStream is, OutputStream os) throws
>>>> IOException
>>>>> {
>>>>> byte[] buf = new byte[BUFFER_SIZE];
>>>>> while (true) {
>>>>> int tam = is.read(buf);
>>>>> if (tam == -1) {
>>>>> return;
>>>>> }
>>>>> os.write(buf, 0, tam);
>>>>> }
>>>>> }
>>>>> public static  byte[] bytes(InputStream is) throws IOException {
>>>>> ByteArrayOutputStream out = new ByteArrayOutputStream();
>>>>> copy(is, out);
>>>>> return out.toByteArray();
>>>>> }
>>>>> private static ImageFromFolderWebResource dynamicResource;
>>>>> private static class ImageFromFolderWebResource extends
>>>>> DynamicImageResource {
>>>>> private static final long serialVersionUID = 1L;
>>>>>
>>>>> private File folder;
>>>>> public ImageFromFolderWebResource(File folder, String  
>>>>> mountPoint) {
>>>>> this.folder = folder;
>>>>> WebApplication.get().getSharedResources().add(mountPoint, this);
>>>>> WebApplication.get().mountSharedResource(mountPoint,
>>>>> "org.apache.wicket.Application/"+mountPoint);
>>>>> }
>>>>> @Override
>>>>> protected byte[] getImageData() {
>>>>> try {
>>>>> String name =
>> WebRequestCycle.get().getRequest().getParameter("name");
>>>>> return bytes(new FileInputStream(new
>> File(getFolder().getAbsolutePath()
>>> +
>>>>> System.getProperty("file.separator")+(name))));
>>>>> } catch (Exception e) {
>>>>> //TODO: do this properly
>>>>> return null;
>>>>> }
>>>>> }
>>>>>
>>>>> public File getFolder() {
>>>>> return folder;
>>>>> }
>>>>> }
>>>>> /**
>>>>> * @return Folder from where images will be retrieved.
>>>>> */
>>>>> protected abstract Folder getFolder();
>>>>> /**
>>>>> * @return the URL to mount the dynamic WEB resource.e.g.
>>>>> */
>>>>> protected abstract String getMountPoint();
>>>>> public Image createImage(String id, final String imageName) {
>>>>> if(dynamicResource == null)
>>>>> dynamicResource = new ImageFromFolderWebResource(getFolder(),
>>>>> getMountPoint());
>>>>> return new Image(id) {
>>>>> private static final long serialVersionUID = 1L;
>>>>>
>>>>> @Override
>>>>> protected void onBeforeRender() {
>>>>> String path = WebRequestCycle.get().getRequest().getURL();
>>>>> path = path.substring(0, path.indexOf('/'));
>>>>> add(new AttributeModifier("src",true, new
>>>>> Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
>>>>> super.onBeforeRender();
>>>>> }
>>>>> };
>>>>> }
>>>>> }
>>>>>
>>>>> 2- Create a test page.
>>>>>
>>>>> import org.apache.wicket.markup.html.WebPage;
>>>>> import org.apache.wicket.markup.html.image.Image;
>>>>> import org.apache.wicket.util.file.Folder;
>>>>>
>>>>> /**
>>>>> * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>>>>> *
>>>>> */
>>>>> public class TestPage extends WebPage {
>>>>>
>>>>> private static final MountedImageFactory IMAGE_FACTORY = new
>>>>> MountedImageFactory() {
>>>>> @Override
>>>>> protected Folder getFolder() {
>>>>> return new Folder("C:/temp/images");
>>>>> }
>>>>> @Override
>>>>> protected String getMountPoint() {
>>>>> return "test";
>>>>> }
>>>>> };
>>>>> /**
>>>>> *
>>>>> */
>>>>> public TestPage() {
>>>>> Image img = IMAGE_FACTORY.createImage("img", "test.png");
>>>>> add(img);
>>>>> }
>>>>> }
>>>>>
>>>>> and the HTML markup
>>>>>
>>>>> <html xmlns:wicket="org.apache.wicket">
>>>>> <head></head>
>>>>> <body>
>>>>>   <img wicket:id="img" alt="Test"/>
>>>>> </body>
>>>>> </html>
>>>>>
>>>>> 3- If you place a "test.png" on your "C:/temp/images" then you  
>>>>> should
>>> be
>>>>> able to see the image when you hit the page.
>>>>>
>>>>> Hope you can adapt this to your needs?
>>>>>
>>>>> Regards,
>>>>>
>>>>> Ernesto
>>>>>
>>>>> 2010/1/27 François Meillet <fm...@meillet.com>
>>>>>
>>>>>> Thank for yours posts.
>>>>>> I try the solutions, but  I can't figure out how to serve  
>>>>>> images as
>>>>> static
>>>>>> images.
>>>>>> F.
>>>>>>
>>>>>> Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
>>>>>>
>>>>>>> On 01/27/10 15:57, Jonas wrote:
>>>>>>>> Have you tried the following:
>>>>>>>>
>>>>>>>> WebComponent image = new WebComponent("someWicketId");
>>>>>>>> image.add(new SimpleAttributeModifier("src", "http://
>> .....jpg"));
>>>>>>>> add(image);
>>>>>>>>
>>>>>>>> with markup
>>>>>>>>
>>>>>>>> <img wicket:id="someWicketId" />
>>>>>>>>
>>>>>>>>
>>>>>>>> that should work just fine...
>>>>>>>>
>>>>>>>> if you cannot hardcode the image url, you can use the following
>>>>>>>> instead of SimpleAttributeModifier
>>>>>>>> image.add(new AttributeModifier("src", true new
>>>>>>>> AbstractReadOnlyModel<String>() {
>>>>>>>>    public String getObject() {
>>>>>>>>        String url = ... (fetch the image url from anywhere
>> else)
>>>>>>>>        // e.g. '/xxx/yyyy/image893748.png'
>>>>>>>>        return url;
>>>>>>>>    }
>>>>>>>> ));
>>>>>>>
>>>>>>> Or, maybe a bit nicer, encapsulate it into a component and let
>> the
>>>> URI
>>>>>> come from a Model, as usual in Wicket:
>>>>>>>
>>>>>>> class ExternalImageUri
>>>>>>> extends WebComponent
>>>>>>> {
>>>>>>>      public ExternalImageUri(String id, IModel<String> uri)
>>>>>>>      {
>>>>>>>              super(id, uri);
>>>>>>>              add(new AttributeModifier("src", true, uri));
>>>>>>>      }
>>>>>>>
>>>>>>>      @Override
>>>>>>>      protected void onComponentTag(ComponentTag tag)
>>>>>>>      {
>>>>>>>              super.onComponentTag(tag);
>>>>>>>              checkComponentTag(tag, "img");
>>>>>>>      }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> This in the Wiki at
>>>>>> http://cwiki.apache.org/WICKET/how-to-load-an-external- 
>>>>>> image.html.
>>>>>>>
>>>>>>>
>>>>>>> -- Thomas
>>>>>>>
>>>>>>>
>>>>>>>> 2010/1/27 François Meillet<fm...@meillet.com>:
>>>>>>>>> Hi Wicketers,
>>>>>>>>>
>>>>>>>>> I have a directory, /xxx/images with uploaded images, which is
>>> not
>>>>>> under the application context root directory.
>>>>>>>>> How can I serve them as static images ?
>>>>>>>>>
>>>>>>>>> I tried the StaticImage class I found in the forum (
>>>>>> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543)
>>>>>>>>> but it doesn't work for me. It just work if the image files  
>>>>>>>>> are
>>>> under
>>>>>> the context root directory.
>>>>>>>>>
>>>>>>>>> Thanks for your help.
>>>>>>>>>
>>>>>>>>> François
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>> -------------------------------------------------------------------
>>>>>>> Thomas Kappler                        thomas.kappler@isb-sib.ch
>>>>>>> Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
>>>>>>> CMU, rue Michel Servet 1
>>>>>>> 1211 Geneve 4
>>>>>>> Switzerland                              http://www.uniprot.org
>>>>>>>
>> -------------------------------------------------------------------
>>>>>>>
>>>>>>>
>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>
>>>>>>
>>>>>> François Meillet
>>>>>> fmtdc@meillet.com
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>


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


Re: images not under the context root directory

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi Riyad,

I didn't get offended by your message... which otherwise raised a very valid
issue.

Cheers,

Ernesto

On Thu, Jan 28, 2010 at 5:26 PM, Riyad Kalla <rk...@gmail.com> wrote:

> Ernesto,
>
> Sorry about that -- I didn't mean to imply your impl was back, that was
> more
> directed at Francois along the lines of "that's a lot of overhead, are you
> sure you need to do that?" -- but now that I understand what his use-case
> is
> (saw his last reply about /usr/ext/img/<IMAGES HERE>) I get it. I was
> thinking they were under /webapp/images.
>
> I'll go back to sitting in my corner ;)
>
> -R
>
> On Wed, Jan 27, 2010 at 9:54 PM, Ernesto Reinaldo Barreiro <
> reiern70@gmail.com> wrote:
>
> > Sure it is overhead but he wanted to serve images from a folder not
> > under application
> > context root directory... Then, you have to serve them somehow? The
> options
> > I see are
> >
> > 1-A dedicated servlet?
> > 2-With Wicket... and thats what the code shows... and for sure it can be
> > done in a simpler way...
> >
> > A would try to use 1. As then Wicket would not have to serve the images.
> >
> > Regards,
> >
> > Ernesto
> >
> > On Wed, Jan 27, 2010 at 9:43 PM, Riyad Kalla <rk...@gmail.com> wrote:
> >
> > > This seems like adding a large amount of overhead to an image-heavy
> site
> > > (e.g. image blog or something), I thought I read in Wicket in Action
> that
> > > WicketFilter ignored HTTP requests for non-wicket resources now and
> > passed
> > > them through to the underlying server to handle avoiding the need to
> > remap
> > > your wicket URLs to something like /app/* so you could have /images and
> > > other resources under root and not have them go through the filter.
> > >
> > > Is this not the case?
> > >
> > > On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
> > > reiern70@gmail.com> wrote:
> > >
> > > > Hi Francois,
> > > >
> > > > Following example works.....
> > > >
> > > > 1-Create this class anywhere you want need.
> > > >
> > > > package com.antilia.demo.manager.img;
> > > >
> > > > import java.io.ByteArrayOutputStream;
> > > > import java.io.File;
> > > > import java.io.FileInputStream;
> > > > import java.io.IOException;
> > > > import java.io.InputStream;
> > > > import java.io.OutputStream;
> > > >
> > > > import org.apache.wicket.AttributeModifier;
> > > > import org.apache.wicket.markup.html.image.Image;
> > > > import
> > org.apache.wicket.markup.html.image.resource.DynamicImageResource;
> > > > import org.apache.wicket.model.Model;
> > > > import org.apache.wicket.protocol.http.WebApplication;
> > > > import org.apache.wicket.protocol.http.WebRequestCycle;
> > > > import org.apache.wicket.util.file.Folder;
> > > >
> > > > /**
> > > >  *
> > > >  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
> > > >  *
> > > >  */
> > > > public abstract class MountedImageFactory {
> > > >
> > > >
> > > > static int BUFFER_SIZE = 10*1024;
> > > >  /**
> > > >     * Copies one stream into the other..
> > > >  * @param is source Stream
> > > >  * @param os destination Stream
> > > >  * */
> > > > static public void copy(InputStream is, OutputStream os) throws
> > > IOException
> > > > {
> > > > byte[] buf = new byte[BUFFER_SIZE];
> > > > while (true) {
> > > > int tam = is.read(buf);
> > > > if (tam == -1) {
> > > > return;
> > > > }
> > > > os.write(buf, 0, tam);
> > > > }
> > > > }
> > > >  public static  byte[] bytes(InputStream is) throws IOException {
> > > > ByteArrayOutputStream out = new ByteArrayOutputStream();
> > > > copy(is, out);
> > > > return out.toByteArray();
> > > > }
> > > >  private static ImageFromFolderWebResource dynamicResource;
> > > >  private static class ImageFromFolderWebResource extends
> > > > DynamicImageResource {
> > > >  private static final long serialVersionUID = 1L;
> > > >
> > > >  private File folder;
> > > >  public ImageFromFolderWebResource(File folder, String mountPoint) {
> > > > this.folder = folder;
> > > > WebApplication.get().getSharedResources().add(mountPoint, this);
> > > > WebApplication.get().mountSharedResource(mountPoint,
> > > > "org.apache.wicket.Application/"+mountPoint);
> > > > }
> > > >  @Override
> > > > protected byte[] getImageData() {
> > > > try {
> > > > String name =
> WebRequestCycle.get().getRequest().getParameter("name");
> > > > return bytes(new FileInputStream(new
> File(getFolder().getAbsolutePath()
> > +
> > > > System.getProperty("file.separator")+(name))));
> > > > } catch (Exception e) {
> > > > //TODO: do this properly
> > > > return null;
> > > > }
> > > > }
> > > >
> > > > public File getFolder() {
> > > > return folder;
> > > > }
> > > > }
> > > >  /**
> > > >  * @return Folder from where images will be retrieved.
> > > >  */
> > > > protected abstract Folder getFolder();
> > > >  /**
> > > >  * @return the URL to mount the dynamic WEB resource.e.g.
> > > >  */
> > > > protected abstract String getMountPoint();
> > > >  public Image createImage(String id, final String imageName) {
> > > > if(dynamicResource == null)
> > > > dynamicResource = new ImageFromFolderWebResource(getFolder(),
> > > > getMountPoint());
> > > > return new Image(id) {
> > > >  private static final long serialVersionUID = 1L;
> > > >
> > > > @Override
> > > > protected void onBeforeRender() {
> > > > String path = WebRequestCycle.get().getRequest().getURL();
> > > > path = path.substring(0, path.indexOf('/'));
> > > > add(new AttributeModifier("src",true, new
> > > > Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
> > > > super.onBeforeRender();
> > > > }
> > > > };
> > > > }
> > > > }
> > > >
> > > > 2- Create a test page.
> > > >
> > > > import org.apache.wicket.markup.html.WebPage;
> > > > import org.apache.wicket.markup.html.image.Image;
> > > > import org.apache.wicket.util.file.Folder;
> > > >
> > > > /**
> > > >  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
> > > >  *
> > > >  */
> > > > public class TestPage extends WebPage {
> > > >
> > > > private static final MountedImageFactory IMAGE_FACTORY = new
> > > > MountedImageFactory() {
> > > >  @Override
> > > > protected Folder getFolder() {
> > > > return new Folder("C:/temp/images");
> > > > }
> > > >  @Override
> > > > protected String getMountPoint() {
> > > > return "test";
> > > > }
> > > >  };
> > > >  /**
> > > >  *
> > > >  */
> > > > public TestPage() {
> > > > Image img = IMAGE_FACTORY.createImage("img", "test.png");
> > > > add(img);
> > > > }
> > > > }
> > > >
> > > > and the HTML markup
> > > >
> > > > <html xmlns:wicket="org.apache.wicket">
> > > > <head></head>
> > > > <body>
> > > >    <img wicket:id="img" alt="Test"/>
> > > > </body>
> > > > </html>
> > > >
> > > > 3- If you place a "test.png" on your "C:/temp/images" then you should
> > be
> > > > able to see the image when you hit the page.
> > > >
> > > > Hope you can adapt this to your needs?
> > > >
> > > > Regards,
> > > >
> > > > Ernesto
> > > >
> > > > 2010/1/27 François Meillet <fm...@meillet.com>
> > > >
> > > > > Thank for yours posts.
> > > > > I try the solutions, but  I can't figure out how to serve images as
> > > > static
> > > > > images.
> > > > > F.
> > > > >
> > > > > Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
> > > > >
> > > > > > On 01/27/10 15:57, Jonas wrote:
> > > > > >> Have you tried the following:
> > > > > >>
> > > > > >> WebComponent image = new WebComponent("someWicketId");
> > > > > >> image.add(new SimpleAttributeModifier("src", "http://
> .....jpg"));
> > > > > >> add(image);
> > > > > >>
> > > > > >> with markup
> > > > > >>
> > > > > >> <img wicket:id="someWicketId" />
> > > > > >>
> > > > > >>
> > > > > >> that should work just fine...
> > > > > >>
> > > > > >> if you cannot hardcode the image url, you can use the following
> > > > > >> instead of SimpleAttributeModifier
> > > > > >> image.add(new AttributeModifier("src", true new
> > > > > >> AbstractReadOnlyModel<String>() {
> > > > > >>     public String getObject() {
> > > > > >>         String url = ... (fetch the image url from anywhere
> else)
> > > > > >>         // e.g. '/xxx/yyyy/image893748.png'
> > > > > >>         return url;
> > > > > >>     }
> > > > > >> ));
> > > > > >
> > > > > > Or, maybe a bit nicer, encapsulate it into a component and let
> the
> > > URI
> > > > > come from a Model, as usual in Wicket:
> > > > > >
> > > > > > class ExternalImageUri
> > > > > > extends WebComponent
> > > > > > {
> > > > > >       public ExternalImageUri(String id, IModel<String> uri)
> > > > > >       {
> > > > > >               super(id, uri);
> > > > > >               add(new AttributeModifier("src", true, uri));
> > > > > >       }
> > > > > >
> > > > > >       @Override
> > > > > >       protected void onComponentTag(ComponentTag tag)
> > > > > >       {
> > > > > >               super.onComponentTag(tag);
> > > > > >               checkComponentTag(tag, "img");
> > > > > >       }
> > > > > > }
> > > > > >
> > > > > >
> > > > > > This in the Wiki at
> > > > > http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
> > > > > >
> > > > > >
> > > > > > -- Thomas
> > > > > >
> > > > > >
> > > > > >> 2010/1/27 François Meillet<fm...@meillet.com>:
> > > > > >>> Hi Wicketers,
> > > > > >>>
> > > > > >>> I have a directory, /xxx/images with uploaded images, which is
> > not
> > > > > under the application context root directory.
> > > > > >>> How can I serve them as static images ?
> > > > > >>>
> > > > > >>> I tried the StaticImage class I found in the forum (
> > > > > http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543)
> > > > > >>> but it doesn't work for me. It just work if the image files are
> > > under
> > > > > the context root directory.
> > > > > >>>
> > > > > >>> Thanks for your help.
> > > > > >>>
> > > > > >>> François
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > ---------------------------------------------------------------------
> > > > > >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > > >>> For additional commands, e-mail: users-help@wicket.apache.org
> > > > > >>>
> > > > > >>>
> > > > > >>
> > > > > >>
> > > ---------------------------------------------------------------------
> > > > > >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > > >> For additional commands, e-mail: users-help@wicket.apache.org
> > > > > >>
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> -------------------------------------------------------------------
> > > > > >  Thomas Kappler                        thomas.kappler@isb-sib.ch
> > > > > >  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
> > > > > >  CMU, rue Michel Servet 1
> > > > > >  1211 Geneve 4
> > > > > >  Switzerland                              http://www.uniprot.org
> > > > > >
> -------------------------------------------------------------------
> > > > > >
> > > > > >
> > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > > > For additional commands, e-mail: users-help@wicket.apache.org
> > > > > >
> > > > >
> > > > > François Meillet
> > > > > fmtdc@meillet.com
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > > For additional commands, e-mail: users-help@wicket.apache.org
> > > > >
> > > > >
> > > >
> > >
> >
>

Re: images not under the context root directory

Posted by Riyad Kalla <rk...@gmail.com>.
Ernesto,

Sorry about that -- I didn't mean to imply your impl was back, that was more
directed at Francois along the lines of "that's a lot of overhead, are you
sure you need to do that?" -- but now that I understand what his use-case is
(saw his last reply about /usr/ext/img/<IMAGES HERE>) I get it. I was
thinking they were under /webapp/images.

I'll go back to sitting in my corner ;)

-R

On Wed, Jan 27, 2010 at 9:54 PM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> Sure it is overhead but he wanted to serve images from a folder not
> under application
> context root directory... Then, you have to serve them somehow? The options
> I see are
>
> 1-A dedicated servlet?
> 2-With Wicket... and thats what the code shows... and for sure it can be
> done in a simpler way...
>
> A would try to use 1. As then Wicket would not have to serve the images.
>
> Regards,
>
> Ernesto
>
> On Wed, Jan 27, 2010 at 9:43 PM, Riyad Kalla <rk...@gmail.com> wrote:
>
> > This seems like adding a large amount of overhead to an image-heavy site
> > (e.g. image blog or something), I thought I read in Wicket in Action that
> > WicketFilter ignored HTTP requests for non-wicket resources now and
> passed
> > them through to the underlying server to handle avoiding the need to
> remap
> > your wicket URLs to something like /app/* so you could have /images and
> > other resources under root and not have them go through the filter.
> >
> > Is this not the case?
> >
> > On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
> > reiern70@gmail.com> wrote:
> >
> > > Hi Francois,
> > >
> > > Following example works.....
> > >
> > > 1-Create this class anywhere you want need.
> > >
> > > package com.antilia.demo.manager.img;
> > >
> > > import java.io.ByteArrayOutputStream;
> > > import java.io.File;
> > > import java.io.FileInputStream;
> > > import java.io.IOException;
> > > import java.io.InputStream;
> > > import java.io.OutputStream;
> > >
> > > import org.apache.wicket.AttributeModifier;
> > > import org.apache.wicket.markup.html.image.Image;
> > > import
> org.apache.wicket.markup.html.image.resource.DynamicImageResource;
> > > import org.apache.wicket.model.Model;
> > > import org.apache.wicket.protocol.http.WebApplication;
> > > import org.apache.wicket.protocol.http.WebRequestCycle;
> > > import org.apache.wicket.util.file.Folder;
> > >
> > > /**
> > >  *
> > >  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
> > >  *
> > >  */
> > > public abstract class MountedImageFactory {
> > >
> > >
> > > static int BUFFER_SIZE = 10*1024;
> > >  /**
> > >     * Copies one stream into the other..
> > >  * @param is source Stream
> > >  * @param os destination Stream
> > >  * */
> > > static public void copy(InputStream is, OutputStream os) throws
> > IOException
> > > {
> > > byte[] buf = new byte[BUFFER_SIZE];
> > > while (true) {
> > > int tam = is.read(buf);
> > > if (tam == -1) {
> > > return;
> > > }
> > > os.write(buf, 0, tam);
> > > }
> > > }
> > >  public static  byte[] bytes(InputStream is) throws IOException {
> > > ByteArrayOutputStream out = new ByteArrayOutputStream();
> > > copy(is, out);
> > > return out.toByteArray();
> > > }
> > >  private static ImageFromFolderWebResource dynamicResource;
> > >  private static class ImageFromFolderWebResource extends
> > > DynamicImageResource {
> > >  private static final long serialVersionUID = 1L;
> > >
> > >  private File folder;
> > >  public ImageFromFolderWebResource(File folder, String mountPoint) {
> > > this.folder = folder;
> > > WebApplication.get().getSharedResources().add(mountPoint, this);
> > > WebApplication.get().mountSharedResource(mountPoint,
> > > "org.apache.wicket.Application/"+mountPoint);
> > > }
> > >  @Override
> > > protected byte[] getImageData() {
> > > try {
> > > String name = WebRequestCycle.get().getRequest().getParameter("name");
> > > return bytes(new FileInputStream(new File(getFolder().getAbsolutePath()
> +
> > > System.getProperty("file.separator")+(name))));
> > > } catch (Exception e) {
> > > //TODO: do this properly
> > > return null;
> > > }
> > > }
> > >
> > > public File getFolder() {
> > > return folder;
> > > }
> > > }
> > >  /**
> > >  * @return Folder from where images will be retrieved.
> > >  */
> > > protected abstract Folder getFolder();
> > >  /**
> > >  * @return the URL to mount the dynamic WEB resource.e.g.
> > >  */
> > > protected abstract String getMountPoint();
> > >  public Image createImage(String id, final String imageName) {
> > > if(dynamicResource == null)
> > > dynamicResource = new ImageFromFolderWebResource(getFolder(),
> > > getMountPoint());
> > > return new Image(id) {
> > >  private static final long serialVersionUID = 1L;
> > >
> > > @Override
> > > protected void onBeforeRender() {
> > > String path = WebRequestCycle.get().getRequest().getURL();
> > > path = path.substring(0, path.indexOf('/'));
> > > add(new AttributeModifier("src",true, new
> > > Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
> > > super.onBeforeRender();
> > > }
> > > };
> > > }
> > > }
> > >
> > > 2- Create a test page.
> > >
> > > import org.apache.wicket.markup.html.WebPage;
> > > import org.apache.wicket.markup.html.image.Image;
> > > import org.apache.wicket.util.file.Folder;
> > >
> > > /**
> > >  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
> > >  *
> > >  */
> > > public class TestPage extends WebPage {
> > >
> > > private static final MountedImageFactory IMAGE_FACTORY = new
> > > MountedImageFactory() {
> > >  @Override
> > > protected Folder getFolder() {
> > > return new Folder("C:/temp/images");
> > > }
> > >  @Override
> > > protected String getMountPoint() {
> > > return "test";
> > > }
> > >  };
> > >  /**
> > >  *
> > >  */
> > > public TestPage() {
> > > Image img = IMAGE_FACTORY.createImage("img", "test.png");
> > > add(img);
> > > }
> > > }
> > >
> > > and the HTML markup
> > >
> > > <html xmlns:wicket="org.apache.wicket">
> > > <head></head>
> > > <body>
> > >    <img wicket:id="img" alt="Test"/>
> > > </body>
> > > </html>
> > >
> > > 3- If you place a "test.png" on your "C:/temp/images" then you should
> be
> > > able to see the image when you hit the page.
> > >
> > > Hope you can adapt this to your needs?
> > >
> > > Regards,
> > >
> > > Ernesto
> > >
> > > 2010/1/27 François Meillet <fm...@meillet.com>
> > >
> > > > Thank for yours posts.
> > > > I try the solutions, but  I can't figure out how to serve images as
> > > static
> > > > images.
> > > > F.
> > > >
> > > > Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
> > > >
> > > > > On 01/27/10 15:57, Jonas wrote:
> > > > >> Have you tried the following:
> > > > >>
> > > > >> WebComponent image = new WebComponent("someWicketId");
> > > > >> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
> > > > >> add(image);
> > > > >>
> > > > >> with markup
> > > > >>
> > > > >> <img wicket:id="someWicketId" />
> > > > >>
> > > > >>
> > > > >> that should work just fine...
> > > > >>
> > > > >> if you cannot hardcode the image url, you can use the following
> > > > >> instead of SimpleAttributeModifier
> > > > >> image.add(new AttributeModifier("src", true new
> > > > >> AbstractReadOnlyModel<String>() {
> > > > >>     public String getObject() {
> > > > >>         String url = ... (fetch the image url from anywhere else)
> > > > >>         // e.g. '/xxx/yyyy/image893748.png'
> > > > >>         return url;
> > > > >>     }
> > > > >> ));
> > > > >
> > > > > Or, maybe a bit nicer, encapsulate it into a component and let the
> > URI
> > > > come from a Model, as usual in Wicket:
> > > > >
> > > > > class ExternalImageUri
> > > > > extends WebComponent
> > > > > {
> > > > >       public ExternalImageUri(String id, IModel<String> uri)
> > > > >       {
> > > > >               super(id, uri);
> > > > >               add(new AttributeModifier("src", true, uri));
> > > > >       }
> > > > >
> > > > >       @Override
> > > > >       protected void onComponentTag(ComponentTag tag)
> > > > >       {
> > > > >               super.onComponentTag(tag);
> > > > >               checkComponentTag(tag, "img");
> > > > >       }
> > > > > }
> > > > >
> > > > >
> > > > > This in the Wiki at
> > > > http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
> > > > >
> > > > >
> > > > > -- Thomas
> > > > >
> > > > >
> > > > >> 2010/1/27 François Meillet<fm...@meillet.com>:
> > > > >>> Hi Wicketers,
> > > > >>>
> > > > >>> I have a directory, /xxx/images with uploaded images, which is
> not
> > > > under the application context root directory.
> > > > >>> How can I serve them as static images ?
> > > > >>>
> > > > >>> I tried the StaticImage class I found in the forum (
> > > > http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
> > > > >>> but it doesn't work for me. It just work if the image files are
> > under
> > > > the context root directory.
> > > > >>>
> > > > >>> Thanks for your help.
> > > > >>>
> > > > >>> François
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > ---------------------------------------------------------------------
> > > > >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > >>> For additional commands, e-mail: users-help@wicket.apache.org
> > > > >>>
> > > > >>>
> > > > >>
> > > > >>
> > ---------------------------------------------------------------------
> > > > >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > >> For additional commands, e-mail: users-help@wicket.apache.org
> > > > >>
> > > > >
> > > > >
> > > > > --
> > > > > -------------------------------------------------------------------
> > > > >  Thomas Kappler                        thomas.kappler@isb-sib.ch
> > > > >  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
> > > > >  CMU, rue Michel Servet 1
> > > > >  1211 Geneve 4
> > > > >  Switzerland                              http://www.uniprot.org
> > > > > -------------------------------------------------------------------
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > > For additional commands, e-mail: users-help@wicket.apache.org
> > > > >
> > > >
> > > > François Meillet
> > > > fmtdc@meillet.com
> > > >
> > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > For additional commands, e-mail: users-help@wicket.apache.org
> > > >
> > > >
> > >
> >
>

Re: images not under the context root directory

Posted by François Meillet <fm...@meillet.com>.
Thanks Ernesto, Jonas, Riyad, Don and Thomas.

I implemented all of your solutions.
I ended up with this one :

1) In the application init method I call this method, which add a directory to the WebApplicationPath
    private void initPath() {

		WebApplicationPath resourceFinder = (WebApplicationPath) getResourceSettings().getResourceFinder();

       		 String dir = "/usr/ext/img";  // the images are under this dir

		resourceFinder.add( imp );

		getResourceSettings().setResourceFinder( resourceFinder );
    }


2) in the panel I add
add(new Image("imageid", "/test/test.gif"));

3) the image url is 
resources/xxx.yyy.zzz.TestPage3//test/test.gif


François

Le 28 janv. 2010 à 05:54, Ernesto Reinaldo Barreiro a écrit :

> Sure it is overhead but he wanted to serve images from a folder not
> under application
> context root directory... Then, you have to serve them somehow? The options
> I see are
> 
> 1-A dedicated servlet?
> 2-With Wicket... and thats what the code shows... and for sure it can be
> done in a simpler way...
> 
> A would try to use 1. As then Wicket would not have to serve the images.
> 
> Regards,
> 
> Ernesto
> 
> On Wed, Jan 27, 2010 at 9:43 PM, Riyad Kalla <rk...@gmail.com> wrote:
> 
>> This seems like adding a large amount of overhead to an image-heavy site
>> (e.g. image blog or something), I thought I read in Wicket in Action that
>> WicketFilter ignored HTTP requests for non-wicket resources now and passed
>> them through to the underlying server to handle avoiding the need to remap
>> your wicket URLs to something like /app/* so you could have /images and
>> other resources under root and not have them go through the filter.
>> 
>> Is this not the case?
>> 
>> On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
>> reiern70@gmail.com> wrote:
>> 
>>> Hi Francois,
>>> 
>>> Following example works.....
>>> 
>>> 1-Create this class anywhere you want need.
>>> 
>>> package com.antilia.demo.manager.img;
>>> 
>>> import java.io.ByteArrayOutputStream;
>>> import java.io.File;
>>> import java.io.FileInputStream;
>>> import java.io.IOException;
>>> import java.io.InputStream;
>>> import java.io.OutputStream;
>>> 
>>> import org.apache.wicket.AttributeModifier;
>>> import org.apache.wicket.markup.html.image.Image;
>>> import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
>>> import org.apache.wicket.model.Model;
>>> import org.apache.wicket.protocol.http.WebApplication;
>>> import org.apache.wicket.protocol.http.WebRequestCycle;
>>> import org.apache.wicket.util.file.Folder;
>>> 
>>> /**
>>> *
>>> * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>>> *
>>> */
>>> public abstract class MountedImageFactory {
>>> 
>>> 
>>> static int BUFFER_SIZE = 10*1024;
>>> /**
>>>    * Copies one stream into the other..
>>> * @param is source Stream
>>> * @param os destination Stream
>>> * */
>>> static public void copy(InputStream is, OutputStream os) throws
>> IOException
>>> {
>>> byte[] buf = new byte[BUFFER_SIZE];
>>> while (true) {
>>> int tam = is.read(buf);
>>> if (tam == -1) {
>>> return;
>>> }
>>> os.write(buf, 0, tam);
>>> }
>>> }
>>> public static  byte[] bytes(InputStream is) throws IOException {
>>> ByteArrayOutputStream out = new ByteArrayOutputStream();
>>> copy(is, out);
>>> return out.toByteArray();
>>> }
>>> private static ImageFromFolderWebResource dynamicResource;
>>> private static class ImageFromFolderWebResource extends
>>> DynamicImageResource {
>>> private static final long serialVersionUID = 1L;
>>> 
>>> private File folder;
>>> public ImageFromFolderWebResource(File folder, String mountPoint) {
>>> this.folder = folder;
>>> WebApplication.get().getSharedResources().add(mountPoint, this);
>>> WebApplication.get().mountSharedResource(mountPoint,
>>> "org.apache.wicket.Application/"+mountPoint);
>>> }
>>> @Override
>>> protected byte[] getImageData() {
>>> try {
>>> String name = WebRequestCycle.get().getRequest().getParameter("name");
>>> return bytes(new FileInputStream(new File(getFolder().getAbsolutePath() +
>>> System.getProperty("file.separator")+(name))));
>>> } catch (Exception e) {
>>> //TODO: do this properly
>>> return null;
>>> }
>>> }
>>> 
>>> public File getFolder() {
>>> return folder;
>>> }
>>> }
>>> /**
>>> * @return Folder from where images will be retrieved.
>>> */
>>> protected abstract Folder getFolder();
>>> /**
>>> * @return the URL to mount the dynamic WEB resource.e.g.
>>> */
>>> protected abstract String getMountPoint();
>>> public Image createImage(String id, final String imageName) {
>>> if(dynamicResource == null)
>>> dynamicResource = new ImageFromFolderWebResource(getFolder(),
>>> getMountPoint());
>>> return new Image(id) {
>>> private static final long serialVersionUID = 1L;
>>> 
>>> @Override
>>> protected void onBeforeRender() {
>>> String path = WebRequestCycle.get().getRequest().getURL();
>>> path = path.substring(0, path.indexOf('/'));
>>> add(new AttributeModifier("src",true, new
>>> Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
>>> super.onBeforeRender();
>>> }
>>> };
>>> }
>>> }
>>> 
>>> 2- Create a test page.
>>> 
>>> import org.apache.wicket.markup.html.WebPage;
>>> import org.apache.wicket.markup.html.image.Image;
>>> import org.apache.wicket.util.file.Folder;
>>> 
>>> /**
>>> * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>>> *
>>> */
>>> public class TestPage extends WebPage {
>>> 
>>> private static final MountedImageFactory IMAGE_FACTORY = new
>>> MountedImageFactory() {
>>> @Override
>>> protected Folder getFolder() {
>>> return new Folder("C:/temp/images");
>>> }
>>> @Override
>>> protected String getMountPoint() {
>>> return "test";
>>> }
>>> };
>>> /**
>>> *
>>> */
>>> public TestPage() {
>>> Image img = IMAGE_FACTORY.createImage("img", "test.png");
>>> add(img);
>>> }
>>> }
>>> 
>>> and the HTML markup
>>> 
>>> <html xmlns:wicket="org.apache.wicket">
>>> <head></head>
>>> <body>
>>>   <img wicket:id="img" alt="Test"/>
>>> </body>
>>> </html>
>>> 
>>> 3- If you place a "test.png" on your "C:/temp/images" then you should be
>>> able to see the image when you hit the page.
>>> 
>>> Hope you can adapt this to your needs?
>>> 
>>> Regards,
>>> 
>>> Ernesto
>>> 
>>> 2010/1/27 François Meillet <fm...@meillet.com>
>>> 
>>>> Thank for yours posts.
>>>> I try the solutions, but  I can't figure out how to serve images as
>>> static
>>>> images.
>>>> F.
>>>> 
>>>> Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
>>>> 
>>>>> On 01/27/10 15:57, Jonas wrote:
>>>>>> Have you tried the following:
>>>>>> 
>>>>>> WebComponent image = new WebComponent("someWicketId");
>>>>>> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
>>>>>> add(image);
>>>>>> 
>>>>>> with markup
>>>>>> 
>>>>>> <img wicket:id="someWicketId" />
>>>>>> 
>>>>>> 
>>>>>> that should work just fine...
>>>>>> 
>>>>>> if you cannot hardcode the image url, you can use the following
>>>>>> instead of SimpleAttributeModifier
>>>>>> image.add(new AttributeModifier("src", true new
>>>>>> AbstractReadOnlyModel<String>() {
>>>>>>    public String getObject() {
>>>>>>        String url = ... (fetch the image url from anywhere else)
>>>>>>        // e.g. '/xxx/yyyy/image893748.png'
>>>>>>        return url;
>>>>>>    }
>>>>>> ));
>>>>> 
>>>>> Or, maybe a bit nicer, encapsulate it into a component and let the
>> URI
>>>> come from a Model, as usual in Wicket:
>>>>> 
>>>>> class ExternalImageUri
>>>>> extends WebComponent
>>>>> {
>>>>>      public ExternalImageUri(String id, IModel<String> uri)
>>>>>      {
>>>>>              super(id, uri);
>>>>>              add(new AttributeModifier("src", true, uri));
>>>>>      }
>>>>> 
>>>>>      @Override
>>>>>      protected void onComponentTag(ComponentTag tag)
>>>>>      {
>>>>>              super.onComponentTag(tag);
>>>>>              checkComponentTag(tag, "img");
>>>>>      }
>>>>> }
>>>>> 
>>>>> 
>>>>> This in the Wiki at
>>>> http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
>>>>> 
>>>>> 
>>>>> -- Thomas
>>>>> 
>>>>> 
>>>>>> 2010/1/27 François Meillet<fm...@meillet.com>:
>>>>>>> Hi Wicketers,
>>>>>>> 
>>>>>>> I have a directory, /xxx/images with uploaded images, which is not
>>>> under the application context root directory.
>>>>>>> How can I serve them as static images ?
>>>>>>> 
>>>>>>> I tried the StaticImage class I found in the forum (
>>>> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
>>>>>>> but it doesn't work for me. It just work if the image files are
>> under
>>>> the context root directory.
>>>>>>> 
>>>>>>> Thanks for your help.
>>>>>>> 
>>>>>>> François
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>> 
>>>>>>> 
>>>>>> 
>>>>>> 
>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> -------------------------------------------------------------------
>>>>> Thomas Kappler                        thomas.kappler@isb-sib.ch
>>>>> Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
>>>>> CMU, rue Michel Servet 1
>>>>> 1211 Geneve 4
>>>>> Switzerland                              http://www.uniprot.org
>>>>> -------------------------------------------------------------------
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>> 
>>>> 
>>>> François Meillet
>>>> fmtdc@meillet.com
>>>> 
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>> 
>>>> 
>>> 
>> 

François Meillet
fmtdc@meillet.com




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


Re: images not under the context root directory

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Sure it is overhead but he wanted to serve images from a folder not
under application
context root directory... Then, you have to serve them somehow? The options
I see are

1-A dedicated servlet?
2-With Wicket... and thats what the code shows... and for sure it can be
done in a simpler way...

A would try to use 1. As then Wicket would not have to serve the images.

Regards,

Ernesto

On Wed, Jan 27, 2010 at 9:43 PM, Riyad Kalla <rk...@gmail.com> wrote:

> This seems like adding a large amount of overhead to an image-heavy site
> (e.g. image blog or something), I thought I read in Wicket in Action that
> WicketFilter ignored HTTP requests for non-wicket resources now and passed
> them through to the underlying server to handle avoiding the need to remap
> your wicket URLs to something like /app/* so you could have /images and
> other resources under root and not have them go through the filter.
>
> Is this not the case?
>
> On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
> reiern70@gmail.com> wrote:
>
> > Hi Francois,
> >
> > Following example works.....
> >
> > 1-Create this class anywhere you want need.
> >
> > package com.antilia.demo.manager.img;
> >
> > import java.io.ByteArrayOutputStream;
> > import java.io.File;
> > import java.io.FileInputStream;
> > import java.io.IOException;
> > import java.io.InputStream;
> > import java.io.OutputStream;
> >
> > import org.apache.wicket.AttributeModifier;
> > import org.apache.wicket.markup.html.image.Image;
> > import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
> > import org.apache.wicket.model.Model;
> > import org.apache.wicket.protocol.http.WebApplication;
> > import org.apache.wicket.protocol.http.WebRequestCycle;
> > import org.apache.wicket.util.file.Folder;
> >
> > /**
> >  *
> >  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
> >  *
> >  */
> > public abstract class MountedImageFactory {
> >
> >
> > static int BUFFER_SIZE = 10*1024;
> >  /**
> >     * Copies one stream into the other..
> >  * @param is source Stream
> >  * @param os destination Stream
> >  * */
> > static public void copy(InputStream is, OutputStream os) throws
> IOException
> > {
> > byte[] buf = new byte[BUFFER_SIZE];
> > while (true) {
> > int tam = is.read(buf);
> > if (tam == -1) {
> > return;
> > }
> > os.write(buf, 0, tam);
> > }
> > }
> >  public static  byte[] bytes(InputStream is) throws IOException {
> > ByteArrayOutputStream out = new ByteArrayOutputStream();
> > copy(is, out);
> > return out.toByteArray();
> > }
> >  private static ImageFromFolderWebResource dynamicResource;
> >  private static class ImageFromFolderWebResource extends
> > DynamicImageResource {
> >  private static final long serialVersionUID = 1L;
> >
> >  private File folder;
> >  public ImageFromFolderWebResource(File folder, String mountPoint) {
> > this.folder = folder;
> > WebApplication.get().getSharedResources().add(mountPoint, this);
> > WebApplication.get().mountSharedResource(mountPoint,
> > "org.apache.wicket.Application/"+mountPoint);
> > }
> >  @Override
> > protected byte[] getImageData() {
> > try {
> > String name = WebRequestCycle.get().getRequest().getParameter("name");
> > return bytes(new FileInputStream(new File(getFolder().getAbsolutePath() +
> > System.getProperty("file.separator")+(name))));
> > } catch (Exception e) {
> > //TODO: do this properly
> > return null;
> > }
> > }
> >
> > public File getFolder() {
> > return folder;
> > }
> > }
> >  /**
> >  * @return Folder from where images will be retrieved.
> >  */
> > protected abstract Folder getFolder();
> >  /**
> >  * @return the URL to mount the dynamic WEB resource.e.g.
> >  */
> > protected abstract String getMountPoint();
> >  public Image createImage(String id, final String imageName) {
> > if(dynamicResource == null)
> > dynamicResource = new ImageFromFolderWebResource(getFolder(),
> > getMountPoint());
> > return new Image(id) {
> >  private static final long serialVersionUID = 1L;
> >
> > @Override
> > protected void onBeforeRender() {
> > String path = WebRequestCycle.get().getRequest().getURL();
> > path = path.substring(0, path.indexOf('/'));
> > add(new AttributeModifier("src",true, new
> > Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
> > super.onBeforeRender();
> > }
> > };
> > }
> > }
> >
> > 2- Create a test page.
> >
> > import org.apache.wicket.markup.html.WebPage;
> > import org.apache.wicket.markup.html.image.Image;
> > import org.apache.wicket.util.file.Folder;
> >
> > /**
> >  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
> >  *
> >  */
> > public class TestPage extends WebPage {
> >
> > private static final MountedImageFactory IMAGE_FACTORY = new
> > MountedImageFactory() {
> >  @Override
> > protected Folder getFolder() {
> > return new Folder("C:/temp/images");
> > }
> >  @Override
> > protected String getMountPoint() {
> > return "test";
> > }
> >  };
> >  /**
> >  *
> >  */
> > public TestPage() {
> > Image img = IMAGE_FACTORY.createImage("img", "test.png");
> > add(img);
> > }
> > }
> >
> > and the HTML markup
> >
> > <html xmlns:wicket="org.apache.wicket">
> > <head></head>
> > <body>
> >    <img wicket:id="img" alt="Test"/>
> > </body>
> > </html>
> >
> > 3- If you place a "test.png" on your "C:/temp/images" then you should be
> > able to see the image when you hit the page.
> >
> > Hope you can adapt this to your needs?
> >
> > Regards,
> >
> > Ernesto
> >
> > 2010/1/27 François Meillet <fm...@meillet.com>
> >
> > > Thank for yours posts.
> > > I try the solutions, but  I can't figure out how to serve images as
> > static
> > > images.
> > > F.
> > >
> > > Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
> > >
> > > > On 01/27/10 15:57, Jonas wrote:
> > > >> Have you tried the following:
> > > >>
> > > >> WebComponent image = new WebComponent("someWicketId");
> > > >> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
> > > >> add(image);
> > > >>
> > > >> with markup
> > > >>
> > > >> <img wicket:id="someWicketId" />
> > > >>
> > > >>
> > > >> that should work just fine...
> > > >>
> > > >> if you cannot hardcode the image url, you can use the following
> > > >> instead of SimpleAttributeModifier
> > > >> image.add(new AttributeModifier("src", true new
> > > >> AbstractReadOnlyModel<String>() {
> > > >>     public String getObject() {
> > > >>         String url = ... (fetch the image url from anywhere else)
> > > >>         // e.g. '/xxx/yyyy/image893748.png'
> > > >>         return url;
> > > >>     }
> > > >> ));
> > > >
> > > > Or, maybe a bit nicer, encapsulate it into a component and let the
> URI
> > > come from a Model, as usual in Wicket:
> > > >
> > > > class ExternalImageUri
> > > > extends WebComponent
> > > > {
> > > >       public ExternalImageUri(String id, IModel<String> uri)
> > > >       {
> > > >               super(id, uri);
> > > >               add(new AttributeModifier("src", true, uri));
> > > >       }
> > > >
> > > >       @Override
> > > >       protected void onComponentTag(ComponentTag tag)
> > > >       {
> > > >               super.onComponentTag(tag);
> > > >               checkComponentTag(tag, "img");
> > > >       }
> > > > }
> > > >
> > > >
> > > > This in the Wiki at
> > > http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
> > > >
> > > >
> > > > -- Thomas
> > > >
> > > >
> > > >> 2010/1/27 François Meillet<fm...@meillet.com>:
> > > >>> Hi Wicketers,
> > > >>>
> > > >>> I have a directory, /xxx/images with uploaded images, which is not
> > > under the application context root directory.
> > > >>> How can I serve them as static images ?
> > > >>>
> > > >>> I tried the StaticImage class I found in the forum (
> > > http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
> > > >>> but it doesn't work for me. It just work if the image files are
> under
> > > the context root directory.
> > > >>>
> > > >>> Thanks for your help.
> > > >>>
> > > >>> François
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> ---------------------------------------------------------------------
> > > >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > >>> For additional commands, e-mail: users-help@wicket.apache.org
> > > >>>
> > > >>>
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > >> For additional commands, e-mail: users-help@wicket.apache.org
> > > >>
> > > >
> > > >
> > > > --
> > > > -------------------------------------------------------------------
> > > >  Thomas Kappler                        thomas.kappler@isb-sib.ch
> > > >  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
> > > >  CMU, rue Michel Servet 1
> > > >  1211 Geneve 4
> > > >  Switzerland                              http://www.uniprot.org
> > > > -------------------------------------------------------------------
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > For additional commands, e-mail: users-help@wicket.apache.org
> > > >
> > >
> > > François Meillet
> > > fmtdc@meillet.com
> > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
>

Re: images not under the context root directory

Posted by Riyad Kalla <rk...@gmail.com>.
This seems like adding a large amount of overhead to an image-heavy site
(e.g. image blog or something), I thought I read in Wicket in Action that
WicketFilter ignored HTTP requests for non-wicket resources now and passed
them through to the underlying server to handle avoiding the need to remap
your wicket URLs to something like /app/* so you could have /images and
other resources under root and not have them go through the filter.

Is this not the case?

On Wed, Jan 27, 2010 at 1:38 PM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> Hi Francois,
>
> Following example works.....
>
> 1-Create this class anywhere you want need.
>
> package com.antilia.demo.manager.img;
>
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
>
> import org.apache.wicket.AttributeModifier;
> import org.apache.wicket.markup.html.image.Image;
> import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.protocol.http.WebApplication;
> import org.apache.wicket.protocol.http.WebRequestCycle;
> import org.apache.wicket.util.file.Folder;
>
> /**
>  *
>  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>  *
>  */
> public abstract class MountedImageFactory {
>
>
> static int BUFFER_SIZE = 10*1024;
>  /**
>     * Copies one stream into the other..
>  * @param is source Stream
>  * @param os destination Stream
>  * */
> static public void copy(InputStream is, OutputStream os) throws IOException
> {
> byte[] buf = new byte[BUFFER_SIZE];
> while (true) {
> int tam = is.read(buf);
> if (tam == -1) {
> return;
> }
> os.write(buf, 0, tam);
> }
> }
>  public static  byte[] bytes(InputStream is) throws IOException {
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> copy(is, out);
> return out.toByteArray();
> }
>  private static ImageFromFolderWebResource dynamicResource;
>  private static class ImageFromFolderWebResource extends
> DynamicImageResource {
>  private static final long serialVersionUID = 1L;
>
>  private File folder;
>  public ImageFromFolderWebResource(File folder, String mountPoint) {
> this.folder = folder;
> WebApplication.get().getSharedResources().add(mountPoint, this);
> WebApplication.get().mountSharedResource(mountPoint,
> "org.apache.wicket.Application/"+mountPoint);
> }
>  @Override
> protected byte[] getImageData() {
> try {
> String name = WebRequestCycle.get().getRequest().getParameter("name");
> return bytes(new FileInputStream(new File(getFolder().getAbsolutePath() +
> System.getProperty("file.separator")+(name))));
> } catch (Exception e) {
> //TODO: do this properly
> return null;
> }
> }
>
> public File getFolder() {
> return folder;
> }
> }
>  /**
>  * @return Folder from where images will be retrieved.
>  */
> protected abstract Folder getFolder();
>  /**
>  * @return the URL to mount the dynamic WEB resource.e.g.
>  */
> protected abstract String getMountPoint();
>  public Image createImage(String id, final String imageName) {
> if(dynamicResource == null)
> dynamicResource = new ImageFromFolderWebResource(getFolder(),
> getMountPoint());
> return new Image(id) {
>  private static final long serialVersionUID = 1L;
>
> @Override
> protected void onBeforeRender() {
> String path = WebRequestCycle.get().getRequest().getURL();
> path = path.substring(0, path.indexOf('/'));
> add(new AttributeModifier("src",true, new
> Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
> super.onBeforeRender();
> }
> };
> }
> }
>
> 2- Create a test page.
>
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.image.Image;
> import org.apache.wicket.util.file.Folder;
>
> /**
>  * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
>  *
>  */
> public class TestPage extends WebPage {
>
> private static final MountedImageFactory IMAGE_FACTORY = new
> MountedImageFactory() {
>  @Override
> protected Folder getFolder() {
> return new Folder("C:/temp/images");
> }
>  @Override
> protected String getMountPoint() {
> return "test";
> }
>  };
>  /**
>  *
>  */
> public TestPage() {
> Image img = IMAGE_FACTORY.createImage("img", "test.png");
> add(img);
> }
> }
>
> and the HTML markup
>
> <html xmlns:wicket="org.apache.wicket">
> <head></head>
> <body>
>    <img wicket:id="img" alt="Test"/>
> </body>
> </html>
>
> 3- If you place a "test.png" on your "C:/temp/images" then you should be
> able to see the image when you hit the page.
>
> Hope you can adapt this to your needs?
>
> Regards,
>
> Ernesto
>
> 2010/1/27 François Meillet <fm...@meillet.com>
>
> > Thank for yours posts.
> > I try the solutions, but  I can't figure out how to serve images as
> static
> > images.
> > F.
> >
> > Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
> >
> > > On 01/27/10 15:57, Jonas wrote:
> > >> Have you tried the following:
> > >>
> > >> WebComponent image = new WebComponent("someWicketId");
> > >> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
> > >> add(image);
> > >>
> > >> with markup
> > >>
> > >> <img wicket:id="someWicketId" />
> > >>
> > >>
> > >> that should work just fine...
> > >>
> > >> if you cannot hardcode the image url, you can use the following
> > >> instead of SimpleAttributeModifier
> > >> image.add(new AttributeModifier("src", true new
> > >> AbstractReadOnlyModel<String>() {
> > >>     public String getObject() {
> > >>         String url = ... (fetch the image url from anywhere else)
> > >>         // e.g. '/xxx/yyyy/image893748.png'
> > >>         return url;
> > >>     }
> > >> ));
> > >
> > > Or, maybe a bit nicer, encapsulate it into a component and let the URI
> > come from a Model, as usual in Wicket:
> > >
> > > class ExternalImageUri
> > > extends WebComponent
> > > {
> > >       public ExternalImageUri(String id, IModel<String> uri)
> > >       {
> > >               super(id, uri);
> > >               add(new AttributeModifier("src", true, uri));
> > >       }
> > >
> > >       @Override
> > >       protected void onComponentTag(ComponentTag tag)
> > >       {
> > >               super.onComponentTag(tag);
> > >               checkComponentTag(tag, "img");
> > >       }
> > > }
> > >
> > >
> > > This in the Wiki at
> > http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
> > >
> > >
> > > -- Thomas
> > >
> > >
> > >> 2010/1/27 François Meillet<fm...@meillet.com>:
> > >>> Hi Wicketers,
> > >>>
> > >>> I have a directory, /xxx/images with uploaded images, which is not
> > under the application context root directory.
> > >>> How can I serve them as static images ?
> > >>>
> > >>> I tried the StaticImage class I found in the forum (
> > http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
> > >>> but it doesn't work for me. It just work if the image files are under
> > the context root directory.
> > >>>
> > >>> Thanks for your help.
> > >>>
> > >>> François
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> ---------------------------------------------------------------------
> > >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > >>> For additional commands, e-mail: users-help@wicket.apache.org
> > >>>
> > >>>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > >> For additional commands, e-mail: users-help@wicket.apache.org
> > >>
> > >
> > >
> > > --
> > > -------------------------------------------------------------------
> > >  Thomas Kappler                        thomas.kappler@isb-sib.ch
> > >  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
> > >  CMU, rue Michel Servet 1
> > >  1211 Geneve 4
> > >  Switzerland                              http://www.uniprot.org
> > > -------------------------------------------------------------------
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> >
> > François Meillet
> > fmtdc@meillet.com
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>

Re: images not under the context root directory

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi Francois,

Following example works.....

1-Create this class anywhere you want need.

package com.antilia.demo.manager.img;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequestCycle;
import org.apache.wicket.util.file.Folder;

/**
 *
 * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
 *
 */
public abstract class MountedImageFactory {


static int BUFFER_SIZE = 10*1024;
 /**
     * Copies one stream into the other..
 * @param is source Stream
 * @param os destination Stream
 * */
static public void copy(InputStream is, OutputStream os) throws IOException
{
byte[] buf = new byte[BUFFER_SIZE];
while (true) {
int tam = is.read(buf);
if (tam == -1) {
return;
}
os.write(buf, 0, tam);
}
}
 public static  byte[] bytes(InputStream is) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(is, out);
return out.toByteArray();
}
 private static ImageFromFolderWebResource dynamicResource;
 private static class ImageFromFolderWebResource extends
DynamicImageResource {
 private static final long serialVersionUID = 1L;

 private File folder;
 public ImageFromFolderWebResource(File folder, String mountPoint) {
this.folder = folder;
WebApplication.get().getSharedResources().add(mountPoint, this);
WebApplication.get().mountSharedResource(mountPoint,
"org.apache.wicket.Application/"+mountPoint);
}
 @Override
protected byte[] getImageData() {
try {
String name = WebRequestCycle.get().getRequest().getParameter("name");
return bytes(new FileInputStream(new File(getFolder().getAbsolutePath() +
System.getProperty("file.separator")+(name))));
} catch (Exception e) {
//TODO: do this properly
return null;
}
}

public File getFolder() {
return folder;
}
}
 /**
 * @return Folder from where images will be retrieved.
 */
protected abstract Folder getFolder();
 /**
 * @return the URL to mount the dynamic WEB resource.e.g.
 */
protected abstract String getMountPoint();
 public Image createImage(String id, final String imageName) {
if(dynamicResource == null)
dynamicResource = new ImageFromFolderWebResource(getFolder(),
getMountPoint());
return new Image(id) {
 private static final long serialVersionUID = 1L;

@Override
protected void onBeforeRender() {
String path = WebRequestCycle.get().getRequest().getURL();
path = path.substring(0, path.indexOf('/'));
add(new AttributeModifier("src",true, new
Model<String>("/"+path+"/"+getMountPoint()+"?name="+imageName)));
super.onBeforeRender();
}
};
}
}

2- Create a test page.

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.util.file.Folder;

/**
 * @author  Ernesto Reinaldo Barreiro (reiern70@gmail.com)
 *
 */
public class TestPage extends WebPage {

private static final MountedImageFactory IMAGE_FACTORY = new
MountedImageFactory() {
 @Override
protected Folder getFolder() {
return new Folder("C:/temp/images");
}
 @Override
protected String getMountPoint() {
return "test";
}
 };
 /**
 *
 */
public TestPage() {
Image img = IMAGE_FACTORY.createImage("img", "test.png");
add(img);
}
}

and the HTML markup

<html xmlns:wicket="org.apache.wicket">
<head></head>
<body>
    <img wicket:id="img" alt="Test"/>
</body>
</html>

3- If you place a "test.png" on your "C:/temp/images" then you should be
able to see the image when you hit the page.

Hope you can adapt this to your needs?

Regards,

Ernesto

2010/1/27 François Meillet <fm...@meillet.com>

> Thank for yours posts.
> I try the solutions, but  I can't figure out how to serve images as static
> images.
> F.
>
> Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :
>
> > On 01/27/10 15:57, Jonas wrote:
> >> Have you tried the following:
> >>
> >> WebComponent image = new WebComponent("someWicketId");
> >> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
> >> add(image);
> >>
> >> with markup
> >>
> >> <img wicket:id="someWicketId" />
> >>
> >>
> >> that should work just fine...
> >>
> >> if you cannot hardcode the image url, you can use the following
> >> instead of SimpleAttributeModifier
> >> image.add(new AttributeModifier("src", true new
> >> AbstractReadOnlyModel<String>() {
> >>     public String getObject() {
> >>         String url = ... (fetch the image url from anywhere else)
> >>         // e.g. '/xxx/yyyy/image893748.png'
> >>         return url;
> >>     }
> >> ));
> >
> > Or, maybe a bit nicer, encapsulate it into a component and let the URI
> come from a Model, as usual in Wicket:
> >
> > class ExternalImageUri
> > extends WebComponent
> > {
> >       public ExternalImageUri(String id, IModel<String> uri)
> >       {
> >               super(id, uri);
> >               add(new AttributeModifier("src", true, uri));
> >       }
> >
> >       @Override
> >       protected void onComponentTag(ComponentTag tag)
> >       {
> >               super.onComponentTag(tag);
> >               checkComponentTag(tag, "img");
> >       }
> > }
> >
> >
> > This in the Wiki at
> http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
> >
> >
> > -- Thomas
> >
> >
> >> 2010/1/27 François Meillet<fm...@meillet.com>:
> >>> Hi Wicketers,
> >>>
> >>> I have a directory, /xxx/images with uploaded images, which is not
> under the application context root directory.
> >>> How can I serve them as static images ?
> >>>
> >>> I tried the StaticImage class I found in the forum (
> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
> >>> but it doesn't work for me. It just work if the image files are under
> the context root directory.
> >>>
> >>> Thanks for your help.
> >>>
> >>> François
> >>>
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >
> >
> > --
> > -------------------------------------------------------------------
> >  Thomas Kappler                        thomas.kappler@isb-sib.ch
> >  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
> >  CMU, rue Michel Servet 1
> >  1211 Geneve 4
> >  Switzerland                              http://www.uniprot.org
> > -------------------------------------------------------------------
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
>
> François Meillet
> fmtdc@meillet.com
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: images not under the context root directory

Posted by François Meillet <fm...@meillet.com>.
Thank for yours posts.
I try the solutions, but  I can't figure out how to serve images as static images.
F.

Le 27 janv. 2010 à 16:10, Thomas Kappler a écrit :

> On 01/27/10 15:57, Jonas wrote:
>> Have you tried the following:
>> 
>> WebComponent image = new WebComponent("someWicketId");
>> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
>> add(image);
>> 
>> with markup
>> 
>> <img wicket:id="someWicketId" />
>> 
>> 
>> that should work just fine...
>> 
>> if you cannot hardcode the image url, you can use the following
>> instead of SimpleAttributeModifier
>> image.add(new AttributeModifier("src", true new
>> AbstractReadOnlyModel<String>() {
>>     public String getObject() {
>>         String url = ... (fetch the image url from anywhere else)
>>         // e.g. '/xxx/yyyy/image893748.png'
>>         return url;
>>     }
>> ));
> 
> Or, maybe a bit nicer, encapsulate it into a component and let the URI come from a Model, as usual in Wicket:
> 
> class ExternalImageUri
> extends WebComponent
> {
> 	public ExternalImageUri(String id, IModel<String> uri)
> 	{
> 		super(id, uri);
> 		add(new AttributeModifier("src", true, uri));
> 	}
> 		
> 	@Override
> 	protected void onComponentTag(ComponentTag tag)
> 	{
> 		super.onComponentTag(tag);
> 		checkComponentTag(tag, "img");
> 	}
> }
> 
> 
> This in the Wiki at http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.
> 
> 
> -- Thomas
> 
> 
>> 2010/1/27 François Meillet<fm...@meillet.com>:
>>> Hi Wicketers,
>>> 
>>> I have a directory, /xxx/images with uploaded images, which is not under the application context root directory.
>>> How can I serve them as static images ?
>>> 
>>> I tried the StaticImage class I found in the forum (http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
>>> but it doesn't work for me. It just work if the image files are under the context root directory.
>>> 
>>> Thanks for your help.
>>> 
>>> François
>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> 
> -- 
> -------------------------------------------------------------------
>  Thomas Kappler                        thomas.kappler@isb-sib.ch
>  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
>  CMU, rue Michel Servet 1
>  1211 Geneve 4
>  Switzerland                              http://www.uniprot.org
> -------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

François Meillet
fmtdc@meillet.com




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


Re: images not under the context root directory

Posted by Thomas Kappler <th...@isb-sib.ch>.
On 01/27/10 15:57, Jonas wrote:
> Have you tried the following:
>
> WebComponent image = new WebComponent("someWicketId");
> image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
> add(image);
>
> with markup
>
> <img wicket:id="someWicketId" />
>
>
> that should work just fine...
>
> if you cannot hardcode the image url, you can use the following
> instead of SimpleAttributeModifier
> image.add(new AttributeModifier("src", true new
> AbstractReadOnlyModel<String>() {
>      public String getObject() {
>          String url = ... (fetch the image url from anywhere else)
>          // e.g. '/xxx/yyyy/image893748.png'
>          return url;
>      }
> ));

Or, maybe a bit nicer, encapsulate it into a component and let the URI 
come from a Model, as usual in Wicket:

class ExternalImageUri
extends WebComponent
{
	public ExternalImageUri(String id, IModel<String> uri)
	{
		super(id, uri);
		add(new AttributeModifier("src", true, uri));
	}
		
	@Override
	protected void onComponentTag(ComponentTag tag)
	{
		super.onComponentTag(tag);
		checkComponentTag(tag, "img");
	}
}


This in the Wiki at 
http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html.


-- Thomas


> 2010/1/27 François Meillet<fm...@meillet.com>:
>> Hi Wicketers,
>>
>> I have a directory, /xxx/images with uploaded images, which is not under the application context root directory.
>> How can I serve them as static images ?
>>
>> I tried the StaticImage class I found in the forum (http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
>> but it doesn't work for me. It just work if the image files are under the context root directory.
>>
>> Thanks for your help.
>>
>> François
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


-- 
-------------------------------------------------------------------
   Thomas Kappler                        thomas.kappler@isb-sib.ch
   Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
   CMU, rue Michel Servet 1
   1211 Geneve 4
   Switzerland                              http://www.uniprot.org
-------------------------------------------------------------------

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


Re: images not under the context root directory

Posted by Jonas <ba...@gmail.com>.
Have you tried the following:

WebComponent image = new WebComponent("someWicketId");
image.add(new SimpleAttributeModifier("src", "http://.....jpg"));
add(image);

with markup

<img wicket:id="someWicketId" />


that should work just fine...

if you cannot hardcode the image url, you can use the following
instead of SimpleAttributeModifier
image.add(new AttributeModifier("src", true new
AbstractReadOnlyModel<String>() {
    public String getObject() {
        String url = ... (fetch the image url from anywhere else)
        // e.g. '/xxx/yyyy/image893748.png'
        return url;
    }
));



2010/1/27 François Meillet <fm...@meillet.com>:
> Hi Wicketers,
>
> I have a directory, /xxx/images with uploaded images, which is not under the application context root directory.
> How can I serve them as static images ?
>
> I tried the StaticImage class I found in the forum (http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
> but it doesn't work for me. It just work if the image files are under the context root directory.
>
> Thanks for your help.
>
> François
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: images not under the context root directory

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
nice trick with the alias... was what I intended to say.

On Wed, Jan 27, 2010 at 4:00 PM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> this trick with the alias... I has done it mounting a dynamic WebResource
> and streaming back the contents myself. Like in here
>
>
> http://code.google.com/p/antilia/source/browse/trunk/com.antilia.demo.manager/src/com/antilia/demo/manager/img/MyImageMountedFactory.java
>
> Best,
>
> Ernesto
>
>
>
>
>
>
>
> On Wed, Jan 27, 2010 at 3:45 PM, Don Ferguson <do...@gmail.com>wrote:
>
>> I used this suggestion to serve images out of a database, and it worked
>> very well:
>>
>>
>> http://dotev.blogspot.com/2009/11/serving-images-and-other-resources-with.html
>>
>>
>>
>> On Jan 27, 2010, at 5:56 AM, Ernesto Reinaldo Barreiro wrote:
>>
>>  Just a couple of ideas...
>>>
>>> -Use a servlet to serve them? You don´t need Wicket for this... and
>>> combine
>>> this with simpleimage?
>>> -With Wicket mount a dynamic web-resource and combine this with
>>> simpleimage?
>>>
>>>
>>> Ernesto
>>>
>>> 2010/1/27 François Meillet <fm...@meillet.com>
>>>
>>>  Hi Wicketers,
>>>>
>>>> I have a directory, /xxx/images with uploaded images, which is not under
>>>> the application context root directory.
>>>> How can I serve them as static images ?
>>>>
>>>> I tried the StaticImage class I found in the forum (
>>>> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
>>>> but it doesn't work for me. It just work if the image files are under
>>>> the
>>>> context root directory.
>>>>
>>>> Thanks for your help.
>>>>
>>>> François
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

Re: images not under the context root directory

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
this trick with the alias... I has done it mounting a dynamic WebResource
and streaming back the contents myself. Like in here

http://code.google.com/p/antilia/source/browse/trunk/com.antilia.demo.manager/src/com/antilia/demo/manager/img/MyImageMountedFactory.java

Best,

Ernesto






On Wed, Jan 27, 2010 at 3:45 PM, Don Ferguson <do...@gmail.com>wrote:

> I used this suggestion to serve images out of a database, and it worked
> very well:
>
>
> http://dotev.blogspot.com/2009/11/serving-images-and-other-resources-with.html
>
>
>
> On Jan 27, 2010, at 5:56 AM, Ernesto Reinaldo Barreiro wrote:
>
>  Just a couple of ideas...
>>
>> -Use a servlet to serve them? You don´t need Wicket for this... and
>> combine
>> this with simpleimage?
>> -With Wicket mount a dynamic web-resource and combine this with
>> simpleimage?
>>
>>
>> Ernesto
>>
>> 2010/1/27 François Meillet <fm...@meillet.com>
>>
>>  Hi Wicketers,
>>>
>>> I have a directory, /xxx/images with uploaded images, which is not under
>>> the application context root directory.
>>> How can I serve them as static images ?
>>>
>>> I tried the StaticImage class I found in the forum (
>>> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
>>> but it doesn't work for me. It just work if the image files are under the
>>> context root directory.
>>>
>>> Thanks for your help.
>>>
>>> François
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: images not under the context root directory

Posted by Don Ferguson <do...@gmail.com>.
I used this suggestion to serve images out of a database, and it  
worked very well:

http://dotev.blogspot.com/2009/11/serving-images-and-other-resources-with.html


On Jan 27, 2010, at 5:56 AM, Ernesto Reinaldo Barreiro wrote:

> Just a couple of ideas...
>
> -Use a servlet to serve them? You don´t need Wicket for this... and  
> combine
> this with simpleimage?
> -With Wicket mount a dynamic web-resource and combine this with  
> simpleimage?
>
>
> Ernesto
>
> 2010/1/27 François Meillet <fm...@meillet.com>
>
>> Hi Wicketers,
>>
>> I have a directory, /xxx/images with uploaded images, which is not  
>> under
>> the application context root directory.
>> How can I serve them as static images ?
>>
>> I tried the StaticImage class I found in the forum (
>> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
>> but it doesn't work for me. It just work if the image files are  
>> under the
>> context root directory.
>>
>> Thanks for your help.
>>
>> François
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>


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


Re: images not under the context root directory

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Just a couple of ideas...

-Use a servlet to serve them? You don´t need Wicket for this... and combine
this with simpleimage?
-With Wicket mount a dynamic web-resource and combine this with simpleimage?


Ernesto

2010/1/27 François Meillet <fm...@meillet.com>

> Hi Wicketers,
>
> I have a directory, /xxx/images with uploaded images, which is not under
> the application context root directory.
> How can I serve them as static images ?
>
> I tried the StaticImage class I found in the forum (
> http://old.nabble.com/Plain-IMG-src-urls-td21547371.html#a21547543 )
> but it doesn't work for me. It just work if the image files are under the
> context root directory.
>
> Thanks for your help.
>
> François
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>