Ignore:
Timestamp:
03/14/08 16:07:32 (4 years ago)
Author:
jharrop
Message:

Workaround for docx4all java.util.prefs.FileSystemPreferences? syncWorld, WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException?: java.lang.IllegalArgumentException?: Not supported: indent-number, every 30 seconds, caused by use of Xalan (non xsltc).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java

    r186 r192  
    248248 *              We want to use plain old Xalan J, not xsltc 
    249249 *  
    250  *              Following is not necessary provided Xalan is on the classpath. 
    251  *                                                                 ================================== 
     250 *              Following would not be necessary provided Xalan is on the classpath 
    252251 *  
    253252                System.setProperty("javax.xml.transform.TransformerFactory", "FQCN"); 
     
    255254                examples of FQCN: 
    256255                 
    257                   org.apache.xalan.transformer.TransformerImpl (this is the one we want) 
     256                  org.apache.xalan.processor.TransformerFactoryImpl (this is the one we want) 
    258257                  com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl 
    259258                  org.apache.xalan.xsltc.trax.TransformerFactoryImpl 
     259                  net.sf.saxon.TransformerFactoryImpl 
     260                   
     261                  (unfortunately, there is no com.sun.org.apache.xalan.processor.TransformerFactoryImpl, 
     262                   so we have to bundle xalan jar, which is 2.7 MB 
     263                    
     264                   But we can make it smaller: 
     265                    
     266                        org/apache/xalan/lib$ rm sql -rf 
     267                    org/apache/xalan$ rm xsltc -rf 
     268 
     269          That gets us from 2.7 MB to 1.85 MB. 
     270           
     271          But Sun already has: 
     272           
     273                        com.sun.org.apache.xpath;                        
     274                        com.sun.org.apache.xml.internal.dtm;                     
     275                        com.sun.org.apache.xalan.internal.extensions|lib|res|templates 
     276                    
     277                  So why not refactor Xalan and leave all that out as well? 
     278                   
     279                   
     280                HOWEVER, docx4all encounters http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6396599 
     281                 
     282                        java.util.prefs.FileSystemPreferences syncWorld 
     283                        WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: java.lang.IllegalArgumentException: Not supported: indent-number 
     284                 
     285                every 30 seconds 
     286 
     287                The workaround implemented is to remove META-INF/services from the xalan jar  
     288                to prevent xalan being picked up as the default provider for jaxp transform, 
     289                so we have to use it explicitly. 
     290                 
     291                .. which means  
     292 
     293                        System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl"); 
    260294                         
    261295*/               
     296                 
     297                 
     298                javax.xml.transform.TransformerFactory tfactory = javax.xml.transform.TransformerFactory.newInstance(); 
     299                String originalFactory = tfactory.getClass().getName(); 
     300                System.out.println("original TransformerFactory: " + originalFactory); 
     301                // com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl resolves the syncWorld problem 
     302                // net.sf.saxon.TransformerFactoryImpl is no good. 
     303                 
     304                System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl"); 
     305                 
    262306                // Now transform this into XHTML 
    263                 javax.xml.transform.TransformerFactory tfactory = javax.xml.transform.TransformerFactory.newInstance(); 
     307                tfactory = javax.xml.transform.TransformerFactory.newInstance(); 
    264308                javax.xml.transform.dom.DOMSource domSource = new javax.xml.transform.dom.DOMSource(doc); 
    265309 
     
    274318                // Use the template to create a transformer 
    275319                javax.xml.transform.Transformer xformer = template.newTransformer(); 
     320                 
     321                 
     322                // Finished with the factory, so set it back again! 
     323                // The "Not supported: indent-number" problem will only occur if a user creates  
     324                // a new document during the time between these 2 calls to setProperty 
     325                // (and syncWorld is called?) 
     326                System.setProperty("javax.xml.transform.TransformerFactory", originalFactory); 
    276327                 
    277328                if (!xformer.getClass().getName().equals("org.apache.xalan.transformer.TransformerImpl")) { 
Note: See TracChangeset for help on using the changeset viewer.