Because I had to work very often with a list of pages I introduced an own class PageArrayList (not Java 5 enabled yet) as a subclass of ArrayList. Every jRQL method which needs to return a list of pages returns an instance of it, so you can immediately get benefit from it’s functionality.
Let’s assume you want to access all pages linked to the list content_pages_list and all block pages linked to container blocks_bottom of the following page.
To get all pages linked to content_pages_list you can use the following lines of code (shortened; without client and project creation).
Page currentPg = project.getPageById("228766");
PageArrayList listChildren1 = currentPg.getListChildPages("content_pages_list");
PageArrayList listChildren2 = currentPg.getListChildPages("content_pages_list", "content_page");
The first method getListChildPages() is straight forward. The second version automatically filter the children by content class. That means, all pages contained in listChildren2 are based only on content class content_page, all other children are not within this list.
Similar to these methods for children of list elements there exists 2 methods for container elements.
PageArrayList containerChildren1 = currentPg.getContainerChildPages("blocks_bottom");
PageArrayList containerChildren2 = currentPg.getContainerChildPages("containerTemplateElementName", "link_table_block");
After explaining how to get a PageArrayList let’s focus on the functionality offered by PageArrayList. I often needed to find a specific page by different criteria, see below how.
listChildren1.findByStandardFieldTextValue(“templateElementName”, “search value”);
listChildren1.findByStandardFieldDateValue(“templateElementName”, new ReddotDate());
All these find methods return only the first page matching the criteria or null, if no page is found.
There are some methods available getting a list of specific values from all pages in list.
List<String> collectHeadlines = listChildren1.collectHeadlines();
List<String> collectHeadlinesAndIds = listChildren1.collectHeadlinesAndIds();
List<String> collectTemplateNames = listChildren1.collectTemplateNames();
Set collectLastChangedByUsers = listChildren1.collectLastChangedByUsers();
All collect methods return a list of the same size as the listChildren1 list, except the last method which returns a set with all distinct user which had last modified the children.
The following select methods filter the children by specific criteria.They all return a PageArrayList instance with usually less size.
// by page attribute
listChildren1.selectAllCreatedBy(project.getUserGroupByName("user group name"));
listChildren1.selectAllPagesBasedOn(“content class name”);
// by workflow state
listChildren1.selectAllPagesInStates(draft, draftNew, draftChanged, waitingForRelease, waitingForCorrection, released);
These should give you an overview of what is available. For detailed information about a specific method, please refer to the javadoc of class PageArrayList.