dims 01/08/20 05:36:59 Modified: src/org/apache/cocoon cocoon.roles src/org/apache/cocoon/components/parser JaxpParser.java Added: lib resolver.jar src/org/apache/cocoon/components/resolver Resolver.java ResolverImpl.java Log: This is the initial commit for support for Catalogs for Entity Resolution. - Uses the XML Entity and URI Resolvers Java [tm] classes at http://www.sun.com/xml/developers/resolver/ - The spec for catalogs are at http://www.oasis-open.org/committees/entity/spec.html - Componentized such that others (like the folks at www.indexgeo.com.au/work/cocoon/catalog.html) can use their own catalog components. Needs more work: - Add sample CatalogManager.properties file - Samples to show Entity Resolution at work. - Updates to the Documentation. - etc, etc... Revision Changes Path 1.1 xml-cocoon2/lib/resolver.jar <<Binary file>> 1.19 +4 -0 xml-cocoon2/src/org/apache/cocoon/cocoon.roles Index: cocoon.roles =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- cocoon.roles 2001/08/14 11:19:54 1.18 +++ cocoon.roles 2001/08/20 12:36:59 1.19 @@ -49,6 +49,10 @@ shorthand="jsp-engine" default-class="org.apache.cocoon.components.jsp.JSPEngineImpl"/> + <role name="org.apache.cocoon.components.resolver.Resolver" + shorthand="resolver" + default-class="org.apache.cocoon.components.resolver.ResolverImpl"/> + <role name="org.apache.cocoon.components.classloader.ClassLoaderManager" shorthand="classloader" default-class="org.apache.cocoon.components.classloader.ClassLoaderManagerImpl"/> 1.5 +29 -2 xml-cocoon2/src/org/apache/cocoon/components/parser/JaxpParser.java Index: JaxpParser.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/parser/JaxpParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JaxpParser.java 2001/07/30 10:50:44 1.4 +++ JaxpParser.java 2001/08/20 12:36:59 1.5 @@ -16,6 +16,7 @@ import org.apache.cocoon.util.ClassUtils; import org.apache.cocoon.xml.AbstractXMLProducer; import org.apache.cocoon.xml.dom.DOMFactory; +import org.apache.cocoon.components.resolver.Resolver; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.xml.sax.ErrorHandler; @@ -24,20 +25,32 @@ import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.apache.avalon.framework.thread.SingleThreaded; +import org.apache.avalon.framework.component.ComponentManager; +import org.apache.avalon.framework.component.Composable; +import org.apache.avalon.framework.component.ComponentException; /** * An XMLParser that is only dependant on JAXP 1.1 compliant parsers. * If only we can get rid of the need for the Document... * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version CVS $Revision: 1.4 $ $Date: 2001/07/30 10:50:44 $ + * @version CVS $Revision: 1.5 $ $Date: 2001/08/20 12:36:59 $ */ public class JaxpParser extends AbstractXMLProducer -implements Parser, ErrorHandler, SingleThreaded { +implements Parser, ErrorHandler, Composable, SingleThreaded { + /** the SAX Parser factory */ final SAXParserFactory factory = SAXParserFactory.newInstance(); + + /** the Document Builder factory */ final DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance(); + /** the component manager */ + protected ComponentManager manager; + + /** the Entity Resolver */ + protected Resolver resolver = null; + public JaxpParser () throws SAXException, ParserConfigurationException { this.factory.setNamespaceAware(true); @@ -46,6 +59,19 @@ this.docfactory.setValidating(false); } + /** + * Get the Entity Resolver from the component manager + */ + public void compose(ComponentManager manager) throws ComponentException { + try { + this.manager = manager; + getLogger().debug("Looking up Resolver" + Resolver.ROLE); + this.resolver = (Resolver)manager.lookup(Resolver.ROLE); + } catch(ComponentException e) { + getLogger().error("Error in JaxpParser!",e); + } + } + public void parse(InputSource in) throws SAXException, IOException { SAXParser parser = null; @@ -69,6 +95,7 @@ reader.setErrorHandler(this); reader.setContentHandler(super.contentHandler); + reader.setEntityResolver(this.resolver); reader.parse(in); } 1.1 xml-cocoon2/src/org/apache/cocoon/components/resolver/Resolver.java Index: Resolver.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 file. * *****************************************************************************/ package org.apache.cocoon.components.resolver; import org.apache.avalon.framework.component.Component; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; /** * A component that uses catalogs for resolving Entities. * * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> * @version CVS $Revision: 1.1 $ $Date: 2001/08/20 12:36:59 $ */ public interface Resolver extends Component, EntityResolver { String ROLE = "org.apache.cocoon.components.resolver.Resolver"; /** * Allow the application to resolve external entities. * * <p>The Parser will call this method before opening any external * entity except the top-level document entity (including the * external DTD subset, external entities referenced within the * DTD, and external entities referenced within the document * element): the application may request that the parser resolve * the entity itself, that it use an alternative URI, or that it * use an entirely different input source.</p> * * <p>Application writers can use this method to redirect external * system identifiers to secure and/or local URIs, to look up * public identifiers in a catalogue, or to read an entity from a * database or other input source (including, for example, a dialog * box).</p> * * <p>If the system identifier is a URL, the SAX parser must * resolve it fully before reporting it to the application.</p> * * @param publicId The public identifier of the external entity * being referenced, or null if none was supplied. * @param systemId The system identifier of the external entity * being referenced. * @return An InputSource object describing the new input source, * or null to request that the parser open a regular * URI connection to the system identifier. * @exception org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. * @exception java.io.IOException A Java-specific IO exception, * possibly the result of creating a new InputStream * or Reader for the InputSource. * @see org.xml.sax.InputSource */ public abstract InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException; } 1.1 xml-cocoon2/src/org/apache/cocoon/components/resolver/ResolverImpl.java Index: ResolverImpl.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 file. * *****************************************************************************/ package org.apache.cocoon.components.resolver; import com.sun.resolver.tools.CatalogResolver; import org.apache.avalon.framework.activity.Disposable; 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.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; /** * A component that uses catalogs for resolving Entities. This implementation uses the * XML Entity and URI Resolvers from http://www.sun.com/xml/developers/resolver/ * published by Sun's Norman Walsh. More information on the catalogs can be found at * http://www.oasis-open.org/committees/entity/spec.html * * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> * @version CVS $Revision: 1.1 $ $Date: 2001/08/20 12:36:59 $ */ public class ResolverImpl extends AbstractLoggable implements Resolver, Contextualizable, Composable, Configurable, ThreadSafe, Disposable { /** The catalog resolver */ protected CatalogResolver catalogResolver = new CatalogResolver(); /** The component manager */ protected ComponentManager manager = null; /** Contextualize this class */ public void contextualize(Context context) throws ContextException { } /** * Set the sitemap-provided configuration. * @param conf The configuration information * @exception ConfigurationException */ public void configure(Configuration conf) throws ConfigurationException { Parameters params = Parameters.fromConfiguration(conf); } /** * Set the global component manager. This metod also sets the * <code>ComponentSelector</code> used as language factory for both markup and programming languages. * @param manager The global component manager */ public void compose(ComponentManager manager) throws ComponentException { if ((this.manager == null) && (manager != null)) { this.manager = manager; } } /** * Allow the application to resolve external entities. * * <p>The Parser will call this method before opening any external * entity except the top-level document entity (including the * external DTD subset, external entities referenced within the * DTD, and external entities referenced within the document * element): the application may request that the parser resolve * the entity itself, that it use an alternative URI, or that it * use an entirely different input source.</p> * * <p>Application writers can use this method to redirect external * system identifiers to secure and/or local URIs, to look up * public identifiers in a catalogue, or to read an entity from a * database or other input source (including, for example, a dialog * box).</p> * * <p>If the system identifier is a URL, the SAX parser must * resolve it fully before reporting it to the application.</p> * * @param publicId The public identifier of the external entity * being referenced, or null if none was supplied. * @param systemId The system identifier of the external entity * being referenced. * @return An InputSource object describing the new input source, * or null to request that the parser open a regular * URI connection to the system identifier. * @exception org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. * @exception java.io.IOException A Java-specific IO exception, * possibly the result of creating a new InputStream * or Reader for the InputSource. * @see org.xml.sax.InputSource */ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return catalogResolver.resolveEntity(publicId, systemId); } /** * dispose */ public void dispose() { } } ---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]