You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Kanze <pe...@gmail.com> on 2009/03/10 13:42:11 UTC

T5: How to load image Asset from filesystem?

Hello

I want to load images from the filesystem, like for example
D:/category/1/products/55/thumb.jpg

So the file path is dynamic and is based on the categoryId and the
productId.

How can I load such an image into my webpage using a Tapestry Asset?
This looks like a common usecase to me, but I couldn't find any info about
it.

Has somebody already done this? And could he/she show me some code examples?
Any help is welcome!

Thanks,
Peter

Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
Hi Daniel,

Currently I load my (user uploaded) images using a StreamResponse as you
explained.

The pictures are shown in my webpage, but for every loaded picture the
onActivate is called.
With a result list of 15 rows per page, this is 16 times. In my onActivate I
also call my doSearch method.

So this behaviour is not what I want. Is there a way to solve this problem?

Thanks!
Peter

On Fri, Mar 13, 2009 at 3:42 AM, Daniel Jones <da...@murieston.com> wrote:

>
> Hi Peter,
>
> I'm using nabble to post and it seems to have stripped out the img tag.
>
> you need an img tag in your template and set the src attribute to
> ${imagePath}
>
> img src="${imagePath}"
>
> Hope this helps,
> Daniel
>
>
> Peter Kanze wrote:
> >
> > Hi Daniel,
> >
> > Thanks for your example. I tried this one, but the Object onImage is
> never
> > called when the page loads.
> > I am using Tapestry 5.1. The code is equal to your example.
> >
> > What could I do wrong?
> >
> > regards,
> > Peter
> >
> > On Thu, Mar 12, 2009 at 10:54 AM, Daniel Jones <da...@murieston.com>
> wrote:
> >
> >>
> >> PAGE CLASS
> >>
> >> inject component resources so that you can create an action link
> >>    @Inject
> >>    private ComponentResources mComponentResources;
> >>
> >> when the path is requested by the template, create and return an action
> >> link
> >>        public Link getImagePath() {
> >>                return mComponentResources.createActionLink("image",
> >> false,
> >> mItem.getID());
> >>        }
> >>
> >> handle this action link
> >>        public Object onImage(long pID) {
> >> "StreamResponseBuilder" is a class that I have implemented, it basically
> >> figures out what image to served based on
> >> the id passed in the context and then gets an "InputStream" for the
> image
> >> file on disk and creates and returns a "StreamResponse", so essentially
> >> you
> >> want this action handler to return a "StreamResponse" of the image you
> >> want
> >> to display.
> >>                return StreamResponseBuilder.getItemImage(pID);
> >>        }
> >>
> >> PAGE TEMPLATE
> >>
> >> ${imagePath}
> >>
> >> Hope this helps
> >> Regards,
> >> Daniel
> >>
> >>
> >>
> >> Peter Kanze wrote:
> >> >
> >> > Hello
> >> >
> >> > I want to load images from the filesystem, like for example
> >> > D:/category/1/products/55/thumb.jpg
> >> >
> >> > So the file path is dynamic and is based on the categoryId and the
> >> > productId.
> >> >
> >> > How can I load such an image into my webpage using a Tapestry Asset?
> >> > This looks like a common usecase to me, but I couldn't find any info
> >> about
> >> > it.
> >> >
> >> > Has somebody already done this? And could he/she show me some code
> >> > examples?
> >> > Any help is welcome!
> >> >
> >> > Thanks,
> >> > Peter
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22471474.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22489180.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by Daniel Jones <da...@murieston.com>.
Thanks for pointing that out Luther.  I copied it from a project using an
older version of tapestry.


