| 1 | |
package org.webslinger.ext.image; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.IOException; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import org.apache.commons.vfs.FileObject; |
| 8 | |
|
| 9 | |
import org.webslinger.lang.ConcurrentCache; |
| 10 | |
import org.webslinger.util.TTLObject; |
| 11 | |
|
| 12 | 0 | public final class ImageConvertingCache extends ConcurrentCache<ImageDescriptor, TTLObject<FileObject>> { |
| 13 | |
private final ImageConvertor convertor; |
| 14 | |
|
| 15 | |
public ImageConvertingCache(Class<?> owner, String field, String label, ImageConvertor convertor) { |
| 16 | 0 | super(owner, field, label, ConcurrentCache.SOFT); |
| 17 | 0 | this.convertor = convertor; |
| 18 | 0 | } |
| 19 | |
|
| 20 | |
public List<ImageTransformerFactory> getFactories() { |
| 21 | 0 | return convertor.getFactories(); |
| 22 | |
} |
| 23 | |
|
| 24 | |
public TTLObject<FileObject> get(ImageDescriptor key) throws IOException { |
| 25 | |
try { |
| 26 | 0 | return super.get(key); |
| 27 | 0 | } catch (IOException e) { |
| 28 | 0 | throw e; |
| 29 | 0 | } catch (RuntimeException e) { |
| 30 | 0 | throw e; |
| 31 | 0 | } catch (Exception e) { |
| 32 | 0 | throw (InternalError) new InternalError(e.getMessage()).initCause(e); |
| 33 | |
} |
| 34 | |
} |
| 35 | |
|
| 36 | |
protected TTLObject<FileObject> createValue(ImageDescriptor key) { |
| 37 | 0 | return convertor.load(key); |
| 38 | |
} |
| 39 | |
} |