Collaborative services :- Collaborative services are methods and java server pages tlds provided by portal to integrate lotus collaborative options. Portal provides a tld file under this location{C:\IBM\WebSphere\PortalServer\people\people.impl\persontag\taglib\shared\app\WEB-INF\tld}. Generally it contains jar file you need to unzip and look for WEB-INF folder.
PersonTag :- Using person tag we can get links in your custom portlet. These links can be used as person tags on hover over these tags we can show person image or some status details. Default provided options are click to view business card, actions to provide custom email action. If there is no business card it just shows the person name. If lotus notes is integrated it provides option to add as a sametime contact.
Integrating business card and online status in custom portlet :-
Step1 :- Create portal project and then create a portlet in it. then modify the view jsp as given below.
Step 2 :- In portlet doView write code to fill above dynamic data in view jsp
package com.ibm.bussinesscardportlet;
import java.io.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.*;
import com.ibm.portal.ObjectID;
import com.ibm.portal.identification.Identification;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.serialize.SerializationException;
import com.ibm.portal.um.PumaProfile;
import com.ibm.portal.um.User;
import com.ibm.portal.um.exceptions.PumaException;
import com.ibm.portal.um.portletservice.PumaHome;
/**
* A sample portlet based on GenericPortlet
*/
public class BussinessCardPortlet extends GenericPortlet {
public static final String JSP_FOLDER = "/_BussinessCardPortlet/jsp/"; // JSP folder name
public static final String VIEW_JSP = "BussinessCardPortletView"; // JSP file name to be rendered on the view mode
public String PUMA_JNDI_NAME = "portletservice/com.ibm.portal.um.portletservice.PumaHome";
public static PortletServiceHome psh = null;
public Identification identification = null;
/**
* @see javax.portlet.Portlet#init()
*/
public void init() throws PortletException{
super.init();
Context ctx;
try {
ctx = new InitialContext();
//Retrieve the service object
psh = (PortletServiceHome)ctx.lookup(PUMA_JNDI_NAME);
identification = (Identification)ctx.lookup(Identification.JNDI_NAME);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Serve up the <code>view</code> mode.
*
* @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
//displayName
String user = request.getRemoteUser();
request.setAttribute("displayName", user);
PumaHome pumHome = psh.getPortletService(PumaHome.class);
PumaProfile pumaProfile = pumHome.getProfile(request);
try {
User currentUser = pumaProfile.getCurrentUser();
ObjectID objectId = currentUser.getObjectID();
request.setAttribute("objectId",identification.serialize(objectId));
} catch (PumaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SerializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Invoke the JSP to render
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
rd.include(request,response);
}
/**
* Process an action request.
*
* @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
*/
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
}
/**
* Returns JSP file path.
*
* @param request Render request
* @param jspFile JSP file name
* @return JSP file path
*/
private static String getJspFilePath(RenderRequest request, String jspFile) {
String markup = request.getProperty("wps.markup");
if( markup == null )
markup = getMarkup(request.getResponseContentType());
return JSP_FOLDER + markup + "/" + jspFile + "." + getJspExtension(markup);
}
/**
* Convert MIME type to markup name.
*
* @param contentType MIME type
* @return Markup name
*/
private static String getMarkup(String contentType) {
if( "text/vnd.wap.wml".equals(contentType) )
return "wml";
else
return "html";
}
/**
* Returns the file extension for the JSP file
*
* @param markupName Markup name
* @return JSP extension
*/
private static String getJspExtension(String markupName) {
return "jsp";
}
}
PersonTag :- Using person tag we can get links in your custom portlet. These links can be used as person tags on hover over these tags we can show person image or some status details. Default provided options are click to view business card, actions to provide custom email action. If there is no business card it just shows the person name. If lotus notes is integrated it provides option to add as a sametime contact.
Integrating business card and online status in custom portlet :-
Step1 :- Create portal project and then create a portlet in it. then modify the view jsp as given below.
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.bussinesscardportlet.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model" prefix="portlet-client-model" %>
<%@taglib uri="/WEB-INF/tld/people.tld"prefix="pa"%>
<portlet:defineObjects/>
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*"/>
<portlet-client-model:require module="ibm.portal.portlet.*"/>
</portlet-client-model:init>
<DIV style="margin: 6px">
<h1>Using person tag</h1>
<pa:person value="uid=wpsadmin,O=defaultWIMFileBasedRealm" valueType="LDAPDN" displayName="wpsadmin" isActive="true" />
<br/>
<h1>Using live text</h1>
<span class='vcard'>
<a class='fn' href='javascript:SemTagMenu.a11y(event)' style='color:black; text-decoration:none;'
onclick='return false;'>${displayName}</a>
<span class='userObjectId' style='display:none;'>${objectId}</span>
</span>
</DIV>
Step 2 :- In portlet doView write code to fill above dynamic data in view jsp
package com.ibm.bussinesscardportlet;
import java.io.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.*;
import com.ibm.portal.ObjectID;
import com.ibm.portal.identification.Identification;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.serialize.SerializationException;
import com.ibm.portal.um.PumaProfile;
import com.ibm.portal.um.User;
import com.ibm.portal.um.exceptions.PumaException;
import com.ibm.portal.um.portletservice.PumaHome;
/**
* A sample portlet based on GenericPortlet
*/
public class BussinessCardPortlet extends GenericPortlet {
public static final String JSP_FOLDER = "/_BussinessCardPortlet/jsp/"; // JSP folder name
public static final String VIEW_JSP = "BussinessCardPortletView"; // JSP file name to be rendered on the view mode
public String PUMA_JNDI_NAME = "portletservice/com.ibm.portal.um.portletservice.PumaHome";
public static PortletServiceHome psh = null;
public Identification identification = null;
/**
* @see javax.portlet.Portlet#init()
*/
public void init() throws PortletException{
super.init();
Context ctx;
try {
ctx = new InitialContext();
//Retrieve the service object
psh = (PortletServiceHome)ctx.lookup(PUMA_JNDI_NAME);
identification = (Identification)ctx.lookup(Identification.JNDI_NAME);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Serve up the <code>view</code> mode.
*
* @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
//displayName
String user = request.getRemoteUser();
request.setAttribute("displayName", user);
PumaHome pumHome = psh.getPortletService(PumaHome.class);
PumaProfile pumaProfile = pumHome.getProfile(request);
try {
User currentUser = pumaProfile.getCurrentUser();
ObjectID objectId = currentUser.getObjectID();
request.setAttribute("objectId",identification.serialize(objectId));
} catch (PumaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SerializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Invoke the JSP to render
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
rd.include(request,response);
}
/**
* Process an action request.
*
* @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
*/
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
}
/**
* Returns JSP file path.
*
* @param request Render request
* @param jspFile JSP file name
* @return JSP file path
*/
private static String getJspFilePath(RenderRequest request, String jspFile) {
String markup = request.getProperty("wps.markup");
if( markup == null )
markup = getMarkup(request.getResponseContentType());
return JSP_FOLDER + markup + "/" + jspFile + "." + getJspExtension(markup);
}
/**
* Convert MIME type to markup name.
*
* @param contentType MIME type
* @return Markup name
*/
private static String getMarkup(String contentType) {
if( "text/vnd.wap.wml".equals(contentType) )
return "wml";
else
return "html";
}
/**
* Returns the file extension for the JSP file
*
* @param markupName Markup name
* @return JSP extension
*/
private static String getJspExtension(String markupName) {
return "jsp";
}
}
Step 3 :- Output
hover on any one of it to see the menu
Hover on the other one also
Now click on it to see user business card
Now click on profile to see full profile of user
Now hover on second approach and click on menu link
Now click on profile to view full profile of user
No comments:
Post a Comment