URL Paths

Brightspot provides the Directory class for managing URL paths to Content-based objects stored in the database. Directory and its inner classes provide several APIs to support URL pathing.

Use Directory.Static.hasPathPredicate to verify that an object has a URL path, for example:

Query query = Query.from(Article.class).where("_id = '00000161-d80b-ddd6-a37d-fc3bb47a0000");
Article article = (Article) query.where(Directory.Static.hasPathPredicate()).first();
if (article == null) // set a URL path


Use Directory.ObjectModification#addPath to set a URL path on an object, for example:

 Article article = new Article();
 article.setHeadline("Hurricane-force Winds on Mt. Washington");
 String path = StringUtils.toNormalized(article.getHeadline());
 article.as(Directory.ObjectModification.class).addPath(path, Directory.PathType.PERMALINK);

In the above snippet, the addPath method takes parameters for the URL path and the path type. The path is formed from the headline of the article, and the path type is specified with the Directory.PathType enumeration. PERMALINK is a link that never expires. See the table Types of URLs for a description of all URL options.

An object can have different paths for different sites. The addPath method creates a path for the site that owns the object. If you have multiple sites, you can use the addSitePath method to create a path that is associated with a specified site.

The following code extends the above example, adding the path before the object is saved. The addSitePath method creates a path to the object for a second site, News.

public void beforeSave() {
    List<Site> sites = Query.from(Site.class).selectAll();
    for (Site site : sites) {
        if (site.getName().equals("News")) {
            String path = StringUtils.toNormalized(this.getHeadline());
                     .addSitePath(site, "news//" + path, Directory.PathType.PERMALINK);


In order for an object’s site-specified path to work, that site must be given access to the object; otherwise, the object is not visible to the site. For more information about site ownership and access, see Permissions and multiple sites.

The URLs widget in an object’s content edit page shows assigned URL paths. For the article example, there is a path for the owner site, Global, and for a second site, News.