01: /*
02:
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 java.io.*;
14: import org.mmbase.util.functions.*;
15: import org.mmbase.util.logging.Logger;
16: import org.mmbase.util.logging.Logging;
17:
18: /**
19: * This renderer simply calles the methods of a number of other Renderes sequentially. Only
20: * {@link Renderer.Type.HEAD} renderers can be chained, because they don't have to produce a well defined
21: * block.
22: *
23: * @author Michiel Meeuwissen
24: * @version $Id: ChainedRenderer.java,v 1.4 2008/02/03 17:33:56 nklasens Exp $
25: * @since MMBase-1.9
26: */
27:
28: public class ChainedRenderer extends AbstractRenderer {
29: private static final Logger log = Logging
30: .getLoggerInstance(ChainedRenderer.class);
31:
32: protected final List<Renderer> chain = new ArrayList<Renderer>();
33: protected Parameter[] parameters = Parameter.EMPTY;
34:
35: public ChainedRenderer(String t, Block parent) {
36: super (t, parent);
37: }
38:
39: public void add(Renderer render) {
40: chain.add(render);
41: List<Parameter> params = new ArrayList<Parameter>(Arrays
42: .asList(parameters));
43: params.addAll(Arrays.asList(render.getParameters()));
44: parameters = params.toArray(Parameter.EMPTY);
45: }
46:
47: public Parameter[] getParameters() {
48: return parameters;
49: }
50:
51: public void render(Parameters blockParameters,
52: Parameters frameworkParameters, Writer w, WindowState state)
53: throws FrameworkException {
54: for (Renderer renderer : chain) {
55: renderer.render(blockParameters, frameworkParameters, w,
56: state);
57: }
58: }
59:
60: public String toString() {
61: return chain.toString();
62: }
63:
64: public java.net.URI getUri() {
65: if (chain.size() > 0) {
66: return chain.get(0).getUri();
67: } else {
68: return null;
69: }
70: }
71: }
|