Monday, August 02, 2010

Portlet Modes (WebSphere Portal 6.0 Onwards)

The below are the portlet modes and its use in WebSphere Portal.


View Mode -
Default portlet mode, It will be used to display all end user functionalities.
Edit Mode (Personalize) - This is user specific personalize mode. What ever changes are made and stored into portlet preference, that will affect only that specific user.
Edit Defaults Mode (Edit Shared Settings) - This mode will be available only for portal admins. Also, this will be available for users with minimum page level access rights as Editor and Portlet access rights as Administrator. The changes into this preference value will affect all the users.
NOTE: This is only for the portlet occurence in that page.
Config Mode -
This is configuration mode. What ever changes are made into this mode will affect all occurence on that portal.
Help Mode - Generally this will be used to give more details about that portlet functionality and its use.

Tuesday, July 06, 2010

Reading LTPA Cookie from Portlet & Servlet and passing the LTPA cookie into remote WebSphere Server using REST call.

Sample code which shows how you can get the LTPA cookie value from portlet and servlet.

######### Reading from Servlet Starts #############

String ltpaToken = null;
Cookie[] cookies = httpServletRequest.getCookies();

for (int i = 0; i < cookies.length; i++)
{
if (cookies[i].getName().equals("LtpaToken"))
{
ltpaToken = cookies[i].getValue(); break;
}
}
######### Reading from Servlet Ends #############

########## Reading from Portlet Starts #############

String myCookie = renderRequest.getProperty("cookie");
String ltpaToken = "";
StringTokenizer st = new StringTokenizer (myCookie, "; ");
while(st.hasMoreTokens())
{
String key = st.nextToken();
if(key.indexOf("LtpaToken") > -1)
{
int equalSign = key.indexOf("=");
ltpaToken = key.substring(equalSign+1);
}
}

