01: /*
02: f
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.framework;
11:
12: import java.util.*;
13: import javax.servlet.http.*;
14: import java.lang.reflect.Method;
15: import java.io.*;
16: import org.mmbase.util.functions.*;
17: import org.mmbase.util.logging.Logger;
18: import org.mmbase.util.logging.Logging;
19:
20: /**
21: * The overly simple renderer which is simply based on a String present in the configuration
22: * file. Based on {@link PatterNodeFunctionProvider} so several parameters can be present.
23: *
24: * @author Michiel Meeuwissen
25: * @version $Id: StringRenderer.java,v 1.10 2008/02/20 17:44:07 michiel Exp $
26: * @since MMBase-1.9
27: */
28: public class StringRenderer extends AbstractRenderer {
29: private static final Logger log = Logging
30: .getLoggerInstance(StringRenderer.class);
31:
32: protected String string;
33: protected Map<String, Method> requestMethods;
34:
35: public StringRenderer(String t, Block parent) {
36: super (t, parent);
37: }
38:
39: public void setString(String s) {
40: string = s;
41: requestMethods = PatternNodeFunctionProvider
42: .getRequestMethods(string);
43: }
44:
45: /**
46: * @todo should consider the string
47: */
48: public Parameter[] getParameters() {
49: return new Parameter[] { Parameter.REQUEST };
50: }
51:
52: public void render(Parameters blockParameters,
53: Parameters frameworkParameters, Writer w,
54: Renderer.WindowState state) throws FrameworkException {
55: log.debug("Rendering " + string);
56: try {
57: HttpServletRequest request = blockParameters
58: .get(Parameter.REQUEST);
59: if (request == null)
60: throw new RuntimeException("No request parameter in "
61: + blockParameters);
62: StringBuffer sb = new StringBuffer(string);
63: PatternNodeFunctionProvider.handleRequest(sb,
64: blockParameters, requestMethods);
65: w.write(sb.toString());
66: } catch (IOException ioe) {
67: throw new FrameworkException(ioe.getMessage(), ioe);
68: }
69: }
70:
71: public String toString() {
72: return string;
73: }
74: }
|