KickJava   Java API By Example, From Geeks To Geeks.

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


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: HTMLInputRenderer.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 list in an HTML view.
35  */

36 public class HTMLInputRenderer extends HTMLComponentRenderer {
37
38     protected static final Logger logger = Logger.getLogger(HTMLInputRenderer.class.getName());
39     
40     protected EnabledHelper eh = new EnabledHelper();
41         
42     protected BInput bicomp = null;
43     
44     /**
45      * The purpose of this method is to create a default Node to be used when
46      * the component is not bound to any specific view.
47      *
48      * @param doc the master Document which can be used to create elements
49      * from scratch
50      * @param comp the component that we're dealing with for the current request
51      * @param vc the view context for the current request
52      * @return a default node (created from scratch)
53      * @throws UnsupportedFormatException if the renderer has no default node
54      */

55 //csc_110501.1 public Node createDefaultNode(Document doc, ViewContext vc) throws UnsupportedFormatException;
56
public Node createDefaultNode(Document doc, BComponent comp, ViewContext vc) throws UnsupportedFormatException { //csc_110501.1
57
//ask the renderer to create the default Node
58
/*
59 //removed - should clone the default node
60         Element inputEl = (HTMLInputElement) doc.createElement("INPUT");
61         Node defaultNode = inputEl;
62 */

63         Node templateNode = vc.getTemplateNode();
64         Node defaultNode = null;
65         if (templateNode instanceof HTMLInputElement) {
66             defaultNode = templateNode.cloneNode(true);
67         } else {
68             defaultNode = (HTMLInputElement) doc.createElement("INPUT");
69         }
70         
71         if (logger.isInfoEnabled()) logger.info("Creating default node:"+defaultNode);
72         return defaultNode;
73     }
74
75     /**
76      *
77      */

78     public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException {
79         //make sure the component is a list component
80
if (!(comp instanceof BInput)) throw new NoSuitableRendererException("This renderer can only render BInput components; comp is of type:"+comp.getClass().getName());
81         bicomp = (BInput) comp;
82         Node node = view.getNode();
83
84         //show what we're doing
85
if (logger.isDebugEnabled()) showNodeInterfaces(view, logger);
86
87         //first, allow the parent class to do anything it needs to
88
super.renderComponent(comp, view, vc);
89
90         //..HTMLInputElement - set the "type" and "value" attributes
91
if (node instanceof HTMLInputElement) {
92             if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLInputElement interface...");
93             HTMLInputElement el = (HTMLInputElement) node;
94
95             //set the type (if specified)
96
String JavaDoc type = bicomp.getType();
97             if (type!=null) el.setAttribute("type", type);
98
99             //set the value (if specified)
100
String JavaDoc value = bicomp.getValue();
101             if (value!=null) el.setValue(value);
102             
103         } else {
104             String JavaDoc errmsg = "Node does not implement HTMLInputElement and cannot be rendered: "+node;
105             logger.warn(errmsg);
106             throw new NoSuitableRendererException(errmsg);
107         }
108
109         //finally, make sure we reflect the components enabled/disabled status
110
eh.setEnabled(node, comp.isEnabled());
111     }
112 }
Popular Tags