01: /*
02: * Copyright 2005-2007 jWic group (http://www.jwic.de)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: * de.jwic.renderer.self.SelfRenderer
17: * Created on 12.03.2007
18: * $Id: SelfRenderer.java,v 1.1 2007/03/15 11:58:28 lordsam Exp $
19: */
20: package de.jwic.renderer.self;
21:
22: import java.io.PrintWriter;
23:
24: import de.jwic.base.Control;
25: import de.jwic.base.IControlRenderer;
26: import de.jwic.base.RenderContext;
27:
28: /**
29: * This renderer passes the renderContext to a control so that it can
30: * render itself to HTML. This rendering method may be used by controls
31: * that do not use templates and create the HTML "by code".
32: *
33: * A control that wants to use this renderer must implement the ISelfRenderingControl
34: * interface.
35: *
36: * @author Florian Lippisch
37: */
38: public class SelfRenderer implements IControlRenderer {
39:
40: public final static String RENDERER_ID = "jwic.selfRenderer";
41:
42: /* (non-Javadoc)
43: * @see de.jwic.base.IControlRenderer#renderControl(de.jwic.base.Control, de.jwic.base.RenderContext)
44: */
45: public void renderControl(Control control, RenderContext context) {
46:
47: control.setRequireRedraw(false);
48: PrintWriter writer = context.getWriter();
49: String ctrlDivID = "ctrl_" + control.getControlID();//.replace('.', '_');
50:
51: writer.print("<span><span id=\"" + ctrlDivID + "\">");
52: if (control instanceof ISelfRenderingControl) {
53: ISelfRenderingControl sfCtrl = (ISelfRenderingControl) control;
54: if (control.isVisible()) {
55: sfCtrl.render(context);
56: }
57: } else {
58: writer.write("[" + control.getControlID()
59: + " does not implement ISelfRenderingControl]");
60: }
61: writer.print("</span></span>");
62:
63: }
64:
65: }
|