At any moment,you may recover the page content. To date,a page may contain two versions maximum:
Eventually other versions will complete this list (ex.archived version).
The following example shows how to recover a specific version of a page.
public void page_getPageContent( ISiteModule siteModule, IContext context, ISite site ) throws SiteModuleException { IPageContainer pageContainer = siteModule.getPageContainer( context, site, "my-lovely-page" ); // 1st case: recover the draft version of a page IContent draftContent = pageContainer.getContent( IContent.IStatus.DRAFT ); // 1st case: recover the approved version of a page IContent approuvedContent = pageContainer.getContent( IContent.IStatus.APPROVED ); }
The following example shows how to recover the root block of a page. By using this block,or any other tree element,you may achieve treatments such as:
public void page_getPageContentBlock( ISiteModule siteModule, IContext context, ISite site ) throws SiteModuleException { IContent content = null; // retrieving the main block of a version IBlock block = content.getBlock(); System.out.println( content.getOwner().getFullName() ); }
From an extension page, you may add components dynamically. This example shows how to use "the components work" to add a title level 1 to the page root block.
public void page_completeBlockWithComponents( ISiteModule siteModule, IContext context, ISite site ) throws SiteModuleException { // recover the page version IContent content = null; // use the components work to get a title component HeadingComponent headingComponent = siteModule.getComponentsFactory().newHeadingComponent(); headingComponent.setContent( "Hello everyone!!!" ); headingComponent.setLevel( "1" ); // add the component to the main block of the page content.getBlock().addComponent( headingComponent ); }
From an extension page, you may add blocks and sub-blocks dynamically. This example shows how to use "the components work" to add a site form to the page root block.
public void page_completeBlockWithBlocks( ISiteModule siteModule, IContext context, ISite site ) throws SiteModuleException { // recover the page version IContent content = null; // use the blocks work to get a form-type block FormBlock formBlock = siteModule.getBlocksFactory().newFormBlock(); formBlock.setName( "frmContacts" ); formBlock.setLabel( "Les contacts" ); // create a fields block FieldsetBlock fieldsetBlock = siteModule.getBlocksFactory().newFieldsetBlock(); // create two text-type fields TextInputComponent firstName = siteModule.getComponentsFactory().newTextInputComponent(); firstName.setLabel( "First name" ); firstName.setName( "fldFirstName" ); TextInputComponent lastName = siteModule.getComponentsFactory().newTextInputComponent(); lastName.setLabel( "Last name" ); lastName.setName( "fldLastName" ); // add the fields to the block fieldsetBlock.addComponent( firstName ); fieldsetBlock.addComponent( lastName ); // create two form validation buttons ButtonInputComponent createButton = siteModule.getComponentsFactory().newButtonInputComponent(); createButton.setLabel( "Create" ); createButton.setValue( "type", ButtonInputComponent.Action.SAVEANDCLOSE ); ButtonInputComponent resetButton = siteModule.getComponentsFactory().newButtonInputComponent(); resetButton.setLabel( "Reset" ); resetButton.setValue( "type", ButtonInputComponent.Action.RESET ); // add the fields block to the form formBlock.addBlock( fieldsetBlock ); // add the buttons to the form block formBlock.addComponent( createButton ); formBlock.addComponent( resetButton ); // add the form block to the main block of the page content.getBlock().addBlock( formBlock ); // save the modifications (transactional context needed) content.save( context ); }
Each page is linked to a validation cycle. After modifying the "draft" version of a page, it is required to approve the page so that it can be consulted by the site users. If nevertheless, the user approving the page does not have enough rights,he must do an approval request. The manager may then approve or refuse the request.
The following example shows the page validation cycle.
public void page_approuvePage( ISiteModule siteModule, IContext context, ISite site ) throws SiteModuleException { // recover a page to approve IPageContainer pageContainer = siteModule.getPageContainer( context, site, "my-lovely-page" ); // Requesting Approval of a Page siteModule.requestApproval( context, pageContainer, "Please..." ); // Approving a Page siteModule.approve( context, pageContainer ); // Request approval siteModule.reject( context, pageContainer, "No way." ); }