1 17 package org.alfresco.web.ui.common.component.debug; 18 19 import java.io.IOException ; 20 import java.util.Map ; 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 33 public abstract class BaseDebugComponent extends SelfRenderingComponent 34 { 35 private String title; 36 37 42 public abstract Map getDebugData(); 43 44 47 public void encodeBegin(FacesContext context) throws IOException 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 session = getDebugData(); 67 for (Object 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 obj = session.get(key); 73 if (obj == null) 74 { 75 out.write("null"); 76 } 77 else 78 { 79 String value = obj.toString(); 80 if (value.length() == 0) 81 { 82 out.write(" "); 83 } 84 else 85 { 86 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 102 public boolean getRendersChildren() 103 { 104 return false; 105 } 106 107 110 public void restoreState(FacesContext context, Object state) 111 { 112 Object values[] = (Object [])state; 113 super.restoreState(context, values[0]); 115 this.title = (String )values[1]; 116 } 117 118 121 public Object saveState(FacesContext context) 122 { 123 Object values[] = new Object [2]; 124 values[0] = super.saveState(context); 126 values[1] = this.title; 127 return (values); 128 } 129 130 135 public String getTitle() 136 { 137 ValueBinding vb = getValueBinding("title"); 138 if (vb != null) 139 { 140 this.title = (String )vb.getValue(getFacesContext()); 141 } 142 143 return this.title; 144 } 145 146 151 public void setTitle(String title) 152 { 153 this.title = title; 154 } 155 } 156 | Popular Tags |