luther.baker wrote:
> 
> Great example - similar to an example on the Wiki ...
> 
> Note that 'createActionLink' was deprecated ...
> 
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/ComponentResources.html#createActionLink(java.lang.String,%20boolean,%20java.lang.Object..
> .)
> 
> *Deprecated.* *Use createEventLink(String,
> Object[])<http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/ComponentResources.html#createEventLink%28java.lang.String,%20java.lang.Object...%29>instead
> *
> -Luther
> 
> 
> 
> On Thu, Mar 12, 2009 at 9:42 PM, Daniel Jones <da...@murieston.com> wrote:
> 
>>
>> Hi Peter,
>>
>> I'm using nabble to post and it seems to have stripped out the img tag.
>>
>> you need an img tag in your template and set the src attribute to
>> ${imagePath}
>>
>> img src="${imagePath}"
>>
>> Hope this helps,
>> Daniel
>>
>>
>> Peter Kanze wrote:
>> >
>> > Hi Daniel,
>> >
>> > Thanks for your example. I tried this one, but the Object onImage is
>> never
>> > called when the page loads.
>> > I am using Tapestry 5.1. The code is equal to your example.
>> >
>> > What could I do wrong?
>> >
>> > regards,
>> > Peter
>> >
>> > On Thu, Mar 12, 2009 at 10:54 AM, Daniel Jones <da...@murieston.com>
>> wrote:
>> >
>> >>
>> >> PAGE CLASS
>> >>
>> >> inject component resources so that you can create an action link
>> >>    @Inject
>> >>    private ComponentResources mComponentResources;
>> >>
>> >> when the path is requested by the template, create and return an
>> action
>> >> link
>> >>        public Link getImagePath() {
>> >>                return mComponentResources.createActionLink("image",
>> >> false,
>> >> mItem.getID());
>> >>        }
>> >>
>> >> handle this action link
>> >>        public Object onImage(long pID) {
>> >> "StreamResponseBuilder" is a class that I have implemented, it
>> basically
>> >> figures out what image to served based on
>> >> the id passed in the context and then gets an "InputStream" for the
>> image
>> >> file on disk and creates and returns a "StreamResponse", so
>> essentially
>> >> you
>> >> want this action handler to return a "StreamResponse" of the image you
>> >> want
>> >> to display.
>> >>                return StreamResponseBuilder.getItemImage(pID);
>> >>        }
>> >>
>> >> PAGE TEMPLATE
>> >>
>> >> ${imagePath}
>> >>
>> >> Hope this helps
>> >> Regards,
>> >> Daniel
>> >>
>> >>
>> >>
>> >> Peter Kanze wrote:
>> >> >
>> >> > Hello
>> >> >
>> >> > I want to load images from the filesystem, like for example
>> >> > D:/category/1/products/55/thumb.jpg
>> >> >
>> >> > So the file path is dynamic and is based on the categoryId and the
>> >> > productId.
>> >> >
>> >> > How can I load such an image into my webpage using a Tapestry Asset?
>> >> > This looks like a common usecase to me, but I couldn't find any info
>> >> about
>> >> > it.
>> >> >
>> >> > Has somebody already done this? And could he/she show me some code
>> >> > examples?
>> >> > Any help is welcome!
>> >> >
>> >> > Thanks,
>> >> > Peter
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22471474.html
>> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22489180.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22501228.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to load image Asset from filesystem?

Posted by Luther Baker <lu...@gmail.com>.
Great example - similar to an example on the Wiki ...

Note that 'createActionLink' was deprecated ...

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/ComponentResources.html#createActionLink(java.lang.String,%20boolean,%20java.lang.Object..
.)

*Deprecated.* *Use createEventLink(String,
Object[])<http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/ComponentResources.html#createEventLink%28java.lang.String,%20java.lang.Object...%29>instead
*
-Luther



On Thu, Mar 12, 2009 at 9:42 PM, Daniel Jones <da...@murieston.com> wrote:

>
> Hi Peter,
>
> I'm using nabble to post and it seems to have stripped out the img tag.
>
> you need an img tag in your template and set the src attribute to
> ${imagePath}
>
> img src="${imagePath}"
>
> Hope this helps,
> Daniel
>
>
> Peter Kanze wrote:
> >
> > Hi Daniel,
> >
> > Thanks for your example. I tried this one, but the Object onImage is
> never
> > called when the page loads.
> > I am using Tapestry 5.1. The code is equal to your example.
> >
> > What could I do wrong?
> >
> > regards,
> > Peter
> >
> > On Thu, Mar 12, 2009 at 10:54 AM, Daniel Jones <da...@murieston.com>
> wrote:
> >
> >>
> >> PAGE CLASS
> >>
> >> inject component resources so that you can create an action link
> >>    @Inject
> >>    private ComponentResources mComponentResources;
> >>
> >> when the path is requested by the template, create and return an action
> >> link
> >>        public Link getImagePath() {
> >>                return mComponentResources.createActionLink("image",
> >> false,
> >> mItem.getID());
> >>        }
> >>
> >> handle this action link
> >>        public Object onImage(long pID) {
> >> "StreamResponseBuilder" is a class that I have implemented, it basically
> >> figures out what image to served based on
> >> the id passed in the context and then gets an "InputStream" for the
> image
> >> file on disk and creates and returns a "StreamResponse", so essentially
> >> you
> >> want this action handler to return a "StreamResponse" of the image you
> >> want
> >> to display.
> >>                return StreamResponseBuilder.getItemImage(pID);
> >>        }
> >>
> >> PAGE TEMPLATE
> >>
> >> ${imagePath}
> >>
> >> Hope this helps
> >> Regards,
> >> Daniel
> >>
> >>
> >>
> >> Peter Kanze wrote:
> >> >
> >> > Hello
> >> >
> >> > I want to load images from the filesystem, like for example
> >> > D:/category/1/products/55/thumb.jpg
> >> >
> >> > So the file path is dynamic and is based on the categoryId and the
> >> > productId.
> >> >
> >> > How can I load such an image into my webpage using a Tapestry Asset?
> >> > This looks like a common usecase to me, but I couldn't find any info
> >> about
> >> > it.
> >> >
> >> > Has somebody already done this? And could he/she show me some code
> >> > examples?
> >> > Any help is welcome!
> >> >
> >> > Thanks,
> >> > Peter
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22471474.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22489180.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by Daniel Jones <da...@murieston.com>.
Hi Peter,

