org.carrot2.util.xslt
Class TemplatesPool

java.lang.Object
  extended by org.carrot2.util.xslt.TemplatesPool

public final class TemplatesPool
extends Object

A pool of precompiled XSLT stylesheets (Templates). Caching can be disabled via constructor parameter or via setting a system property:

 template.caching
 
to false.


Field Summary
static String TEMPLATE_CACHING_PROPERTY
          Global system property disabling template caching.
 SAXTransformerFactory tFactory
          SAXTransformerFactory capable of producing SAX-based transformers.
 
Constructor Summary
TemplatesPool()
          Creates a TemplatesPool with caching enabled.
TemplatesPool(boolean templateCaching)
          Check for required facilities.
 
Method Summary
 void addTemplate(String key, Templates template)
          Add a new template to the pool.
 Templates compileTemplate(InputStream stream)
          Compile a Templates from a given stream.
 Templates compileTemplate(String systemId)
          Compile a Templates from a given system identifier.
 TransformerHandler getIdentityTransformerHandler()
           
 Templates getTemplate(String key)
          Retrieves a previously stored template, if available.
 Transformer newTransformer(Templates t)
          Return a new Transformer.
 TransformerHandler newTransformerHandler(Templates template)
          Return a new TransformerHandler based on a given precompiled Templates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATE_CACHING_PROPERTY

public static final String TEMPLATE_CACHING_PROPERTY
Global system property disabling template caching. This property can also be set at runtime (after the pool is initialized).

See Also:
Constant Field Values

tFactory

public final SAXTransformerFactory tFactory
SAXTransformerFactory capable of producing SAX-based transformers.

Constructor Detail

TemplatesPool

public TemplatesPool()
              throws Exception
Creates a TemplatesPool with caching enabled.

Throws:
Exception

TemplatesPool

public TemplatesPool(boolean templateCaching)
              throws Exception
Check for required facilities. If not available, an exception will be thrown.

Throws:
Exception
Method Detail

getIdentityTransformerHandler

public TransformerHandler getIdentityTransformerHandler()
                                                 throws TransformerConfigurationException
Returns:
returns the identity transformer handler.
Throws:
TransformerConfigurationException

getTemplate

public Templates getTemplate(String key)
Retrieves a previously stored template, if available.


addTemplate

public void addTemplate(String key,
                        Templates template)
Add a new template to the pool. Addition is quite costly as it replaces the internal stylesheets HashMap.


compileTemplate

public Templates compileTemplate(String systemId)
                          throws SAXException
Compile a Templates from a given system identifier. The template is not added to the pool, a manual call to addTemplate(String, Templates) is required.

Throws:
SAXException

compileTemplate

public Templates compileTemplate(InputStream stream)
                          throws SAXException
Compile a Templates from a given stream. The template is not added to the pool automatically.

Throws:
SAXException

newTransformerHandler

public TransformerHandler newTransformerHandler(Templates template)
                                         throws TransformerConfigurationException
Return a new TransformerHandler based on a given precompiled Templates. The handler Transformer's ErrorListener is set to TransformerErrorListener to raise exceptions and give proper warnings.

Throws:
TransformerConfigurationException

newTransformer

public Transformer newTransformer(Templates t)
                           throws TransformerConfigurationException
Return a new Transformer.

Throws:
TransformerConfigurationException
See Also:
newTransformerHandler(Templates)


Copyright (c) Dawid Weiss, Stanislaw Osinski