01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/DebugRenderer.java $
03: * $Id: DebugRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004 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.jsf.renderer;
21:
22: import java.io.IOException;
23: import java.util.Iterator;
24: import java.util.Map;
25:
26: import javax.faces.component.UIComponent;
27: import javax.faces.component.UIOutput;
28: import javax.faces.context.FacesContext;
29: import javax.faces.context.ResponseWriter;
30: import javax.faces.render.Renderer;
31:
32: public class DebugRenderer extends Renderer {
33: public boolean supportsComponentType(UIComponent component) {
34: return (component instanceof UIOutput);
35: }
36:
37: public void encodeBegin(FacesContext context, UIComponent component)
38: throws IOException {
39: if (!component.isRendered())
40: return;
41:
42: ResponseWriter writer = context.getResponseWriter();
43: writer.write("<xmp>");
44: writer.write("***** DEBUG TAG RENDER OUTPUT *****\n\n");
45:
46: dumpJSFVariable("applicationScope", context);
47: dumpJSFVariable("sessionScope", context);
48: dumpJSFVariable("requestScope", context);
49: dumpJSFVariable("toolScope", context);
50: dumpJSFVariable("toolConfig", context);
51: dumpJSFVariable("param", context);
52: writer.write("</xmp>");
53: }
54:
55: private void dumpJSFVariable(String varName, FacesContext context)
56: throws IOException {
57: Object varValue = context.getApplication()
58: .getVariableResolver()
59: .resolveVariable(context, varName);
60: ResponseWriter writer = context.getResponseWriter();
61:
62: if (varValue instanceof Map) {
63: dumpMap((Map) varValue, varName, writer);
64: } else {
65: writer.write(varName);
66: writer.write(": ");
67: writer.write(String.valueOf(varValue));
68: writer.write("\n\n");
69: }
70:
71: }
72:
73: private void dumpMap(Map map, String mapName, ResponseWriter writer)
74: throws IOException {
75: writer.write(mapName);
76: if (map == null) {
77: writer.write(" is null\n\n");
78: return;
79: }
80:
81: writer.write(" " + map + " contains: \n");
82: Iterator i = map.keySet().iterator();
83: while (i.hasNext()) {
84: Object name = i.next();
85: Object value = map.get(name);
86: writer.write(String.valueOf(name));
87: writer.write(" -> ");
88: writer.write(String.valueOf(value));
89: writer.write('\n');
90: }
91:
92: writer.write("\n\n");
93: }
94: }
|