I'm using nabble to post and it seems to have stripped out the img tag.

you need an img tag in your template and set the src attribute to
${imagePath}

img src="${imagePath}"

Hope this helps,
Daniel


Peter Kanze wrote:
> 
> Hi Daniel,
> 
> Thanks for your example. I tried this one, but the Object onImage is never
> called when the page loads.
> I am using Tapestry 5.1. The code is equal to your example.
> 
> What could I do wrong?
> 
> regards,
> Peter
> 
> On Thu, Mar 12, 2009 at 10:54 AM, Daniel Jones <da...@murieston.com> wrote:
> 
>>
>> PAGE CLASS
>>
>> inject component resources so that you can create an action link
>>    @Inject
>>    private ComponentResources mComponentResources;
>>
>> when the path is requested by the template, create and return an action
>> link
>>        public Link getImagePath() {
>>                return mComponentResources.createActionLink("image",
>> false,
>> mItem.getID());
>>        }
>>
>> handle this action link
>>        public Object onImage(long pID) {
>> "StreamResponseBuilder" is a class that I have implemented, it basically
>> figures out what image to served based on
>> the id passed in the context and then gets an "InputStream" for the image
>> file on disk and creates and returns a "StreamResponse", so essentially
>> you
>> want this action handler to return a "StreamResponse" of the image you
>> want
>> to display.
>>                return StreamResponseBuilder.getItemImage(pID);
>>        }
>>
>> PAGE TEMPLATE
>>
>> ${imagePath}
>>
>> Hope this helps
>> Regards,
>> Daniel
>>
>>
>>
>> Peter Kanze wrote:
>> >
>> > Hello
>> >
>> > I want to load images from the filesystem, like for example
>> > D:/category/1/products/55/thumb.jpg
>> >
>> > So the file path is dynamic and is based on the categoryId and the
>> > productId.
>> >
>> > How can I load such an image into my webpage using a Tapestry Asset?
>> > This looks like a common usecase to me, but I couldn't find any info
>> about
>> > it.
>> >
>> > Has somebody already done this? And could he/she show me some code
>> > examples?
>> > Any help is welcome!
>> >
>> > Thanks,
>> > Peter
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22471474.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22489180.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
Hi Daniel,

Thanks for your example. I tried this one, but the Object onImage is never
called when the page loads.
I am using Tapestry 5.1. The code is equal to your example.

What could I do wrong?

regards,
Peter

On Thu, Mar 12, 2009 at 10:54 AM, Daniel Jones <da...@murieston.com> wrote:

>
> PAGE CLASS
>
> inject component resources so that you can create an action link
>    @Inject
>    private ComponentResources mComponentResources;
>
> when the path is requested by the template, create and return an action
> link
>        public Link getImagePath() {
>                return mComponentResources.createActionLink("image", false,
> mItem.getID());
>        }
>
> handle this action link
>        public Object onImage(long pID) {
> "StreamResponseBuilder" is a class that I have implemented, it basically
> figures out what image to served based on
> the id passed in the context and then gets an "InputStream" for the image
> file on disk and creates and returns a "StreamResponse", so essentially you
> want this action handler to return a "StreamResponse" of the image you want
> to display.
>                return StreamResponseBuilder.getItemImage(pID);
>        }
>
> PAGE TEMPLATE
>
> ${imagePath}
>
> Hope this helps
> Regards,
> Daniel
>
>
>
> Peter Kanze wrote:
> >
> > Hello
> >
> > I want to load images from the filesystem, like for example
> > D:/category/1/products/55/thumb.jpg
> >
> > So the file path is dynamic and is based on the categoryId and the
> > productId.
> >
> > How can I load such an image into my webpage using a Tapestry Asset?
> > This looks like a common usecase to me, but I couldn't find any info
> about
> > it.
> >
> > Has somebody already done this? And could he/she show me some code
> > examples?
> > Any help is welcome!
> >
> > Thanks,
> > Peter
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22471474.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
On Thu, Mar 12, 2009 at 12:05 PM, Andy Pahne <an...@googlemail.com>wrote:

