Navigate through the project’s page tree

Assume you want have a page within a project which has structural elements, like a List or Container. jRQL makes it now easy to access children of the list fields_list or the container blocks_bottom.

Sample page with list and container

Let’s start getting some page information (page last updated by whom and when) for all children of list fields_list.

As explained in the getting started post we need these lines of code first. Don’t forget to replace logonGuid, sessionKey and projectGuid with your current values (you can get these values from the IIS session). The last line access page F5030 which has page ID 34009.

String logonGuid="89CAE058B3DF476F96484982772BE963";
String sessionKey="CBE43738755E4D018198CA7D18A43BDF";
String projectGuid="06BE79A1D9F549388F06F6B649E27152";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

Page currentPg = project.getPageById(“34009”);

Remember, to access the list fields_list on page F5030 you have to know the template element name. In our case the structural element in the content class is named the same.  The reason for using only content class element names is, that you can change the name of e.g. a list or container element on page level.

Because we are interested only in the children of list fields_list we asked the F5030 page directly for it:

PageArrayList listChildren = currentPg.getListChildPages("fields_list");

Class PageArrayList offers specialized methods for selecting and collecting page details (but not yet Java 5 enabled). Next lines iterate over all pages and log the time and author name of last change on it:


for (Iterator iterator = listChildren.iterator(); iterator.hasNext();) {
Page page = (Page) iterator.next();
 System.out.println(page.getInfoText());
System.out.println(page.getLastChangedByUserName());
System.out.println(page.getLastChangedOnAsddMMyyyyHmma());
}

For this page F5030 I got the following results:

34005 f5030.base.date (field_page)
boettmc
03 Mar 2009 5:27 PM
34004 f5030.currency.code (field_page)
boettmc
03 Mar 2009 5:25 PM
34007 f5030.select.btn (field_page)
boettmc
03 Mar 2009 5:29 PM
34006 f5030.currency.table (field_page)
boettmc
03 Mar 2009 5:34 PM

The method getInfoText() delivers the most important information of a page: page ID, headline and name of content class.  Both  getLastChanged*() methods delivers what you would expect.

In the very same manner you can get the children on the F5030 container blocks_bottom.
Assume you want to check, if the child page of container blocks_bottom is in state released, means not in Task of another author.

if (currentPg.hasContainerChildPages("blocks_bottom")) {
Page child = currentPg.getContainerChildPages("blocks_bottom").first();
System.out.println("page=" + child.getHeadlineAndId());
System.out.println("released=" + child.isInStateSavedAsDraft());
}

This will print like this:

page=F5030 deactivated_fields_table_block (ID 34136)
released=false

First I check, if the container has a page connected at all, because this is optional. The method getHeadlineAndId() write out some page details and the last check tells you if page 34136 is in workflow at any stage.

I am sure you understand now how to navigate top down. If you need a navigation bottom top please have a look into the following methods:

Page parentPg = currentPg.getMainLinkParentPage();
List<MultiLink> multiLinksToThisPage = currentPg.getMultiLinksToThisPage();

The class MultiLink is the common super class of List and Container, but doesn’t cover Anchor content class elements. jRQL has it’s  main focus on lists and containers, but access to Anchors or Dynamic Anchors are available, but limited in some way.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: