01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-4-1/podcasts-app/src/java/org/sakaiproject/tool/podcasts/jsf/renderer/util/RendererUtil.java $
03: * $Id: RendererUtil.java 14691 2006-09-15 12:36:27Z ajpoland@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the"License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.podcasts.jsf.renderer.util;
21:
22: import java.io.IOException;
23: import java.util.Iterator;
24:
25: import javax.faces.component.UIComponent;
26: import javax.faces.context.FacesContext;
27:
28: /**
29: * <p>Place for common utilities for renderers </p>
30: * <p> </p>
31: * @author Ed Smiley esmiley@stanford.edu
32: * @version $Id: RendererUtil.java 14691 2006-09-15 12:36:27Z ajpoland@iupui.edu $
33: */
34:
35: public class RendererUtil {
36: /**
37: * Helper method for recursively encoding a component.
38: * @param context the given FacesContext
39: * @param component the UIComponent to render
40: * @throws IOException
41: */
42: public static void encodeRecursive(FacesContext context,
43: UIComponent component) throws IOException {
44: if (!component.isRendered()) {
45: return;
46: }
47:
48: component.encodeBegin(context);
49:
50: if (component.getRendersChildren()) {
51: component.encodeChildren(context);
52: } else {
53: Iterator iter = component.getChildren().iterator();
54:
55: while (iter.hasNext()) {
56: UIComponent child = (UIComponent) iter.next();
57: encodeRecursive(context, child);
58: }
59: }
60: component.encodeEnd(context);
61: }
62:
63: /**
64: * If renderer supports disabled or readonly attributes use this method to
65: * obtain an early exit from decode method. Good idea to include it anyway,
66: * compnent will continue to work when these properties are added.
67: * @param component
68: * @return
69: */
70: public static boolean isDisabledOrReadonly(UIComponent component) {
71: boolean disabled = false;
72: boolean readOnly = false;
73:
74: Object disabledAttr = component.getAttributes().get("disabled");
75: if (disabledAttr != null) {
76: disabled = disabledAttr.equals(Boolean.TRUE);
77: }
78:
79: Object readOnlyAttr = component.getAttributes().get("readonly");
80: if (readOnlyAttr != null) {
81: readOnly = readOnlyAttr.equals(Boolean.TRUE);
82: }
83:
84: return readOnly | disabled;
85: }
86:
87: }
|