package org.jboss.resteasy.plugins.server.servlet;
import org.jboss.resteasy.resteasy_jaxrs.i18n.Messages;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.util.CaseInsensitiveMap;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.RuntimeDelegate;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@SuppressWarnings(value = "unchecked")
public class implements MultivaluedMap<String, Object>
{
private CaseInsensitiveMap = new CaseInsensitiveMap();
private HttpServletResponse response;
private ResteasyProviderFactory ;
public HttpServletResponseHeaders(final HttpServletResponse response, final ResteasyProviderFactory factory)
{
this.response = response;
this.factory = factory;
}
@Override
public void (String key, Object... newValues)
{
for (Object value : newValues)
{
add(key, value);
}
}
@Override
public void (String key, List<Object> valueList)
{
for (Object value : valueList)
{
add(key, value);
}
}
@Override
public void (String key, Object value)
{
List<Object> list = get(key);
if (list == null)
{
add(key, value);
return;
}
else
{
list.add(0, value);
}
}
public void (String key, Object value)
{
if (value == null)
{
return;
}
cachedHeaders.putSingle(key, value);
RuntimeDelegate.HeaderDelegate delegate = factory.getHeaderDelegate(value.getClass());
if (delegate != null)
{
response.setHeader(key, delegate.toString(value));
}
else
{
response.setHeader(key, value.toString());
}
}
public void (String key, Object value)
{
cachedHeaders.add(key, value);
addResponseHeader(key, value);
}
protected void (String key, Object value)
{
if (value == null)
{
return;
}
RuntimeDelegate.HeaderDelegate delegate = factory.getHeaderDelegate(value.getClass());
if (delegate != null)
{
response.addHeader(key, delegate.toString(value));
}
else
{
response.addHeader(key, value.toString());
}
}
public Object (String key)
{
return cachedHeaders.getFirst(key);
}
public int ()
{
return cachedHeaders.size();
}
public boolean ()
{
return cachedHeaders.isEmpty();
}
public boolean (Object o)
{
return cachedHeaders.containsKey(o);
}
public boolean (Object o)
{
return cachedHeaders.containsValue(o);
}
public List<Object> (Object o)
{
return cachedHeaders.get(o);
}
public List<Object> (String s, List<Object> objs)
{
for (Object obj : objs)
{
addResponseHeader(s, obj);
}
return cachedHeaders.put(s, objs);
}
public List<Object> (Object o)
{
throw new RuntimeException(Messages.MESSAGES.removingHeaderIllegal());
}
public void (Map<? extends String, ? extends List<Object>> map)
{
for (Map.Entry<? extends String, ? extends List<Object>> entry : map.entrySet())
{
List<Object> objs = entry.getValue();
if (!objs.isEmpty()) {
putResponseHeader(entry.getKey(), objs.get(0));
for (int i = 1; i < objs.size(); i++) {
add(entry.getKey(), objs.get(i));
}
}
}
}
protected void (String key, Object value)
{
if (value == null)
{
return;
}
RuntimeDelegate.HeaderDelegate delegate = factory.getHeaderDelegate(value.getClass());
if (delegate != null)
{
response.setHeader(key, delegate.toString(value));
}
else
{
response.setHeader(key, value.toString());
}
cachedHeaders.add(key, value);
}
public void ()
{
throw new RuntimeException(Messages.MESSAGES.removingHeaderIllegal());
}
public Set<String> ()
{
return cachedHeaders.keySet();
}
public Collection<List<Object>> ()
{
return cachedHeaders.values();
}
public Set<Entry<String, List<Object>>> ()
{
return cachedHeaders.entrySet();
}
public boolean (Object o)
{
return cachedHeaders.equals(o);
}
public int ()
{
return cachedHeaders.hashCode();
}
@Override
public boolean (MultivaluedMap<String, Object> otherMap)
{
return cachedHeaders.equalsIgnoreValueOrder(otherMap);
}
}