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/11 12:21:13 UTC

Image Asset Help Needed

Here am I again.

I am struggling for 2 days now to load an image from the filesystem into my
webpage.
The image needs to be loaded based on the product id.

The steps I did was:

1. Implemented a FileSystemAssetFactory based on the ClasspathAssetFactory
2. Implemented a FileSystemResource;
See the code below:
In my html the following code is generated:

<img src="
/advertaza/assets/classpath/6675930334be219a/C:/tmp/pictures/8/71/1001/thumb1.jpg
" alt=""/>

As you can see the file system path is exposed into the webpage. I don't
want this.
The second problem is that the image is not loaded/visible in the webpage.

What am I doing wrong? Are there tapestry guru's who can help me out?

Thanks,
Peter

/*
*My quick example code
*/

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

    private final ClasspathAssetAliasManager aliasManager;

    private final Map<Resource, String> resourceToDefaultPath =
CollectionFactory.newConcurrentMap();

    private final FileSystemResource rootResource;

    private final AssetPathConverter converter;

    private final boolean invariant;


    public FileSystemAssetFactory(ClasspathAssetAliasManager aliasManager,
AssetPathConverter converter) {
        this.aliasManager = aliasManager;
        this.converter = converter;

        rootResource = new FileSystemResource("C:/tmp/pictures/");
        invariant = converter.isInvariant();
    }


    private String clientURL(Resource resource) {
        String defaultPath = resourceToDefaultPath.get(resource);

        if (defaultPath == null) {
            defaultPath = buildDefaultPath(resource);

            resourceToDefaultPath.put(resource, defaultPath);
        }

        return converter.convertAssetPath(defaultPath);
    }

    private String buildDefaultPath(Resource resource) {
        //boolean requiresDigest = cache.requiresDigest(resource);

        String path = resource.getPath();
        int lastdotx = path.lastIndexOf('.');
        path = path.substring(0, lastdotx + 1)  + path.substring(lastdotx);

          return aliasManager.toClientURL(path);
    }

    public Asset createAsset(final Resource resource) {
        return new AbstractAsset(invariant) {
            public Resource getResource() {
                return resource;
            }

            public String toClientURL() {
                return clientURL(resource);
            }
        };
    }

    public Resource getRootResource() {
        return rootResource;
    }

}

public class FileSystemResource extends AbstractResource {

    private static final int PRIME = 37;

    /**
     * Constructor with the root path
     * @param path the root
     */
    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;
    }

    @Override
    public String toString() {
        return getPath();
    }

    @Override
    public int hashCode() {
        return PRIME * getPath().hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;

        final FileSystemResource other = (FileSystemResource) obj;

        return getPath().equals(other.getPath());
    }

}

Re: Image Asset Help Needed

Posted by manuel aldana <al...@gmx.de>.
Currently am working on this tapestry jira issue to provide a patch 
maybe in around 10 days.

As current workaround you could go for:
1) Use plain Apache2 for accessing your images on different port from 
tapestry app. Of course firewall could be a problem...
2) If port is an issue (has to be 80), then you could use apache mod_jk 
(mod_jk2), passing tapestry stuff to the servlet-container and serving 
static images by Apache.
3) If the images aren't dynamic at all (e.g. not uploaded by user) I 
would use the context asset and place the stuff in the webapp/ root context.


