1 4 package com.opensymphony.module.sitemesh.filter; 5 6 import javax.servlet.ServletOutputStream ; 7 import javax.servlet.http.Cookie ; 8 import javax.servlet.http.HttpServletResponse ; 9 import javax.servlet.http.HttpServletResponseWrapper ; 10 import java.io.IOException ; 11 import java.io.PrintWriter ; 12 import java.util.Locale ; 13 14 18 public class DebugResponseWrapper extends HttpServletResponseWrapper { 19 private static int lastCount = 0; 20 private int count = 0; 21 22 public DebugResponseWrapper(HttpServletResponse response) { 23 super(response); 24 if (enabled()) { 25 lastCount++; 26 count = lastCount; 27 debug("<CONSTRUCT>", null, null); 28 } 29 } 30 31 public void addCookie(Cookie cookie) { 32 if (enabled()) debug("addCookie", cookie.getName(), cookie.toString()); 33 super.addCookie(cookie); 34 } 35 36 public void addDateHeader(String name, long date) { 37 if (enabled()) debug("addDateHeader", name, String.valueOf(date)); 38 super.addDateHeader(name, date); 39 } 40 41 public void addHeader(String name, String value) { 42 if (enabled()) debug("addHeader", name, value); 43 super.addHeader(name, value); 44 } 45 46 public void addIntHeader(String name, int value) { 47 if (enabled()) debug("addIntHeader", name, String.valueOf(value)); 48 super.addIntHeader(name, value); 49 } 50 51 public boolean containsHeader(String name) { 52 return super.containsHeader(name); 53 } 54 55 public String encodeRedirectUrl(String url) { 56 return super.encodeRedirectUrl(url); 57 } 58 59 public String encodeRedirectURL(String url) { 60 return super.encodeRedirectURL(url); 61 } 62 63 public void sendError(int sc) throws IOException { 64 if (enabled()) debug("sendError", String.valueOf(sc), null); 65 super.sendError(sc); 66 } 67 68 public void sendError(int sc, String msg) throws IOException { 69 if (enabled()) debug("sendError", String.valueOf(sc), msg); 70 super.sendError(sc, msg); 71 } 72 73 public void sendRedirect(String location) throws IOException { 74 if (enabled()) debug("sendRedirect", location, null); 75 super.sendRedirect(location); 76 } 77 78 public void setDateHeader(String name, long date) { 79 if (enabled()) debug("setDateHeader", name, String.valueOf(date)); 80 super.setDateHeader(name, date); 81 } 82 83 public void setHeader(String name, String value) { 84 if (enabled()) debug("setHeader", name, value); 85 super.setHeader(name, value); 86 } 87 88 public void setIntHeader(String name, int value) { 89 if (enabled()) debug("setIntHeader", name, String.valueOf(value)); 90 super.setIntHeader(name, value); 91 } 92 93 public void setStatus(int sc) { 94 if (enabled()) debug("setStatus", String.valueOf(sc), null); 95 super.setStatus(sc); 96 } 97 98 public void setStatus(int sc, String msg) { 99 if (enabled()) debug("setStatus", String.valueOf(sc), msg); 100 super.setStatus(sc, msg); 101 } 102 103 public void flushBuffer() throws IOException { 104 if (enabled()) debug("flushBuffer", null, null); 105 super.flushBuffer(); 106 } 107 108 public int getBufferSize() { 109 return super.getBufferSize(); 111 } 112 113 public String getCharacterEncoding() { 114 return super.getCharacterEncoding(); 116 } 117 118 public Locale getLocale() { 119 return super.getLocale(); 121 } 122 123 public ServletOutputStream getOutputStream() throws IOException { 124 if (enabled()) debug("getOutputStream", null, null); 125 return super.getOutputStream(); 126 } 127 128 public PrintWriter getWriter() throws IOException { 129 if (enabled()) debug("getWriter", null, null); 130 return super.getWriter(); 131 } 132 133 public boolean isCommitted() { 134 return super.isCommitted(); 136 } 137 138 public void reset() { 139 if (enabled()) debug("reset", null, null); 140 super.reset(); 141 } 142 143 146 147 public void setBufferSize(int size) { 148 if (enabled()) debug("setBufferSize", String.valueOf(size), null); 149 super.setBufferSize(size); 150 } 151 152 public void setContentLength(int len) { 153 if (enabled()) debug("setContentLength", String.valueOf(len), null); 154 super.setContentLength(len); 155 } 156 157 public void setContentType(String type) { 158 if (enabled()) debug("setContentType", type, null); 159 super.setContentType(type); 160 } 161 162 public void setLocale(Locale locale) { 163 if (enabled()) debug("setBufferSize", locale.getDisplayName(), null); 164 super.setLocale(locale); 165 } 166 167 private boolean enabled() { 168 return true; 169 } 170 171 private void debug(String methodName, String arg1, String arg2) { 172 StringBuffer s = new StringBuffer (); 173 s.append("[debug "); 174 s.append(count); 175 s.append("] "); 176 s.append(methodName); 177 s.append("()"); 178 if (arg1 != null) { 179 s.append(" : '"); 180 s.append(arg1); 181 s.append("'"); 182 } 183 if (arg2 != null) { 184 s.append(" = '"); 185 s.append(arg2); 186 s.append("'"); 187 } 188 System.out.println(s); 189 } 190 } | Popular Tags |