Home Blog Services Resume Contact

The Turn-In Blog

Philip Cheshire's personal blog, rants regarding anything and everything but mainly regarding his findings in day to day programming of java and websphere portal as well as his weekend actities at the autocross course.

What to be notified when a new blog post is published? Sign up here!

Your Name:
Email:
What's 12+7?

Your information will be safe. I will not, under any circumstances,
disclose or sell your personal information for any reason at all.
You will have the ability to unsubscribe at any time with a link in the
email you will receive when a new post is entered.

View All Posts

Using WCM API in Virtual Portal with Managed Pages Enabled in Portal V8
posted on Fri Sep 06, 2013 at 01:08 PM

With the addition of the new managed pages functionality in Portal V8, using the WCM API within portlets or themes running in a virtual portal poses a new set of challenges. Using repository.getSystemWorkspace is just not enough anymore to access your libraries. If you're still on v8.0.0.0, you're in trouble as the following was not enabled until v8.0.0.1!

First, let's keep in mind that when your java code executes, it's being executed in the base portal as all portlets and themes are running there. Only pages and WCM assets are running within the scope of the virutal portal. If you need to access a particular library within your custom portlet or theme, you must know your virtual portal context, or at least be able to determine it using the request object. For the following, we're going to assume we know the VP context we're running in.

This is going to be a simple example, but you'll be able to take this concept and apply it to your situation.

My servlet:

 public class MyServlet extends HttpServlet{

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//First, access the repository like normal

Repository repo = WCM_API.getRepository();

//Create the required VirtualPortalContext using the repository

VirtualPortalContext vctx = repo.generateVPContextFromContextPath("testvp");

//Create VP Scoped Action object

VPScopedActionContentSearch vpA = new VPScopedActionContentSearch();

//execute code in the VP

repo.executeInVP(vctx, vpA);

//get the returned value

Content content = vpA.getReturnedValue();

}

}

Create custom class of VPScopedActionContentSearch

 public class VPScopedActionContentSearch implements VirtualPortalScopedAction{

//class level variables

private Content returnedValue = null;

//public constructor

public VPScopedActionContentSearch(){

}


//method to retrieve found content

public Content getReturnedValue(){

return returnedValue;

}


//overwritten method

@Override

public void run() throws WCMException {

Repository repo = WCM_API.getRepository();

Workspace ws = repo.getSystemWorkspace();

ws.login();

DocumentLibrary docLib = ws.getDocumentLibrary(“My VP Scoped Lib”);

ws.setCurrentDocumentLibrary(docLib);

QueryService qs = qs.createQuery(Content.class);

query.addSelector(ProfileSelectors.categoriesContains(someCategory.getId()));

ResultIterator results = qs.execute(query);

while(results.hasNext()){

returnedValue = (Content)results.next();

}

ws.logout();

repo.endWorkspace();

}

}

There you have an example of how to create your own custom class implementing the VirtualPortalScopedAction interface and use it to execute code scoped to a specific virtual portal.

View Comments      

Blog Posts

08/28/2014
I stand with Ferrari against Deadmau5, and here's why.

08/01/2014
Themes in WPS v8.5 - What's different?

09/06/2013
Using WCM API in Virtual Portal with Managed Pages Enabled in Portal V8

07/15/2013
Everything Happens for a Reason

07/12/2012
IBM WebSphere Portal v7 Theme Metadata, the NEW Theme Policy

07/09/2012
Creating a custom Portal theme based on the 7.0.0.2 Theme

05/23/2012
Philip v3.0

02/01/2012
You can be surprised as to what you can do with 8 people in 52hrs!

12/21/2011
Turns out, putting a Ford V8 in a BMW takes a lot of work!

08/17/2011
Creating URLs to Portal Pages and/or Portlets

08/05/2011
Gathering User Metrics with Custom Portlet Service

07/08/2011
BMW Update

03/11/2011
Choosing a Software Vendor

02/08/2011
The Art of Successful Software Development

02/04/2011
Accessing PUMA Service from a Java Servlet in IBM WebSphere Portal 6.1.x

02/04/2011
Retrieving WCM Components Using IBM Web Content Management Java API in WebSphere Portal 6.1.x

02/03/2011
Uploading an Image, Resizing, and Saving to Web Content Management using IBM WebSphere Portal 6.1.x

02/03/2011
Retrieving URL Parameters in IBM WebSphere Portal 6.1.5

02/02/2011
New Website Design Launched!

02/02/2011
Gauging Interest: Free AutoX Registration Software

10/21/2010
e36 Acquired!

03/09/2009
This Week

02/15/2009
Starting to come together!