// PICSFilter.java // $Id: PICSFilter.java,v 1.11 1998/08/14 11:10:10 bmahe Exp $ // (c) COPYRIGHT MIT and INRIA, 1996. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.jigsaw.pics ; import java.io.* ; import java.util.*; import java.net.*; import org.w3c.tools.resources.*; import org.w3c.www.http.*; import org.w3c.jigsaw.http.* ; import org.w3c.jigsaw.resources.*; import org.w3c.jigsaw.html.HtmlGenerator ; /** * This package implements a PICS filter. The PICS filters allows server * administrator to rate the documents they deliver. The references for this * protocol is here.
*The PICS filter defines the following attributes:
*Parameter name | *Semantics | *Default value | *Type | *
---|---|---|---|
bureau | *The label bureau to query for this entity labels. | *none | *java.lang.String | *
outgoingFilter
method that takes
* only the request and the reply as parameters.
* @param request The request that has been processed.
* @param reply The original reply as emitted by the resource.
* @param filters The whole filter that applies to the resource.
* @param i The current index of filters. The i filter is ourself,
* filters with lower indexes have already been applied, and filters with
* greater indexes are still to be applied.
* @return A Reply instance, if that filter know how to complete the
* request processing, or null if reminaing filters
* are to be called by Jigsaw engine.
* @exception HTTPException If processing should be interrupted,
* because an abnormal situation occured.
*/
public ReplyInterface outgoingFilter (RequestInterface req,
ReplyInterface rep)
throws HTTPException
{
Request request = (Request) req;
Reply reply = (Reply) rep;
HttpBag pics = isPICSQuery (request) ;
if ( pics == null )
return reply ;
// Get the requested services:
HttpBag params = pics.getBag("params") ;
HttpBag services = params.getBag("services") ;
URL url = request.getURL();
int format = LabelBureauInterface.FMT_MINIMAL ;
// Get any format parameter:
if ( params.hasItem ("minimal") ) {
format = LabelBureauInterface.FMT_MINIMAL ;
} else if ( params.hasItem ("short") ) {
format = LabelBureauInterface.FMT_SHORT ;
} else if ( params.hasItem ("full") ) {
format = LabelBureauInterface.FMT_FULL ;
} else if ( params.hasItem ("signed") ) {
format = LabelBureauInterface.FMT_SIGNED ;
} else {
Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
error.setContent ("Invalid label format: "+format) ;
throw new HTTPException (error) ;
}
// Get labels for each service, building out the ret hashtable
StringBuffer sb = new StringBuffer(128) ;
Enumeration e = services.keys() ;
sb.append ("("+PICS.PICS_PROTOCOL_ID) ;
sloop:
while ( e.hasMoreElements() ) {
String n = (String) e.nextElement() ;
LabelServiceInterface s = bureau.getLabelService (n) ;
if ( s == null ) {
sb.append (" error "
+ "(service-unavailable \"unknown service\")") ;
continue sloop ;
}
s.dump(sb, format) ;
LabelInterface l = s.getSpecificLabel (url) ;
if ( (l == null) && ((l = s.getGenericLabel (url)) == null) ) {
sb.append (" error (not-labeled \"" + url +"\")") ;
} else {
sb.append (" labels ") ;
l.dump (sb, format) ;
}
}
sb.append (")") ;
// Add additional reply headers:
reply.setProtocol(PICS.PICS_EXTENSION);
reply.setValue("PICS-label", sb.toString());
return reply ;
}
public void initialize (Object values[]) {
super.initialize(values);
acquireBureau() ;
}
}