KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > samples > components > renderkit > BaseRenderer


1 /*
2  * $Id: BaseRenderer.java 55441 2004-10-24 16:14:10Z cziegeler $
3  */

4
5 /*
6  * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
7  *
8  * Redistribution and use in source and binary forms, with or
9  * without modification, are permitted provided that the following
10  * conditions are met:
11  *
12  * - Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * - Redistribution in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials
18  * provided with the distribution.
19  *
20  * Neither the name of Sun Microsystems, Inc. or the names of
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * This software is provided "AS IS," without a warranty of any
25  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
26  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
28  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
29  * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
30  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
31  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
32  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
33  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
34  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
35  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
36  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37  *
38  * You acknowledge that this software is not designed, licensed or
39  * intended for use in the design, construction, operation or
40  * maintenance of any nuclear facility.
41  */

42
43 package org.apache.cocoon.faces.samples.components.renderkit;
44
45
46 import javax.faces.component.UIComponent;
47 import javax.faces.context.FacesContext;
48 import javax.faces.render.Renderer;
49
50 import java.io.IOException JavaDoc;
51 import java.util.Iterator JavaDoc;
52
53 /**
54  * <p>Convenient base class for <code>Renderer</code> implementations.</p>
55  */

56
57 public abstract class BaseRenderer extends Renderer {
58
59     public static final String JavaDoc BUNDLE_ATTR = "com.sun.faces.bundle";
60
61
62     public String JavaDoc convertClientId(FacesContext context, String JavaDoc clientId) {
63         return clientId;
64     }
65
66     /*
67      * NOTE: Commented out to remove JSTL dependency.
68     protected String getKeyAndLookupInBundle(FacesContext context,
69                                              UIComponent component,
70                                              String keyAttr)
71         throws MissingResourceException {
72         String key = null, bundleName = null;
73         ResourceBundle bundle = null;
74
75         key = (String) component.getAttributes().get(keyAttr);
76         bundleName = (String) component.getAttributes().get(BUNDLE_ATTR);
77
78         // if the bundleName is null for this component, it might have
79         // been set on the root component.
80         if (bundleName == null) {
81             UIComponent root = context.getViewRoot();
82
83             bundleName = (String) root.getAttributes().get(BUNDLE_ATTR);
84         }
85         // verify our component has the proper attributes for key and bundle.
86         if (null == key || null == bundleName) {
87             throw new MissingResourceException("Can't load JSTL classes",
88                                                bundleName, key);
89         }
90
91         // verify the required Class is loadable
92         // PENDING(edburns): Find a way to do this once per ServletContext.
93         if (null == Thread.currentThread().getContextClassLoader().
94             getResource("javax.servlet.jsp.jstl.fmt.LocalizationContext")) {
95             Object[] params = {
96                 "javax.servlet.jsp.jstl.fmt.LocalizationContext"
97             };
98             throw new MissingResourceException("Can't load JSTL classes",
99                                                bundleName, key);
100         }
101
102         // verify there is a ResourceBundle in scoped namescape.
103         javax.servlet.jsp.jstl.fmt.LocalizationContext locCtx = null;
104         if (null == (locCtx = (javax.servlet.jsp.jstl.fmt.LocalizationContext)
105             (Util.getValueBinding(bundleName)).getValue(context)) ||
106             null == (bundle = locCtx.getResourceBundle())) {
107             throw new MissingResourceException("Can't load ResourceBundle ",
108                                                bundleName, key);
109         }
110
111         return bundle.getString(key);
112     }
113     */

114
115     protected void encodeRecursive(FacesContext context, UIComponent component)
116         throws IOException JavaDoc {
117
118         component.encodeBegin(context);
119         if (component.getRendersChildren()) {
120             component.encodeChildren(context);
121         } else {
122             Iterator JavaDoc kids = component.getChildren().iterator();
123             while (kids.hasNext()) {
124                 UIComponent kid = (UIComponent) kids.next();
125                 encodeRecursive(context, kid);
126             }
127         }
128         component.encodeEnd(context);
129
130     }
131
132
133 }
134
Popular Tags