In This Topic
Creating a Page
The method createAndInsertPage handles the creation of pages. It returns the page that it creates. It takes up to two parameters:
page
- the page under which the new page should be created. This parameter is required.position
- determines the position the new page will have in the list of subpages of its parent page. If this parameter is omitted, the page will be added to the bottom of the list of subpages of its parent page. The first subpage has position number 0. This parameter is optional.
The following code fragment will create two new pages directly underneath the homepage:
Page homepage = mySession.getXperienCentralApplication().getWebsites()[0].getHomePage(); // Create a new page underneath the homepage of the first website on this installation Page newPage1 = myPageService.createAndInsertPage(homepage); // Create another new page underneath the homepage that will placed above // newPage1 in the ordering of pages of the Homepage
The Current Editing Language
In XperienCentral, multiple languages can be defined in which the website(s) can be made available for visitors. An editor is always working on one specific website language version. This language is called the “current editing language”. These languages are not related to the languages of the XperienCentral user interface.
When creating a page, the page will always be created in one specific language. This language is set on the context of the XperienCentral Session and can be retrieved as follows:
Language lang = mySession.getContext().getCurrentEditingLanguage();
The language can also be set as follows:
mySession.getContext().setCurrentEditingLanguage(newEditingLanguage);
If you don't explicitly set the current editing language, the following rules apply:
- When working from the XperienCentral user interface (GUI), the current editing language will always be set to the language in which the editor is working on at that moment.
- When working from outside the GUI, the current editing language will be set to the default language of the page.
Moving a Page
The pageService contains the method movePage
, used to move a page underneath another page. This method returns a boolean that indicates whether the movement process has been successful. It takes up to three parameters:
page
- the page which has to be moved. This parameter is required.newParentPage
- the new parent of the page that has to be moved. This parameter is required.position
- Determines the position the new page will get in the list of subpages of its new parent page. If this parameter is omitted, the page will be added to the bottom of the list of subpages of its new parent page. The first subpage has position number 0. This parameter is optional.
For example:
Page homepage = mySession.getXperienCentralApplication().getWebsites()[0].getHomePage(); Page newPage1 = myPageService.createAndInsertPage(homepage); Page newPage2 = myPageService.createAndInsertPage(homepage); Page newPage3 = myPageService.createAndInsertPage(homepage); Page newPage4 = myPageService.createAndInsertPage(newPage1); if (!myPageService.movePage(newPage2, newPage1)) { LOG.severe("Failed to move page: " + newPage2 + " underneath page: " + newPage1); } if (!myPageService.movePage(newPage3, newPage1, 0)) { LOG.severe("Failed to move page: " + newPage3 + " underneath page: " + newPage1); }
After executing this code, the resulting page structure will be:
homepage
newPage1
newPage3
newPage4
newPage2
Deleting a Page
The pageService
contains a method called deletePage
for deleting a page. This method returns a boolean which indicates whether the deletion was successful. This method takes two parameters:
page
- the page to be deleted. This parameter is required.also delete subpages
: boolean that determines if all the pages underneath the pages should also be deleted. This parameter is required.
If a page is deleted that contains subpages, the subpages will be moved to the "Orphan Pages" section of the navigation tree in the Site Structure widget.
For example:
Page homepage = mySession.getXperienCentralApplication().getWebsites()[0].getHomePage(); Page newPage1 = myPageService.createAndInsertPage(homepage); Page newPage2 = myPageService.createAndInsertPage(newPage1); Page newPage3 = myPageService.createAndInsertPage(homepage); Page newPage4 = myPageService.createAndInsertPage(newPage3); if (!myPageService.deletePage(newPage1, false)) { LOG.severe("Failed to delete page: " + newPage1); } if (!myPageService.deletePage(newPage3, true)) { LOG.severe("Failed to delete page: " + newPage3 + " and all its subpages."); }
After executing this code, the resulting page structure will be:
homepage
orphan pages
newPage2