ccs.http
Class AbstractXhtmlHandler

java.lang.Object
  extended by org.mortbay.http.handler.AbstractHttpHandler
      extended by ccs.http.AbstractXhtmlHandler
All Implemented Interfaces:
java.io.Serializable, org.mortbay.http.HttpHandler, org.mortbay.util.LifeCycle
Direct Known Subclasses:
ExceptionHandler, ThrowingHandler

public abstract class AbstractXhtmlHandler
extends org.mortbay.http.handler.AbstractHttpHandler

Infrastructure to handle XHTML correctly. In subclasses, all content should be returned using sendBuffer. All HTML should be typed as text/html. This class deals with retyping XHTML correctly for browsers which support it.

See Also:
Serialized Form

Nested Class Summary
protected static class AbstractXhtmlHandler.XHMode
           
 
Field Summary
static boolean isEnabled
          Whether to enable rigorous XHTML handling.
protected  MimeRegProvider mrp
           
 
Constructor Summary
AbstractXhtmlHandler(MimeRegProvider mrp)
          Ctor.
 
Method Summary
protected abstract  AbstractXhtmlHandler.XHMode getDefaultXHMode()
          The XHTML handling mode to use if no request-specific handling mode has been set.
protected  boolean isXhtmlUA(org.mortbay.http.HttpRequest ha)
           
protected  void makeUncacheable(org.mortbay.http.HttpResponse hq)
          Utility method.
protected  void sendBuffer(java.lang.String objectID, SwappingBuffer q, org.mortbay.http.HttpRequest ha, org.mortbay.http.HttpResponse hq)
          Send back a filled SwappingBuffer.
protected  void sendCDBFile(CDBeeTree cdb, java.lang.String internalPath, org.mortbay.http.HttpRequest ha, org.mortbay.http.HttpResponse hq)
          Send back a CDBFile, using either sendBuffer or sendStream depending on size.
protected  void sendStream(java.lang.String objectID, CallbackStreamProducer src, java.lang.String mimeType, org.mortbay.http.HttpRequest ha, org.mortbay.http.HttpResponse hq)
          Send back a stream via a stream-producer / stream-consumer callback.
protected  void setXHMode(AbstractXhtmlHandler.XHMode mode, org.mortbay.http.HttpResponse hq)
          Set a request-specific XHTML handling mode for this request (if different from the default for this handler.)
 
Methods inherited from class org.mortbay.http.handler.AbstractHttpHandler
getHttpContext, getName, handleTrace, initialize, isStarted, setName, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mortbay.http.HttpHandler
handle
 

Field Detail

isEnabled

public static final boolean isEnabled
Whether to enable rigorous XHTML handling. See CCSDev 398 and 400 for the full story: in brief, we were going to do this but it created too much bustage in the chrome, and we don't have time to fix it all right now. We hope to re-enable this at some point in the future. However, for now, it's disabled. This means that this class doesn't really do anything.

See Also:
Constant Field Values

mrp

protected MimeRegProvider mrp
Constructor Detail

AbstractXhtmlHandler

public AbstractXhtmlHandler(MimeRegProvider mrp)
Ctor.

Parameters:
mrp - provides the MimeRegistry to be used by sendBuffer to determine the correct MIME type of buffers which don't specify their own MIME type. If null, a default provider will be used.
Method Detail

getDefaultXHMode

protected abstract AbstractXhtmlHandler.XHMode getDefaultXHMode()
The XHTML handling mode to use if no request-specific handling mode has been set.


setXHMode

protected final void setXHMode(AbstractXhtmlHandler.XHMode mode,
                               org.mortbay.http.HttpResponse hq)
Set a request-specific XHTML handling mode for this request (if different from the default for this handler.)


makeUncacheable

protected void makeUncacheable(org.mortbay.http.HttpResponse hq)
Utility method. Marks the supplied response as uncacheable in both HTTP dialects; this ought to get the point across to all but the most thoroughly broken UAs / proxy chains.

Parameters:
hq - The response to make cache-proof.

sendBuffer

protected void sendBuffer(java.lang.String objectID,
                          SwappingBuffer q,
                          org.mortbay.http.HttpRequest ha,
                          org.mortbay.http.HttpResponse hq)
                   throws java.io.IOException
Send back a filled SwappingBuffer. This is the recommended way to return content for a request; it sorts out the XHTML question.

Parameters:
objectID - The Object ID for the object in the buffer. This is used to determine the MIME type, iff one is not supplied in...
q - The buffer to send.
ha - The request to which this is a response. Used mostly for XHTML handling.
hq - The response to send to.
Throws:
java.io.IOException

isXhtmlUA

protected boolean isXhtmlUA(org.mortbay.http.HttpRequest ha)

sendStream

protected void sendStream(java.lang.String objectID,
                          CallbackStreamProducer src,
                          java.lang.String mimeType,
                          org.mortbay.http.HttpRequest ha,
                          org.mortbay.http.HttpResponse hq)
                   throws java.io.IOException
Send back a stream via a stream-producer / stream-consumer callback. This approach can be a little more difficult to get your head around, but may well be more cost-effective for large objects. There may be tradeoffs to consider; consult the documentation for your chosen stream producer. This is intended for large, opaque, binaries, and does not support the XHTML management that sendBuffer does.

Parameters:
objectID - The Object ID for the object in the buffer. This is used to determine the MIME type, iff mimeType is null.
src - The stream producer which will conjure up the stream we're to send.
mimeType - The required MIME type of the stream, if known a priori. Usually, it won't be, in which case supply null and the method will work it out from the objectID.
ha - The request to which this is a response. Not currently used, but supply it anyway (this might change in future).
hq - The response to send to.
Throws:
java.io.IOException

sendCDBFile

protected void sendCDBFile(CDBeeTree cdb,
                           java.lang.String internalPath,
                           org.mortbay.http.HttpRequest ha,
                           org.mortbay.http.HttpResponse hq)
                    throws java.io.IOException
Send back a CDBFile, using either sendBuffer or sendStream depending on size.

Parameters:
cdb - The CDBeeTree containing the file.
internalPath - The path (key) of the CDBFile within the CDB filesystem.
ha - The request.
hq - The response.
Throws:
java.io.IOException