Snap Preview

So now the links in the blog have a snap preview. I am not sure how it happened. I tried to add it but could not figure out how to do that. Place your cursor on one of the hyperlinks. It is nice.

WebSphere Portal PUMA API

The details of our WebSphere Portal users are stored in IBM Tivoli LDAP server. This code prints what attributes of users are actually available and enables us to show them in a theme JSP. So our JSR 168 portlets have to further rely on IBM-specific code. Portability is really a lost cause.


     javax.naming.Context ctx = new javax.naming.InitialContext(); home = (
     PumaProfile profile = home.getProfile( request );
     List attributes = profile.getDefinedUserAttributeNames();
     User user = profile.getCurrentUser();
     Map map = profile.getAttributes(user, attributes);
     Iterator iterator = attributes.iterator();

      while (iterator.hasNext()) {
        String attribute = (String);
        System.out.println("["+ attribute +"][" +
                                  map.get(attribute) + "]");

}catch( PumaSystemException pse ){
     System.out.println( "PumaSystemException" );
}catch( PumaModelException pme ){
     System.out.println( "PumaModelException" );
}catch( PumaMissingAccessRightsException pmare ){
     System.out.println( "PumaMissingAccessRightsException" );
}catch( Exception e ){
     System.out.println( "Exception" );

Java Regular Expression

Some of the requests from the client could be weird but they seem to serve their purpose. We have been using WebSphere portal and we were given the task of filtering the output rendered by the Portal. So I created a custom
HttpServletResponseWrapper and took a copy of the HTML before sending it to the browser. This part was easy.
A filter can be configured in the web.xml of wps.war since the Portal code itself is a WAR deployed on WAS. Stripping the HTML of certain tags and filtering it was more difficult.
I tried to use Java Regex. It worked for some cases but it was very hard to use it to massage nested HTML.

Regex is cool. The following code actually closes the ‘img’ tag. Regex can be used to close HTML tags easily if they are not nested too deeply and there no newlines .Nested HTML tags broken into separate lines are pretty hard to manipulate using Regex.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegularExpression{

private String source =
"<img width=\"30\" height=\"18\" border=\"0\" src=\'/wps/images/dot.gif\' alt=\"\">";

public static void main( String[] argv ){
RegularExpression regex = new RegularExpression();


public void changePattern(){
String content = source.replaceAll("<img[^>]+[>]", "$0</img> ");
System.out.println( content );