Peter Kanze schrieb:
> Here am I again.
>
> I am struggling for 2 days now to load an image from the filesystem into my
> webpage.
> The image needs to be loaded based on the product id.
>
> The steps I did was:
>
> 1. Implemented a FileSystemAssetFactory based on the ClasspathAssetFactory
> 2. Implemented a FileSystemResource;
> See the code below:
> In my html the following code is generated:
>
> <img src="
> /advertaza/assets/classpath/6675930334be219a/C:/tmp/pictures/8/71/1001/thumb1.jpg
> " alt=""/>
>
> As you can see the file system path is exposed into the webpage. I don't
> want this.
> The second problem is that the image is not loaded/visible in the webpage.
>
> What am I doing wrong? Are there tapestry guru's who can help me out?
>
> Thanks,
> Peter
>
> /*
> *My quick example code
> */
>
> public String getThumbnailPath() {
>          Asset asset = assetSource.getAsset(null,
> "file:/8/71/1001/thumb1.jpg", null);
>          return asset.toClientURL();
>     }
> public class FileSystemAssetFactory implements AssetFactory {
>
>     private final ClasspathAssetAliasManager aliasManager;
>
>     private final Map<Resource, String> resourceToDefaultPath =
> CollectionFactory.newConcurrentMap();
>
>     private final FileSystemResource rootResource;
>
>     private final AssetPathConverter converter;
>
>     private final boolean invariant;
>
>
>     public FileSystemAssetFactory(ClasspathAssetAliasManager aliasManager,
> AssetPathConverter converter) {
>         this.aliasManager = aliasManager;
>         this.converter = converter;
>
>         rootResource = new FileSystemResource("C:/tmp/pictures/");
>         invariant = converter.isInvariant();
>     }
>
>
>     private String clientURL(Resource resource) {
>         String defaultPath = resourceToDefaultPath.get(resource);
>
>         if (defaultPath == null) {
>             defaultPath = buildDefaultPath(resource);
>
>             resourceToDefaultPath.put(resource, defaultPath);
>         }
>
>         return converter.convertAssetPath(defaultPath);
>     }
>
>     private String buildDefaultPath(Resource resource) {
>         //boolean requiresDigest = cache.requiresDigest(resource);
>
>         String path = resource.getPath();
>         int lastdotx = path.lastIndexOf('.');
>         path = path.substring(0, lastdotx + 1)  + path.substring(lastdotx);
>
>           return aliasManager.toClientURL(path);
>     }
>
>     public Asset createAsset(final Resource resource) {
>         return new AbstractAsset(invariant) {
>             public Resource getResource() {
>                 return resource;
>             }
>
>             public String toClientURL() {
>                 return clientURL(resource);
>             }
>         };
>     }
>
>     public Resource getRootResource() {
>         return rootResource;
>     }
>
> }
>
> public class FileSystemResource extends AbstractResource {
>
>     private static final int PRIME = 37;
>
>     /**
>      * Constructor with the root path
>      * @param path the root
>      */
>     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;
>     }
>
>     @Override
>     public String toString() {
>         return getPath();
>     }
>
>     @Override
>     public int hashCode() {
>         return PRIME * getPath().hashCode();
>     }
>
>     @Override
>     public boolean equals(Object obj) {
>         if (this == obj)
>             return true;
>         if (obj == null)
>             return false;
>         if (getClass() != obj.getClass())
>             return false;
>
>         final FileSystemResource other = (FileSystemResource) obj;
>
>         return getPath().equals(other.getPath());
>     }
>
> }
>
>   


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


Re: Image Asset Help Needed

Posted by Peter Stavrinides <P....@albourne.com>.
//One correction, forgot the parameter
public StreamResponse onPhoto(int pId) {
//get the photo from file system here

final ByteArrayInputStream stream = new ByteArrayInputStream(photo
					.getPhoto());
...
}

----- Original Message -----
From: "Andy Pahne" <an...@googlemail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Wednesday, 11 March, 2009 14:27:53 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: Image Asset Help Needed

Peter Kanze schrieb:
> Hi Andy,
>
> Yes I read that thread, I started that thread as well.
> I will vote for the issue, but the problem is I need a solution now..
>
> Maybe I add a good old servlet that returns the image....
> Any other ideas?
>
>   


Yeah, that was my workaround.



