330 likes | 448 Views
XSLTC to the Rescue Brief Introduction to XSLTC and a uPortal Case Study. Katya Sadovsky Administrative Computing Services UC Irvine. Agenda. Overview What is XSLTC XSLT/XSTLC performance comparison demo How it works XSLTC Transformer Attributes Compiling & Running Translets
E N D
XSLTC to the RescueBrief Introduction to XSLTC and a uPortal Case Study Katya Sadovsky Administrative Computing Services UC Irvine Presented at the JA-SIG conference, December 2003
Agenda • Overview • What is XSLTC • XSLT/XSTLC performance comparison demo • How it works • XSLTC Transformer Attributes • Compiling & Running Translets • Case study: using XSLTC with uPortal • Setting up uPortal with XSLTC • Required Code Modifications • Q&A Presented at the JA-SIG conference, December 2003
Overview: What is XSLTC • Java-based XSLTC was originally developed by Sun Microsystems XML Technology Center. • It has since been donated to Apache’s Xalan-J2 project (This presentation will cover the Apache Xalan 2.5.1 XSLTC tool). • As opposed to using interpreted XSL transformations, XSLTC allows users to pre-compile style-sheets into reusable byte code. • XSTLC yields significant performance improvement for server-side processing. Presented at the JA-SIG conference, December 2003
Performance Demo Presented at the JA-SIG conference, December 2003
Overview: How it Works Presented at the JA-SIG conference, December 2003
Overview: How it Works • XSL style-sheet instructions are compiled into Java byte code: translet classes. • Translets typically have a very small memory footprint. • Once translets are compiled, they can be used for transformations. • You may save translet class files on disk and re-use them at a later time. Presented at the JA-SIG conference, December 2003
XSLTC Transformer Attributes Presented at the JA-SIG conference, December 2003
Compiling Translets • There are several ways to compile translets: • pre-compile translets into class files using a command-line utility • compile translets on the fly while running a transformation with command-line utility • Compile translets on the fly while running transformations using Java APIs Presented at the JA-SIG conference, December 2003
Running Translets • There are also two ways to run transformations: • Using command-line utilities: • XSLTC-specific transformation processor class • Regular Xalan transformation processor class with a few extra options • Using Java APIs Presented at the JA-SIG conference, December 2003
Compiling Translets: Command Line Utility • Xalan-J XSLTC library comes with a command line utility to pre-compile style-sheets: • Executing java -classpath xalan.jar:xercesImpl.jar:xml-apis.jar org.apache.xalan.xsltc.cmdline.Compile xhtml.xsl will create xhtml.class under the current working directory. • Executing java -classpath xalan.jar:xercesImpl.jar:xml-apis.jar org.apache.xalan.xsltc.cmdline.Compile –p edu.uci.translets xhtml.xsl will create edu/uci/translets/xhtml.class under the current working directory. Presented at the JA-SIG conference, December 2003
Running Translets: Command Line Utility • To run a transformation with a pre-compiled translet execute java -classpath xalan.jar:xercesImpl.jar:xml-apis.jar org.apache.xalan.xsltc.cmdline.Transform sample.xhtml org.jasig.portal.channels.webproxy.translet.xhtml • You may also use the regular Xalan command line utility to run XSLTC transformations and generate translets: java -classpath xalan.jar:xercesImpl.jar:xml-apis.jar org.apache.xalan.xslt.Process -XSLTC -IN sample.xhtml -XSL xhtml.xsl -XO –XP org.jasig.portal.channels.webproxy.translet Presented at the JA-SIG conference, December 2003
XSLTC Translets: Using Java APIs Presented at the JA-SIG conference, December 2003
Configuring uPortal 2.1.3 with XSLTC Presented at the JA-SIG conference, December 2003
Outline • Performance Improvement Stats • uPortal Code Modifications • Issues & Solutions • Pre-compiling Translets Presented at the JA-SIG conference, December 2003
Performance Improvement Stats • The following are results of running XSLT and XSLTC based transformations on uPortal’s CGenericXSLT channel with style-sheet caching set to 'on' Presented at the JA-SIG conference, December 2003
Issues & Solutions • Issue • XSLTC functionality is still limited, so not all the style-sheets will work with it • Solution • Apply XSLTC selectively : only use it if a pre-compiled translet exists. Use XSLT in all other cases. Presented at the JA-SIG conference, December 2003
Issues & Solutions, cont’d • Issue • XSLTC bug: NullPointerException in org.apache.xalan.xsltc.trax.DOM2SAX (line 350): • Solution • Fixed the bug: • Recompiled the code and rebuilt xalan.jar Presented at the JA-SIG conference, December 2003
Issues & Solutions, cont’d • Issue • When the destination-directory attribute is not set, the transformer factory will look for the translet in <path_to_the_xsl_file>/<package_path>. • Solution • Keep this in mind when pre-compiling the style-sheets: set the destination-directory to <path_to_the_xsl_file>. Presented at the JA-SIG conference, December 2003
uPortal Code Modifications • Our uPortal implementation uses a combination of XSLT and XSLTC based transformations. • The following uPortal files had to be modified to enable XSLTC processing: • properties/portal.properties • source/org/jasig/portal/utils/XSLT.java Presented at the JA-SIG conference, December 2003
Code Modifications: portal.properties • We wanted to have the ability to turn off all XSLTC based transformations in uPortal. Hence, we added the following property to portal.properties file:org.jasig.portal.utils.XSLT.useXSLTC=true Presented at the JA-SIG conference, December 2003
Code Modifications: XSLT.java • Since we use a combination of XSLT and XSLTC based transformations, we needed to operate with two different transformer factories. The following methods were changed: • getSAXTFactory() • getTemplates() • getTransformerHandler() • The following slides contain a simplified view of our implementation. Presented at the JA-SIG conference, December 2003
XSLT.java: Global Class Changes Presented at the JA-SIG conference, December 2003
XSLT.java: original getSAXTFactory method Presented at the JA-SIG conference, December 2003
XSLT.java: modified getSAXTFactory method Presented at the JA-SIG conference, December 2003
XSLT.java: original getTemplates method Presented at the JA-SIG conference, December 2003
XSLT.java: modified getTemplates method Presented at the JA-SIG conference, December 2003
XSLT.java: original getTrasformerHandler method Presented at the JA-SIG conference, December 2003
XSLT.java: modified getTrasformerHandler method Presented at the JA-SIG conference, December 2003
Pre-compiling Translets • We use an Ant target to compile translets: Presented at the JA-SIG conference, December 2003
Pre-compiling Translets • uPortal style-sheets we pre-compile: • org/jasig/portal/layout/tab-column/nested-tables/*.xsl • org/jasig/portal/layout/tab-column/*.xsl • org/jasig/portal/channels/permissionsmanager/*.xsl • org/jasig/portal/channels/webproxy/*.xsl • org/jasig/portal/channels/CHeader/*.xsl • org/jasig/portal/channels/Clogin/*.xsl • org/jasig/portal/channels/Capplet/*.xsl • org/jasig/portal/channels/CSelectSystemProfile/*.xsl • org/jasig/portal/channels/CGenericXSLT/*.xsl • org/jasig/portal/channels/CGenericXSLT/footer/*.xsl • org/jasig/portal/channels/CGenericXSLT/RSS/*.xsl • org/jasig/portal/channels/CError/*.xsl • org/jasig/portal/channels/CUserPreferences/*.xsl • org/jasig/portal/channels/CUserPreferences/tab-column • org/jasig/portal/channels/CInlineFrame/*.xsl • org/jasig/portal/channels/CImage/*.xsl • org/jasig/portal/channels/bookmarks/*.xsl Presented at the JA-SIG conference, December 2003
Conclusions • XSLTC technology is still relatively new. However, • In most situations it may significantly improve transformation performance,especially for large input documents. • Performance improvements also allow for better scalability. • uPortal software can be XSLTC-enabled with minimal code modifications. Presented at the JA-SIG conference, December 2003
Links & References • Xalan XSLTC Home: http://xml.apache.org/xalan-j/xsltc_usage.html • XSLTC and the Java Web Services Developer Pack (Sun): http://wwws.sun.com/software/xml/developers/xsltc/xsltc_webpack.html • This presentation is available at http://snap.uci.edu/PortalDocs/articles/XSLTC.ppt • Our uPortal-based site: http://snap.uci.edu Presented at the JA-SIG conference, December 2003
Q & A Presented at the JA-SIG conference, December 2003