org.apache.cocoon.components.source
Class AbstractStreamSource

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.components.source.AbstractStreamSource
All Implemented Interfaces:
org.apache.avalon.framework.logger.Loggable, ModifiableSource, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.excalibur.pool.Recyclable, Source, XMLizable
Direct Known Subclasses:
AbstractStreamWriteableSource, URLSource

public abstract class AbstractStreamSource
extends org.apache.avalon.framework.logger.AbstractLoggable
implements ModifiableSource

This abstract class provides convenience methods to implement a stream based Source. Implement getInputStream(), getSystemId() and optionally override refresh(), recycle(), getLastModified() and getContentLength() to obtain a valid Source implementation.

This base implementation provides services to parse HTML sources (HTML is not valid XML) using JTidy, if present. The source is considered to contain HTML if isHTMLContent() returns true.

Version:
$Id: AbstractStreamSource.java,v 1.2.2.2 2002/09/21 02:21:37 vgritsenko Exp $
Author:
Sylvain Wallez, Carsten Ziegeler

Field Summary
protected  org.apache.avalon.framework.component.ComponentManager manager
          The ComponentManager needed for streaming
static javax.xml.transform.TransformerFactory transformerFactory
          The TrAX factory for serializing xml
 
Constructor Summary
protected AbstractStreamSource(org.apache.avalon.framework.component.ComponentManager manager)
          Construct a new object
 
Method Summary
 boolean exists()
          Returns true if getInputStream() succeeds.
 long getContentLength()
          Override this method to set the Content Length
 org.xml.sax.InputSource getInputSource()
          Return a new InputSource object
 long getLastModified()
          Override this method to set the Last Modification date
protected  boolean isHTMLContent()
          Does this source contain HTML ?
 void recycle()
          To be overriden in concrete subclasses if needed.
 void refresh()
          To be overriden in concrete subclasses if needed.
 void toSAX(org.xml.sax.ContentHandler handler)
          Stream content to a content handler or to an XMLConsumer.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.environment.Source
getInputStream, getSystemId
 

Field Detail

transformerFactory

public static javax.xml.transform.TransformerFactory transformerFactory
The TrAX factory for serializing xml

manager

protected org.apache.avalon.framework.component.ComponentManager manager
The ComponentManager needed for streaming
Constructor Detail

AbstractStreamSource

protected AbstractStreamSource(org.apache.avalon.framework.component.ComponentManager manager)
Construct a new object
Method Detail

isHTMLContent

protected boolean isHTMLContent()
Does this source contain HTML ? If true, JTidy will be used (if available) to parse the input as XML.

The default here is to return false. Concrete subclasses should override this if needed.


getInputSource

public org.xml.sax.InputSource getInputSource()
                                       throws java.io.IOException,
                                              ProcessingException
Return a new InputSource object
Specified by:
getInputSource in interface Source
Following copied from interface: org.apache.cocoon.environment.Source
Returns:
an InputSource value
Throws:
ProcessingException - if an error occurs
java.io.IOException - if an error occurs

toSAX

public void toSAX(org.xml.sax.ContentHandler handler)
           throws org.xml.sax.SAXException,
                  ProcessingException
Stream content to a content handler or to an XMLConsumer.
Specified by:
toSAX in interface XMLizable
Throws:
ResourceNotFoundException - if file not found or HTTP location does not exist.
org.xml.sax.SAXException - if failed to parse source document.

getContentLength

public long getContentLength()
Override this method to set the Content Length
Specified by:
getContentLength in interface Source

getLastModified

public long getLastModified()
Override this method to set the Last Modification date
Specified by:
getLastModified in interface Source

exists

public boolean exists()
Returns true if getInputStream() succeeds. Subclasses can provide a more efficient implementation.

recycle

public void recycle()
To be overriden in concrete subclasses if needed.
Specified by:
recycle in interface org.apache.avalon.excalibur.pool.Recyclable

refresh

public void refresh()
To be overriden in concrete subclasses if needed.
Specified by:
refresh in interface ModifiableSource


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.