001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.framework;
011:
012: import java.io.*;
013: import java.net.URI;
014: import org.mmbase.util.functions.*;
015:
016: /**
017: * A Renderer renders a certain aspect of a {@link Block}. Currently every block has two renderers,
018: * which are identified by the renderer 'type' (see {@link #getType }). Every block also has a
019: * {@link Processor}, which is similar to a Renderer, but a processor never generates content, only
020: * handles interaction.
021: *
022: * A Renderer is stateless.
023: *
024: * @author Michiel Meeuwissen
025: * @version $Id: Renderer.java,v 1.19 2008/01/25 09:32:23 michiel Exp $
026: * @since MMBase-1.9
027: */
028: public interface Renderer {
029:
030: /**
031: * Every block can be in a certain window state, which could be considered during rendering.
032: */
033:
034: enum WindowState {
035: /**
036: * Rendering may suppose a full browser window
037: */
038: MAXIMIZED,
039: /**
040: * Rendering should suppose only a 'link' version from the component.
041: */
042: MINIMIZED,
043: /**
044: * Rendering may suppose quite a large area, but should be aware that other blocks are in a
045: * similar state.
046: */
047: NORMAL;
048: }
049:
050: enum Type {
051: /**
052: * Not yet rendering
053: */
054: NOT,
055: /**
056: * Rendering for 'HEAD' typically happens in the <head> block of HTML, and can
057: * e.g. produce links to javascript.
058: */
059: HEAD,
060: /**
061: * A body typed renderer renders the actual content of a block. It should produce a <div>
062: */
063: BODY;
064:
065: /**
066: * Returns a renderer that does nothing.
067: */
068: Renderer getEmpty(final Block block) {
069: return new Renderer() {
070: public Type getType() {
071: return Type.this ;
072: }
073:
074: public void render(Parameters parameters,
075: Parameters urlparameters, Writer w,
076: WindowState state) {
077: };
078:
079: public Parameter[] getParameters() {
080: return Parameter.emptyArray();
081: };
082:
083: public Block getBlock() {
084: return block;
085: };
086:
087: public String toString() {
088: return "EMPTY Renderer";
089: }
090:
091: public URI getUri() {
092: try {
093: return new URI("mmbase:/renderer/" + Type.this
094: + "/empty");
095: } catch (Exception e) {
096: return null;
097: }
098: }
099: };
100: }
101: }
102:
103: /**
104: * Describes what kind of renderer this is
105: */
106: Type getType();
107:
108: /**
109: * Every renderer renders for a certain block.
110: */
111: Block getBlock();
112:
113: /**
114: * A renderer may need certain parameters. These are added to the block-parameters. This method
115: * is called on instantation of the renderer.
116: */
117: Parameter[] getParameters();
118:
119: /**
120: * Renders to a writer. In case of e.g. a JSPView, the parameters must also contain
121: * the Http Servlet response and request, besided specific parameters for this component.
122: */
123: void render(Parameters blockParameters,
124: Parameters frameworkParameters, Writer w, WindowState state)
125: throws FrameworkException;
126:
127: /**
128: * An URI which may identify the implementation of this Renderer.
129: */
130:
131: URI getUri();
132: }
|