>
> That one is really nice. Thanks.
>
>
> Daniel Jones schrieb:
>
>  PAGE CLASS
>>
>> inject component resources so that you can create an action link
>>    @Inject    private ComponentResources mComponentResources;
>> when the path is requested by the template, create and return an action
>> link
>>        public Link getImagePath() {
>>                return mComponentResources.createActionLink("image", false,
>> mItem.getID());
>>        }
>>
>> handle this action link
>>        public Object onImage(long pID) { "StreamResponseBuilder" is a
>> class that I have implemented, it basically
>> figures out what image to served based on
>> the id passed in the context and then gets an "InputStream" for the image
>> file on disk and creates and returns a "StreamResponse", so essentially
>> you
>> want this action handler to return a "StreamResponse" of the image you
>> want
>> to display.
>>                return StreamResponseBuilder.getItemImage(pID);
>>        }
>>
>> PAGE TEMPLATE
>>
>> ${imagePath}
>> Hope this helps
>> Regards,
>> Daniel
>>
>>
>>
>> Peter Kanze wrote:
>>
>>
>>> Hello
>>>
>>> I want to load images from the filesystem, like for example
>>> D:/category/1/products/55/thumb.jpg
>>>
>>> So the file path is dynamic and is based on the categoryId and the
>>> productId.
>>>
>>> How can I load such an image into my webpage using a Tapestry Asset?
>>> This looks like a common usecase to me, but I couldn't find any info
>>> about
>>> it.
>>>
>>> Has somebody already done this? And could he/she show me some code
>>> examples?
>>> Any help is welcome!
>>>
>>> Thanks,
>>> Peter
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by Andy Pahne <an...@googlemail.com>.
That one is really nice. Thanks.


Daniel Jones schrieb:
> PAGE CLASS
>
> inject component resources so that you can create an action link
>     @Inject 
>     private ComponentResources mComponentResources; 
>
> when the path is requested by the template, create and return an action link
> 	public Link getImagePath() {
> 		return mComponentResources.createActionLink("image", false,
> mItem.getID());
> 	}
>
> handle this action link
> 	public Object onImage(long pID) { 
> "StreamResponseBuilder" is a class that I have implemented, it basically
> figures out what image to served based on
> the id passed in the context and then gets an "InputStream" for the image
> file on disk and creates and returns a "StreamResponse", so essentially you
> want this action handler to return a "StreamResponse" of the image you want
> to display.
> 		return StreamResponseBuilder.getItemImage(pID);
> 	}
>
> PAGE TEMPLATE
>
> ${imagePath} 
>
> Hope this helps
> Regards,
> Daniel
>
>
>
> Peter Kanze wrote:
>   
>> Hello
>>
>> I want to load images from the filesystem, like for example
>> D:/category/1/products/55/thumb.jpg
>>
>> So the file path is dynamic and is based on the categoryId and the
>> productId.
>>
>> How can I load such an image into my webpage using a Tapestry Asset?
>> This looks like a common usecase to me, but I couldn't find any info about
>> it.
>>
>> Has somebody already done this? And could he/she show me some code
>> examples?
>> Any help is welcome!
>>
>> Thanks,
>> Peter
>>
>>
>>     
>
>   


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


Re: T5: How to load image Asset from filesystem?

Posted by Daniel Jones <da...@murieston.com>.
PAGE CLASS

inject component resources so that you can create an action link
    @Inject 
    private ComponentResources mComponentResources; 

when the path is requested by the template, create and return an action link
	public Link getImagePath() {
		return mComponentResources.createActionLink("image", false,
mItem.getID());
	}

handle this action link
	public Object onImage(long pID) { 
"StreamResponseBuilder" is a class that I have implemented, it basically
figures out what image to served based on
the id passed in the context and then gets an "InputStream" for the image
file on disk and creates and returns a "StreamResponse", so essentially you
want this action handler to return a "StreamResponse" of the image you want
to display.
		return StreamResponseBuilder.getItemImage(pID);
	}

PAGE TEMPLATE

${imagePath} 

Hope this helps
Regards,
Daniel



Peter Kanze wrote:
> 
> Hello
> 
> I want to load images from the filesystem, like for example
> D:/category/1/products/55/thumb.jpg
> 
> So the file path is dynamic and is based on the categoryId and the
> productId.
> 
> How can I load such an image into my webpage using a Tapestry Asset?
> This looks like a common usecase to me, but I couldn't find any info about
> it.
> 
> Has somebody already done this? And could he/she show me some code
> examples?
> Any help is welcome!
> 
> Thanks,
> Peter
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-load-image-Asset-from-filesystem--tp22433419p22471474.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to load image Asset from filesystem?

Posted by Andy Pahne <an...@googlemail.com>.
Anyway you are right: exposing the full path in the html source is 
certainly not a good idea.


