Wednesday, June 23, 2010

WebCenter WIKI Macro - Table of Contents

WebCenter WIKI Macro - Table of Contents I was asked to help extending Oracle WebCenter's Wiki server, to add a macro to auto-generate a Table of Contents for a wiki page. It follows the same layout as Wikipedia's table of contents, and also has the ability to hide/show itself.

Description:
The <macro:Toc> will generate a simple Table of Contents, in the forms of Wikipedia's Table of Contents. It will search the wiki page content for all Header tags (!, !!, !!!, !!!!) up to 4h level.
Anchors to the title are automatically generated based text for this title
Example: !Description generates anchor <a name="Description"></a><h1>Description</h1>

Syntax:
#1) simple -- will create TOC with title = "Contents" and no auto numbering:
<macro:Toc>
</macro>

#2) with numbering -- numbers are automatically added to the TOC
<macro:Toc numbering="true">
</macro>

#3) with title & numbering -- the title will be set to the text within the macro tags
<macro:Toc numbering="true">
My Table of Contents
</macro>

If you want to give it a try, get the following files and place them on the location below:
Note: It was tested with WebCenter 11g 11.1.1.3.0
-- $WLS_HOME/user_projects/applications//owc_wiki/tags/toc.vm
-- $WLS_HOME/user_projects/applications//owc_wiki/WEB-INF/classes/org/jzwiki/macros/TocMacro.class
-- $WLS_HOME/user_projects/applications//owc_wiki/WEB-INF/lib/yawiki-engine-2.1.jar - file changed is org.jzonic.yawiki.converter.HeaderConverter.class

Here is a screenshot of the macro in action :


Monday, June 7, 2010

WLP Portlet Subscribe/Unsubscribe

Last week, I had to simulate a "subscribe/unsubscribe" mechanism for WebLogic Portal (WLP) 10.3. The basic idea is that the user has an option to subscribe to a portlet, from a list of available portlets, and that is displayed in his main page.

After some research, I found some good reference from Balz Schreier on the WLP Portlet Preferences APIs. In his example, Balz shows how to get access to PortalCustomizationManager which allows us to perform various operations, including removing - .removePlaceable - and adding - .addPlaceable - portlets to a Page.

Using similar code, we could also get access to PortletDefinitionManager , which will give us access to all portlets for the Web Application - .getPublicPortletDefinitions.

In my example, the idea is to "replace" the existing portlet subscription with a new one. To simplify things in my example, I have 2 portlets - weather & stocks - and user can either view one or the other. So, when it is time to change the subscription, I just look for the one that is currently showing - _oldPlaceableView -, so I can get its PlaceholderDefinitionId & PlaceHolderPosition. This is needed, as the new portlet - _newPortletDef - will show up in the same location.

Now, we have all the APIs to:
  • getPortalCustomizationManager -- return instance of PortalCustomizationManager.
  • getPortletDefinitionManager -- return instance of PortletDefinitionManager.
  • getAllPortlets -- returns a list of all available portlets for the Web Application.
  • findPortlet -- finds the PortletDefinition for the new portlet to be subscribed to.
  • findPlaceableView -- finds the PlaceableView instance of the current portlet.
  • deleteCustomizations -- helper to clean up all the customizations for this user, and reset the original state of the page. Useful for the testing, where things start getting messy after some time, and you want to clean it all up. I received this code from an Oracle peer.
  • subscribePortlet -- wraps all the calls into a single method, to make it easier for the test JSP page.
It is also important to say that the user must be authenticated for this to work the way we wanted. In my test.jsp, I have a reference to an authenticate  method, that simply calls  com.bea.p13n.security.Authentication.login.

Putting it all together, here is WlpHelper.java and test.jsp. The idea is to start with a simple JSP just to validate the flow, but that later could turn into a "Preferences Page" of some sort, where user views all the available portlets and can choose which one to subscribe to.

Here is the original page, showing the Stocks portlet:


and this is after executing the test.jsp with the following parameters:
http://localhost:7001/tutorial_portalWeb/test.jsp?username=rolima&password=welcome1&action=subWeather


The example is really simple, but the starting APIs are there for you build from it.
Have fun!