package org.xins.common.servlet.container;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.xins.common.MandatoryArgumentChecker;
public class XINSServletResponse implements HttpServletResponse {
private String _contentType;
private int _contentLength = -99;
private int _status;
private String _encoding = "ISO-8859-1";
private StringWriter _writer;
private Map<String, String> _headers = new HashMap<String, String>();
public XINSServletResponse() {
}
public void addDateHeader(String str, long param) {
throw new UnsupportedOperationException();
}
public void setDateHeader(String str, long param) {
throw new UnsupportedOperationException();
}
public String encodeUrl(String url) {
return url;
}
public String encodeURL(String url) {
return url;
}
public String encodeRedirectUrl(String str) {
throw new UnsupportedOperationException();
}
public String encodeRedirectURL(String str) {
throw new UnsupportedOperationException();
}
public boolean containsHeader(String str) {
return _headers.get(str) != null;
}
public void sendRedirect(String location) {
setStatus(302);
setHeader("Location", location);
}
public void setContentType(String type)
throws IllegalArgumentException {
MandatoryArgumentChecker.check("type", type);
setHeader("Content-Type", type);
String search = "charset=";
int i = type.indexOf(search);
if (i >= 0) {
_encoding = type.substring(i + search.length());
}
_contentType = type;
}
public void setStatus(int sc) {
_status = sc;
}
public void sendError(int sc) {
sendError(sc, null);
}
public void setBufferSize(int param) {
throw new UnsupportedOperationException();
}
int getContentLength() {
return _contentLength;
}
public void setContentLength(int param) {
_contentLength = param;
setIntHeader("Content-Length", param);
}
public void addCookie(Cookie cookie) {
String cookieHeader = cookie.getName() + "=" + cookie.getValue();
if (cookie.getPath() != null) {
cookieHeader += "; path=" + cookie.getPath();
}
if (cookie.getDomain() != null) {
cookieHeader += "; domain=" + cookie.getDomain();
}
setHeader("Set-Cookie", cookieHeader);
}
public void setLocale(Locale locale) {
throw new UnsupportedOperationException();
}
public void setStatus(int param, String str) {
throw new UnsupportedOperationException();
}
public void setIntHeader(String str, int param) {
setHeader(str, "" + param);
}
public void addIntHeader(String str, int param) {
setHeader(str, "" + param);
}
public void sendError(int sc, String msg) {
_status = sc;
}
public void setHeader(String str, String str1) {
_headers.put(str, str1);
}
public Locale getLocale() {
throw new UnsupportedOperationException();
}
public String getCharacterEncoding() {
return _encoding;
}
public int getBufferSize() {
throw new UnsupportedOperationException();
}
public void flushBuffer() {
throw new UnsupportedOperationException();
}
public void addHeader(String str, String str1) {
_headers.put(str, str1);
}
public ServletOutputStream getOutputStream() {
throw new UnsupportedOperationException();
}
public PrintWriter getWriter() {
_writer = new StringWriter();
return new PrintWriter(_writer);
}
public boolean isCommitted() {
throw new UnsupportedOperationException();
}
public void reset() {
throw new UnsupportedOperationException();
}
public void resetBuffer() {
throw new UnsupportedOperationException();
}
public String getResult() {
if (_writer == null) {
return null;
}
return _writer.toString();
}
public int getStatus() {
return _status;
}
public String getContentType() {
return _contentType;
}
public Map<String, String> getHeaders() {
return _headers;
}
}