Peter Kanze schrieb:
> Hi Andy,
>
> Thanks for adding this to Jira.
> See below my code what I have produced so far. The problem is that I now see
> the complete filepath in my html source (<img src="
> C:/tmp/pictures/8/71/1001/thumb1.jpg" alt=""/>)
> I don't want the complete file url in my html source. How can I fix this.
> And how do I map the html url to the file url?
> The last problem is that the file url is correct, but the image is not shown
> in my html page.
> What am I doing wrong?
>   


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


Re: T5: How to load image Asset from filesystem?

Posted by Andy Pahne <an...@googlemail.com>.

I don't know much about the details how you contribute your 
FilesystemAssetFactory. Never had time to take a briefer look at 
tapestry-ioc.

Please note: in the previous example the AssetFactory is injected like this:

@Inject @ClasspathProvider
private AssetFactory assetFactory;


The @ClasspathProvider is necessary, so that tapestry-ioc knows, which of the different implementations to inject.

Maybe, in order to make your solution work, you need to give a hint like that, too?


Andy
 









Peter Kanze schrieb:
> Hi Andy,
>
> Thanks for adding this to Jira.
> See below my code what I have produced so far. The problem is that I now see
> the complete filepath in my html source (<img src="
> C:/tmp/pictures/8/71/1001/thumb1.jpg" alt=""/>)
> I don't want the complete file url in my html source. How can I fix this.
> And how do I map the html url to the file url?
> The last problem is that the file url is correct, but the image is not shown
> in my html page.
> What am I doing wrong?
>
>
> --Quick Example Code Below---
>
> <img src="${ThumbnailPath}" alt="" />
>
> public String getThumbnailPath() {
>          Asset asset = assetSource.getAsset(null,
> "file:/8/71/1001/thumb1.jpg", null);
>          return asset.toClientURL();
> }
>
> public class FileSystemResource extends AbstractResource {
>
>     private static final int PRIME = 37;
>
>     public FileSystemResource(String path) {
>         super(path);
>     }
>
>     @Override
>     protected Resource newResource(String path) {
>         return new FileSystemResource(path);
>     }
>
>     @Override
>     public URL toURL() {
>         String filePath = getPath();
>         File file = new File(filePath);
>
>         if (file != null && file.exists()) {
>             try {
>                 return file.toURL();
>             }
>             catch (MalformedURLException ex) {
>                 throw new RuntimeException(ex);
>             }
>         }
>         return null;
>     }
> }
>
> public class FileSystemAssetFactory implements AssetFactory {
>
>     private static final String assetPath = "/images/";
>
>     public FileSystemAssetFactory() {
>
>     }
>
>    @Override
>     public Resource getRootResource() {
>         return new FileSystemResource("C:/tmp/pictures/");
>     }
>
>     @Override
>     public Asset createAsset(final Resource resource) {
>         final String filePath =  resource.getPath();
>
>         return new Asset()
>         {
>             public Resource getResource()
>             {
>                 return resource;
>             }
>
>             public String toClientURL()
>             {
>                 return filePath;
>             }
>
>             /**
>              * Returns the client URL, which is essiential to allow informal
> parameters of type
>              * Asset to generate a proper value.
>              */
>             @Override
>             public String toString()
>             {
>                 return toClientURL();
>             }
>         };
>     }
>
>
>
> }
>
> //In AppModule.java
> public AssetFactory buildfileSystemAssetFactory() {
>         return new FileSystemAssetFactory();
>     }
>
>     public void contributeAssetSource(MappedConfiguration<String,
> AssetFactory> configuration,
>             @InjectService("fileSystemAssetFactory") AssetFactory
> fileSystemAssetFactory) {
>         configuration.add("file", fileSystemAssetFactory);
>     }
>
>
>
> On Tue, Mar 10, 2009 at 3:28 PM, Andy Pahne <an...@googlemail.com>wrote:
>
>   
>> There is a ClasspathAssetFactory and a ContextAssetFactory. A useful
>> addition to the framework would be a FilesystemAssetFactory. I am going to
>> fill an JIRA issue about it.
>>
>> The way I did it for classpath resources was very simple, see below. Only
>> the first two lines of renderIcon() are relevant for construction an asset.
>>
>>  @BeginRender
>>   public void renderIcon(MarkupWriter writer) {
>>
>>       Resource iconResource = new ClasspathResource(BASE_PATH + src);
>>                   if(assetFactory == null) {
>>           LOG.warn("assertFactory is null");
>>       }
>>             if(iconResource == null) {
>>           LOG.warn("iconResource is null");
>>       }
>>       Asset icon = assetFactory.createAsset(iconResource);
>>
>>       if(icon != null) {
>>
>>           writer.element("img",
>>               "src", icon.toClientURL(),
>>               "alt", getAlt());
>>
>>           resources.renderInformalParameters(writer);
>>
>>           writer.end();
>>
>>       } else {
>>
>>           writer.writeRaw(getAlt());
>>
>>       }
>>
>>   }
>>
>>
>>
>>   @Inject @ClasspathProvider
>>   private AssetFactory assetFactory;
>>
>>   @BeginRender
>>   public void renderIcon(MarkupWriter writer) {
>>
>>       Resource iconResource = new ClasspathResource(BASE_PATH + src);
>>      Asset icon = assetFactory.createAsset(iconResource);
>>
>>       if(icon != null) {
>>
>>           writer.element("img",
>>               "src", icon.toClientURL(),
>>               "alt", getAlt());
>>
>>           resources.renderInformalParameters(writer);
>>
>>           writer.end();
>>
>>       } else {
>>
>>           writer.writeRaw(getAlt());
>>
>>       }
>>
>>   }
>>
>>
>>
>>
>>
>>
>>
>>
>> Peter Kanze schrieb:
>>
>>  The documentation (http://tapestry.apache.org/tapestry5/guide/assets.html
>>     
>>> )
>>> tells me to define a new AssetFactory and contribute it to the AssetSource
>>> service configuration.
>>> Yes okay, but how do I implement an AssetFactory? Is there any
>>> documentation?
>>>
>>> What do I need to do with public Resource getRootResource() and public
>>> Asset
>>> createAsset(Resource resource);
>>> I also looked at ClasspathAssetFactory but don't understand it. The
>>> comment
>>> is too minimal.
>>>
>>> Can someone help me with this?
>>>
>>> Thanks,
>>> Peter!
>>>
>>> On Tue, Mar 10, 2009 at 1:59 PM, Peter Kanze <pe...@gmail.com>
>>> wrote:
>>>
>>>
>>>
>>>       
>>>> Oke thank you.
>>>>
>>>> But how do I map between the web http:// and the file D:/ urls?
>>>> Can you give me some (pseudo) code examples how to do this?
>>>>
>>>> Thanks!
>>>> Peter
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Mar 10, 2009 at 1:56 PM, Thiago H. de Paula Figueiredo <
>>>> thiagohp@gmail.com> wrote:
>>>>
>>>>
>>>>
>>>>         
>>>>> On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <pe...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>
>>>>>           
>>>>>> I already searched the archive and found the question, but it is not
>>>>>>
>>>>>>
>>>>>>             
>>>>> clear
>>>>>
>>>>>
>>>>>           
>>>>>> to me.
>>>>>> There are no examples in it with a dynamic path..
>>>>>>
>>>>>>
>>>>>>             
>>>>> You'll use AssetSource for that.
>>>>>
>>>>> --
>>>>> Thiago
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>           
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>     
>
>   


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


Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
Hi Andy,

Thanks for adding this to Jira.
See below my code what I have produced so far. The problem is that I now see
the complete filepath in my html source (<img src="
C:/tmp/pictures/8/71/1001/thumb1.jpg" alt=""/>)
I don't want the complete file url in my html source. How can I fix this.
And how do I map the html url to the file url?
The last problem is that the file url is correct, but the image is not shown
in my html page.
What am I doing wrong?


--Quick Example Code Below---

<img src="${ThumbnailPath}" alt="" />

public String getThumbnailPath() {
         Asset asset = assetSource.getAsset(null,
"file:/8/71/1001/thumb1.jpg", null);
         return asset.toClientURL();
}

public class FileSystemResource extends AbstractResource {

    private static final int PRIME = 37;

    public FileSystemResource(String path) {
        super(path);
    }

    @Override
    protected Resource newResource(String path) {
        return new FileSystemResource(path);
    }

    @Override
    public URL toURL() {
        String filePath = getPath();
        File file = new File(filePath);

        if (file != null && file.exists()) {
            try {
                return file.toURL();
            }
            catch (MalformedURLException ex) {
                throw new RuntimeException(ex);
            }
        }
        return null;
    }
}

public class FileSystemAssetFactory implements AssetFactory {

    private static final String assetPath = "/images/";

    public FileSystemAssetFactory() {

    }

   @Override
    public Resource getRootResource() {
        return new FileSystemResource("C:/tmp/pictures/");
    }

    @Override
    public Asset createAsset(final Resource resource) {
        final String filePath =  resource.getPath();

        return new Asset()
        {
            public Resource getResource()
            {
                return resource;
            }

            public String toClientURL()
            {
                return filePath;
            }

            /**
             * Returns the client URL, which is essiential to allow informal
parameters of type
             * Asset to generate a proper value.
             */
            @Override
            public String toString()
            {
                return toClientURL();
            }
        };
    }



}

//In AppModule.java
public AssetFactory buildfileSystemAssetFactory() {
        return new FileSystemAssetFactory();
    }

    public void contributeAssetSource(MappedConfiguration<String,
AssetFactory> configuration,
            @InjectService("fileSystemAssetFactory") AssetFactory
fileSystemAssetFactory) {
        configuration.add("file", fileSystemAssetFactory);
    }



On Tue, Mar 10, 2009 at 3:28 PM, Andy Pahne <an...@googlemail.com>wrote:

>
>
> There is a ClasspathAssetFactory and a ContextAssetFactory. A useful
> addition to the framework would be a FilesystemAssetFactory. I am going to
> fill an JIRA issue about it.
>
> The way I did it for classpath resources was very simple, see below. Only
> the first two lines of renderIcon() are relevant for construction an asset.
>
>  @BeginRender
>   public void renderIcon(MarkupWriter writer) {
>
>       Resource iconResource = new ClasspathResource(BASE_PATH + src);
>                   if(assetFactory == null) {
>           LOG.warn("assertFactory is null");
>       }
>             if(iconResource == null) {
>           LOG.warn("iconResource is null");
>       }
>       Asset icon = assetFactory.createAsset(iconResource);
>
>       if(icon != null) {
>
>           writer.element("img",
>               "src", icon.toClientURL(),
>               "alt", getAlt());
>
>           resources.renderInformalParameters(writer);
>
>           writer.end();
>
>       } else {
>
>           writer.writeRaw(getAlt());
>
>       }
>
>   }
>
>
>
>   @Inject @ClasspathProvider
>   private AssetFactory assetFactory;
>
>   @BeginRender
>   public void renderIcon(MarkupWriter writer) {
>
>       Resource iconResource = new ClasspathResource(BASE_PATH + src);
>      Asset icon = assetFactory.createAsset(iconResource);
>
>       if(icon != null) {
>
>           writer.element("img",
>               "src", icon.toClientURL(),
>               "alt", getAlt());
>
>           resources.renderInformalParameters(writer);
>
>           writer.end();
>
>       } else {
>
>           writer.writeRaw(getAlt());
>
>       }
>
>   }
>
>
>
>
>
>
>
>
> Peter Kanze schrieb:
>
>  The documentation (http://tapestry.apache.org/tapestry5/guide/assets.html
>> )
>> tells me to define a new AssetFactory and contribute it to the AssetSource
>> service configuration.
>> Yes okay, but how do I implement an AssetFactory? Is there any
>> documentation?
>>
>> What do I need to do with public Resource getRootResource() and public
>> Asset
>> createAsset(Resource resource);
>> I also looked at ClasspathAssetFactory but don't understand it. The
>> comment
>> is too minimal.
>>
>> Can someone help me with this?
>>
>> Thanks,
>> Peter!
>>
>> On Tue, Mar 10, 2009 at 1:59 PM, Peter Kanze <pe...@gmail.com>
>> wrote:
>>
>>
>>
>>> Oke thank you.
>>>
>>> But how do I map between the web http:// and the file D:/ urls?
>>> Can you give me some (pseudo) code examples how to do this?
>>>
>>> Thanks!
>>> Peter
>>>
>>>
>>>
>>>
>>> On Tue, Mar 10, 2009 at 1:56 PM, Thiago H. de Paula Figueiredo <
>>> thiagohp@gmail.com> wrote:
>>>
>>>
>>>
>>>> On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <pe...@gmail.com>
>>>> wrote:
>>>>
>>>>
>>>>> I already searched the archive and found the question, but it is not
>>>>>
>>>>>
>>>> clear
>>>>
>>>>
>>>>> to me.
>>>>> There are no examples in it with a dynamic path..
>>>>>
>>>>>
>>>> You'll use AssetSource for that.
>>>>
>>>> --
>>>> Thiago
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by Andy Pahne <an...@googlemail.com>.
The proposed solution in the issue is a bit different. Both is possible, 
I hope the developers pick up the issue and choose a nice solution.

Andy



Andy Pahne schrieb:
>
> https://issues.apache.org/jira/browse/TAP5-567
>
>
>
>
> Thiago H. de Paula Figueiredo schrieb:
>> On Tue, Mar 10, 2009 at 11:28 AM, Andy Pahne 
>> <an...@googlemail.com> wrote:
>>  
>>> There is a ClasspathAssetFactory and a ContextAssetFactory. A useful
>>> addition to the framework would be a FilesystemAssetFactory. I am 
>>> going to
>>> fill an JIRA issue about it.
>>>     
>>
>> +1 to that. I guess we only have to decide if only one root directory
>> will be used or more than one.
>> By the way, nice example. :)
>>
>>   
>


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


Re: T5: How to load image Asset from filesystem?

Posted by Andy Pahne <an...@googlemail.com>.
https://issues.apache.org/jira/browse/TAP5-567




Thiago H. de Paula Figueiredo schrieb:
> On Tue, Mar 10, 2009 at 11:28 AM, Andy Pahne <an...@googlemail.com> wrote:
>   
>> There is a ClasspathAssetFactory and a ContextAssetFactory. A useful
>> addition to the framework would be a FilesystemAssetFactory. I am going to
>> fill an JIRA issue about it.
>>     
>
> +1 to that. I guess we only have to decide if only one root directory
> will be used or more than one.
> By the way, nice example. :)
>
>   


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


Re: T5: How to load image Asset from filesystem?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Mar 10, 2009 at 11:28 AM, Andy Pahne <an...@googlemail.com> wrote:
> There is a ClasspathAssetFactory and a ContextAssetFactory. A useful
> addition to the framework would be a FilesystemAssetFactory. I am going to
> fill an JIRA issue about it.

+1 to that. I guess we only have to decide if only one root directory
will be used or more than one.
By the way, nice example. :)

