01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.render;
19:
20: import java.io.IOException;
21: import java.io.Writer;
22: import java.util.Collection;
23: import java.util.Map;
24:
25: import de.finix.contelligent.CallData;
26: import de.finix.contelligent.content.BooleanContent;
27: import de.finix.contelligent.content.Content;
28: import de.finix.contelligent.content.NumberContent;
29: import de.finix.contelligent.content.StringContent;
30: import de.finix.contelligent.content.TextContent;
31: import de.finix.contelligent.exception.ContelligentException;
32: import de.finix.contelligent.logging.LoggingService;
33:
34: public class DefaultRenderer implements Renderer {
35: final static org.apache.log4j.Logger log = LoggingService
36: .getLogger(DefaultRenderer.class);
37:
38: private Content content;
39:
40: private Collection sensitiveCategories;
41:
42: public DefaultRenderer(Content content) {
43: this .content = content;
44: this .sensitiveCategories = content.getSensitiveCategories();
45: }
46:
47: public ParameterDescription[] getParameterDescription() {
48: return new ParameterDescription[0];
49: }
50:
51: public Collection getSensitiveCategories() {
52: return sensitiveCategories;
53: }
54:
55: public String getContentAsString(CallData callData)
56: throws ContelligentException, IOException,
57: MissingParameterException {
58: if (content instanceof StringContent) {
59: return ((StringContent) content).getString(callData);
60: } else if (content instanceof TextContent) {
61: return ((TextContent) content).getText(callData);
62: } else if (content instanceof NumberContent) {
63: Number nc = ((NumberContent) content).getNumber(callData);
64: return ((nc != null) ? nc.toString() : null);
65: } else if (content instanceof BooleanContent) {
66: Boolean bc = ((BooleanContent) content)
67: .getBoolean(callData);
68: return ((bc != null) ? bc.toString() : null);
69: } else {
70: throw new ContelligentException(
71: "render(): Cannot handle content [" + content + "]");
72: }
73: }
74:
75: public void render(Writer writer, Map parameterMap,
76: CallData callData) throws ContelligentException,
77: IOException {
78: String stringContent = getContentAsString(callData);
79: if (stringContent != null && stringContent.length() > 0) {
80: writer.write(stringContent);
81: }
82: }
83: }
|