donaldp 2002/07/07 00:11:45
Modified: xmlbundle/src/java/org/apache/excalibur/xmlizer/impl
HTMLXMLizer.java TextXMLizer.java
Log:
Rework parser aquisition as lookup() will never return null.
Revision Changes Path
1.5 +23 -18
jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/HTMLXMLizer.java
Index: HTMLXMLizer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/HTMLXMLizer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HTMLXMLizer.java 7 Jul 2002 05:27:27 -0000 1.4
+++ HTMLXMLizer.java 7 Jul 2002 07:11:45 -0000 1.5
@@ -41,23 +41,15 @@
extends AbstractLogEnabled
implements XMLizer, ThreadSafe, Composable
{
- /** The component manager */
- protected ComponentManager manager;
-
/** Used for converting DOM -> SAX */
- protected static Properties format;
+ private static final Properties c_format = createFormatProperties();
- static
- {
- format = new Properties();
- format.put( OutputKeys.METHOD, "xml" );
- format.put( OutputKeys.OMIT_XML_DECLARATION, "no" );
- format.put( OutputKeys.INDENT, "yes" );
- }
+ /** The component manager */
+ private ComponentManager m_manager;
public void compose( final ComponentManager manager )
{
- this.manager = manager;
+ this.m_manager = manager;
}
/**
@@ -115,9 +107,10 @@
try
{
final Transformer transformer =
TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperties( format );
- transformer.transform( new DOMSource( xhtmlconvert.parseDOM( stream,
null ) ),
- new StreamResult( writer ) );
+ transformer.setOutputProperties( c_format );
+ final DOMSource domSource = new DOMSource( xhtmlconvert.parseDOM(
stream, null ) );
+ final StreamResult streamResult = new StreamResult( writer );
+ transformer.transform( domSource, streamResult );
}
catch( final TransformerException te )
{
@@ -128,15 +121,27 @@
new InputSource( new java.io.StringReader( writer.toString() ) );
if( null != systemID ) inputSource.setSystemId( systemID );
- final Parser parser = (Parser)manager.lookup( Parser.ROLE );
+ final Parser parser = (Parser)m_manager.lookup( Parser.ROLE );
try
{
parser.parse( inputSource, handler );
}
finally
{
- manager.release( parser );
+ m_manager.release( parser );
}
+ }
+
+ /**
+ * Utility method to create format properties for XMLizer.
+ */
+ private static Properties createFormatProperties()
+ {
+ final Properties format = new Properties();
+ format.put( OutputKeys.METHOD, "xml" );
+ format.put( OutputKeys.OMIT_XML_DECLARATION, "no" );
+ format.put( OutputKeys.INDENT, "yes" );
+ return format;
}
}
1.2 +45 -34
jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/TextXMLizer.java
Index: TextXMLizer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/TextXMLizer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TextXMLizer.java 24 Apr 2002 07:46:30 -0000 1.1
+++ TextXMLizer.java 7 Jul 2002 07:11:45 -0000 1.2
@@ -7,16 +7,15 @@
*/
package org.apache.excalibur.xmlizer.impl;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
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.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.excalibur.xmlizer.XMLizer;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -28,72 +27,84 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Revision$ $Date$
*/
-
public class TextXMLizer
extends AbstractLogEnabled
implements XMLizer, ThreadSafe, Composable
{
-
/** The component manager */
- protected ComponentManager manager;
+ private ComponentManager m_manager;
/**
* Composable interface
*/
- public void compose(ComponentManager manager)
+ public void compose( final ComponentManager manager )
{
- this.manager = manager;
+ m_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 {@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 text/xml");
+
+ if( null == mimeType )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ "No mime-type for xmlizing " + systemID +
+ ", guessing text/xml";
+ getLogger().debug( message );
}
- } else if ( !mimeType.equalsIgnoreCase("text/xml") ) {
- if ( this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug("Mime-type " + mimeType +
- "not supported for xmlizing " + systemID +
- ", guessing text/xml");
+ }
+ else if( !mimeType.equalsIgnoreCase( "text/xml" ) )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "Mime-type " + mimeType +
+ "not supported for xmlizing " + systemID +
+ ", guessing text/xml";
+ getLogger().debug( message );
}
}
-
final InputSource inputSource = new InputSource( stream );
- if ( null != systemID ) inputSource.setSystemId( systemID );
+ if( null != systemID )
+ {
+ inputSource.setSystemId( systemID );
+ }
- Parser parser = null;
+ final Parser parser = (Parser)m_manager.lookup( Parser.ROLE );
try
{
- parser = (Parser)this.manager.lookup( Parser.ROLE );
-
parser.parse( inputSource, handler );
}
finally
{
- if( parser != null ) this.manager.release( parser );
+ m_manager.release( parser );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>