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 <andy.pa...@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-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >