cziegeler 02/04/29 03:52:53 Modified: src/java/org/apache/cocoon/components/language/markup Logicsheet.java src/java/org/apache/cocoon/components/xslt XSLTProcessor.java XSLTProcessorImpl.java src/java/org/apache/cocoon/transformation TraxTransformer.java Log: XSLT Processor now uses the new source resolver Revision Changes Path 1.10 +1 -2 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/Logicsheet.java Index: Logicsheet.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/Logicsheet.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Logicsheet.java 20 Mar 2002 05:16:34 -0000 1.9 +++ Logicsheet.java 29 Apr 2002 10:52:52 -0000 1.10 @@ -83,7 +83,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> - * @version CVS $Id: Logicsheet.java,v 1.9 2002/03/20 05:16:34 vgritsenko Exp $ + * @version CVS $Id: Logicsheet.java,v 1.10 2002/04/29 10:52:52 cziegeler Exp $ */ public class Logicsheet extends AbstractLoggable { @@ -115,7 +115,6 @@ this.manager = manager; try { this.xsltProcessor = (XSLTProcessor)this.manager.lookup(XSLTProcessor.ROLE); - this.xsltProcessor.setSourceResolver(resolver); } catch (ComponentException e) { throw new ProcessingException("Could not obtain XSLT processor", e); } 1.8 +6 -5 xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessor.java Index: XSLTProcessor.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XSLTProcessor.java 10 Apr 2002 12:56:23 -0000 1.7 +++ XSLTProcessor.java 29 Apr 2002 10:52:52 -0000 1.8 @@ -64,7 +64,7 @@ * This is the interface of the XSLT processor in Cocoon. * * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> - * @version CVS $Id: XSLTProcessor.java,v 1.7 2002/04/10 12:56:23 stefano Exp $ + * @version CVS $Id: XSLTProcessor.java,v 1.8 2002/04/29 10:52:52 cziegeler Exp $ * @version 1.0 * @since July 11, 2001 */ @@ -86,22 +86,23 @@ * this instance. The <code>resolver</code> is invoked to return a * <code>Source</code> object, given an HREF. * + * @deprecated The processor can now simply lookup the source resolver. * @param resolver a <code>SourceResolver</code> value */ void setSourceResolver(SourceResolver resolver); /** - * Set the TransformerFactory for this instance. + * Set the TransformerFactory for this instance. * The <code>factory</code> is invoked to return a * <code>TransformerHandler</code> to perform the transformation. * - * @param classname the name of the class implementing + * @param classname the name of the class implementing * <code>TransformerFactory</code> value. If an error is found * or the indicated class doesn't implement the required interface * the original factory of the component is maintained. */ void setTransformerFactory(String classname); - + /** * <p>Return a <code>TransformerHandler</code> for a given * stylesheet <code>Source</code>. This can be used in a pipeline to @@ -124,7 +125,7 @@ TransformerHandler getTransformerHandler(Source stylesheet, XMLFilter filter) throws ProcessingException; - + /** * Same as {@link #getTransformerHandler(Source,XMLFilter)}, with * <code>filter</code> set to <code>null</code> and <code>factory</code> 1.21 +48 -41 xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java Index: XSLTProcessorImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- XSLTProcessorImpl.java 14 Apr 2002 00:39:28 -0000 1.20 +++ XSLTProcessorImpl.java 29 Apr 2002 10:52:52 -0000 1.21 @@ -58,12 +58,14 @@ import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.avalon.framework.parameters.ParameterException; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceException; +import org.apache.excalibur.source.SourceResolver; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.components.store.Store; -import org.apache.cocoon.environment.Source; -import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.util.ClassUtils; import org.apache.cocoon.util.TraxErrorHandler; import org.xml.sax.InputSource; @@ -112,7 +114,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Id: XSLTProcessorImpl.java,v 1.20 2002/04/14 00:39:28 vgritsenko Exp $ + * @version CVS $Id: XSLTProcessorImpl.java,v 1.21 2002/04/29 10:52:52 cziegeler Exp $ * @version 1.0 * @since July 11, 2001 */ @@ -131,7 +133,7 @@ /** The trax TransformerFactory lookup table*/ protected HashMap factories; - + /** The trax TransformerFactory this component uses */ protected SAXTransformerFactory factory; @@ -144,6 +146,9 @@ /** The source resolver used by this processor **/ protected SourceResolver resolver; + /** The error handler for the transformer */ + protected TraxErrorHandler errorHandler; + /** * Compose. Try to get the store */ @@ -152,6 +157,8 @@ this.manager = manager; this.getLogger().debug("XSLTProcessorImpl component initialized."); this.store = (Store) manager.lookup(Store.TRANSIENT_CACHE); + this.errorHandler = new TraxErrorHandler( this.getLogger() ); + this.resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); } /** @@ -161,10 +168,11 @@ if (this.manager != null) { this.manager.release(this.store); this.store = null; + this.manager.release(this.resolver); + this.resolver = null; } - + this.errorHandler = null; this.manager = null; - this.resolver = null; } /** @@ -179,24 +187,28 @@ /** * Set the source resolver used by this component + * @deprecated The processor can now simply lookup the source resolver. */ - public void setSourceResolver(SourceResolver resolver) { - this.resolver = resolver; + public void setSourceResolver(org.apache.cocoon.environment.SourceResolver resolver) { + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("XSLTProcessor: the setSourceResolver() method is deprecated."); + } } - + /** * Set the transformer factory used by this component */ public void setTransformerFactory(String classname) { this.factory = getTransformerFactory(classname); } - - public TransformerHandler getTransformerHandler(Source stylesheet) + + public TransformerHandler getTransformerHandler(org.apache.cocoon.environment.Source stylesheet) throws ProcessingException { return getTransformerHandler(stylesheet, null); } - public TransformerHandler getTransformerHandler(Source stylesheet, XMLFilter filter) + public TransformerHandler getTransformerHandler(org.apache.cocoon.environment.Source stylesheet, + XMLFilter filter) throws ProcessingException { try { final String id = stylesheet.getSystemId(); @@ -209,8 +221,8 @@ // Create a Templates ContentHandler to handle parsing of the // stylesheet. TemplatesHandler templatesHandler = this.factory.newTemplatesHandler(); - - // Set the system ID for the template handler since some + + // Set the system ID for the template handler since some // TrAX implementations (XSLTC) rely on this in order to obtain // a meaningful identifier for the Templates instances. templatesHandler.setSystemId(id); @@ -257,7 +269,7 @@ } */ - handler.getTransformer().setErrorListener(new TraxErrorHandler(getLogger())); + handler.getTransformer().setErrorListener(this.errorHandler); return handler; } catch (ProcessingException e) { throw e; @@ -273,8 +285,8 @@ } } - public void transform(Source source, - Source stylesheet, + public void transform(org.apache.cocoon.environment.Source source, + org.apache.cocoon.environment.Source stylesheet, Parameters params, Result result) throws ProcessingException { @@ -314,7 +326,7 @@ */ private SAXTransformerFactory getTransformerFactory(String factoryName) { SAXTransformerFactory _factory; - + if ((factoryName == null) || (factoryName == XSLTProcessor.DEFAULT_FACTORY)) { _factory = (SAXTransformerFactory) TransformerFactory.newInstance(); } else { @@ -338,30 +350,31 @@ } } - _factory.setErrorListener(new TraxErrorHandler(getLogger())); + _factory.setErrorListener(this.errorHandler); _factory.setURIResolver(this); - - // FIXME (SM): implementation-specific parameter passing should be + + // FIXME (SM): implementation-specific parameter passing should be // made more extensible. if (_factory.getClass().getName().equals("org.apache.xalan.processor.TransformerFactoryImpl")) { _factory.setAttribute("http://xml.apache.org/xalan/features/incremental", new Boolean (incrementalProcessing)); } - + return _factory; } - private Templates getTemplates(Source stylesheet, String id) + private Templates getTemplates(org.apache.cocoon.environment.Source stylesheet, + String id) throws IOException, ProcessingException { if (!useStore) { return null; } // we must augment the template ID with the factory classname since one - // transformer implementation cannot handle the instances of a + // transformer implementation cannot handle the instances of a // template created by another one. id += factory.getClass().getName(); - + Templates templates = null; // only stylesheets with a last modification date are stored if (stylesheet.getLastModified() != 0) { @@ -386,14 +399,15 @@ return templates; } - private void putTemplates (Templates templates, Source stylesheet, String id) + private void putTemplates (Templates templates, org.apache.cocoon.environment.Source stylesheet, + String id) throws IOException, ProcessingException { if (!useStore) { return; } // we must augment the template ID with the factory classname since one - // transformer implementation cannot handle the instances of a + // transformer implementation cannot handle the instances of a // template created by another one. id += factory.getClass().getName(); @@ -432,7 +446,7 @@ Source xslSource = null; try { if (href.indexOf(":") > 1) { - xslSource = resolver.resolve(href); + xslSource = resolver.resolveURI(href); } else { // patch for a null pointer passed as base if (base == null) @@ -446,38 +460,31 @@ // always be protocol:/.... return null; // we can't resolve this } else { - xslSource = resolver.resolve(new StringBuffer(base.substring(0, lastPathElementPos)) + xslSource = resolver.resolveURI(new StringBuffer(base.substring(0, lastPathElementPos)) .append("/").append(href).toString()); } } else { File parent = new File(base.substring(5)); File parent2 = new File(parent.getParentFile(), href); - xslSource = resolver.resolve(parent2.toURL().toExternalForm()); + xslSource = resolver.resolveURI(parent2.toURL().toExternalForm()); } } - InputSource is = xslSource.getInputSource(); if (this.getLogger().isDebugEnabled()) { getLogger().debug("xslSource = " + xslSource - + ", system id = " + is.getSystemId()); + + ", system id = " + xslSource.getSystemId()); } - return new StreamSource(is.getByteStream(), is.getSystemId()); + return new StreamSource(xslSource.getInputStream(), xslSource.getSystemId()); - } catch (ResourceNotFoundException rnfe) { - // to obtain the same behaviour as when the resource is - // transformed by the XSLT Transformer we should return null here. - return null; } catch (java.net.MalformedURLException mue) { return null; } catch (IOException ioe) { return null; - } catch (SAXException se) { - throw new TransformerException(se); - } catch (ProcessingException pe) { + } catch (SourceException pe) { throw new TransformerException(pe); } finally { - if (xslSource != null) xslSource.recycle(); + this.resolver.release( xslSource ); } } } 1.25 +12 -16 xml-cocoon2/src/java/org/apache/cocoon/transformation/TraxTransformer.java Index: TraxTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/TraxTransformer.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- TraxTransformer.java 20 Apr 2002 22:41:57 -0000 1.24 +++ TraxTransformer.java 29 Apr 2002 10:52:52 -0000 1.25 @@ -133,7 +133,7 @@ * * * The <transformer-factory> configuration allows to specify the TrAX transformer factory - * implementation that willbe used to obtain the XSLT processor. This allows to have + * implementation that willbe used to obtain the XSLT processor. This allows to have * several XSLT processors in the configuration * (e.g. Xalan, XSTLC, Saxon, ...) and choose one or the other depending on the needs of stylesheet * specificities.<br> @@ -157,7 +157,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @author <a href="mailto:[EMAIL PROTECTED]">Mark H. Butler</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Id: TraxTransformer.java,v 1.24 2002/04/20 22:41:57 huber Exp $ + * @version CVS $Id: TraxTransformer.java,v 1.25 2002/04/29 10:52:52 cziegeler Exp $ */ public class TraxTransformer extends AbstractTransformer implements Transformer, Composable, Configurable, Cacheable, Disposable { @@ -191,7 +191,7 @@ /** The trax TransformerHandler */ TransformerHandler transformerHandler; - + /** The Source */ private Source inputSource; /** The parameters */ @@ -212,34 +212,34 @@ throws ConfigurationException { if (conf != null) { Configuration child; - + child = conf.getChild("use-request-parameters"); this.useParameters = child.getValueAsBoolean(false); this._useParameters = this.useParameters; - + child = conf.getChild("use-cookies"); this.useCookies = child.getValueAsBoolean(false); this._useCookies = this.useCookies; - + child = conf.getChild("use-browser-capabilities-db"); this.useBrowserCap = child.getValueAsBoolean(false); this._useBrowserCap = this.useBrowserCap; - + child = conf.getChild("use-session-info"); this.useSessionInfo = child.getValueAsBoolean(false); this._useSessionInfo = this.useSessionInfo; - + child = conf.getChild("transformer-factory"); // traxFactory is null, if transformer-factory config is unspecified this.traxFactory = child.getValue(null); - + if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("Use parameters is " + this.useParameters + " for " + this); this.getLogger().debug("Use cookies is " + this.useCookies + " for " + this); this.getLogger().debug("Use browser capabilities is " + this.useBrowserCap + " for " + this); this.getLogger().debug("Use session info is " + this.useSessionInfo + " for " + this); - + if (this.traxFactory != null) { this.getLogger().debug("Use TrAX Transformer Factory " + this.traxFactory); } else { @@ -295,16 +295,15 @@ if (src == null) { throw new ProcessingException("Stylesheet URI can't be null"); } - + this.par = par; this.objectModel = objectModel; this.inputSource = resolver.resolve(src); - this.xsltProcessor.setSourceResolver(resolver); _useParameters = par.getParameterAsBoolean("use-request-parameters", this.useParameters); _useBrowserCap = par.getParameterAsBoolean("use-browser-capabilities-db", this.useBrowserCap); _useCookies = par.getParameterAsBoolean("use-cookies", this.useCookies); _useSessionInfo = par.getParameterAsBoolean("use-session-info", this.useSessionInfo); - + if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("Using stylesheet: '" + this.inputSource.getSystemId() + "' in " + this + ", last modified: " + this.inputSource.getLastModified()); } @@ -557,9 +556,6 @@ } public void recycle() { - // Remove per-request resolver from the XSLT processor - this.xsltProcessor.setSourceResolver(null); - this.transformerHandler = null; this.objectModel = null; if (this.inputSource != null) {
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]