BIP by Extension

BIP Extensions? Regular readers may remember I wrote about building BIP extensions a while back. Its a means of adding functionality to your templates by making an external call to a java class. Its very very powerful and completely unsupported right now, as I warned before - do not log an SR if you get into trouble.
When I last wrote about them I got a few comments and Frank Menne from HSM in Germany went ahead and built one. Im only bringing them up again because I had cause to use one in a recent POC. In my orignal post I showed how you could pass a value thru to the extension for it to return some processed text. This POC required some more sophisticated processing. Take the following data:

<RECORD>
<CNT>1</CNT>
<TYPE>In Bulk</TYPE>
</RECORD>
<RECORD>
<CNT>2</CNT>
<TYPE>In Bulk</TYPE>
</RECORD>
<RECORD>
<CNT>3</CNT>
<TYPE>In Bulk</TYPE>
</RECORD>
<RECORD>
<CNT>4</CNT>
<TYPE>Individual</TYPE>
</RECORD>
<RECORD>
<CNT>5</CNT>
<TYPE>In Bulk</TYPE>
</RECORD>
<RECORD>
<CNT>6</CNT>
<TYPE>Individual</TYPE>
</RECORD>
This needs to be summarized into

1-3,5 In Bulk
4,6 Individual

Possible using XSL but, it gets very complex very quickly. So I thought if I could push the data to an extension, process it in java with some loops and objects and push the text back Id save myself a whole bunch of XSL templating. But I needed to pass a complete XML tree fragment, not just a single value. Its turns out that that is not very tough. I had registered my extention as 'cert:' so my call to the extension from the RTF template was as follows:

<?cert:NumDesc(.//COMMODITY,'PACKAGE_DESCRIPTION')?>

NumDesc is my function in the java class
.//COMMODITY - passes everything under COMMODITY in the XML tree
'PACKAGE_DESCRIPTION - was the element I wanted summarized. I wrote a function to summarize any data this way, just need to pass the element name you are interested in summarizing.

The java class was as follows:

public class certExtension {
    public certExtension() {
    }

    public static final String NumDesc(NodeList nodes, String eleName)
               {
                    String retStr ="";                  
                    NodeList nl;
                    Element pkg;
                    Element element;
                   String outp = "";
                    for (int i = 0; i < nodes.getLength(); i++) {
                           element = (Element) nodes.item(i);
                           nl = element.getElementsByTagName(eleName);
                           pkg = (Element) nl.item(0);
                           Node pd = pkg.getFirstChild();
                           CharacterData cd = (CharacterData) pd;
                           ...
                           }
                        }
                      return(retStr);
                 }

Sorry, but Im not able to share all of the secret sauce or template right now. The loop you can see is passing over the nodeset passed from the template looking for the specified element name (eleName)

I think its a neat solution and worked really well and saved a bunch of time. Do you need to be a java whiz? Not on your nelly, as former BIP colleagues will attest, my java skills are not the hottest on the block. But I get by and spend time Googling and scouring web pages for help :0)
There is a caveat, its a little tough to debug. The template is passing the tree fragment at runtime, if things fail, error messages do bubble up to the template builder but they might be a little cryptic.
If you have a certain function that you need across templates or even within a template, give it a try.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today