Novell Home

Calling a Java Program from an XPath Expression

Novell Cool Solutions: Tip
By Perin Blanchard

Digg This - Slashdot This

Posted: 17 Aug 2005
 

Problem

A reader asked:

"What is the syntax for calling a Java program from an XPath expression? I'd like to call it and set the return value to a local variable.

And here's the response from Novell's Perin Blanchard ...

Solution

A namespace must be declared with the following form:

xmlns:<whatever>="http://www.novell.com/nxsl/java/<package.class>"

So, to use the java.lang.String class, the declaration could be as follows:

xmlns:jstring="http://www.novell.com/nxsl/java/java.lang.String"

Using Policy Builder, click on the "Edit namespaces" button and enter the prefix in the "Name" field, and the name of the class in the "URL" field. Policy Builder will then create a namespace of the correct form for you in your policy definition.

(If you are using XSLT, just declare the namespace as above.)

Then, in the XPath expression, use the prefix and the name of the method (New is a special case that means constructor):

jstring:new('this is a string')

An instance method is called like this:

jstring:indexOf($, 'something')

A static method is called the same way, but without the instance being passed as the first parameter.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell