The following code indicates how to use the publication API. The method initialize() is used to position a certain number of parameters. In most of cases, this method will get the null value as argument, because inside the VDoc system every needed property is positioned.
public void general_useModule() { // creation of an object of publication module ILibraryModule libraryModule = new PortalLibraryModule(); try { // initialization of the module libraryModule.initialize( null ); } catch( Exception e ) { // if an error has occurred getNavigator().processErrors( e ); } finally { libraryModule.unInitialize(); } }
The context notion enables to run processing with a user account. Several cases are displayed. Their using depends on the execution context and the available objects.
public void general_getContext( ILibraryModule libraryModule ) throws Exception { // 1st case : retrieving the context from a user object IUser user = libraryModule.getUserByLogin( "sysadmin" ); IContext userContext = libraryModule.getContext( user ); // 2nd case: retrieving the context from an external ID IContext externalIDContext = libraryModule.getContext( libraryModule.getLoggedOnUser() ); // 3rd case : retrieving the context from a login IContext loginContext = libraryModule.getContextByLogin( "sysadmin" ); }
In numerous cases, we need to gather several processing in a same transaction. Each module has its own transactional mechanism.
The following example shows how to use this transactional mechanism from the directory module.
public void general_useTransaction( IContext context, ILibraryModule libraryModule ) { try { // starting a transaction libraryModule.beginTransaction( this ); // doing something // ... // validating the transaction libraryModule.commitTransaction( this ); } catch( Exception e ) { // if an error has occurred, canceling the previous processing libraryModule.rollbackTransaction( this ); } }
The publication module offers a request system based on JDO. In the following example we use a search-type controller (SearchController) to request the database and retrieve IFile objects.
public void general_useSearch( ILibraryModule libraryModule ) throws LibraryModuleException { try { ISearchController searchController = libraryModule.getSearchController(); Collection files = searchController.findElements( IFile.class, "(status == 0)", null ); for ( Iterator iter = files.iterator() ; iter.hasNext() ; ) { IFile iFile = (IFile)iter.next(); System.out.println( iFile.getName() ); } } catch( Exception e ) { getNavigator().processErrors( e, true ); } }