donaldp 2002/07/07 00:15:02 Modified: xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt TraxErrorHandler.java XSLTProcessor.java XSLTProcessorException.java XSLTProcessorImpl.java Log: Minor touchups and addition of finals, brackets etc where appropriate. Revision Changes Path 1.3 +54 -39 jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/TraxErrorHandler.java Index: TraxErrorHandler.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/TraxErrorHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TraxErrorHandler.java 2 May 2002 10:04:05 -0000 1.2 +++ TraxErrorHandler.java 7 Jul 2002 07:15:01 -0000 1.3 @@ -10,7 +10,6 @@ import javax.xml.transform.ErrorListener; import javax.xml.transform.SourceLocator; import javax.xml.transform.TransformerException; - import org.apache.avalon.framework.logger.Logger; /** @@ -21,59 +20,75 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ */ -public class TraxErrorHandler implements ErrorListener { - - private Logger logger = null; - - public TraxErrorHandler( Logger logger ) { - this.logger = logger; +public class TraxErrorHandler + implements ErrorListener +{ + private Logger m_logger; + + public TraxErrorHandler( final Logger logger ) + { + m_logger = logger; } - public void warning( TransformerException exception ) - throws TransformerException { - final String message = getMessage( exception ); - if ( this.logger != null ) { - this.logger.warn( message, exception ); - } else { + public void warning( final TransformerException te ) + throws TransformerException + { + final String message = getMessage( te ); + if( null != m_logger ) + { + m_logger.warn( message, te ); + } + else + { System.out.println( "WARNING: " + message ); } } - public void error( TransformerException exception ) - throws TransformerException { - final String message = getMessage( exception ); - if ( this.logger != null ) { - this.logger.error( message, exception ); - } else { + public void error( final TransformerException te ) + throws TransformerException + { + final String message = getMessage( te ); + if( null != m_logger ) + { + m_logger.error( message, te ); + } + else + { System.out.println( "ERROR: " + message ); } } - public void fatalError( TransformerException exception ) - throws TransformerException { - final String message = getMessage( exception ); - if ( this.logger != null ) { - this.logger.fatalError( message, exception ); - } else { + public void fatalError( final TransformerException te ) + throws TransformerException + { + final String message = getMessage( te ); + if( null != m_logger ) + { + m_logger.fatalError( message, te ); + } + else + { System.out.println( "FATAL-ERROR: " + message ); } - throw exception; + throw te; } - private String getMessage( TransformerException exception ) { - SourceLocator locator = exception.getLocator(); - - if ( null != locator ) { + private String getMessage( final TransformerException te ) + { + final SourceLocator locator = te.getLocator(); + if( null != locator ) + { // System.out.println("Parser fatal error: "+exception.getMessage()); - String id = ( locator.getPublicId() != locator.getPublicId() ) - ? locator.getPublicId() - : ( null != locator.getSystemId() ) - ? locator.getSystemId() : "SystemId Unknown"; + final String id = + ( locator.getPublicId() != locator.getPublicId() ) + ? locator.getPublicId() + : ( null != locator.getSystemId() ) + ? locator.getSystemId() : "SystemId Unknown"; return new StringBuffer( "Error in TraxTransformer: " ) - .append( id ).append( "; Line " ).append( locator.getLineNumber() ) - .append( "; Column " ).append( locator.getColumnNumber() ) - .append( "; " ).toString(); + .append( id ).append( "; Line " ).append( locator.getLineNumber() ) + .append( "; Column " ).append( locator.getColumnNumber() ) + .append( "; " ).toString(); } - return "Error in TraxTransformer: " + exception; + return "Error in TraxTransformer: " + te; } } 1.6 +33 -34 jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/XSLTProcessor.java Index: XSLTProcessor.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/XSLTProcessor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XSLTProcessor.java 1 Jul 2002 01:26:57 -0000 1.5 +++ XSLTProcessor.java 7 Jul 2002 07:15:01 -0000 1.6 @@ -9,13 +9,11 @@ import javax.xml.transform.Result; import javax.xml.transform.sax.TransformerHandler; - -import org.xml.sax.XMLFilter; - import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.parameters.Parameters; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceValidity; +import org.xml.sax.XMLFilter; /** * This is the interface of the XSLT processor. @@ -26,7 +24,8 @@ * @version 1.0 * @since July 11, 2001 */ -public interface XSLTProcessor extends Component +public interface XSLTProcessor + extends Component { /** * The role implemented by an <code>XSLTProcessor</code>. @@ -38,21 +37,21 @@ private final TransformerHandler transformerHandler; private final SourceValidity transformerValidity; - protected TransformerHandlerAndValidity ( TransformerHandler transformerHandler, - SourceValidity transformerValidity ) + protected TransformerHandlerAndValidity( final TransformerHandler transformerHandler, + final SourceValidity transformerValidity ) { this.transformerHandler = transformerHandler; this.transformerValidity = transformerValidity; } - public TransformerHandler getTransfomerHandler () + public TransformerHandler getTransfomerHandler() { - return this.transformerHandler; + return transformerHandler; } - public SourceValidity getTransfomerValidity () + public SourceValidity getTransfomerValidity() { - return this.transformerValidity; + return transformerValidity; } } @@ -66,11 +65,11 @@ * or the indicated class doesn't implement the required interface * the original factory of the component is maintained. */ - void setTransformerFactory(String classname); + 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 + * stylesheet {@link Source}. This can be used in a pipeline to * handle the transformation of a stream of SAX events. See {@link * org.apache.cocoon.transformation.TraxTransformer#setConsumer} for * an example of how to use this method. @@ -83,18 +82,18 @@ * (modification time and list of included stylesheets) and performs * a reparsing only if this changes. * - * @param stylesheet a <code>Source</code> value - * @param filter a <code>XMLFilter</code> value - * @return a <code>TransformerHandler</code> value + * @param stylesheet a {@link Source} value + * @param filter a {@link XMLFilter} value + * @return a {@link TransformerHandler} value * @exception XSLTProcessorException if an error occurs */ TransformerHandler getTransformerHandler( Source stylesheet, XMLFilter filter ) - throws XSLTProcessorException; + throws XSLTProcessorException; /** - * <p>Return a <code>TransformerHandler</code> and + * <p>Return a {@link TransformerHandler} and * <code>SourceValidity</code> for a given stylesheet - * <code>Source</code>. This can be used in a pipeline to + * {@link Source}. This can be used in a pipeline to * handle the transformation of a stream of SAX events. See {@link * org.apache.cocoon.transformation.TraxTransformer#setConsumer} for * an example of how to use this method. @@ -107,50 +106,50 @@ * (modification time and list of included stylesheets) and performs * a reparsing only if this changes. * - * @param stylesheet a <code>Source</code> value - * @param filter a <code>XMLFilter</code> value + * @param stylesheet a {@link Source} value + * @param filter a {@link XMLFilter} value * @return a <code>TransformerHandlerAndValidity</code> value * @exception XSLTProcessorException if an error occurs */ TransformerHandlerAndValidity getTransformerHandlerAndValidity( Source stylesheet, XMLFilter filter ) - throws XSLTProcessorException; + throws XSLTProcessorException; /** * Same as {@link #getTransformerHandler(Source,XMLFilter)}, with * <code>filter</code> set to <code>null</code>. * - * @param stylesheet a <code>Source</code> value - * @return a <code>TransformerHandler</code> value + * @param stylesheet a {@link Source} value + * @return a {@link TransformerHandler} value * @exception XSLTProcessorException if an error occurs */ TransformerHandler getTransformerHandler( Source stylesheet ) - throws XSLTProcessorException; + throws XSLTProcessorException; /** * Same as {@link #getTransformerHandlerAndValidity(Source,XMLFilter)}, with * <code>filter</code> set to <code>null</code>. * - * @param stylesheet a <code>Source</code> value - * @return a <code>TransformerHandlerAndValidity</code> value + * @param stylesheet a {@link Source} value + * @return a {@link TransformerHandlerAndValidity} value * @exception XSLTProcessorException if an error occurs */ TransformerHandlerAndValidity getTransformerHandlerAndValidity( Source stylesheet ) - throws XSLTProcessorException; + throws XSLTProcessorException; /** * Applies an XSLT stylesheet to an XML document. The source and - * stylesheet documents are specified as <code>Source</code> + * stylesheet documents are specified as {@link Source} * objects. The result of the transformation is placed in - * <code>result</code>, which should be properly initialized before + * {@link Result}, which should be properly initialized before * invoking this method. Any additional parameters passed in - * <code>params</code> will become arguments to the stylesheet. + * {@link Parameters params} will become arguments to the stylesheet. * - * @param source a <code>Source</code> value - * @param stylesheet a <code>Source</code> value + * @param source a {@link Source} value + * @param stylesheet a {@link Source} value * @param params a <code>Parameters</code> value * @param result a <code>Result</code> value * @exception XSLTProcessorException if an error occurs */ void transform( Source source, Source stylesheet, Parameters params, Result result ) - throws XSLTProcessorException; + throws XSLTProcessorException; } 1.3 +7 -5 jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/XSLTProcessorException.java Index: XSLTProcessorException.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/XSLTProcessorException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XSLTProcessorException.java 2 May 2002 10:04:05 -0000 1.2 +++ XSLTProcessorException.java 7 Jul 2002 07:15:01 -0000 1.3 @@ -15,15 +15,17 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ -public class XSLTProcessorException extends CascadingException +public class XSLTProcessorException + extends CascadingException { - public XSLTProcessorException(final String message) + public XSLTProcessorException( final String message ) { - super(message); + super( message ); } - public XSLTProcessorException(final String message, final Throwable throwable) + public XSLTProcessorException( final String message, + final Throwable throwable ) { - super(message, throwable); + super( message, throwable ); } } 1.9 +197 -164 jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/XSLTProcessorImpl.java Index: XSLTProcessorImpl.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xslt/XSLTProcessorImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XSLTProcessorImpl.java 1 Jul 2002 00:52:07 -0000 1.8 +++ XSLTProcessorImpl.java 7 Jul 2002 07:15:01 -0000 1.9 @@ -9,9 +9,10 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.ArrayList; import java.util.Map; import javax.xml.transform.Result; import javax.xml.transform.Templates; @@ -23,29 +24,26 @@ import javax.xml.transform.sax.TemplatesHandler; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamSource; - -import org.xml.sax.ContentHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLFilter; - import org.apache.avalon.excalibur.xml.XMLizable; - 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.logger.AbstractLogEnabled; -import org.apache.avalon.framework.parameters.Parameters; -import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.avalon.framework.parameters.ParameterException; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.Parameters; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceResolver; import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.impl.validity.AggregatedValidity; -import org.apache.excalibur.xmlizer.XMLizer; import org.apache.excalibur.store.Store; +import org.apache.excalibur.xmlizer.XMLizer; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLFilter; /** * This class defines the implementation of the {@link XSLTProcessor} @@ -69,12 +67,13 @@ * @since July 11, 2001 */ public class XSLTProcessorImpl - extends AbstractLogEnabled - implements XSLTProcessor, - Composable, - Disposable, - Parameterizable, - URIResolver { + extends AbstractLogEnabled + implements XSLTProcessor, + Composable, + Disposable, + Parameterizable, + URIResolver +{ protected ComponentManager manager; @@ -91,7 +90,7 @@ protected boolean useStore = false; /** Is incremental processing turned on? (default for Xalan: no) */ - protected boolean incrementalProcessing = false; + protected boolean incrementalProcessing; /** Resolver used to resolve XSLT document() calls, imports and includes */ protected SourceResolver resolver; @@ -105,12 +104,12 @@ /** * Compose. Try to get the store */ - public void compose( ComponentManager manager ) - throws ComponentException + public void compose( final ComponentManager manager ) + throws ComponentException { this.manager = manager; - this.errorHandler = new TraxErrorHandler( getLogger() ); - this.resolver = (SourceResolver)this.manager.lookup( SourceResolver.ROLE ); + errorHandler = new TraxErrorHandler( getLogger() ); + resolver = (SourceResolver)manager.lookup( SourceResolver.ROLE ); } /** @@ -118,35 +117,38 @@ */ public void dispose() { - if ( null != this.manager ) + if( null != manager ) { - this.manager.release(this.store); - this.store = null; - this.manager.release( this.resolver ); - this.resolver = null; + manager.release( store ); + store = null; + manager.release( resolver ); + resolver = null; } - this.errorHandler = null; - this.manager = null; + errorHandler = null; + manager = null; } /** * Configure the component */ - public void parameterize( Parameters params ) - throws ParameterException + public void parameterize( final Parameters params ) + throws ParameterException { - this.useStore = params.getParameterAsBoolean( "use-store", this.useStore ); - this.incrementalProcessing = params.getParameterAsBoolean( "incremental-processing", this.incrementalProcessing ); - this.factory = getTransformerFactory(params.getParameter("transformer-factory", null)); - if ( this.useStore ) { + useStore = params.getParameterAsBoolean( "use-store", this.useStore ); + incrementalProcessing = params.getParameterAsBoolean( "incremental-processing", this.incrementalProcessing ); + factory = getTransformerFactory( params.getParameter( "transformer-factory", null ) ); + if( useStore ) + { try { - this.store = (Store)manager.lookup(Store.TRANSIENT_STORE); + store = (Store)manager.lookup( Store.TRANSIENT_STORE ); } - catch (ComponentException ce) + catch( final ComponentException ce ) { - throw new ParameterException("XSLTProcessor: use-store is set to true, " - +"but the lookup of the Store failed.", ce); + final String message = + "XSLTProcessor: use-store is set to true, " + + "but the lookup of the Store failed."; + throw new ParameterException( message, ce ); } } } @@ -154,37 +156,39 @@ /** * Set the transformer factory used by this component */ - public void setTransformerFactory(String classname) { - this.factory = getTransformerFactory(classname); + public void setTransformerFactory( final String classname ) + { + factory = getTransformerFactory( classname ); } - public TransformerHandler getTransformerHandler( Source stylesheet ) - throws XSLTProcessorException + public TransformerHandler getTransformerHandler( final Source stylesheet ) + throws XSLTProcessorException { return getTransformerHandler( stylesheet, null ); } - public TransformerHandler getTransformerHandler( Source stylesheet, - XMLFilter filter ) - throws XSLTProcessorException + public TransformerHandler getTransformerHandler( final Source stylesheet, + final XMLFilter filter ) + throws XSLTProcessorException { - return getTransformerHandlerAndValidity( stylesheet, filter ).getTransfomerHandler(); + final XSLTProcessor.TransformerHandlerAndValidity validity = getTransformerHandlerAndValidity( stylesheet, filter ); + return validity.getTransfomerHandler(); } - public TransformerHandlerAndValidity getTransformerHandlerAndValidity( Source stylesheet ) - throws XSLTProcessorException + public TransformerHandlerAndValidity getTransformerHandlerAndValidity( final Source stylesheet ) + throws XSLTProcessorException { return getTransformerHandlerAndValidity( stylesheet, null ); } public TransformerHandlerAndValidity getTransformerHandlerAndValidity( Source stylesheet, XMLFilter filter ) - throws XSLTProcessorException + throws XSLTProcessorException { try { final String id = stylesheet.getSystemId(); - TransformerHandlerAndValidity handlerAndValidity = getTemplates(stylesheet, id); - if( handlerAndValidity == null ) + TransformerHandlerAndValidity handlerAndValidity = getTemplates( stylesheet, id ); + if( null == handlerAndValidity ) { if( getLogger().isDebugEnabled() ) { @@ -198,7 +202,7 @@ // 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 ); + templatesHandler.setSystemId( id ); if( filter != null ) { filter.setContentHandler( templatesHandler ); @@ -211,41 +215,48 @@ } // Initialize List for included validities - SourceValidity validity = stylesheet.getValidity(); - if (validity != null) { + final SourceValidity validity = stylesheet.getValidity(); + if( validity != null ) + { includesMap.put( id, new ArrayList() ); } - try { + try + { // Process the stylesheet. sourceToSAX( stylesheet, - filter != null ? ( ContentHandler ) filter : ( ContentHandler ) templatesHandler ); + filter != null ? (ContentHandler)filter : (ContentHandler)templatesHandler ); // Get the Templates object (generated during the parsing of // the stylesheet) from the TemplatesHandler. - Templates t = templatesHandler.getTemplates(); - putTemplates (t, stylesheet, id); + final Templates template = templatesHandler.getTemplates(); + putTemplates( template, stylesheet, id ); // Create transformer handler - TransformerHandler handler = this.factory.newTransformerHandler(t); + final TransformerHandler handler = this.factory.newTransformerHandler( template ); handler.getTransformer().setErrorListener( this.errorHandler ); // Create aggregated validity AggregatedValidity aggregated = null; - if (validity != null) { - List includes = (List) includesMap.get( id ); - if (includes != null) { + if( validity != null ) + { + List includes = (List)includesMap.get( id ); + if( includes != null ) + { aggregated = new AggregatedValidity(); aggregated.add( validity ); - for ( int i = includes.size() - 1; i >= 0; i-- ) { - aggregated.add( (SourceValidity) ((Object[])includes.get(i))[1] ); + for( int i = includes.size() - 1; i >= 0; i-- ) + { + aggregated.add( (SourceValidity)( (Object[])includes.get( i ) )[ 1 ] ); } } } // Create result handlerAndValidity = new TransformerHandlerAndValidity( handler, aggregated ); - } finally { + } + finally + { includesMap.remove( id ); } } @@ -278,53 +289,53 @@ } private void sourceToSAX( Source source, ContentHandler handler ) - throws SAXException, IOException, ComponentException, SourceException + throws SAXException, IOException, ComponentException, SourceException { if( source instanceof XMLizable ) { - ( ( XMLizable ) source ).toSAX( handler ); + ( (XMLizable)source ).toSAX( handler ); } else { - XMLizer xmlizer = null; - + final XMLizer xmlizer = (XMLizer)manager.lookup( XMLizer.ROLE ); try { - xmlizer = ( XMLizer ) this.manager.lookup( XMLizer.ROLE ); - - xmlizer.toSAX( source.getInputStream(), source.getMimeType(), source.getSystemId(), handler ); + final InputStream inputStream = source.getInputStream(); + final String mimeType = source.getMimeType(); + final String systemId = source.getSystemId(); + xmlizer.toSAX( inputStream, mimeType, systemId, handler ); } finally { - this.manager.release( xmlizer ); + manager.release( xmlizer ); } } } - public void transform( Source source, - Source stylesheet, - Parameters params, - Result result ) - throws XSLTProcessorException + public void transform( final Source source, + final Source stylesheet, + final Parameters params, + final Result result ) + throws XSLTProcessorException { try { if( getLogger().isDebugEnabled() ) { - getLogger().debug( "Transform source = " + source - + ", stylesheet = " + stylesheet - + ", parameters = " + params - + ", result = " + result ); + getLogger().debug( "Transform source = " + source + + ", stylesheet = " + stylesheet + + ", parameters = " + params + + ", result = " + result ); } - TransformerHandler handler = getTransformerHandler( stylesheet ); + final TransformerHandler handler = getTransformerHandler( stylesheet ); if( params != null ) { - Transformer transformer = handler.getTransformer(); + final Transformer transformer = handler.getTransformer(); transformer.clearParameters(); String[] names = params.getNames(); for( int i = names.length - 1; i >= 0; i-- ) { - transformer.setParameter( names[i], params.getParameter( names[i] ) ); + transformer.setParameter( names[ i ], params.getParameter( names[ i ] ) ); } } @@ -335,21 +346,24 @@ getLogger().debug( "Transform done" ); } } - catch (SAXException e) + catch( SAXException e ) { if( e.getException() == null ) { - throw new XSLTProcessorException( "Error in running Transformation", e ); + final String message = "Error in running Transformation"; + throw new XSLTProcessorException( message, e ); } else { - getLogger().debug( "Got SAXException. Rethrowing cause exception.", e ); + final String message = "Got SAXException. Rethrowing cause exception."; + getLogger().debug( message, e ); throw new XSLTProcessorException( "Error in running Transformation", e.getException() ); } } catch( Exception e ) { - throw new XSLTProcessorException( "Error in running Transformation", e ); + final String message = "Error in running Transformation"; + throw new XSLTProcessorException( message, e ); } } @@ -358,13 +372,13 @@ * the class can't be found or the given class doesn't implement * the required interface, the default factory is returned. */ - private SAXTransformerFactory getTransformerFactory(String factoryName) + private SAXTransformerFactory getTransformerFactory( String factoryName ) { SAXTransformerFactory _factory; - if ( null == factoryName ) + if( null == factoryName ) { - _factory = (SAXTransformerFactory) TransformerFactory.newInstance(); + _factory = (SAXTransformerFactory)TransformerFactory.newInstance(); } else { @@ -375,48 +389,53 @@ { loader = this.getClass().getClassLoader(); } - _factory = (SAXTransformerFactory) loader.loadClass(factoryName).newInstance(); + _factory = (SAXTransformerFactory)loader.loadClass( factoryName ).newInstance(); } - catch (ClassNotFoundException cnfe) + catch( ClassNotFoundException cnfe ) { - getLogger().error("Cannot find the requested TrAX factory '" + factoryName - + "'. Using default TrAX Transformer Factory instead."); - if (this.factory != null) return this.factory; - _factory = (SAXTransformerFactory) TransformerFactory.newInstance(); + getLogger().error( "Cannot find the requested TrAX factory '" + factoryName + + "'. Using default TrAX Transformer Factory instead." ); + if( this.factory != null ) + return this.factory; + _factory = (SAXTransformerFactory)TransformerFactory.newInstance(); } - catch (ClassCastException cce) + catch( ClassCastException cce ) { - getLogger().error("The indicated class '" + factoryName - + "' is not a TrAX Transformer Factory. Using default TrAX Transformer Factory instead."); - if (this.factory != null) return this.factory; - _factory = (SAXTransformerFactory) TransformerFactory.newInstance(); + getLogger().error( "The indicated class '" + factoryName + + "' is not a TrAX Transformer Factory. Using default TrAX Transformer Factory instead." ); + if( this.factory != null ) + return this.factory; + _factory = (SAXTransformerFactory)TransformerFactory.newInstance(); } - catch (Exception e) + catch( Exception e ) { - getLogger().error("Error found loading the requested TrAX Transformer Factory '" - + factoryName + "'. Using default TrAX Transformer Factory instead."); - if (this.factory != null) return this.factory; - _factory = (SAXTransformerFactory) TransformerFactory.newInstance(); + getLogger().error( "Error found loading the requested TrAX Transformer Factory '" + + factoryName + "'. Using default TrAX Transformer Factory instead." ); + if( this.factory != null ) + return this.factory; + _factory = (SAXTransformerFactory)TransformerFactory.newInstance(); } } - _factory.setErrorListener(this.errorHandler); - _factory.setURIResolver(this); + _factory.setErrorListener( this.errorHandler ); + _factory.setURIResolver( this ); // FIXME (SM): implementation-specific parameter passing should be // made more extensible. - if (_factory.getClass().getName().equals("org.apache.xalan.processor.TransformerFactoryImpl")) + if( _factory.getClass().getName().equals( "org.apache.xalan.processor.TransformerFactoryImpl" ) ) { - _factory.setAttribute("http://xml.apache.org/xalan/features/incremental", - new Boolean( incrementalProcessing ) ); + _factory.setAttribute( "http://xml.apache.org/xalan/features/incremental", + new Boolean( incrementalProcessing ) ); } return _factory; } - private TransformerHandlerAndValidity getTemplates(Source stylesheet, String id) - throws IOException, SourceException, TransformerException { - if (!useStore) { + private TransformerHandlerAndValidity getTemplates( Source stylesheet, String id ) + throws IOException, SourceException, TransformerException + { + if( !useStore ) + { return null; } @@ -425,81 +444,94 @@ // template created by another one. String key = id + this.factory.getClass().getName(); - if (getLogger().isDebugEnabled()) + if( getLogger().isDebugEnabled() ) { - getLogger().debug("getTemplates: stylesheet " + id); + getLogger().debug( "getTemplates: stylesheet " + id ); } SourceValidity newValidity = stylesheet.getValidity(); // Only stylesheets with validity are stored - if (newValidity == null) { + if( newValidity == null ) + { // Remove an old template - store.remove(key); + store.remove( key ); return null; } // Stored is an array of the templates and the caching time and list of includes - Object[] templateAndValidityAndIncludes = (Object[]) store.get(key); - if (templateAndValidityAndIncludes == null) { + Object[] templateAndValidityAndIncludes = (Object[])store.get( key ); + if( templateAndValidityAndIncludes == null ) + { // Templates not found in cache return null; } // Check template modification time - SourceValidity storedValidity = (SourceValidity) templateAndValidityAndIncludes[1]; + SourceValidity storedValidity = (SourceValidity)templateAndValidityAndIncludes[ 1 ]; int valid = storedValidity.isValid(); boolean isValid; - if ( valid == 0 ) { + if( valid == 0 ) + { isValid = storedValidity.isValid( newValidity ); - } else { - isValid = (valid == 1); } - if ( !isValid ) { - store.remove(key); + else + { + isValid = ( valid == 1 ); + } + if( !isValid ) + { + store.remove( key ); return null; } // Check includes AggregatedValidity aggregated = null; - List includes = (List)templateAndValidityAndIncludes[2]; - if (includes != null) { + List includes = (List)templateAndValidityAndIncludes[ 2 ]; + if( includes != null ) + { aggregated = new AggregatedValidity(); aggregated.add( storedValidity ); - for (int i = includes.size() - 1; i >= 0; i--) { + for( int i = includes.size() - 1; i >= 0; i-- ) + { // Every include stored as pair of source ID and validity - Object[] pair = (Object[])includes.get(i); - storedValidity = (SourceValidity)pair[1]; + Object[] pair = (Object[])includes.get( i ); + storedValidity = (SourceValidity)pair[ 1 ]; aggregated.add( storedValidity ); valid = storedValidity.isValid(); isValid = false; - if ( valid == 0 ) { - SourceValidity included = resolver.resolveURI((String)pair[0]).getValidity(); - if (included != null) { + if( valid == 0 ) + { + SourceValidity included = resolver.resolveURI( (String)pair[ 0 ] ).getValidity(); + if( included != null ) + { isValid = storedValidity.isValid( included ); } - } else { - isValid = (valid == 1); } - if ( !isValid ) { - store.remove(key); + else + { + isValid = ( valid == 1 ); + } + if( !isValid ) + { + store.remove( key ); return null; } } } TransformerHandler handler = factory.newTransformerHandler( - (Templates)templateAndValidityAndIncludes[0]); + (Templates)templateAndValidityAndIncludes[ 0 ] ); handler.getTransformer().setErrorListener( this.errorHandler ); return new TransformerHandlerAndValidity( handler, aggregated ); } - private void putTemplates (Templates templates, Source stylesheet, String id) - throws IOException + private void putTemplates( Templates templates, Source stylesheet, String id ) + throws IOException { - if (!useStore) + if( !useStore ) return; // we must augment the template ID with the factory classname since one @@ -509,13 +541,14 @@ // only stylesheets with a last modification date are stored SourceValidity validity = stylesheet.getValidity(); - if ( null != validity ) { + if( null != validity ) + { // Stored is an array of the template and the current time - Object[] templateAndValidityAndIncludes = new Object[3]; - templateAndValidityAndIncludes[0] = templates; - templateAndValidityAndIncludes[1] = validity; - templateAndValidityAndIncludes[2] = includesMap.get(id); - store.store(key, templateAndValidityAndIncludes); + Object[] templateAndValidityAndIncludes = new Object[ 3 ]; + templateAndValidityAndIncludes[ 0 ] = templates; + templateAndValidityAndIncludes[ 1 ] = validity; + templateAndValidityAndIncludes[ 2 ] = includesMap.get( id ); + store.store( key, templateAndValidityAndIncludes ); } } @@ -534,12 +567,12 @@ * resolve the URI. */ public javax.xml.transform.Source resolve( String href, String base ) - throws TransformerException + throws TransformerException { if( getLogger().isDebugEnabled() ) { getLogger().debug( "resolve(href = " + href + - ", base = " + base + "); resolver = " + this.resolver ); + ", base = " + base + "); resolver = " + this.resolver ); } Source xslSource = null; @@ -589,13 +622,13 @@ } // Populate included validities - List includes = (List)includesMap.get(base); + List includes = (List)includesMap.get( base ); if( includes != null ) { SourceValidity included = xslSource.getValidity(); if( included != null ) { - includes.add( new Object[] { xslSource.getSystemId(), xslSource.getValidity() } ); + includes.add( new Object[]{xslSource.getSystemId(), xslSource.getValidity()} ); } else { @@ -610,8 +643,8 @@ { if( getLogger().isDebugEnabled() ) { - getLogger().debug("Failed to resolve " + href - + "(base = " + base + "), return null", e); + getLogger().debug( "Failed to resolve " + href + + "(base = " + base + "), return null", e ); } // CZ: To obtain the same behaviour as when the resource is @@ -622,8 +655,8 @@ { if( getLogger().isDebugEnabled() ) { - getLogger().debug("Failed to resolve " + href - + "(base = " + base + "), return null", mue); + getLogger().debug( "Failed to resolve " + href + + "(base = " + base + "), return null", mue ); } return null; @@ -632,8 +665,8 @@ { if( getLogger().isDebugEnabled() ) { - getLogger().debug("Failed to resolve " + href - + "(base = " + base + "), return null", ioe); + getLogger().debug( "Failed to resolve " + href + + "(base = " + base + "), return null", ioe ); } return null; @@ -651,8 +684,8 @@ * * @throws IOException if I/O error occured. */ - private static InputSource getInputSource( Source source ) - throws IOException, SourceException + private static InputSource getInputSource( final Source source ) + throws IOException, SourceException { final InputSource newObject = new InputSource( source.getInputStream() ); newObject.setSystemId( source.getSystemId() );
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>