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 aTemplates
cache, for performance purpose.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ThreadSafeTraxProcessor.CachedTemplates
static class
ThreadSafeTraxProcessor.CacheValidity
The validity of the current stylesheet.static class
ThreadSafeTraxProcessor.ExtendedTransformerHandlerAndValidity
SpecialXSLTProcessor.TransformerHandlerAndValidity
with information about the cache state of the underlyingTemplates
.private static class
ThreadSafeTraxProcessor.ResolvedURI
private static class
ThreadSafeTraxProcessor.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_ATTR
private Context
_context
private SAXTransformerFactory
_factory
The trax TransformerFactory this component usesprivate boolean
_incrementalProcessing
Is incremental processing turned on? (default for Xalan: no)private ServiceManager
_manager
The ServiceManagerprivate SourceResolver
_resolver
Resolver used to resolve XSLT document() calls, imports and includesprivate Map<String,Collection<ThreadSafeTraxProcessor.CachedTemplates>>
_templatesCache
private String
_transformerFactory
The 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:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
Compose. Try to get the store- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
Initialize- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
dispose
public void dispose()
Disposable- Specified by:
dispose
in interfaceDisposable
-
parameterize
public void parameterize(Parameters params) throws ParameterException
Configure the component- Specified by:
parameterize
in interfaceParameterizable
- Throws:
ParameterException
-
setTransformerFactory
public void setTransformerFactory(String classname)
- Specified by:
setTransformerFactory
in interfaceXSLTProcessor
-
getTransformerHandler
public TransformerHandler getTransformerHandler(Source stylesheet) throws XSLTProcessorException
- Specified by:
getTransformerHandler
in interfaceXSLTProcessor
- Throws:
XSLTProcessorException
-
getTransformerHandler
public TransformerHandler getTransformerHandler(Source stylesheet, XMLFilter filter) throws XSLTProcessorException
- Specified by:
getTransformerHandler
in interfaceXSLTProcessor
- Throws:
XSLTProcessorException
-
getTransformerHandlerAndValidity
public XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet) throws XSLTProcessorException
- Specified by:
getTransformerHandlerAndValidity
in interfaceXSLTProcessor
- Throws:
XSLTProcessorException
-
getTransformerHandlerAndValidity
public XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet, XMLFilter filter) throws XSLTProcessorException
- Specified by:
getTransformerHandlerAndValidity
in interfaceXSLTProcessor
- Throws:
XSLTProcessorException
-
_getTemplates
private Pair<Templates,ThreadSafeTraxProcessor.CacheValidity> _getTemplates(Source stylesheet, XMLFilter filter) throws XSLTProcessorException, IOException
- Throws:
XSLTProcessorException
IOException
-
_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:
SAXException
IOException
SourceException
-
transform
public void transform(Source source, Source stylesheet, Parameters params, Result result) throws XSLTProcessorException
- Specified by:
transform
in 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:
resolve
in 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 newInputSource
object that uses theInputStream
and the system ID of theSource
object.- Parameters:
source
- The source concerned- Returns:
- The input source
- Throws:
IOException
- if I/O error occurred.SourceException
- if an error occurred.
-
-