You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "ross.efi" <ro...@att.net> on 2010/01/23 06:13:20 UTC

Return image asset from onActivate

How do I get an input stream from an injected asset on my page?
The activation context is which image to use, so I want to stream one asset
or the other.


    @Inject
    @Path( "context:/images/myimage1.png")
    private Asset myImageLogo1;

    @Inject
    @Path( "context:/images/myimage2.png")
    private Asset myImageLogo2;

    StreamResponse onActivate( String logoName ) {
        if ( "logo1".equals( imageName ) {
            return new StreamResponse() {

                public String getContentType() {
                    return "image/png";
                }

                public InputStream getStream() throws IOException {
                    return ????? stream from myImageLogo1 ????
                }

                public void prepareResponse( Response response ) {
                    // Nothing needed.
                }
            };
        }
        else {  // use image 2
       }
    }

-- 
View this message in context: http://old.nabble.com/Return-image-asset-from-onActivate-tp27283549p27283549.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

Re: Return image asset from onActivate

Posted by "ross.efi" <ro...@att.net>.
I figured it out on my own.  The ???? section below just needs to be replaced
with


        public InputStream getStream() throws IOException {
            return myImageLogo1.getResource().openStream()
        }


Works great!


Ross


ross.efi wrote:
> 
> How do I get an input stream from an injected asset on my page?
> The activation context is which image to use, so I want to stream one
> asset or the other.
> 
> 

>     @Inject
>     @Path( "context:/images/myimage1.png")
>     private Asset myImageLogo1;
> 
>     @Inject
>     @Path( "context:/images/myimage2.png")
>     private Asset myImageLogo2;
> 
>     StreamResponse onActivate( String logoName ) {
>         if ( "logo1".equals( imageName ) {
>             return new StreamResponse() {
> 
>                 public String getContentType() {
>                     return "image/png";
>                 }
> 
>                 public InputStream getStream() throws IOException {
>                     return ????? stream from myImageLogo1 ????
>                 }
> 
>                 public void prepareResponse( Response response ) {
>                     // Nothing needed.
>                 }
>             };
>         }
>         else {  // use image 2
>        }
>     }
> 

> 

-- 
View this message in context: http://old.nabble.com/Return-image-asset-from-onActivate-tp27283549p27283617.html
Sent from the Tapestry - User mailing list archive at Nabble.com.