01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ImageContentLoaderBackend.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.loader;
09:
10: import com.uwyn.rife.cmf.dam.exceptions.ContentManagerException;
11: import java.awt.Image;
12: import java.util.Set;
13:
14: /**
15: * This is an abstract class that should be implemented by all image content
16: * loader back-ends.
17: * <p>The {@link #load(Object, boolean, Set) load} method simply checks the
18: * type of the data and delegates the handling to typed methods that should be
19: * implemented by the back-ends.
20: *
21: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
22: * @version $Revision: 3634 $
23: * @since 1.0
24: */
25: public abstract class ImageContentLoaderBackend implements
26: ContentLoaderBackend<Image> {
27: /**
28: * Loads the data from a byte array.
29: *
30: * @param data the raw data that has to be loaded
31: * @param errors a set to which possible error messages will be added
32: * @return an instance of the <code>Image</code>; or
33: * <p><code>null</code> if the raw data couldn't be loaded
34: */
35: protected abstract Image loadFromBytes(byte[] data,
36: Set<String> errors) throws ContentManagerException;
37:
38: public Image load(Object data, boolean fragment, Set<String> errors)
39: throws ContentManagerException {
40: Image image = null;
41:
42: if (data instanceof byte[]) {
43: image = loadFromBytes((byte[]) data, errors);
44: } else {
45: return null;
46: }
47:
48: return image;
49: }
50: }
|