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: RawFormatter.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.format;
09:
10: import com.uwyn.rife.cmf.Content;
11: import com.uwyn.rife.cmf.format.exceptions.FormatException;
12: import com.uwyn.rife.cmf.format.exceptions.InvalidContentDataTypeException;
13: import com.uwyn.rife.cmf.transform.ContentTransformer;
14: import java.io.InputStream;
15:
16: /**
17: * Formats raw <code>Content</code> data.
18: * <p>This merely executes the provided transformer on the data.
19: *
20: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
21: * @version $Revision: 3634 $
22: * @since 1.0
23: * @see Formatter
24: */
25: public class RawFormatter implements
26: Formatter<InputStream, InputStream> {
27: public InputStream format(Content content,
28: ContentTransformer<InputStream> transformer)
29: throws FormatException {
30: if (!(content.getData() instanceof InputStream)) {
31: throw new InvalidContentDataTypeException(this , content
32: .getMimeType(), InputStream.class, content
33: .getData().getClass());
34: }
35:
36: InputStream data = (InputStream) content.getData();
37:
38: // transform the content, if needed
39: if (transformer != null) {
40: data = transformer.transform(data, content.getAttributes());
41: }
42:
43: return data;
44: }
45: }
|