10.5.1. Site

Warning

You are looking at documentation for an older release. Not what you want? See the current release documentation.

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.

Retrieving Sites

A specific site can be retrieved by 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 of Retrieving Sites is Shown below:



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.

The example below finds standard sites that a user has access permissions to, limited to the 10 first 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());

Note

The default number of results to return is 15. Which means that if no pagination is set while building the query, the maximum number of results will be 15. So be sure to set the correct pagination while querying.

Creating a Site

To create a site, first create a new site through the Portal, then set the configuration for the site (such as localized display names and skin), and finally save it using the Portal.

The example below creates a new standard site with the name mysite and a non-localized display name:



Site site = portal.createSite(new SiteId("foo"));
site.setDisplayName("My Site");
portal.saveSite(site);

Note

The site is not visible (or persisted) until saveSitesaveSite is invoked.

Setting Attributes for a Site

It is possible to change attributes for the site, supported attributes are:

The attributes are set by using the associated Key, the example below changes the sessionAlive attribute:



site.getAttributes().put(Site.AttributeKeys.SESSION_BEHAVIOR, "always");

Setting Permission for a Site

Associated with a site is an access permission and an edit permission, which controls what users and groups are allowed to access and edit the site respectively.

The example below makes a site accessible by everyone, but only editable by users in the /platform/administrators group:



site.setAccessPermission(Permission.everyone());
site.setEditPermission(Permission.any("platform", "administrators"));
 
portal.saveSite(site);

Note

The changed permissions do not take affect until saveSite is invoked.

Deleting a site

A site is deleted by invoking removeSite on the Portal.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus