RE: using both Xalan and Saxon with C3

Robby Pelssers <[email protected]>
Newsgroups gmane.text.xml.cocoon.user
Message-ID <A5838A1302A3AC48B4A90FAD790B51AB01F70C@AMXPRD0410MB366.eurprd04.prod.outlook.com>
I did some investigation into this matter and the problem is in
org.apache.cocoon.sax.component.XSLTTransformer

It has two constructor methods:

    public XSLTTransformer(final URL source) {
        this(source, null);
    }

And

    public XSLTTransformer(final URL source, final Map<String, Object> attributes) {
        super();
        this.loadXSLT(source, attributes);
    }

So we can set attributes for the transformerfactory but not choose the implementation. First of all I see something in the code that makes no sense to me:

    /**
     * A generic transformer factory to parse XSLTs.
     */
    private static final SAXTransformerFactory TRAX_FACTORY = createNewSAXTransformerFactory();

this always falls back to  

    private static SAXTransformerFactory createNewSAXTransformerFactory() {
        return (SAXTransformerFactory) TransformerFactory.newInstance();
    }


But on lines 148 to 157 I see following code.  If the attributes are not null and not empty we STILL use createNewSAXTransformerFactory.  So the else block seems like a complete waste here?!


            // XSLT has to be parsed
            SAXTransformerFactory transformerFactory;
            if (attributes != null && !attributes.isEmpty()) {
                transformerFactory = createNewSAXTransformerFactory();
                for (Entry<String, Object> attribute : attributes.entrySet()) {
                    transformerFactory.setAttribute(attribute.getKey(), attribute.getValue());
                }
            } else {
                transformerFactory = TRAX_FACTORY;
            }

Ideally I would like to see a third constructor method which would allow us to set  the factoryClassName of the 
Javax.xml.transform.TransformerFactory

And default use:

public static TransformerFactory newInstance(String factoryClassName, ClassLoader classLoader)  throws TransformerFactoryConfigurationError

We could from Cocoon side default set this to be "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl" if the factoryClassName is null or empty.

Just thinking out loud here... 

Robby


-----Original Message-----
From: Robby Pelssers [mailto:[email protected]] 
Sent: Tuesday, December 04, 2012 2:21 PM
To: [email protected]; [email protected]
Subject: using both Xalan and Saxon with C3

Hi guys,

Just wondering how I would configure a C3 project so I could use both Xalan and Saxon from my sitemap and java

I currently took the approach to just create a file META-INF/services/javax.xml.transform.TransformerFactory
With following content:
net.sf.saxon.TransformerFactoryImpl

But I guess that restricts me to always use Saxon by default?

Robby

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.