Project

Profile

Help

Saxon bundle in openoffice

Added by Anonymous about 16 years ago

Legacy ID: #4986760 Legacy Poster: Vincent Biragnet (vinzb)

Hi, I'm new to java. I'm trying to perform xslt transformations with saxon in openoffice. I created a java project (openoffice add-on) in Netbeans and included some code to try a first transformation with saxon threw openoffice. I used the code in saxon samples directory : TraxExamples.java. here is what I tried : public static NodeInfo exampleSaxonToSaxon(String sourceID, String xslID) throws TransformerException { System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); // I haded this line javax.xml.transform.TransformerFactory tfactory = javax.xml.transform.TransformerFactory.newInstance(); net.sf.saxon.Configuration config = ((net.sf.saxon.TransformerFactoryImpl)tfactory).getConfiguration(); ......... return builder.getCurrentRoot(); } But the first line, defining system properties, causes a crash of openoffice. I tried the same without the first line (System.setProperty...), but got the following error message : EXCEPTION: java.lang.ClassCastException: org.apache.xalan.processor.TransformerFactoryImpl java.lang.ClassCastException: org.apache.xalan.processor.TransformerFactoryImpl The error occurs at the line where the method getConfiguration is called. I really thank you for your help and hope I've been clear enough, VB


Replies (1)

RE: Saxon bundle in openoffice - Added by Anonymous about 16 years ago

Legacy ID: #4986775 Legacy Poster: Michael Kay (mhkay)

Without the System.setProperty() you have very little control over which XSLT processor will be loaded; it depends on the order that things are found on the classpath. If Xalan gets loaded, then casting tFactory to net.sf.saxon.TransformerFactoryImpl is going to fail. If you're going to do such a cast, then you might as well load the Saxon TransformerFactory directly rather than relying on the factory mechanism: just do tfactory = new net.sf.saxon.TransformerFactoryImpl(); which is much faster and more reliable. It may also be enough to avoid the crash. I'm afraid there are quite a few applications out there that use the JAXP factory mechanism to load an XSLT engine, and then assume either deliberately or accidentally that the XSLT engine they are using is Xalan. If you load Saxon explicitly when needed, but avoid setting the global system property, then such applications will continue to load Xalan and may therefore continue to work.

    (1-1/1)

    Please register to reply