Programming tasks

Using the SDK API site module

The following code indicates how to use the site management API.

public void general_useModule() {
	// creation of an object of site module
	ISiteModule siteModule = (ISiteModule)Modules.getSiteModule();
	try {
		...
	}
	catch( Exception e ) {
		// if an error has occurred
		getNavigator().processErrors( e );
	} finally {
		Modules.releaseModule( siteModule );
	}
}

Recovering a context to use the SDK API

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( ISiteModule siteModule ) throws Exception {
	// 1st case : retrieving the context from a user object
	IUser user = null;
	IContext userContext = siteModule.getContext( user );

	// 2nd case: retrieving the context from an external ID
	IContext externalIDContext = siteModule.getContext( siteModule.getLoggedOnUser() );

	// 3rd case : retrieving the context from a login
	IContext loginContext = siteModule.getContextByLogin( "sysadmin" );
}

Using the transactions

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 site module.

public void general_useTransaction( IContext context, ISiteModule siteModule ) {
	try {
		// starting a transaction
		siteModule.beginTransaction( this );

		// doing something
		// ...

		// validating the transaction
		siteModule.commitTransaction( this );
	} catch( Exception e ) {
		// if an error has occurred, canceling the previous processing
		siteModule.rollbackTransaction( this );
	}
}