> Regards,
> Peter
>
>
> On Wed, Mar 11, 2009 at 12:49 PM, Andy Pahne <an...@googlemail.com>wrote:
>
>   
>> Did you read the thread "How to load image Asset from filesystem"?
>>
>> You might want to vote for the issue.
>>
>> Regards,
>> Andy
>>
>>
>> Peter Kanze schrieb:
>>
>>  Here am I again.
>>     
>>> I am struggling for 2 days now to load an image from the filesystem into
>>> my
>>> webpage.
>>> The image needs to be loaded based on the product id.
>>>
>>> The steps I did was:
>>>
>>> 1. Implemented a FileSystemAssetFactory based on the ClasspathAssetFactory
>>> 2. Implemented a FileSystemResource;
>>> See the code below:
>>> In my html the following code is generated:
>>>
>>> <img src="
>>>
>>> /advertaza/assets/classpath/6675930334be219a/C:/tmp/pictures/8/71/1001/thumb1.jpg
>>> " alt=""/>
>>>
>>> As you can see the file system path is exposed into the webpage. I don't
>>> want this.
>>> The second problem is that the image is not loaded/visible in the webpage.
>>>
>>> What am I doing wrong? Are there tapestry guru's who can help me out?
>>>
>>> Thanks,
>>> Peter
>>>
>>> /*
>>> *My quick example code
>>> */
>>>
>>> public String getThumbnailPath() {
>>>         Asset asset = assetSource.getAsset(null,
>>> "file:/8/71/1001/thumb1.jpg", null);
>>>         return asset.toClientURL();
>>>    }
>>> public class FileSystemAssetFactory implements AssetFactory {
>>>
>>>    private final ClasspathAssetAliasManager aliasManager;
>>>
>>>    private final Map<Resource, String> resourceToDefaultPath =
>>> CollectionFactory.newConcurrentMap();
>>>
>>>    private final FileSystemResource rootResource;
>>>
>>>    private final AssetPathConverter converter;
>>>
>>>    private final boolean invariant;
>>>
>>>
>>>    public FileSystemAssetFactory(ClasspathAssetAliasManager aliasManager,
>>> AssetPathConverter converter) {
>>>        this.aliasManager = aliasManager;
>>>        this.converter = converter;
>>>
>>>        rootResource = new FileSystemResource("C:/tmp/pictures/");
>>>        invariant = converter.isInvariant();
>>>    }
>>>
>>>
>>>    private String clientURL(Resource resource) {
>>>        String defaultPath = resourceToDefaultPath.get(resource);
>>>
>>>        if (defaultPath == null) {
>>>            defaultPath = buildDefaultPath(resource);
>>>
>>>            resourceToDefaultPath.put(resource, defaultPath);
>>>        }
>>>
>>>        return converter.convertAssetPath(defaultPath);
>>>    }
>>>
>>>    private String buildDefaultPath(Resource resource) {
>>>        //boolean requiresDigest = cache.requiresDigest(resource);
>>>
>>>        String path = resource.getPath();
>>>        int lastdotx = path.lastIndexOf('.');
>>>        path = path.substring(0, lastdotx + 1)  + path.substring(lastdotx);
>>>
>>>          return aliasManager.toClientURL(path);
>>>    }
>>>
>>>    public Asset createAsset(final Resource resource) {
>>>        return new AbstractAsset(invariant) {
>>>            public Resource getResource() {
>>>                return resource;
>>>            }
>>>
>>>            public String toClientURL() {
>>>                return clientURL(resource);
>>>            }
>>>        };
>>>    }
>>>
>>>    public Resource getRootResource() {
>>>        return rootResource;
>>>    }
>>>
>>> }
>>>
>>> public class FileSystemResource extends AbstractResource {
>>>
>>>    private static final int PRIME = 37;
>>>
>>>    /**
>>>     * Constructor with the root path
>>>     * @param path the root
>>>     */
>>>    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;
>>>    }
>>>
>>>    @Override
>>>    public String toString() {
>>>        return getPath();
>>>    }
>>>
>>>    @Override
>>>    public int hashCode() {
>>>        return PRIME * getPath().hashCode();
>>>    }
>>>
>>>    @Override
>>>    public boolean equals(Object obj) {
>>>        if (this == obj)
>>>            return true;
>>>        if (obj == null)
>>>            return false;
>>>        if (getClass() != obj.getClass())
>>>            return false;
>>>
>>>        final FileSystemResource other = (FileSystemResource) obj;
>>>
>>>        return getPath().equals(other.getPath());
>>>    }
>>>
>>> }
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> 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: Image Asset Help Needed

Posted by Andy Pahne <an...@googlemail.com>.
Peter Kanze schrieb:
> Hi Andy,
>
> Yes I read that thread, I started that thread as well.
> I will vote for the issue, but the problem is I need a solution now..
>
> Maybe I add a good old servlet that returns the image....
> Any other ideas?
>
>   


Yeah, that was my workaround.



