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 code 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 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, where the addSitePath method creates a path to the object for a second site, Mountain.

 List<Site> sites = Query.from(Site.class).selectAll();
 for (Site site : sites)
    if (site.getName().equals("Mountain"))
              .addSitePath(site, "mountain//" + 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 on site ownership and access, see Permissions and Multiple Sites.

In Brightspot, 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, Mountain.