Caucho maker of Resin Server | Application Server (Java EE Certified) and Web Server


 

Resin Documentation

home company blog wiki docs 
app server web server 
health cloud java ee pro 
 Resin Server | Application Server (Java EE Certified) and Web Server
 

jaxp - specifying xml and xslt implementations


JAXP is a standard interface which supports pluggable XML and XSL implementations. JAXP selects the parser based on system properties. You can set the properties to select a different parser than the default one.

By default, Resin will use the JDK's parsers. Other parsers, including Resin's own parsers can be selected with the <system-property> tag.

The Resin parsers and transformers

Resin XML DOM parsers
JAXP PROPERTYRESIN CLASS
javax.xml.parsers.DocumentBuilderFactorycom.caucho.xml.parsers.XmlDocumentBuilderFactory
javax.xml.parsers.DocumentBuilderFactorycom.caucho.xml.parsers.HtmlDocumentBuilderFactory
javax.xml.parsers.DocumentBuilderFactorycom.caucho.xml.parsers.LooseXmlDocumentBuilderFactory
javax.xml.parsers.DocumentBuilderFactorycom.caucho.xml.parsers.LooseHtmlDocumentBuilderFactory
Resin XML SAX parsers
javax.xml.parsers.SAXParserFactorycom.caucho.xml.parsers.XmlSAXParserFactory
javax.xml.parsers.SAXParserFactorycom.caucho.xml.parsers.HtmlSAXParserFactory
javax.xml.parsers.SAXParserFactorycom.caucho.xml.parsers.LooseXmlSAXParserFactory
javax.xml.parsers.SAXParserFactorycom.caucho.xml.parsers.LooseHtmlSAXParserFactory
Resin XSLT transformer
JAXP PROPERTYRESIN CLASS
javax.xml.transform.TransformerFactory com.caucho.xsl.Xsl

Usually Resin will use its XML parsers and fast XSLT transformer. Sometimes placement of certain jars in the classpath causes problems. system-property can be used to explicitly set the Resin XML and XSLT implementation classes.

system-property for using Resin XML and XSLT
<!-- xml -->

<system-property javax.xml.parsers.DocumentBuilderFactory=
                 "com.caucho.xml.parsers.XmlDocumentBuilderFactory"/>
<system-property javax.xml.parsers.SAXParserFactory=
                 "com.caucho.xml.parsers.XmlSAXParserFactory"/>

<!--  xslt -->

<system-property javax.xml.transform.TransformerFactory=
                 "com.caucho.xsl.Xsl"/>

JDK 1.5 JAXP implementation

The Sun JDK 1.5 includes the Xerces and Xalan JAXP implementations packaged under a different name.

JDK 1.5 system-property for JAXP implementations

<web-app>
  <!-- xml -->

  <system-property javax.xml.parsers.DocumentBuilderFactory=
                   "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>

  <system-property javax.xml.parsers.SAXParserFactory=
                   "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl">

  <!--  xslt -->

  <system-property javax.xml.transform.TransformerFactory=
                   "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>

</web-app>

Using alternative XML and XSLT implementations

system-property

JAXP system properties are used to specify the XML and XSLT implementations that are used. Resin defaults to using it's own XML parsers and fast XSLT transformer. Other implementations are used with the specification of the appropriate system properties and values.

Examples of using system-property for commonly used alternative XML parsers and XSLT transformers are in separate sections below. The system property configuration tags can be placed at the web-app or the server level.

system-property to specify xml parser for web-app

<web-app>
  <!-- xml -->

  <system-property javax.xml.parsers.DocumentBuilderFactory=
               "..."/>
  <system-property javax.xml.parsers.SAXParserFactory=
               "..."/>

  <!--  xslt -->

  <system-property javax.xml.transform.TransformerFactory=
               "..."/>
</web-app>

system-property to specify xml parser for server

<server>
  <!-- xml -->

  <system-property javax.xml.parsers.DocumentBuilderFactory=
               "..."/>
  <system-property javax.xml.parsers.SAXParserFactory=
               "..."/>

  <!-- xslt -->

  <system-property javax.xml.transform.TransformerFactory=
               "..."/>
</server>

jar file placement

Setting system properties for alternative libraries requires that the implementation classes, usually in a .jar file, are available in the classpath.

The implementation classes are available for a single web application when the jar file(s) are placed in WEB-INF/lib. Since other web-apps do not see these libraries, this allows you to isolate a particular version of a particular implementation for use by the web-app. It is not uncommon for a new version of these jar files to introduce problems with existing code.

If the system-property is being set at the server level, then the jar files containing the implementation classes need to be placed in $RESIN_HOME/lib. This is also a convenient location for placement if you want to avoid putting the libraries in WEB-INF/lib for every web application. Any jars placed in $RESIN_HOME/lib are avaialable for all web applications.

Using Xalan and Xerces

system-property for using Xalan and Xerces
<!-- xml -->

<system-property javax.xml.parsers.DocumentBuilderFactory=
             "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<system-property javax.xml.parsers.SAXParserFactory=
             "org.apache.xerces.jaxp.SAXParserFactoryImpl"/>

<!--  xslt -->

<system-property javax.xml.transform.TransformerFactory=
             "org.apache.xalan.processor.TransformerFactoryImpl"/>

Cocoon users may need the following:

system-property for cocoon users using Xalan and Xerces
<system-property org.xml.sax.driver=
             "org.apache.xerces.parsers.SAXParser"/>

Put your xerces and xalan jar files in WEB-INF/lib, or to have them available to all of your applications put them in $RESIN_HOME/lib.

Using Crimson

Crimson is the xml parser that is included with JDK 1.4.

system-property for using Crimson

<!-- xml -->

<system-property javax.xml.parsers.DocumentBuilderFactory=
             "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl"/>
<system-property javax.xml.parsers.SAXParserFactory=
             "org.apache.crimson.jaxp.SAXParserFactoryImpl"/>


Copyright © 1998-2012 Caucho Technology, Inc. All rights reserved. Resin ® is a registered trademark. Quercustm, and Hessiantm are trademarks of Caucho Technology.

Cloud-optimized Resin Server is a Java EE certified Java Application Server, and Web Server, and Distributed Cache Server (Memcached).
Leading companies worldwide with demand for reliability and high performance web applications including SalesForce.com, CNET, DZone and many more are powered by Resin.

home company blog wiki docs 
app server web server 
health cloud java ee pro