sylvain 2003/03/19 09:18:57
Modified: src/java/org/apache/cocoon/serialization
AbstractTextSerializer.java
Log:
Allow the TransformerFactory class to be specified in the configuration
Revision Changes Path
1.2 +20 -5
cocoon-2.0/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
Index: AbstractTextSerializer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.0/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractTextSerializer.java 9 Mar 2003 00:03:14 -0000 1.1
+++ AbstractTextSerializer.java 19 Mar 2003 17:18:57 -0000 1.2
@@ -73,6 +73,7 @@
import org.apache.cocoon.caching.CacheValidity;
import org.apache.cocoon.caching.Cacheable;
import org.apache.cocoon.caching.NOPCacheValidity;
+import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.util.TraxErrorHandler;
import org.apache.cocoon.xml.AbstractXMLPipe;
import org.apache.cocoon.xml.XMLConsumer;
@@ -165,10 +166,6 @@
*/
protected SAXTransformerFactory getTransformerFactory()
{
- if(tfactory == null) {
- tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
- tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
- }
return tfactory;
}
@@ -253,6 +250,24 @@
if (! version.getLocation().equals("-")) {
format.put(OutputKeys.VERSION,version.getValue());
}
+
+ Configuration tFactoryConf = conf.getChild("transformer-factory", false);
+ if (tFactoryConf != null) {
+ String tFactoryClass = tFactoryConf.getValue();
+ try {
+ this.tfactory =
(SAXTransformerFactory)ClassUtils.newInstance(tFactoryClass);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Using transformer factory " + tFactoryClass);
+ }
+ } catch(Exception e) {
+ throw new ConfigurationException("Cannot load transformer factory " +
tFactoryClass, e);
+ }
+ } else {
+ // Standard TrAX behaviour
+ this.tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
+ }
+
+ tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
// Check if we need namespace as attributes.
try {