> Regards,
> Peter
>
>
> On Wed, Mar 11, 2009 at 12:49 PM, Andy Pahne <an...@googlemail.com>wrote:
>
>   
>> Did you read the thread "How to load image Asset from filesystem"?
>>
>> You might want to vote for the issue.
>>
>> Regards,
>> Andy
>>
>>
>> Peter Kanze schrieb:
>>
>>  Here am I again.
>>     
>>> I am struggling for 2 days now to load an image from the filesystem into
>>> my
>>> webpage.
>>> The image needs to be loaded based on the product id.
>>>
>>> The steps I did was:
>>>
>>> 1. Implemented a FileSystemAssetFactory based on the ClasspathAssetFactory
>>> 2. Implemented a FileSystemResource;
>>> See the code below:
>>> In my html the following code is generated:
>>>
>>> <img src="
>>>
>>> /advertaza/assets/classpath/6675930334be219a/C:/tmp/pictures/8/71/1001/thumb1.jpg
>>> " alt=""/>
>>>
>>> As you can see the file system path is exposed into the webpage. I don't
>>> want this.
>>> The second problem is that the image is not loaded/visible in the webpage.
>>>
>>> What am I doing wrong? Are there tapestry guru's who can help me out?
>>>
>>> Thanks,
>>> Peter
>>>
>>> /*
>>> *My quick example code
>>> */
>>>
>>> public String getThumbnailPath() {
>>>         Asset asset = assetSource.getAsset(null,
>>> "file:/8/71/1001/thumb1.jpg", null);
>>>         return asset.toClientURL();
>>>    }
>>> public class FileSystemAssetFactory implements AssetFactory {
>>>
>>>    private final ClasspathAssetAliasManager aliasManager;
>>>
>>>    private final Map<Resource, String> resourceToDefaultPath =
>>> CollectionFactory.newConcurrentMap();
>>>
>>>    private final FileSystemResource rootResource;
>>>
>>>    private final AssetPathConverter converter;
>>>
>>>    private final boolean invariant;
>>>
>>>
>>>    public FileSystemAssetFactory(ClasspathAssetAliasManager aliasManager,
>>> AssetPathConverter converter) {
>>>        this.aliasManager = aliasManager;
>>>        this.converter = converter;
>>>
>>>        rootResource = new FileSystemResource("C:/tmp/pictures/");
>>>        invariant = converter.isInvariant();
>>>    }
>>>
>>>
>>>    private String clientURL(Resource resource) {
>>>        String defaultPath = resourceToDefaultPath.get(resource);
>>>
>>>        if (defaultPath == null) {
>>>            defaultPath = buildDefaultPath(resource);
>>>
>>>            resourceToDefaultPath.put(resource, defaultPath);
>>>        }
>>>
>>>        return converter.convertAssetPath(defaultPath);
>>>    }
>>>
>>>    private String buildDefaultPath(Resource resource) {
>>>        //boolean requiresDigest = cache.requiresDigest(resource);
>>>
>>>        String path = resource.getPath();
>>>        int lastdotx = path.lastIndexOf('.');
>>>        path = path.substring(0, lastdotx + 1)  + path.substring(lastdotx);
>>>
>>>          return aliasManager.toClientURL(path);
>>>    }
>>>
>>>    public Asset createAsset(final Resource resource) {
>>>        return new AbstractAsset(invariant) {
>>>            public Resource getResource() {
>>>                return resource;
>>>            }
>>>
>>>            public String toClientURL() {
>>>                return clientURL(resource);
>>>            }
>>>        };
>>>    }
>>>
>>>    public Resource getRootResource() {
>>>        return rootResource;
>>>    }
>>>
>>> }
>>>
>>> public class FileSystemResource extends AbstractResource {
>>>
>>>    private static final int PRIME = 37;
>>>
>>>    /**
>>>     * Constructor with the root path
>>>     * @param path the root
>>>     */
>>>    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;
>>>    }
>>>
>>>    @Override
>>>    public String toString() {
>>>        return getPath();
>>>    }
>>>
>>>    @Override
>>>    public int hashCode() {
>>>        return PRIME * getPath().hashCode();
>>>    }
>>>
>>>    @Override
>>>    public boolean equals(Object obj) {
>>>        if (this == obj)
>>>            return true;
>>>        if (obj == null)
>>>            return false;
>>>        if (getClass() != obj.getClass())
>>>            return false;
>>>
>>>        final FileSystemResource other = (FileSystemResource) obj;
>>>
>>>        return getPath().equals(other.getPath());
>>>    }
>>>
>>> }
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> 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: Image Asset Help Needed

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

