Composum Browser is an Open Source JCR Node browser for Apache Sling which bills itself as “the Swiss knife for the repository”. Composum Browser is included in Apache Sling since Sling 9 and is available in all versions of Apache Sling CMS.
While Composum Browser certainly supports navigating the JCR repository structure in Apache Sling, it can do much more. Here are four useful features in Composum Browser:
Edit Files
Editing files in the repository using Composum is pretty straight-forward. First select the node for the file, select the Text / Code View and then select the Edit Text button which will open the editor.
Run Groovy Scripts
Groovy scripts are tremendously helpful to run ad-hoc scripts for extracting report data, performing bulk updates on the fly or debugging issues.
To execute a Groovy script, create a file with the .groovy extension and then execute the script in the Composum editor. One important thing to note is that you want to make sure your return is not session-bound, because it closes the resource resolver before printing the result.
Default Variables
The Composum Groovy script executor binds the following variables for your use:
- workspace: javax.jcr.Workspace
- resourceResolver: org.apache.sling.resourceresolver.ResourceResolver
- log: org.slf4j.Logger – bound to com.composum.sling.core.script.GroovyRunner
- session: org.apache.jackrabbit.api.JackrabbitSession
- queryManager: javax.jcr.query.QueryManager
- jctx: org.apache.sling.event.jobs.consumer.JobExecutionContext
- job: org.apache.sling.event.jobs.Job
- resourceResolverFactory: org.apache.sling.resourceresolver.ResourceResolverFactory
- out: java.io.PrintWriter – writer to the job output, you can also use println inside Groovy
OSGi Services
Since Groovy is executing in the context of an OSGi container, you may want to retrieve an OSGi service, unfortunately, it’s not quite as easy as the AEM Groovy Console, but it can be done:
import org.osgi.framework.*; import org.apache.sling.api.resource.*; BundleContext bundleContext = FrameworkUtil.getBundle(ResourceResolverFactory.class).getBundleContext(); def serviceReference = bundleContext.getServiceReference(ResourceResolverFactory.class); def service = bundleContext.getService(serviceReference); println service; bundleContext.ungetService(serviceReference);
Installing Groovy
Naturally, to use the Groovy script execution feature in Composum Browser, you need Groovy installed. At the time this post was written, Groovy is not installed in the Apache Sling Starter 11 or Sling CMS 0.16.2. The easiest way to install Groovy is to install Groovy All 2.4.19. In future versions of Sling CMS and Sling Starter the expectation is Groovy 3 will be pre-installed.
View System Nodes
In more recent versions of Composum (at least 1.12+) you can see the system nodes in the JCR, including:
- JCR Namespaces
- JCR Node Types
- Supported Privileges
- Privilege Storage
- Version Storage
To see the system properties change the Filter for tree option to unfiltered and then expand /jcr:system.
Download Query File
Composum supports executing queries in the search bar. In addition, you can download the results of the query by selecting the Export Query Result dropdown on the right-hand side of the search bar. The export option supports JSON (full tree), CSV (summary), and TSV (summary).
Composum Node Browser is a powerful tool for managing Apache Sling based repositories. Check it out via the Apache Sling Starter or Sling CMS or download Composum directly from GitHub.