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: ContentLoader.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.util.List;
12: import java.util.Set;
13:
14: /**
15: * This is an abstract class that needs to be extended by all the classes that
16: * are able to load raw data and converted it to a common internal type.
17: * <p>Each content loader has a collection of back-ends that are able to
18: * interpret the raw data. All that should be done by an extending class, is
19: * implement the {@link #getBackends() getBackends} method and return a
20: * <code>List</code> of supported loader back-ends.
21: *
22: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
23: * @version $Revision: 3634 $
24: * @since 1.0
25: * @see ContentLoaderBackend
26: */
27: public abstract class ContentLoader<InternalType> {
28: /**
29: * Loads raw data and returns the internal type after successful loading
30: * and handling.
31: * <p>Should any errors occur in the back-ends, then they will be added as
32: * text messages to the <code>errors</code> collection.
33: *
34: * @param data the raw data that has to be loaded
35: * @param fragment <code>true</code> if the raw data is a fragment; or
36: * <p><code>false</code> if the raw data is a complete document or file
37: * @param errors a set to which possible error messages will be added
38: * @return an instance of the internal type that is common for all loaders
39: * for the handled content type, for instance <code>java.awt.Image</code>
40: * for loaders that handle images; or
41: * <p><code>null</code> if the raw data couldn't be loaded
42: * @since 1.0
43: */
44: public InternalType load(Object data, boolean fragment,
45: Set<String> errors) throws ContentManagerException {
46: if (null == data) {
47: return null;
48: }
49:
50: InternalType result = null;
51: for (ContentLoaderBackend<InternalType> loader : getBackends()) {
52: if (loader.isBackendPresent()) {
53: result = loader.load(data, fragment, errors);
54: if (result != null) {
55: break;
56: }
57: }
58: }
59:
60: return result;
61: }
62:
63: /**
64: * Returns a list of support content loading back-ends.
65: * <p>This method should be implemented by all concrete content loaders.
66: *
67: * @return the list of content loader back-ends
68: * @since 1.0
69: */
70: public abstract List<ContentLoaderBackend<InternalType>> getBackends();
71: }
|