########## Reading from Portlet Ends#############
### Setting inside URLConnection object & sending to remote portal server ###
// After getting the ltpa token, setting into URL connection to pass the ltpa cookie to the external server url.
if (ltpaToken != null)
{
String cookie = "LtpaToken=" + ltpaToken.toString();
URL url = new URL("http://myportal:port/wps/myportal)
URLConnection conn = url.openConnection();
conn.setRequestProperty("Cookie", cookie);
conn.connect();
}

Tips - Softwares ( During our Work)

The following are the utility software which i felt it will be very useful for Web Developers.

Aptana Studio - Web Resource development such as HTML, CSS, JS e.t.c
7-zip - Extract format such as zip, war, rar e.t.c
Notepad++ - It has many cool features. ( It will open any huge size text file )
Ever Note - Repository to keep all your personal docs. There is a way to encode the file and it can be protected using password.

Will keep you posting with other softwares...

How to set & get a value from Portlet Preference while developing a portlet using WebSphere Portlet Factory

Below is the sample code which will give a clear idea about how you can set/get a value from Portlet Preference while developing a portlet using WebSphere Portlet Factory.

Create a LJO(Linked Java Object) builder and copy the below code and replace MY_DEPARTMENT value into the value you want to set & get from Portlet Preference.


########################## Sample Code Starts #############################

public class PortletPreferenceWPFSample {
PortletRequest portletRequest = null;

private static final String MY_DEPARTMENT="myDepartment";
private static final String DEFAULT_MY_DEPARTMENT="";

public void setPreferences(WebAppAccess webAppAccess , String myDepartment)
{
try{
// Getting HttpServletRequest from WebAppAcces object.
HttpServletRequest request = webAppAccess.getHttpServletRequest();
// Type casting into Portlet Request.
portletRequest = (PortletRequest) request.getAttribute(com.bowstreet.adapters.Constants.PORTLET_REQUEST);
javax.portlet.PortletPreferences preferences = portletRequest.getPreferences();


//Storing the myDepartment in to portlet preferences Object.
preferences.setValue(MY_DEPARTMENT,myDepartment);

preferences.store();


}catch(Exception err)
{
err.printStackTrace();
}

}


public String getPreferences(WebAppAccess webAppAccess)
{
HttpServletRequest request = webAppAccess.getHttpServletRequest();
portletRequest = (PortletRequest) request.getAttribute(com.bowstreet.adapters.Constants.PORTLET_REQUEST);

javax.portlet.PortletPreferences preferences = portletRequest.getPreferences();

String myDepartment= preferences.getValue(MY_DEPARTMENT,DEFAULT_MY_DEPARTMENT);

return myDepartment;

}
}


##### Function call to above method from remote place such as method or other LJO class #####
// Calling setPreferences method to store folder path into it. Where PortletPreferenceWPFSample_LJO is the LJO builder name for PortletPreferenceWPFSample class.
webAppAccess.callMethod("PortletPreferenceWPFSample_LJO.setPreferences", myDepartment);

########################## Sample Code Ends #############################

Wednesday, April 15, 2009

Creating Content using WCM API

This time will tell how you can create a content using WCM API. Before I want you to see my sample code I would like to show the WCM API method to get what is required to create content into Web content management through WCM API.

JavaDoc description for Create Content method in WCM API:

createContent (In API JavaDoc)

Content createContent(DocumentId authoringTemplateId,
DocumentId parentSiteAreaId,
DocumentId siblingId,
int position)
throws DocumentCreationException,
AuthorizationException,
IllegalDocumentTypeException

Creates a new Content object, based on an AuthoringTemplate in the parent SiteArea. The template ID that is specified must be for a template that already exists in the WCM system.

If the ChildPosition is ChildPosition.PREVIOUS or ChildPosition.NEXT, then the siblingId parameter must be specified. If it is not, then an IllegalArgumentException will be thrown. If the ChildPosition is ChildPosition.START or ChildPosition.END then the siblingId parameter, if it is not null, will be ignored.

Parameters:
authoringTemplateId - the authoring template ID
parentSiteAreaId - the parent site area ID
siblingId - the DocumentId of the sibling document, if any. May be null, according to the rules stated
position - the position of the child (docId)

Returns:
a new Content object based on the specified template

Throws:
DocumentCreationException - if the object cannot be created
AuthorizationException - if the user does not have access
IllegalDocumentTypeException - if specified template is not an AuthoringTemplate, the parentSiteArea is not a SiteArea, or the sibling is not a Content or ContentLink.

**** MY SAMPLE CODE STARTS HERE *****

String userName = USER_BALA;
String password = PASS_BALA;
String wcmLibraryName= LBRY_Test;
String contentName = CNTNT_Test;
String contentTitle = CNTNT_Test_Title;
String siteArea= SA_Test;
String authoringTemplate= AT_Test;

// Getting workspace object.
Workspace oWorkspace = WCM_API.getRepository().getWorkspace(username, password);

// Setting current document library
oWorkspace.setCurrentDocumentLibrary(oWorkspace.getDocumentLibrary(wcmLibraryName));

DocumentId oDocumentIdContent = Util.getDocumentId(oWorkspace, DocumentTypes.
Content, contentName);

// Check whether content is already existing or not
if( oDocumentIdContent==null){
/*
* Getting Site Area document id.
*/
DocumentId oDocumentIdSiteArea = Util.getDocumentId(oWorkspace, DocumentTypes.
SiteArea, siteArea);

if(oDocumentIdSiteArea!=null){
// Get the authoring template document id.
DocumentId oDocumentIdAuthoringTemplate = Util.getDocumentId(oWorkspace, DocumentTypes.AuthoringTemplate, authoringTemplate);

if(oDocumentIdAuthoringTemplate!=null){
// Creating content here ...
oContent = oWorkspace.createContent(oDocumentIdAuthoringTemplate, oDocumentIdSiteArea, null, ChildPosition.END);
oContent.setName(contentName);
oContent.setTitle(contentTitle );
}
}
}

String errors[] = oWorkspace.save(oContent);
for(int x=0;x LessThan errors.length;x++) {
System.
out.println("Errors while saving the content into workspace "+errors[x]);
}

**** UTIL METHODS STARTS HERE ****

public static DocumentId getDocumentId(Workspace oWorkspace, DocumentType oDocumentType, String fileName) throws Exception{
DocumentId oDocumentID = null;
DocumentIdIterator oDocumentIdIteratorContents = oWorkspace.findByName(oDocumentType,fileName);
if(oDocumentIdIteratorContents.hasNext()){
oDocumentID= (DocumentId) oDocumentIdIteratorContents.next();
}
return oDocumentID;
}
**** UTIL METHODS ENDS HERE ****

**** MY SAMPLE CODE ENDS HERE ****

I hope this will give clear idea about how to add a content into IBM Web Content Management System using WCM API.

Monday, April 13, 2009

Tracing errors while saving content in to Workspace object using WCM API

This time would like to share my experience with issues which I faced & how I solved that while working with WCM API.
I have written code to upload an image into content management system using WCM API.
Due to missing of file extension I could not able to upload an image into content management system using WCM API.

The following code was very useful to find errors while saving a content into workspace object..

String errors[] = oWorkspace.save(oContent);
for(int x=0;x LessThan errors.length;x++)
{System.out.println("Errors while saving content into workspace object using WCM API"+errors[x]);
}

I hope this will help for the people who works with WCM API to write data into content management system.

Thursday, March 19, 2009

Navigating to other page in Portal from any portlet

The following steps will be used to navigate control from any portlet to any page/ any portlet in other page. Also this can be used to pass parameter to other portlet.

1> Keep the wp[1].l2.urlhelper.jar file under WEB-INF/lib folder.
2> Add the following code in your JSP to achieve the same.

String homeURL = PortletURLHelper.generateUrl(PAGE_UNIQUE_NAME, Portlet Name, null, true, renderRequest, renderResponse);

Use the value of homeURL in href attribute.
3> Download the jar from the following location.
http://www-01.ibm.com/support/docview.wss?rs=688&context=SSHRKX&dc=DB520&uid=swg21265900&loc=en_US&cs=UTF-8&lang=en&rss=ct688websphere