Use the API
The workspace is the heart of the IBM Web Content Manager API. Items are created, saved, deleted and searched for in the workspace item. A workspace is basically an interface to Web Content Manager associated with a user. Using a workspace item, the user can perform operations as that user.
To get a workspace item, first retrieve the WebContentService:
try { // Construct and inital Context InitialContext ctx = new InitialContext(); // Retrieve WebContentService using JNDI name WebContentService webContentService = (WebContentService) ctx.lookup("portal:service/WebContentService"); } catch (NamingException ne) { System.out.print("Naming Exception: " + ne); }We then request one from the repository singleton with the following call:
webContentService.getRepository().getWorkspace("my username", "my password");To get a workspace item without specifying a user name and password, use one of the following calls:
- 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 Web Content Manager user, or for some other reason could not be authenticated , an "OperationFailedException" will be thrown.
Only Web Content Manager 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.
You 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 Web Content Manager.
Use 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: