poniedziałek, 18 października 2010

Xalan Java exensions

Lately, I've been given a task involving some XSLT processing with Java extensions. Transformation was meant to be run from a JSR-168 portlet running in the IBM WebSpere Portal.
First prototype used following declarations:
  • function (namespace) declaration:
    xmlns:custom="java:foo.bar.CustomFunction"
  • class instance injection:
    xsl:param name="instance"
  • sample instance method call:
    custom:setTitle($instance, text())

It run smoothly in Tomcat without any problems, even given that I had to use instance method calls on object passed by param.
Then I moved to IBM WebSphere and things got complicated. At first I was blessed by the TransformerConfgiurationException. I took me plenty of googling to figure out what was happening. Eventually it occurred that WebSphere's Xalan was unable to identify the exact type (!) of injected custom class instance. It's well-known limitation, identified in this Apache JIRA issue.
My final XSLT declarations are as follows:
  • function (namespace) declaration:
    xmlns:my-namespace="xalan://foo.bar.CustomFunction"
  • class instance injection:
    xsl:param name="instance"
  • sample instance method call:
    my-namespace:setTitle(xsltc:cast('foo.bar.CustomFunction', $instance), '', text())

The best thing is that such configuration works in both containers (Tomcat and WebSphere) without any problems :)

Brak komentarzy: