xml.pipeline
Class XmlServlet

xml.pipeline.XmlServlet

public abstract class XmlServlet

This base class provides utility functions making it easy for servlets to send and receive XML data structures through an XML processing pipeline.

This means that either the request to the servlet, or its response, or both of these, may be viewed as a stage in an XML processing pipeline. The request will always be an input; the response, an output. It's easy to convert to DOM or text representations at any point. Other types of event producers and consumers can work with specialized representations that have been tuned to application requirements.

Perhaps the simpest subclass would just add a method something like the following one:


    public void doPost (
        HttpServletRequest  request,
        HttpServletResponse response
    ) throws IOException, ServletException
    {
        EventProducer       producer = getXmlInput (request);
        EventConsumer       consumer = getXmlOutput (response);

        consumer = PipelineFactory.createPipeline (
            " ... filter pipeline descriptor goes here ...",
            consumer);
        producer.produce (consumer);
    }
 

Used in conjuction with a CallFilter, such a servlet could be used by clients to pass data through processing components which need any facilities (such as application resources, or mediated interactions) which are not available to that client.

Version:
$Date: 2000/07/15 00:56:58 $
Author:
David Brownell
See Also:
CallFilter, PipelineFactory

Constructor Summary
XmlServlet()
          The default constructor does nothing.
 
Method Summary
 Document getDocument(xml.pipeline.HttpServletRequest req)
          Returns the input document provided in this request in the form of a single DOM Document.
 EntityResolver getEntityResolver()
          Returns an entity resolver that is set up with some locally established mappings from public identifiers to files.
 ErrorHandler getErrorHandler()
          Returns any error handler that will, by default, be provided to event producers.
 TextConsumer getXhtmlOutput(xml.pipeline.HttpServletResponse res)
          Returns an event consumer which will treat all of its input callbacks as requests to write that portion of an XHTML document to the specified response.
 EventProducer getXmlInput(xml.pipeline.HttpServletRequest req)
          Returns the XML input to this servlet in the form of an event producer, which will fire a stream of events to a event consumer.
 TextConsumer getXmlOutput(xml.pipeline.HttpServletResponse res)
          Returns an event consumer which will treat all of its input callbacks as requests to write that portion of an XML document to the specified response.
 void setEntityResolver(EntityResolver r)
          Assigns an error handler that will, by default, be provided to event producers.
 void setErrorHandler(ErrorHandler e)
          Assigns an error handler that will, by default, be provided to event producers.
 void writeOutput(xml.pipeline.HttpServletResponse res, Document document)
          Writes the response of this servlet as an XML document, encoded in UTF-8 and with the correct MIME type.
 

Constructor Detail

XmlServlet

public XmlServlet()
The default constructor does nothing.
Method Detail

getXmlInput

public EventProducer getXmlInput(xml.pipeline.HttpServletRequest req)
                          throws java.io.IOException,
                                 SAXException
Returns the XML input to this servlet in the form of an event producer, which will fire a stream of events to a event consumer. This assumes that the body of the request is an XML document; do not invoke this method if that is not the case.

NOTE: No multipart mime support at this time.


getXmlOutput

public TextConsumer getXmlOutput(xml.pipeline.HttpServletResponse res)
                          throws java.io.IOException
Returns an event consumer which will treat all of its input callbacks as requests to write that portion of an XML document to the specified response.

getXhtmlOutput

public TextConsumer getXhtmlOutput(xml.pipeline.HttpServletResponse res)
                            throws java.io.IOException
Returns an event consumer which will treat all of its input callbacks as requests to write that portion of an XHTML document to the specified response.

getDocument

public Document getDocument(xml.pipeline.HttpServletRequest req)
                     throws java.io.IOException,
                            SAXException
Returns the input document provided in this request in the form of a single DOM Document.

writeOutput

public void writeOutput(xml.pipeline.HttpServletResponse res,
                        Document document)
                 throws java.io.IOException,
                        SAXException
Writes the response of this servlet as an XML document, encoded in UTF-8 and with the correct MIME type.

getEntityResolver

public EntityResolver getEntityResolver()
Returns an entity resolver that is set up with some locally established mappings from public identifiers to files.

This uses the xhtml1.dtd-dir application parameter (context attribute) to identify the name of a directory with a local copy of the XHTML1 DTDs. (Subject to change.)


setEntityResolver

public void setEntityResolver(EntityResolver r)
Assigns an error handler that will, by default, be provided to event producers. If this is not done, or if a null value is assigned, a default value may be established with mappings from public identifiers to local files.

getErrorHandler

public ErrorHandler getErrorHandler()
Returns any error handler that will, by default, be provided to event producers.

setErrorHandler

public void setErrorHandler(ErrorHandler e)
Assigns an error handler that will, by default, be provided to event producers. Since this will be shared among all pipelines and threads, use caution when accessing state from such a handler.

Source code is GPL'd at http://xmlconf.sourceforge.net.