cziegeler 02/04/18 23:59:38
Modified: all/src/scratchpad/org/apache/avalon/excalibur/source
ResourceSource.java Source.java URLSource.java
Added: all/src/scratchpad/org/apache/excalibur/xmlizer XMLizer.java
all/src/scratchpad/org/apache/excalibur/xmlizer/impl
XMLizerImpl.java
Log:
Added getMimeType() to Source, Removed dependency to XMLizable and added
first shot for XMLizer
Revision Changes Path
1.5 +13 -48
jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/ResourceSource.java
Index: ResourceSource.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/ResourceSource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ResourceSource.java 17 Apr 2002 13:38:48 -0000 1.4
+++ ResourceSource.java 19 Apr 2002 06:59:37 -0000 1.5
@@ -9,22 +9,17 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.avalon.excalibur.xml.Parser;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
/**
* Description of a source which is described by the resource protocol
* which gets a resource from the classloader.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.4 $ $Date: 2002/04/17 13:38:48 $
+ * @version CVS $Revision: 1.5 $ $Date: 2002/04/19 06:59:37 $
*/
public final class ResourceSource
- implements Composable, Source
+ implements Source
{
/** The system identifier */
private String systemId;
@@ -32,9 +27,6 @@
/** Location of the resource */
private String location;
- /** The ComponentManager needed for streaming */
- private ComponentManager manager;
-
/**
* Constructor
*/
@@ -45,11 +37,6 @@
this.location = systemId.substring( pos + 3 );
}
- public void compose( ComponentManager manager )
- {
- this.manager = manager;
- }
-
/**
* Return an <code>InputStream</code> object to read from the source.
*/
@@ -65,39 +52,6 @@
}
/**
- * Stream content to a content handler or to an XMLConsumer.
- *
- * @throws ResourceNotFoundException if file not found or
- * HTTP location does not exist.
- * @throws SAXException if failed to parse source document.
- */
- public void toSAX( ContentHandler handler )
- throws SAXException
- {
- Parser parser = null;
- try
- {
- parser = (Parser)this.manager.lookup( Parser.ROLE );
-
- parser.parse( SourceUtil.getInputSource( this ), handler );
- }
- catch( SAXException e )
- {
- // Preserve original exception
- throw e;
- }
- catch( Exception e )
- {
- throw new SAXException( "Exception during processing of "
- + this.systemId, e );
- }
- finally
- {
- if( parser != null ) this.manager.release( parser );
- }
- }
-
- /**
* Return the unique identifer for this source
*/
public String getSystemId()
@@ -124,6 +78,17 @@
public void discardValidity()
{
// nothing to do
+ }
+
+ /**
+ * The mime-type of the content described by this object.
+ * If the source is not able to determine the mime-type by itself
+ * this can be null.
+ */
+ public String getMimeType()
+ {
+ // FIXME
+ return null;
}
}
1.13 +8 -4
jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/Source.java
Index: Source.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/Source.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Source.java 17 Apr 2002 13:38:48 -0000 1.12
+++ Source.java 19 Apr 2002 06:59:37 -0000 1.13
@@ -7,7 +7,6 @@
*/
package org.apache.avalon.excalibur.source;
-import org.apache.avalon.excalibur.xml.XMLizable;
import java.io.IOException;
import java.io.InputStream;
@@ -52,10 +51,9 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
- * @version CVS $Revision: 1.12 $ $Date: 2002/04/17 13:38:48 $
+ * @version CVS $Revision: 1.13 $ $Date: 2002/04/19 06:59:37 $
*/
-public interface Source
- extends XMLizable {
+public interface Source {
/**
* Return an <code>InputStream</code> object to read from the source.
@@ -85,4 +83,10 @@
*/
void discardValidity();
+ /**
+ * The mime-type of the content described by this object.
+ * If the source is not able to determine the mime-type by itself
+ * this can be null.
+ */
+ String getMimeType();
}
1.17 +8 -58
jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java
Index: URLSource.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- URLSource.java 17 Apr 2002 13:38:48 -0000 1.16
+++ URLSource.java 19 Apr 2002 06:59:37 -0000 1.17
@@ -22,22 +22,16 @@
import org.apache.avalon.excalibur.monitor.Resource;
import org.apache.avalon.excalibur.monitor.SourceResource;
import org.apache.avalon.excalibur.source.validity.TimeStampValidity;
-import org.apache.avalon.excalibur.xml.Parser;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
/**
* Description of a source which is described by an URL.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.16 $ $Date: 2002/04/17 13:38:48 $
+ * @version CVS $Revision: 1.17 $ $Date: 2002/04/19 06:59:37 $
*/
public final class URLSource
- implements Source, Composable, Monitorable
+ implements Source, Monitorable
{
/** With this parameter you can specify the method to use for a http
request.
@@ -71,9 +65,6 @@
/** Are we initialized? */
private boolean gotInfos;
- /** The ComponentManager needed for streaming */
- private ComponentManager manager;
-
/** The <code>SourceParameters</code> used for a post*/
private SourceParameters parameters;
@@ -131,11 +122,6 @@
}
}
- public void compose( ComponentManager manager )
- {
- this.manager = manager;
- }
-
/**
* Get the last modification date and content length of the source.
* Any exceptions are ignored.
@@ -373,49 +359,13 @@
}
/**
- * Return a new <code>InputSource</code> object
- *
- * @throws IOException if I/O error occured.
+ * The mime-type of the content described by this object.
+ * If the source is not able to determine the mime-type by itself
+ * this can be null.
*/
- protected InputSource getInputSource()
- throws IOException
+ public String getMimeType()
{
- InputSource newObject = new InputSource( this.getInputStream() );
- newObject.setSystemId( this.systemId );
- return newObject;
+ // FIXME
+ return null;
}
-
- /**
- * Stream content to a content handler or to an XMLConsumer.
- *
- * @throws ResourceNotFoundException if file not found or
- * HTTP location does not exist.
- * @throws SAXException if failed to parse source document.
- */
- public void toSAX( ContentHandler handler )
- throws SAXException
- {
- Parser parser = null;
- try
- {
- parser = (Parser)this.manager.lookup( Parser.ROLE );
-
- parser.parse( this.getInputSource(), handler );
- }
- catch( SAXException e )
- {
- // Preserve original exception
- throw e;
- }
- catch( Exception e )
- {
- throw new SAXException( "Exception during processing of "
- + this.systemId, e );
- }
- finally
- {
- if( parser != null ) this.manager.release( parser );
- }
- }
-
}
1.1
jakarta-avalon-excalibur/all/src/scratchpad/org/apache/excalibur/xmlizer/XMLizer.java
Index: XMLizer.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.xmlizer;
import java.io.InputStream;
import java.io.IOException;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/**
* Converter for transforming any input stream with a given mime-type
* into SAX events.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/04/19 06:59:38 $
*/
public interface XMLizer
extends Component
{
String ROLE = XMLizer.class.getName();
/**
* Generates SAX events from the given input stream
* <b>NOTE</b> : if the implementation can produce lexical events, care
should be taken
* that <code>handler</code> can actually be a [EMAIL PROTECTED]
XMLConsumer} that accepts such
* events or directly implements the LexicalHandler interface!
* @param stream the data
* @param mimeType the mime-type for the data
* @param systemID the URI defining the data (this is optional and can
be null)
* @throws ComponentException if no suitable converter is found
*/
void toSAX( InputStream stream,
String mimeType,
String systemID,
ContentHandler handler )
throws SAXException, IOException, ComponentException;
}
1.1
jakarta-avalon-excalibur/all/src/scratchpad/org/apache/excalibur/xmlizer/impl/XMLizerImpl.java
Index: XMLizerImpl.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.xmlizer.impl;
import java.io.InputStream;
import java.io.IOException;
import org.apache.avalon.excalibur.xml.Parser;
import org.apache.excalibur.xmlizer.XMLizer;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Converter for transforming any input stream with a given mime-type
* into SAX events.
* ATTENTION: This is a hacky, first-shot implementation which always
* assumes that the input stream contains text/xml !
* This will soon be replaced by a better, configurable approach.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/04/19 06:59:38 $
*/
public class XMLizerImpl
extends AbstractLogEnabled
implements XMLizer, ThreadSafe, Composable
{
/** The component manager */
protected ComponentManager manager;
/**
* Composable interface
*/
public void compose(ComponentManager manager)
{
this.manager = manager;
}
/**
* Generates SAX events from the given input stream
* <b>NOTE</b> : if the implementation can produce lexical events, care
should be taken
* that <code>handler</code> can actually be a [EMAIL PROTECTED]
XMLConsumer} that accepts such
* events or directly implements the LexicalHandler interface!
* @param stream the data
* @param mimeType the mime-type for the data
* @param systemID the URI defining the data (this is optional and can
be null)
* @throws ComponentException if no suitable converter is found
*/
public void toSAX( InputStream stream,
String mimeType,
String systemID,
ContentHandler handler )
throws SAXException, IOException, ComponentException
{
final InputSource inputSource = new InputSource( stream );
inputSource.setSystemId( systemID );
Parser parser = null;
try
{
parser = (Parser)this.manager.lookup( Parser.ROLE );
parser.parse( inputSource, handler );
}
finally
{
if( parser != null ) this.manager.release( parser );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>