Page extension
Visiativ Process provides a basic class which simplifies the extension classes implementation. This basic class has methods to directly access to the elements often used, such as the site module, the execution context and the message controller.
The page extensions processed in the context of building and displaying a page. The system lets to distinguish the page extensions on the published pages and the pages being created in the draft pages.
A page extension enables to perform the following treatments:
- add components and blocks when loading the page;
- hide certain page elements by their system name;
- position of bookmarks;
- evaluation of bookmarks unknown by the product (customized bookmarks);
- reception of messages linked to the recipient.
Page extension lifecycle
Before the page is not displayed to the user, the system triggers a certain number of events:
onBeforeLoad()
: this method is called at the page initialization before its full rebuilding. It is on this event that it is possible to :- add new elements (components or blocks);
- replace elements or modify the used block;
- define universal recipients;
onAfterLoad()
: this method is called once every component or blocks are evaluated. On this event it is possible:- to position the bookmarks value;
- to recover the elements constituting the page to maybe hide or replace them.
- to position the bookmarks value;
onEvaluateBookmarks()
: this method is called for each bookmark put on the page that won’t be interpreted by the system;onMessage()
: this method is called at the reception of the message designed for a recipient non associated with a recipient class. In other words, the recipient is the extension of the page itself.
Implementing a page extension class
To implement an extension class page, you just have to branch off the BasePageExtension class. The extension class must be defined in the animation of the concerned page (Development tab).
The full name is: com.axemble.vdoc.sdk.site.extensions.BasePageExtension
.
Method of the BasePageExtension basic class
This basic class gives access to the site module, the execution context, and the message controller.
public abstract class BasePageExtension implements Serializable {
final protected ISiteModule getSiteModule();
final protected ISiteExecutionContext getExecutionContext();
final protected IMessageController getMessageController();
public boolean onBeforeLoad();
public boolean onAfterLoad( IBlock rebuiltBlock );
public String onEvaluateBookmarks( String expression );
public boolean onMessage( IMessage message );
}
Example of page extension implementation
The following example shows a page extension very simple that overloads the whole events that can be trigger by the system.
public class SimplePageExtension extends BasePageExtension {
public boolean onBeforeLoad() {
return super.onBeforeLoad();
}
public boolean onAfterLoad( IBlock rebuiltBlock ) {
return super.onAfterLoad( rebuiltBlock );
}
public String onEvaluateBookmarks( String expression ) {
return super.onEvaluateBookmarks( expression );
}
public boolean onMessage( IMessage message ) {
return super.onMessage( message );
}
}
Recipients using
The notion of recipient represents an object remains in memory during all the HTTP session. This recipient can receive messages and hold object structures that will be affect according to the type of the received messages.
Example of using a recipient inside a page extension
The following example shows a page extension that defines a recipient and processes the messages sent to this recipient.
public class RecipientPageExtension extends BasePageExtension {
@Override
public boolean onBeforeLoad() {
// define a recipient
getMessageController().registerRecipient( "a-recipient" );
// send a message to the recipient
getMessageController().sendMessage( "a-recipient", 1, "Bonjour le Monde !!!" );
return super.onBeforeLoad();
}
@Override
public boolean onMessage( IMessage message ) {
// receive the message
if ( message.getEventType() == 1 ) {
// position the bookmark value ${message}with the received message content.
this.getExecutionContext().getMarkerModel().setValue( "message", message.getBody() );
}
return super.onMessage( message );
}
}
Javascript extension
The Process development kit offers also the possibility to respond to the events triggered by the system in Javascript.
The Javascript code may be submitted in the animation of the concerned page (Development tab).
Example of code in a Java script extension
The following example shows how respond to the Javascript events (equal to the ones present in the page extensions)
This example shows how to recover the execution context of the current page (IContent) to ass a component “Title” of level 1.
The site module gives access to two works:
- The components work: creation of components instances;
- The blocks work: creation of blocks instances of different kinds.
/**
* This method is called just before building the tree of content components (blocks and components).
*
* @param siteModule The site module object
*/
function onBeforeLoad(siteModule) {
var headingComponent = siteModule.getComponentsFactory().newHeadingComponent();
headingComponent.setContent( "Hello World!!!" );
headingComponent.setLevel( "1" );
siteModule.getExecutionContext().getContent().getBlock().addComponent( headingComponent );
return true;
}
/**
* This method is called each time the block is about to be rendered.
*
* @param siteModule The site module object
* @param rebuiltBlock The rebuilt block
*/
function onAfterLoad(siteModule, rebuiltBlock) {
return true;
}
/**
* This method is called each time an unknown expression has been encountered.
*
* @param siteModule The site module object
* @param expression The expression to evaluate
*/
function onEvaluateBookmarks(siteModule, expression) {
return expression;
}