package org.w3c.jigsaw.filters;
import java.net.*;
import org.w3c.tools.resources.*;
import org.w3c.tools.resources.ProtocolException;
import org.w3c.www.http.*;
import org.w3c.jigsaw.http.*;
public class HeaderFilter extends ResourceFilter {
protected static int ATTR_HEADER_NAME = -1;
protected static int ATTR_HEADER_VALUE = -1;
protected static int ATTR_NOCACHE = -1;
protected static int ATTR_CONNECTION = -1;
static {
Class c = null;
Attribute a = null;
try {
c = Class.forName("org.w3c.jigsaw.filters.HeaderFilter");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
a = new StringAttribute("header-name"
, null
, Attribute.EDITABLE);
ATTR_HEADER_NAME = AttributeRegistry.registerAttribute(c, a);
a = new StringAttribute("header-value"
, null
, Attribute.EDITABLE);
ATTR_HEADER_VALUE = AttributeRegistry.registerAttribute(c, a);
a = new BooleanAttribute("no-cache"
, Boolean.FALSE
, Attribute.EDITABLE);
ATTR_NOCACHE = AttributeRegistry.registerAttribute(c, a);
a = new BooleanAttribute("connection"
, Boolean.FALSE
, Attribute.EDITABLE);
ATTR_CONNECTION = AttributeRegistry.registerAttribute(c, a);
}
@return
public String getHeaderName() {
String value = getString(ATTR_HEADER_NAME, null);
if ( value != null )
return value.toLowerCase();
return null;
}
@return
public String getHeaderValue() {
return getString(ATTR_HEADER_VALUE, null);
}
@return
public boolean checkNoCache() {
return getBoolean(ATTR_NOCACHE, false);
}
@return
public boolean checkConnection() {
return getBoolean(ATTR_CONNECTION, false);
}
public ReplyInterface ingoingFilter(RequestInterface request)
throws ProtocolException
{
return null;
}
@param request@param reply@return
public ReplyInterface outgoingFilter(RequestInterface req,
ReplyInterface rep)
throws ProtocolException
{
Reply reply = (Reply) rep;
String hname = getHeaderName();
if ( hname != null ) {
String hvalue = getHeaderValue();
if ( hvalue == null ) {
reply.removeHeader(hname);
} else {
reply.setValue(hname, hvalue);
}
if ( checkNoCache() )
reply.addNoCache(hname);
if ( checkConnection() )
reply.addConnection(hname);
}
return null;
}
}