Package org.ametys.runtime.cocoon
Class ThreadSafeTraxProcessor
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.runtime.cocoon.ThreadSafeTraxProcessor
-
- All Implemented Interfaces:
URIResolver,Disposable,Initializable,Component,Contextualizable,LogEnabled,Parameterizable,Serviceable,XSLTProcessor
public class ThreadSafeTraxProcessor extends AbstractLogEnabled implements XSLTProcessor, Serviceable, Initializable, Disposable, Parameterizable, URIResolver, Contextualizable
Adaptation of Excalibur's XSLTProcessor implementation to allow for better error reporting. This implementation is also threadsafe.
It also handles aTemplatescache, for performance purpose.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classThreadSafeTraxProcessor.CachedTemplatesstatic classThreadSafeTraxProcessor.CacheValidityThe validity of the current stylesheet.static classThreadSafeTraxProcessor.ExtendedTransformerHandlerAndValiditySpecialXSLTProcessor.TransformerHandlerAndValiditywith information about the cache state of the underlyingTemplates.private static classThreadSafeTraxProcessor.ResolvedURIprivate static classThreadSafeTraxProcessor.UnresolvedURI-
Nested classes/interfaces inherited from interface org.apache.excalibur.xml.xslt.XSLTProcessor
XSLTProcessor.TransformerHandlerAndValidity
-
-
Field Summary
Fields Modifier and Type Field Description private static String__URI_CACHE_ATTRprivate Context_contextprivate SAXTransformerFactory_factoryThe trax TransformerFactory this component usesprivate boolean_incrementalProcessingIs incremental processing turned on? (default for Xalan: no)private ServiceManager_managerThe ServiceManagerprivate SourceResolver_resolverResolver used to resolve XSLT document() calls, imports and includesprivate Map<String,Collection<ThreadSafeTraxProcessor.CachedTemplates>>_templatesCacheprivate String_transformerFactoryThe configured transformer factory to useprivate XMLizer_xmlizer-
Fields inherited from interface org.apache.excalibur.xml.xslt.XSLTProcessor
ROLE
-
-
Constructor Summary
Constructors Constructor Description ThreadSafeTraxProcessor()
-
Method Summary
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
__URI_CACHE_ATTR
private static final String __URI_CACHE_ATTR
- See Also:
- Constant Field Values
-
_transformerFactory
private String _transformerFactory
The configured transformer factory to use
-
_factory
private SAXTransformerFactory _factory
The trax TransformerFactory this component uses
-
_incrementalProcessing
private boolean _incrementalProcessing
Is incremental processing turned on? (default for Xalan: no)
-
_resolver
private SourceResolver _resolver
Resolver used to resolve XSLT document() calls, imports and includes
-
_manager
private ServiceManager _manager
The ServiceManager
-
_templatesCache
private Map<String,Collection<ThreadSafeTraxProcessor.CachedTemplates>> _templatesCache
-
-
Constructor Detail
-
ThreadSafeTraxProcessor
public ThreadSafeTraxProcessor()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
Compose. Try to get the store- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
Initialize- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
dispose
public void dispose()
Disposable- Specified by:
disposein interfaceDisposable
-
parameterize
public void parameterize(Parameters params) throws ParameterException
Configure the component- Specified by:
parameterizein interfaceParameterizable- Throws:
ParameterException
-
setTransformerFactory
public void setTransformerFactory(String classname)
- Specified by:
setTransformerFactoryin interfaceXSLTProcessor
-
getTransformerHandler
public TransformerHandler getTransformerHandler(Source stylesheet) throws XSLTProcessorException
- Specified by:
getTransformerHandlerin interfaceXSLTProcessor- Throws:
XSLTProcessorException
-
getTransformerHandler
public TransformerHandler getTransformerHandler(Source stylesheet, XMLFilter filter) throws XSLTProcessorException
- Specified by:
getTransformerHandlerin interfaceXSLTProcessor- Throws:
XSLTProcessorException
-
getTransformerHandlerAndValidity
public XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet) throws XSLTProcessorException
- Specified by:
getTransformerHandlerAndValidityin interfaceXSLTProcessor- Throws:
XSLTProcessorException
-
getTransformerHandlerAndValidity
public XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet, XMLFilter filter) throws XSLTProcessorException
- Specified by:
getTransformerHandlerAndValidityin interfaceXSLTProcessor- Throws:
XSLTProcessorException
-
_getTemplates
private Pair<Templates,ThreadSafeTraxProcessor.CacheValidity> _getTemplates(Source stylesheet, XMLFilter filter) throws XSLTProcessorException, IOException
- Throws:
XSLTProcessorExceptionIOException
-
_getCachedTemplates
private Pair<ThreadSafeTraxProcessor.CachedTemplates,ThreadSafeTraxProcessor.CacheValidity> _getCachedTemplates(Collection<ThreadSafeTraxProcessor.CachedTemplates> cachedTemplates, Source stylesheet, Map<ThreadSafeTraxProcessor.UnresolvedURI,ThreadSafeTraxProcessor.ResolvedURI> resolutionCache) throws IOException
- Throws:
IOException
-
_getResolutionCache
private Map<ThreadSafeTraxProcessor.UnresolvedURI,ThreadSafeTraxProcessor.ResolvedURI> _getResolutionCache()
-
_isValid
private ThreadSafeTraxProcessor.CacheValidity _isValid(ThreadSafeTraxProcessor.CachedTemplates templates, Source stylesheet, Map<ThreadSafeTraxProcessor.UnresolvedURI,ThreadSafeTraxProcessor.ResolvedURI> resolutionCache) throws IOException
- Throws:
IOException
-
_createTemplates
private Templates _createTemplates(SAXTransformerFactory factory, Source stylesheet, XMLFilter filter) throws XSLTProcessorException
- Throws:
XSLTProcessorException
-
_sourceToSAX
private void _sourceToSAX(Source source, ContentHandler handler) throws SAXException, IOException, SourceException
- Throws:
SAXExceptionIOExceptionSourceException
-
transform
public void transform(Source source, Source stylesheet, Parameters params, Result result) throws XSLTProcessorException
- Specified by:
transformin interfaceXSLTProcessor- Throws:
XSLTProcessorException
-
_createTransformerFactory
private SAXTransformerFactory _createTransformerFactory(String factoryName)
Get the TransformerFactory associated with the given classname. If the class can't be found or the given class doesn't implement the required interface, the default factory is returned.- Parameters:
factoryName- The name of the factory class to create- Returns:
- The instance created
-
resolve
public Source resolve(String href, String base) throws TransformerException
Called by the processor when it encounters an xsl:include, xsl:import, or document() function.- Specified by:
resolvein interfaceURIResolver- Parameters:
href- An href attribute, which may be relative or absolute.base- The base URI in effect when the href attribute was encountered.- Returns:
- A Source object, or null if the href cannot be resolved, and the processor should try to resolve the URI itself.
- Throws:
TransformerException- if an error occurs when trying to resolve the URI.
-
_resolve
private Source _resolve(String href, String base) throws IOException
- Throws:
IOException
-
_resolve
Source _resolve(String href, String base, Collection<String> rawURIs, Collection<String> baseURIs, Collection<Long> timestamps, Collection<String> resolvedURIs)
-
_getInputSource
private InputSource _getInputSource(Source source) throws IOException, SourceException
Return a newInputSourceobject that uses theInputStreamand the system ID of theSourceobject.- Parameters:
source- The source concerned- Returns:
- The input source
- Throws:
IOException- if I/O error occurred.SourceException- if an error occurred.
-
-