-- 
Thiago

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


Re: T5: How to load image Asset from filesystem?

Posted by Andy Pahne <an...@googlemail.com>.

There is a ClasspathAssetFactory and a ContextAssetFactory. A useful 
addition to the framework would be a FilesystemAssetFactory. I am going 
to fill an JIRA issue about it.

The way I did it for classpath resources was very simple, see below. 
Only the first two lines of renderIcon() are relevant for construction 
an asset.

   @BeginRender
    public void renderIcon(MarkupWriter writer) {

        Resource iconResource = new ClasspathResource(BASE_PATH + src);
       
       
        if(assetFactory == null) {
            LOG.warn("assertFactory is null");
        }
       
        if(iconResource == null) {
            LOG.warn("iconResource is null");
        }
        Asset icon = assetFactory.createAsset(iconResource);

        if(icon != null) {

            writer.element("img",
                "src", icon.toClientURL(),
                "alt", getAlt());

            resources.renderInformalParameters(writer);

            writer.end();

        } else {

            writer.writeRaw(getAlt());

        }

    }



    @Inject @ClasspathProvider
    private AssetFactory assetFactory;

    @BeginRender
    public void renderIcon(MarkupWriter writer) {

        Resource iconResource = new ClasspathResource(BASE_PATH + src);
       Asset icon = assetFactory.createAsset(iconResource);

        if(icon != null) {

            writer.element("img",
                "src", icon.toClientURL(),
                "alt", getAlt());

            resources.renderInformalParameters(writer);

            writer.end();

        } else {

            writer.writeRaw(getAlt());

        }

    }