Yes I read that thread, I started that thread as well.
I will vote for the issue, but the problem is I need a solution now..

Maybe I add a good old servlet that returns the image....
Any other ideas?

Regards,
Peter


On Wed, Mar 11, 2009 at 12:49 PM, Andy Pahne <an...@googlemail.com>wrote:

>
>
> Did you read the thread "How to load image Asset from filesystem"?
>
> You might want to vote for the issue.
>
> Regards,
> Andy
>
>
> Peter Kanze schrieb:
>
>  Here am I again.
>>
>> I am struggling for 2 days now to load an image from the filesystem into
>> my
>> webpage.
>> The image needs to be loaded based on the product id.
>>
>> The steps I did was:
>>
>> 1. Implemented a FileSystemAssetFactory based on the ClasspathAssetFactory
>> 2. Implemented a FileSystemResource;
>> See the code below:
>> In my html the following code is generated:
>>
>> <img src="
>>
>> /advertaza/assets/classpath/6675930334be219a/C:/tmp/pictures/8/71/1001/thumb1.jpg
>> " alt=""/>
>>
>> As you can see the file system path is exposed into the webpage. I don't
>> want this.
>> The second problem is that the image is not loaded/visible in the webpage.
>>
>> What am I doing wrong? Are there tapestry guru's who can help me out?
>>
>> Thanks,
>> Peter
>>
>> /*
>> *My quick example code
>> */
>>
>> public String getThumbnailPath() {
>>         Asset asset = assetSource.getAsset(null,
>> "file:/8/71/1001/thumb1.jpg", null);
>>         return asset.toClientURL();
>>    }
>> public class FileSystemAssetFactory implements AssetFactory {
>>
>>    private final ClasspathAssetAliasManager aliasManager;
>>
>>    private final Map<Resource, String> resourceToDefaultPath =
>> CollectionFactory.newConcurrentMap();
>>
>>    private final FileSystemResource rootResource;
>>
>>    private final AssetPathConverter converter;
>>
>>    private final boolean invariant;
>>
>>
>>    public FileSystemAssetFactory(ClasspathAssetAliasManager aliasManager,
>> AssetPathConverter converter) {
>>        this.aliasManager = aliasManager;
>>        this.converter = converter;
>>
>>        rootResource = new FileSystemResource("C:/tmp/pictures/");
>>        invariant = converter.isInvariant();
>>    }
>>
>>
>>    private String clientURL(Resource resource) {
>>        String defaultPath = resourceToDefaultPath.get(resource);
>>
>>        if (defaultPath == null) {
>>            defaultPath = buildDefaultPath(resource);
>>
>>            resourceToDefaultPath.put(resource, defaultPath);
>>        }
>>
>>        return converter.convertAssetPath(defaultPath);
>>    }
>>
>>    private String buildDefaultPath(Resource resource) {
>>        //boolean requiresDigest = cache.requiresDigest(resource);
>>
>>        String path = resource.getPath();
>>        int lastdotx = path.lastIndexOf('.');
>>        path = path.substring(0, lastdotx + 1)  + path.substring(lastdotx);
>>
>>          return aliasManager.toClientURL(path);
>>    }
>>
>>    public Asset createAsset(final Resource resource) {
>>        return new AbstractAsset(invariant) {
>>            public Resource getResource() {
>>                return resource;
>>            }
>>
>>            public String toClientURL() {
>>                return clientURL(resource);
>>            }
>>        };
>>    }
>>
>>    public Resource getRootResource() {
>>        return rootResource;
>>    }
>>
>> }
>>
>> public class FileSystemResource extends AbstractResource {
>>
>>    private static final int PRIME = 37;
>>
>>    /**
>>     * Constructor with the root path
>>     * @param path the root
>>     */
>>    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;
>>    }
>>
>>    @Override
>>    public String toString() {
>>        return getPath();
>>    }
>>
>>    @Override
>>    public int hashCode() {
>>        return PRIME * getPath().hashCode();
>>    }
>>
>>    @Override
>>    public boolean equals(Object obj) {
>>        if (this == obj)
>>            return true;
>>        if (obj == null)
>>            return false;
>>        if (getClass() != obj.getClass())
>>            return false;
>>
>>        final FileSystemResource other = (FileSystemResource) obj;
>>
>>        return getPath().equals(other.getPath());
>>    }
>>
>> }
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Image Asset Help Needed

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

