KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > component > debug > BaseDebugComponent


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.component.debug;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.faces.context.FacesContext;
23 import javax.faces.context.ResponseWriter;
24 import javax.faces.el.ValueBinding;
25
26 import org.alfresco.web.ui.common.component.SelfRenderingComponent;
27
28 /**
29  * Base class for all debug components
30  *
31  * @author gavinc
32  */

33 public abstract class BaseDebugComponent extends SelfRenderingComponent
34 {
35    private String JavaDoc title;
36
37    /**
38     * Retrieves the debug data to show for the component as a Map
39     *
40     * @return The Map of data
41     */

42    public abstract Map JavaDoc getDebugData();
43    
44    /**
45     * @see javax.faces.component.UIComponent#encodeBegin(javax.faces.context.FacesContext)
46     */

47    public void encodeBegin(FacesContext context) throws IOException JavaDoc
48    {
49       if (isRendered() == false)
50       {
51          return;
52       }
53       
54       ResponseWriter out = context.getResponseWriter();
55       out.write("<table cellpadding='2' cellspacing='2' border='0' style='border: 1px solid #aaaaaa;border-collapse: collapse;border-spacing: 0px;'>");
56       
57       if (this.getTitle() != null)
58       {
59          out.write("<tr><td colspan='2'>");
60          out.write(this.getTitle());
61          out.write("</td></tr>");
62       }
63       
64       out.write("<tr style='border: 1px solid #dddddd;'><th align='left'>Property</th><th align='left'>Value</th></tr>");
65       
66       Map JavaDoc session = getDebugData();
67       for (Object JavaDoc key : session.keySet())
68       {
69          out.write("<tr style='border: 1px solid #dddddd;'><td>");
70          out.write(key.toString());
71          out.write("</td><td>");
72          Object JavaDoc obj = session.get(key);
73          if (obj == null)
74          {
75             out.write("null");
76          }
77          else
78          {
79             String JavaDoc value = obj.toString();
80             if (value.length() == 0)
81             {
82                out.write("&nbsp;");
83             }
84             else
85             {
86                // replace any ; characters with ;<space> as that will help break up long lines
87
value = value.replaceAll(";", "; ");
88                out.write(value);
89             }
90          }
91          out.write("</td></tr>");
92       }
93       
94       out.write("</table>");
95       
96       super.encodeBegin(context);
97    }
98
99    /**
100     * @see javax.faces.component.UIComponent#getRendersChildren()
101     */

102    public boolean getRendersChildren()
103    {
104       return false;
105    }
106
107    /**
108     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
109     */

110    public void restoreState(FacesContext context, Object JavaDoc state)
111    {
112       Object JavaDoc values[] = (Object JavaDoc[])state;
113       // standard component attributes are restored by the super class
114
super.restoreState(context, values[0]);
115       this.title = (String JavaDoc)values[1];
116    }
117    
118    /**
119     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
120     */

121    public Object JavaDoc saveState(FacesContext context)
122    {
123       Object JavaDoc values[] = new Object JavaDoc[2];
124       // standard component attributes are saved by the super class
125
values[0] = super.saveState(context);
126       values[1] = this.title;
127       return (values);
128    }
129    
130    /**
131     * Returns the title
132     *
133     * @return The title
134     */

135    public String JavaDoc getTitle()
136    {
137       ValueBinding vb = getValueBinding("title");
138       if (vb != null)
139       {
140          this.title = (String JavaDoc)vb.getValue(getFacesContext());
141       }
142       
143       return this.title;
144    }
145
146    /**
147     * Sets the title
148     *
149     * @param title The title
150     */

151    public void setTitle(String JavaDoc title)
152    {
153       this.title = title;
154    }
155 }
156
Popular Tags