You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/07/07 08:04:00 UTC
cvs commit: jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl XMLizerImpl.java
donaldp 2002/07/06 23:04:00
Modified: xmlbundle/src/java/org/apache/excalibur/xmlizer/impl
XMLizerImpl.java
Log:
Made defaultMimeType setable by constructor.
select() never returns null so rearrange code
to reflect case.
Revision Changes Path
1.2 +49 -28 jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/XMLizerImpl.java
Index: XMLizerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/XMLizerImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLizerImpl.java 24 Apr 2002 07:46:30 -0000 1.1
+++ XMLizerImpl.java 7 Jul 2002 06:04:00 -0000 1.2
@@ -7,12 +7,12 @@
*/
package org.apache.excalibur.xmlizer.impl;
-import java.io.InputStream;
import java.io.IOException;
-import org.apache.excalibur.xmlizer.XMLizer;
-import org.apache.avalon.framework.component.ComponentException;
+import java.io.InputStream;
import org.apache.avalon.excalibur.component.DefaultComponentSelector;
+import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.excalibur.xmlizer.XMLizer;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -26,58 +26,79 @@
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Revision$ $Date$
*/
-
public class XMLizerImpl
extends DefaultComponentSelector
implements XMLizer, ThreadSafe
{
-
/** The default mimeType used when no mimeType is given */
- protected String defaultMimeType = "text/xml";
+ private final String m_defaultMimeType;
+
+ public XMLizerImpl()
+ {
+ this( "text/xml" );
+ }
+
+ public XMLizerImpl( final String defaultMimeType )
+ {
+ m_defaultMimeType = defaultMimeType;
+ }
/**
* 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 {@link XMLConsumer} that accepts such
+ * that <code>handler</code> can actually be a
+ * {@link org.apache.avalon.excalibur.xml.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 )
+ public void toSAX( final InputStream stream,
+ final String mimeType,
+ final String systemID,
+ final ContentHandler handler )
throws SAXException, IOException, ComponentException
{
- if ( null == stream ) {
- throw new ComponentException("Stream must not be null.");
+ if( null == stream )
+ {
+ final String message = "Stream must not be null.";
+ throw new ComponentException( message );
}
- if ( null == handler ) {
- throw new ComponentException("Handler must not be null.");
+
+ if( null == handler )
+ {
+ final String message = "Handler must not be null.";
+ throw new ComponentException( message );
}
- if ( null == mimeType ) {
- if ( this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug("No mime-type for xmlizing " + systemID + ", guessing " + this.defaultMimeType);
+
+ if( null == mimeType )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ "No mime-type for xmlizing " + systemID +
+ ", guessing " + m_defaultMimeType;
+ getLogger().debug( message );
}
- mimeType = this.defaultMimeType;
+ mimeType = m_defaultMimeType;
}
- if ( !this.hasComponent ( mimeType ) ) {
- throw new ComponentException("No XMLizer registered for mimeType " + mimeType);
+ if( !hasComponent( mimeType ) )
+ {
+ final String message = "No XMLizer registered for mimeType " + mimeType;
+ throw new ComponentException( message );
}
- XMLizer realXMLizer = null;
+ final XMLizer realXMLizer = (XMLizer)this.select( mimeType );
try
{
- realXMLizer = (XMLizer) this.select( mimeType );
realXMLizer.toSAX( stream, mimeType, systemID, handler );
- } finally {
- this.release( realXMLizer );
}
-
+ finally
+ {
+ release( realXMLizer );
+ }
}
-
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>