Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.protocol.http;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.apache.wicket.Response;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.util.io.StringBufferWriter;
import org.apache.wicket.util.string.AppendingStringBuffer;
/**
* Implementation of {@link HttpServletResponse} that saves the output in a string buffer. This is
* used in REDIRECT_TO_BUFFER render strategy to create the buffer of the output that can be held on
* to until the redirect part of the render strategy.
*
* @author jcompagner
*/
class BufferedHttpServletResponse implements HttpServletResponse
{
/** the print writer for the response */
private StringBufferWriter sbw = new StringBufferWriter();
private PrintWriter pw = new PrintWriter(sbw);
/** cookies list */
private List cookies;
/** status code */
private int status = -1;
/** headers map */
private Map headers;
/** the real response for encoding the url */
private HttpServletResponse realResponse;
private String redirect;
private String contentType;
private byte[] byteBuffer;
private Locale locale;
private String encoding;
/**
* Constructor.
*
* @param realResponse
* The real response for encoding the url
*/
public BufferedHttpServletResponse(HttpServletResponse realResponse)
{
this.realResponse = realResponse;
}
/**
* @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie)
*/
public void addCookie(Cookie cookie)
{
isOpen();
if (cookies == null)
{
cookies = new ArrayList(2);
}
cookies.add(cookie);
}
/**
* @see javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String)
*/
public boolean containsHeader(String name)
{
isOpen();
if (headers == null)
{
return false;
}
return headers.containsKey(name);
}
/**
* @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String)
*/
public String encodeURL(String url)
{
isOpen();
return realResponse.encodeURL(url);
}
/**
* @see javax.servlet.http.HttpServletResponse#encodeRedirectURL(java.lang.String)
*/
public String encodeRedirectURL(String url)
{
isOpen();
return realResponse.encodeRedirectURL(url);
}
/**
* @see javax.servlet.http.HttpServletResponse#encodeUrl(java.lang.String)
* @deprecated
*/
@Deprecated
public String encodeUrl(String url)
{
isOpen();
return realResponse.encodeURL(url);
}
/**
* @see javax.servlet.http.HttpServletResponse#encodeRedirectUrl(java.lang.String)
* @deprecated
*/
@Deprecated
public String encodeRedirectUrl(String url)
{
isOpen();
return realResponse.encodeRedirectURL(url);
}
/**
* @see javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String)
*/
public void sendError(int sc, String msg) throws IOException
{
isOpen();
realResponse.sendError(sc, msg);
}
/**
* @see javax.servlet.http.HttpServletResponse#sendError(int)
*/
public void sendError(int sc) throws IOException
{
isOpen();
realResponse.sendError(sc);
}
/**
* @see javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String)
*/
public void sendRedirect(String location) throws IOException
{
isOpen();
redirect = location;
}
/**
* @return The redirect url
*/
public String getRedirectUrl()
{
isOpen();
return redirect;
}
private void testAndCreateHeaders()
{
isOpen();
if (headers == null)
{
headers = new HashMap();
}
}
private void isOpen()
{
if (realResponse == null)
{
throw new WicketRuntimeException("the buffered servlet response already closed.");
}
}
@SuppressWarnings("unchecked")
private void addHeaderObject(String name, Object object)
{
Object previousObject = headers.get(name);
if (previousObject == null)
{
headers.put(name, object);
}
else if (previousObject instanceof List)
{
((List