Peter Kanze schrieb:
> The documentation (http://tapestry.apache.org/tapestry5/guide/assets.html)
> tells me to define a new AssetFactory and contribute it to the AssetSource
> service configuration.
> Yes okay, but how do I implement an AssetFactory? Is there any
> documentation?
>
> What do I need to do with public Resource getRootResource() and public Asset
> createAsset(Resource resource);
> I also looked at ClasspathAssetFactory but don't understand it. The comment
> is too minimal.
>
> Can someone help me with this?
>
> Thanks,
> Peter!
>
> On Tue, Mar 10, 2009 at 1:59 PM, Peter Kanze <pe...@gmail.com> wrote:
>
>   
>> Oke thank you.
>>
>> But how do I map between the web http:// and the file D:/ urls?
>> Can you give me some (pseudo) code examples how to do this?
>>
>> Thanks!
>> Peter
>>
>>
>>
>>
>> On Tue, Mar 10, 2009 at 1:56 PM, Thiago H. de Paula Figueiredo <
>> thiagohp@gmail.com> wrote:
>>
>>     
>>> On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <pe...@gmail.com>
>>> wrote:
>>>       
>>>> I already searched the archive and found the question, but it is not
>>>>         
>>> clear
>>>       
>>>> to me.
>>>> There are no examples in it with a dynamic path..
>>>>         
>>> You'll use AssetSource for that.
>>>
>>> --
>>> Thiago
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>       
>
>   


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


Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
The documentation (http://tapestry.apache.org/tapestry5/guide/assets.html)
tells me to define a new AssetFactory and contribute it to the AssetSource
service configuration.
Yes okay, but how do I implement an AssetFactory? Is there any
documentation?

What do I need to do with public Resource getRootResource() and public Asset
createAsset(Resource resource);
I also looked at ClasspathAssetFactory but don't understand it. The comment
is too minimal.

Can someone help me with this?

Thanks,
Peter!

On Tue, Mar 10, 2009 at 1:59 PM, Peter Kanze <pe...@gmail.com> wrote:

> Oke thank you.
>
> But how do I map between the web http:// and the file D:/ urls?
> Can you give me some (pseudo) code examples how to do this?
>
> Thanks!
> Peter
>
>
>
>
> On Tue, Mar 10, 2009 at 1:56 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <pe...@gmail.com>
>> wrote:
>> > I already searched the archive and found the question, but it is not
>> clear
>> > to me.
>> > There are no examples in it with a dynamic path..
>>
>> You'll use AssetSource for that.
>>
>> --
>> Thiago
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
Oke thank you.

But how do I map between the web http:// and the file D:/ urls?
Can you give me some (pseudo) code examples how to do this?

Thanks!
Peter



On Tue, Mar 10, 2009 at 1:56 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <pe...@gmail.com> wrote:
> > I already searched the archive and found the question, but it is not
> clear
> > to me.
> > There are no examples in it with a dynamic path..
>
> You'll use AssetSource for that.
>
> --
> Thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <pe...@gmail.com> wrote:
> I already searched the archive and found the question, but it is not clear
> to me.
> There are no examples in it with a dynamic path..

You'll use AssetSource for that.

-- 
Thiago

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


Re: T5: How to load image Asset from filesystem?

Posted by Peter Kanze <pe...@gmail.com>.
Hello

I already searched the archive and found the question, but it is not clear
to me.
There are no examples in it with a dynamic path..




On Tue, Mar 10, 2009 at 1:45 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Hi!
>
> Search this mailing list archives because this was already asked here:
>
> http://www.nabble.com/forum/Search.jtp?forum=340&local=y&query=asset+filesystem
> .
>
> --
> Thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: How to load image Asset from filesystem?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Hi!

Search this mailing list archives because this was already asked here:
http://www.nabble.com/forum/Search.jtp?forum=340&local=y&query=asset+filesystem.

-- 
Thiago

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