1 16 package org.apache.cocoon.environment.http; 17 18 import org.apache.cocoon.environment.Cookie; 19 import org.apache.cocoon.environment.Response; 20 21 import javax.servlet.ServletOutputStream ; 22 import javax.servlet.http.HttpServletResponse ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import java.util.Locale ; 26 27 34 35 public final class HttpResponse implements Response { 36 37 38 private final HttpServletResponse res; 39 40 43 protected HttpResponse (HttpServletResponse res) { 44 this.res = res; 45 } 46 47 50 public Cookie createCookie(String name, String value) { 51 return new HttpCookie(name, value); 52 } 53 54 public void addCookie(Cookie cookie) { 55 if (cookie instanceof HttpCookie) { 56 this.res.addCookie(((HttpCookie)cookie).getServletCookie()); 57 } else { 58 javax.servlet.http.Cookie newCookie; 59 newCookie = new javax.servlet.http.Cookie (cookie.getName(), cookie.getValue()); 60 newCookie.setComment(cookie.getComment()); 61 newCookie.setDomain(cookie.getDomain()); 62 newCookie.setMaxAge(cookie.getMaxAge()); 63 newCookie.setPath(cookie.getPath()); 64 newCookie.setSecure(cookie.getSecure()); 65 newCookie.setVersion(cookie.getVersion()); 66 this.res.addCookie(newCookie); 67 } 68 } 69 70 public boolean containsHeader(String name) { 71 return this.res.containsHeader(name); 72 } 73 74 public String encodeURL(String url) { 75 if (url != null && url.indexOf(";jsessionid=") != -1) 76 return url; 77 return this.res.encodeURL(url); 78 } 79 80 public String encodeRedirectURL(String url) { 81 if (url != null && url.indexOf(";jsessionid=") != -1) { 82 return url; 83 } 84 85 return this.res.encodeRedirectURL(url); 86 } 87 88 public void sendError(int sc, String msg) throws IOException { 89 this.res.sendError(sc, msg); 90 } 91 92 public void sendError(int sc) throws IOException { 93 this.res.sendError(sc); 94 } 95 96 public void sendRedirect(String location) throws IOException { 97 this.res.sendRedirect(location); 98 } 99 100 public void sendPermanentRedirect(String location) throws IOException { 101 this.res.setHeader("location", location); 102 this.res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); 103 } 104 105 public void setDateHeader(String name, long date) { 106 this.res.setDateHeader(name, date); 107 } 108 109 public void addDateHeader(String name, long date) { 110 this.res.addDateHeader(name, date); 111 } 112 113 public void setHeader(String name, String value) { 114 this.res.setHeader(name, value); 115 } 116 117 public void addHeader(String name, String value) { 118 this.res.addHeader(name, value); 119 } 120 121 public void setIntHeader(String name, int value) { 122 this.res.setIntHeader(name, value); 123 } 124 125 public void addIntHeader(String name, int value) { 126 this.res.addIntHeader(name, value); 127 } 128 129 public void setStatus(int sc) { 130 this.res.setStatus(sc); 131 } 132 133 136 public String encodeUrl(String url) { 137 return this.res.encodeUrl(url); 138 } 139 140 144 public String encodeRedirectUrl(String url) { 145 return this.res.encodeRedirectUrl(url); 146 } 147 148 154 public void setStatus(int sc, String sm) { 155 this.res.setStatus(sc, sm); 156 } 157 158 159 160 public String getCharacterEncoding() { 161 return this.res.getCharacterEncoding(); 162 } 163 164 public ServletOutputStream getOutputStream() throws IOException { 165 return this.res.getOutputStream(); 167 } 168 169 public PrintWriter getWriter() throws IOException { 170 return this.res.getWriter(); 172 } 173 174 public void setContentLength(int len) { 175 this.res.setContentLength(len); 176 } 177 178 public void setContentType(String type) { 179 this.res.setContentType(type); 180 } 181 182 public void setBufferSize(int size) { 183 this.res.setBufferSize(size); 184 } 185 186 public int getBufferSize() { 187 return this.res.getBufferSize(); 188 } 189 190 public void flushBuffer() throws IOException { 191 this.res.flushBuffer(); 192 } 193 194 public boolean isCommitted() { 195 return this.res.isCommitted(); 196 } 197 198 public void reset() { 199 this.res.reset(); 200 } 201 202 public void setLocale(Locale loc) { 203 this.res.setLocale(loc); 204 } 205 206 public Locale getLocale() { 207 return this.res.getLocale(); 208 } 209 } 210 211 | Popular Tags |