Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 35143 invoked from network); 6 Dec 2002 22:11:12 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Dec 2002 22:11:12 -0000 Received: (qmail 28176 invoked by uid 97); 6 Dec 2002 22:12:22 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 28160 invoked by uid 97); 6 Dec 2002 22:12:21 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 28141 invoked by uid 97); 6 Dec 2002 22:12:20 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 6 Dec 2002 22:11:05 -0000 Message-ID: <20021206221105.94377.qmail@icarus.apache.org> From: mirceatoma@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xmlizer DefaultXMLizer.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N mirceatoma 2002/12/06 14:11:05 Added: xmlutil/src/java/org/apache/excalibur/xmlizer DefaultXMLizer.java Log: Moved from ./impl directory. Renamed from XMLizerImpl. Refactored implementation to select an appropriate Parser based on the content mime type. Revision Changes Path 1.1 jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xmlizer/DefaultXMLizer.java Index: DefaultXMLizer.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 org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.excalibur.xml.sax.Parser; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; /** * Converter for transforming any input stream with a given mime-type * into SAX events. * This component acts like a selector. All XMLizer can "register" * themselfes for a given mime-type and this component forwards * the transformation to the registered on. * * @author Carsten Ziegeler * @version CVS $Revision: 1.1 $ $Date: 2002/12/06 22:11:05 $ */ public final class DefaultXMLizer extends AbstractLogEnabled implements XMLizer, Serviceable, Configurable, ThreadSafe, Component { private ServiceManager m_serviceManager; private Map m_mimeTypes = new HashMap(); public void service( ServiceManager serviceManager ) throws ServiceException { m_serviceManager = serviceManager; } public void configure( Configuration configuration ) throws ConfigurationException { final Configuration[] parsers = configuration.getChildren("parser"); for ( int i = 0; i < parsers.length; i++ ) { final Configuration parser = parsers[i]; final String mimeType = parser.getAttribute("mime-type"); final String role = parser.getAttribute("parser"); m_mimeTypes.put(mimeType, role); } } /** * Generates SAX events from the given input stream * @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) */ public void toSAX( final InputStream stream, final String mimeType, final String systemID, final ContentHandler handler ) throws SAXException, IOException { if ( null == stream ) { throw new NullPointerException( "stream" ); } if ( null == handler ) { throw new NullPointerException( "handler" ); } final String parserRole; if ( m_mimeTypes.containsKey(mimeType) ) { parserRole = (String) m_mimeTypes.get(mimeType); } else { if ( getLogger().isDebugEnabled() ) { final String message = "No mime-type for xmlizing " + systemID + ", guessing text/xml"; getLogger().debug( message ); } parserRole = Parser.ROLE; } try { final Parser parser = (Parser) m_serviceManager.lookup( parserRole ); final InputSource inputSource = new InputSource( stream ); inputSource.setSystemId( systemID ); parser.parse( inputSource, handler, null ); } catch ( ServiceException e ) { throw new SAXException( "Cannot parse content of type" + mimeType ); } } } -- To unsubscribe, e-mail: For additional commands, e-mail: