Custom XPath/XSLT Functions for Oracle App Server

Steps in creating custom XSL/XPath functions:

This ones really handy… here are the steps:

1. Create a static inner class that implements IXPathFunction

package customFunctions.sandeepphukan.test;

import java.util.List;
import com.oracle.bpel.xml.xpath.IXPathContext;
import com.oracle.bpel.xml.xpath.IXPathFunction;
import com.oracle.bpel.xml.xpath.XPathFunctionException;

/**
* A class that echoes the parameter
* @author sphukan
*
*/
public class echo {

/**
* XPath function
*/
public static class echoXPathFunction implements IXPathFunction{

public Object call(IXPathContext arg0, List arg1) throws XPathFunctionException {
if (arg1.size()!=1){
throw new XPathFunctionException(“This custom XPath function requires exactly one argument!!!”);
}else{
return echo((String)arg1.get(0));
}

}

}

public static String echo(String text){
return text;
}

}

If you creating the java class via Eclipse then include the path %ORACLE_AS%\bpel\lib in your project.

2. Put the class as a jar in %JDEV_HOME%\jdev\lib\patches
3. Register the jar in the JDev User Defined Extension functions(Tools->Preferences->XSLMaps) file and restart JDev

<extension-functions xmlns:pcui=”http://www.oracle.com/PC/ui”&gt;
<functions xmlns:utl=”http://www.oracle.com/XSL/Transform/java/customFunctions.sandeepphukan.test.echo”&gt;
<function name=”utl:echo” as=”string”>
<param name=”text” as=”string”/>
</function>
</functions>
<functions xmlns:ora=”http://schemas.oracle.com/xpath/extension”&gt;
</functions>
</extension-functions>

You should be able to see the custom Function in User Defined Extension Functions pallette:

XSL Mapper Custom Funtion Display

XSL Mapper Custom Funtion Display

4. Edit the file %SOA_HOME%\bpel\system\config\xpath-functions.xml

<function id=”echo” arity=”1″> <!–Arity is the number of mandatory arguments –>
<comment><![CDATA[This function echoes the parameter….
<p/>
The signature of the function is <i>utl:echo(‘string’)</i>.
The arguments are:
<ol type=”1″>
<li>string – single string parameter.
</ol>]]></comment>
<classname>customFunctions.sandeepphukan.test.echo$EchoFunction</classname> <!–Inner className –>
<property id=”namespace-uri”>
<value>http://www.oracle.com/XSL/Transform/java/customFunctions.sandeepphukan.test.echo</value&gt;
<comment><![CDATA[Namespace URI for this function]]></comment>
</property>
<property id=”namespace-prefix”>
<value>utl</value>
<comment><![CDATA[Namespace prefix for this function]]></comment>
</property>
</function>

5. Drop the custom classes in the location %SOA_HOME%\bpel\system\classes. Incase you are using Eclipse you should be able to find these classes under EclipseWorkspace/ProjectName/bin/
6. Restart Oracle AS.

————————– For JDEV Expressions Builder ————————————
1. Copy the file %JDEV_HOME%/integration/lib/bpm-ide-common.jar to a temp directory.
2. Unjar the file %tempDir%/bpm-ide-common.jar with the following command
jar -xvf bpm-ide-common.jar oracle/tip/tools/ide/common/resource/PreBuiltExtensionFunctions.xml
3. Now edit the infalted PreBuiltExtensionFunctions.xml file and add the entry:
<functions xmlns:utl=”http://www.oracle.com/XSL/Transform/java/customFunctions.sandeepphukan.test.echo”&gt;
<function name=”utl:echo” as=”string”>
<param name=”text” as=”string” required=”yes”/>
<pcui:ui>
<pcui:mapper palettePage=”Advanced Functions”/>
</pcui:ui>
</function>
</functions>
4. Now update the jar file with the command:
jar -uf bpm-ide-common.jar oracle/tip/tools/ide/common/resource/PreBuiltExtensionFunctions.xml
5. Finally put the jar file back into %JDEV_HOME%/integration/lib/ directory. You might want to keep a backup of the original jar before you do this.

Once done, restart JDeveloper and you should be able to see your custom function:

XPath Expressions Builder Custom Function Display

XPath Expressions Builder Custom Function Display

Testing it out :

1. Create a BPEL process
2. Use the transform activity and map input to output.
3. In the XSL file design mode open the components pallette and locate your function in the User Defined Extension Functions pallette.
4. Drag it and assign it.
5. Deploy it and run it in the AS.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: