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: PlainTextFormatter.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:
15: /**
16: * Formats plain test <code>Content</code> data.
17: * <p>This merely executes the provided transformer on the data.
18: *
19: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
20: * @version $Revision: 3634 $
21: * @since 1.0
22: * @see Formatter
23: */
24: public class PlainTextFormatter implements Formatter<String, String> {
25: public String format(Content content,
26: ContentTransformer<String> transformer)
27: throws FormatException {
28: if (!(content.getData() instanceof String)) {
29: throw new InvalidContentDataTypeException(this , content
30: .getMimeType(), String.class, content.getData()
31: .getClass());
32: }
33:
34: String data = (String) content.getData();
35:
36: // transform the content, if needed
37: if (transformer != null) {
38: data = transformer.transform(data, content.getAttributes());
39: }
40:
41: return data;
42: }
43: }
|