KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > div > DivRenderer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 package org.apache.myfaces.custom.div;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.context.ResponseWriter;
23
24 import org.apache.myfaces.renderkit.html.HTML;
25 import org.apache.myfaces.renderkit.html.HtmlRenderer;
26 import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
27 /**
28  * @author bdudney (latest modification by $Author: svieujot $)
29  * @version $Revision: 1.5 $ $Date: 2005/02/09 21:17:57 $
30  * $Log: DivRenderer.java,v $
31  * Revision 1.5 2005/02/09 21:17:57 svieujot
32  * Bugfix for MYFACES-105, thanks to Norm Deane
33  *
34  * Revision 1.4 2005/02/09 17:41:30 svieujot
35  * Apply Sean Schofield's patch for MYFACES-104
36  *
37  * Revision 1.3 2004/11/27 00:00:09 svieujot
38  * Remove the limitation to have a style or a styleClass attribute because sometimes, just a plain <div> can be useful.
39  *
40  * Revision 1.2 2004/11/10 11:09:52 bdudney
41  * div renderer now puts the class/style in quotes
42  *
43  * Revision 1.1 2004/11/08 03:43:20 bdudney
44  * Added a div element. x:div to use, inserts a div with class or style attributes
45  *
46  */

47 public class DivRenderer extends HtmlRenderer {
48   public static final String JavaDoc RENDERER_TYPE = "org.apache.myfaces.DivRenderer";
49
50   public void encodeBegin(FacesContext context, UIComponent component)
51       throws IOException JavaDoc {
52     if ((context == null) || (component == null)) {
53       throw new NullPointerException JavaDoc();
54     }
55     Div div = (Div) component;
56     ResponseWriter writer = context.getResponseWriter();
57     
58     writer.startElement(HTML.DIV_ELEM, component);
59     HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
60     
61     String JavaDoc styleClass = div.getStyleClass();
62     String JavaDoc style = div.getStyle();
63     if(null != styleClass && null != style) {
64       throw new IllegalStateException JavaDoc("Only one of style or styleClass can be specified");
65     }
66     if(null != styleClass) {
67         writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
68     }
69     if(null != style) {
70         writer.writeAttribute(HTML.STYLE_ATTR, style, null);
71     }
72   }
73
74   public void encodeEnd(FacesContext context, UIComponent component)
75       throws IOException JavaDoc {
76     if ((context == null) || (component == null)) {
77       throw new NullPointerException JavaDoc();
78     }
79     ResponseWriter writer = context.getResponseWriter();
80     writer.endElement(HTML.DIV_ELEM);
81   }
82 }
Popular Tags