KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > renderer > html > HTMLTemplateRenderer


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: HTMLTemplateRenderer.java,v 1.12 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp.renderer.html;
21
22 import java.util.*;
23
24 import org.apache.log4j.*;
25 import org.w3c.dom.*;
26 import org.w3c.dom.html.*;
27
28 import org.enhydra.barracuda.core.comp.*;
29 import org.enhydra.barracuda.core.comp.renderer.*;
30 import org.enhydra.barracuda.core.util.dom.*;
31 import org.enhydra.barracuda.plankton.*;
32
33 /**
34  * This class handles the default rendering of a template into an HTML view.
35  */

36 public class HTMLTemplateRenderer extends HTMLComponentRenderer {
37
38     protected static final Logger logger = Logger.getLogger(HTMLTemplateRenderer.class.getName());
39
40     protected EnabledHelper eh = new EnabledHelper();
41     
42     protected TemplateHelper th = null;
43     
44     /**
45      *
46      */

47     public HTMLTemplateRenderer() {
48         this(null);
49     }
50     
51     /**
52      *
53      */

54     public HTMLTemplateRenderer(TemplateHelper ith) {
55         setTemplateHelper(ith);
56     }
57     
58     /**
59      *
60      */

61     public void setTemplateHelper(TemplateHelper ith) {
62         th = ith;
63     }
64     
65     /**
66      *
67      */

68     public TemplateHelper getTemplateHelper() {
69         if (th==null) th = new TemplateHelper(this);
70         return th;
71     }
72     
73     /**
74      * The purpose of this method is for a renderer to provide
75      * a default node (if none exists). This component currently
76      * does not provide a default, so it throws an UnsupportedFormatException
77      * instead.
78      *
79      * @param doc the master Document which can be used to create elements
80      * from scratch
81      * @param comp the component that we're dealing with for the current request
82      * @param vc the view context for the current request
83      * @return a default node (created from scratch)
84      * @throws UnsupportedFormatException if the renderer has no default node
85      */

86 //csc_110501.1 public Node createDefaultNode(Document doc, ViewContext vc) throws UnsupportedFormatException;
87
public Node createDefaultNode(Document doc, BComponent comp, ViewContext vc) throws UnsupportedFormatException { //csc_110501.1
88
throw new UnsupportedFormatException("Cannot create default node");
89     }
90     
91     /**
92      *
93      */

94     public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException {
95         //make sure the component is a template component
96
if (!(comp instanceof BTemplate)) throw new NoSuitableRendererException("This renderer can only render BTemplate components");
97         BTemplate btemplate = (BTemplate) comp;
98         Node node = view.getNode();
99
100         //make sure the View implements TemplateView
101
if (!(view instanceof TemplateView)) throw new InvalidViewException ("Component is bound to an unsupported View:"+view);
102         TemplateView tview = (TemplateView) view;
103
104         //show what we're doing
105
if (logger.isDebugEnabled()) showNodeInterfaces(view, logger);
106
107         //first, allow the parent class to do anything it needs to
108
super.renderComponent(comp, view, vc);
109
110         //now delegate the actual rendering to the TemplateHelper
111
getTemplateHelper().render(btemplate, tview, vc);
112         
113         //finally, make sure we reflect the components enabled/disabled status
114
eh.setEnabled(node, comp.isEnabled());
115     }
116     
117 }
Popular Tags