Chapter 4. Site
A Site is comprised of a set of pages, navigation definitions, and can be assigned a unique skin. There are three different types of sites: standard sites, group spaces and user dashboards.
4.1. Retrieving Sites
A specific site can be retrieved using its
SiteId . The SiteId is constructed by passing either the name for a standard site, the group for a group space or the user for a user dashboard. Alternatively, it can be constructed by passing the SiteType and name.
Example 4.1. Retrieving Sites
This example shows how to retrieve sites.
Site standardSite = portal.getSite(new SiteId("classic")); Site groupSpace = portal.getSite(new SiteId(new Group("platform", "administrators"))); Site userDashboard = portal.getSite(new SiteId(new User("john")));
It is also possible to query for sites using the
SiteQuery . The SiteQuery supports filtering, sorting and pagination when querying for sites.
Note
The default number of returned results is 15. If no pagination is set while building the query, the maximum number of results will be 15. Ensure the correct pagination is set while querying.
Example 4.2. Site Query
This example finds standard sites that a user has access permissions to, limited to the first ten results.
SiteQuery.Builder qb = new SiteQuery.Builder(); qb.withSiteTypes(SiteType.SITE).withPagination(0, 10).withFilter(new Filter<Site>() { public boolean accept(Site site) { return portal.hasPermission(user, site.getAccessPermission()); } }); List<Site> sites = portal.findSites(qb.build());
4.2. Creating a Site
The work flow to create a site is described below:
- Create a new site through the Portal.
- Set the configuration for the site (such as localized display names and skin).
- Save the configuration using
Portal.
Example 4.3. Create a New Standard Site
This example creates a new standard site with the name mysite and a non-localized display name.
The site is not visible (or persisted) until
saveSite is invoked.
Site site = portal.createSite(new SiteId("foo")); site.setDisplayName("My Site"); portal.saveSite(site);
4.2.1. Setting Attributes for a Site
It is possible to change attributes for the site. The supported attributes are:
- sessionAlive
- Specifies whether a session is kept alive or not. Valid values are
"onDemand","always", and"never"with the default being"onDemand" - showPortletInfo
- Specifies whether the info bar is shown by default when adding applications to pages. The default is 'false'
Example 4.4. Set Attributes Using the Key
Attributes are set by using the associated
Key. This example changes the sessionAlive attribute.
site.getAttributes().put(Site.AttributeKeys.SESSION_BEHAVIOR, "always");
4.2.2. Setting permissions for a site
Associated with a site is an access permission and an edit permission, which controls which users and groups are allowed to access and edit the site respectively.
Example 4.5. Setting Access and Edit Permissions
This example demonstrates how to make a site accessible by everyone, but only editable by users in the
/platform/administrators group.
The changed permissions do not take affect until
saveSite is invoked.
site.setAccessPermission(Permission.everyone()); site.setEditPermission(Permission.any("platform", "administrators")); portal.saveSite(site);