Did you read the thread "How to load image Asset from filesystem"?

You might want to vote for the issue.

Regards,
Andy


Peter Kanze schrieb:
> Here am I again.
>
> I am struggling for 2 days now to load an image from the filesystem into my
> webpage.
> The image needs to be loaded based on the product id.
>
> The steps I did was:
>
> 1. Implemented a FileSystemAssetFactory based on the ClasspathAssetFactory
> 2. Implemented a FileSystemResource;
> See the code below:
> In my html the following code is generated:
>
> <img src="
> /advertaza/assets/classpath/6675930334be219a/C:/tmp/pictures/8/71/1001/thumb1.jpg
> " alt=""/>
>
> As you can see the file system path is exposed into the webpage. I don't
> want this.
> The second problem is that the image is not loaded/visible in the webpage.
>
> What am I doing wrong? Are there tapestry guru's who can help me out?
>
> Thanks,
> Peter
>
> /*
> *My quick example code
> */
>
> public String getThumbnailPath() {
>          Asset asset = assetSource.getAsset(null,
> "file:/8/71/1001/thumb1.jpg", null);
>          return asset.toClientURL();
>     }
> public class FileSystemAssetFactory implements AssetFactory {
>
>     private final ClasspathAssetAliasManager aliasManager;
>
>     private final Map<Resource, String> resourceToDefaultPath =
> CollectionFactory.newConcurrentMap();
>
>     private final FileSystemResource rootResource;
>
>     private final AssetPathConverter converter;
>
>     private final boolean invariant;
>
>
>     public FileSystemAssetFactory(ClasspathAssetAliasManager aliasManager,
> AssetPathConverter converter) {
>         this.aliasManager = aliasManager;
>         this.converter = converter;
>
>         rootResource = new FileSystemResource("C:/tmp/pictures/");
>         invariant = converter.isInvariant();
>     }
>
>
>     private String clientURL(Resource resource) {
>         String defaultPath = resourceToDefaultPath.get(resource);
>
>         if (defaultPath == null) {
>             defaultPath = buildDefaultPath(resource);
>
>             resourceToDefaultPath.put(resource, defaultPath);
>         }
>
>         return converter.convertAssetPath(defaultPath);
>     }
>
>     private String buildDefaultPath(Resource resource) {
>         //boolean requiresDigest = cache.requiresDigest(resource);
>
>         String path = resource.getPath();
>         int lastdotx = path.lastIndexOf('.');
>         path = path.substring(0, lastdotx + 1)  + path.substring(lastdotx);
>
>           return aliasManager.toClientURL(path);
>     }
>
>     public Asset createAsset(final Resource resource) {
>         return new AbstractAsset(invariant) {
>             public Resource getResource() {
>                 return resource;
>             }
>
>             public String toClientURL() {
>                 return clientURL(resource);
>             }
>         };
>     }
>
>     public Resource getRootResource() {
>         return rootResource;
>     }
>
> }
>
> public class FileSystemResource extends AbstractResource {
>
>     private static final int PRIME = 37;
>
>     /**
>      * Constructor with the root path
>      * @param path the root
>      */
>     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;
>     }
>
>     @Override
>     public String toString() {
>         return getPath();
>     }
>
>     @Override
>     public int hashCode() {
>         return PRIME * getPath().hashCode();
>     }
>
>     @Override
>     public boolean equals(Object obj) {
>         if (this == obj)
>             return true;
>         if (obj == null)
>             return false;
>         if (getClass() != obj.getClass())
>             return false;
>
>         final FileSystemResource other = (FileSystemResource) obj;
>
>         return getPath().equals(other.getPath());
>     }
>
> }
>
>   


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