Use the Web Content Manager API
To use the IBM Web Content Manager API to get a WCM workspace item...
public void init() throws PortletException { super.init(); try { // Retrieve WebContentService using JNDI name InitialContext ctx = new InitialContext(); WebContentService webContentService = (WebContentService) ctx.lookup("portal:service/wcm/WebContentService"); } catch (NamingException ne) { System.out.print("Naming Exception: " + ne); } webContentService.getRepository().getWorkspace("my username", "my password"); }Alternatively...
public void init() throws PortletException { super.init(); try { myworkspace = WCM_API.getRepository().getWorkspace(); if ( myworkspace != null ){ myworkspace.login(); }else { System.out.println( "Unable to get a valid workspace.<br/>" ); } } catch (Exception e) { // Normally exceptions would be added to logs System.out.println("Exception " + e.getMessage()); e.printStackTrace(); } }To get a workspace item without specifying a user name and password...
- When used in a portlet:
Workspace workspace = webContentService.getRepository().getWorkspace((Principal) portletRequest.getUser());
- When not used in a portlet:
Workspace workspace = webContentService.getRepository().getWorkspace((Principal) request.getUserPrincipal());
If the user is not recognized as a WCM user, or for some other reason could not be authenticated , an "OperationFailedException" will be thrown.
Only WCM users (including external LDAP users if enabled) are recognized. For example, A workspace cannot be retrieved using an LTPA token.
Operations available on the workspace include:
- Search for items with the provided "findBy" methods.
- Create new items of available editable types.
- Saving and deleting editable items.
We must call endWorkspace() when finished with the workspace item.
webContentService.getRepository().endWorkspace();
We don't need to call endWorkspace() when using a JSP component as rendering and session management is handled by WCM.
Use the setCurrentDocumentLibrary method to make calls library-specific. If not specified, the default library that has been configured in the WCM WCMConfigService service is used.
Parent The IBM Web Content Manager APIRelated tasks: