Content Loading and Nodetype Support

The sling-content-jcr bundle provides low-level repository operations which are at the heart of the functionality of Sling:

Node Type Definitions

The class provides methods to register custom node types with a repository given a repository session and a node type definition file in CND format. This class is also used by this bundle to register node types on behalf of other bundles. See below.

Content Mapping

The bundle provides the service which creates objects, which in turn implement mapping of Java objects to repository items and vice versa. See below.

Besides the NodeTypeLoader and the ContentManagerFactory service, the sling-content-jcr bundle provides automatisms for bundles to register declared node types, content loading and object mappings.

Declared Node Type Registration

Bundles may list node type definition files in CND format in the Sling-Nodetypes bundle header. This header is a comma-separated list of resources in the respective bundle. Each resource is taken and fed to the NodeTypeLoader to define the node types.

After a bundle has entered the resolved state, the node types listed in the Sling-Nodetypes bundle header are registered with the repository.

Node types installed by this mechanism will never be removed again by the sling-content-jcr bundle. Likewise, registered node types cannot currently be modified using this feature. The NodeTypeLoader will try to load nodes defined and fail with a log message if a node type has already been defined. To update existing node type definitions, native repository functionality has to be used.

Nodetype management is problematic issue currently, as the only API available is contained in the Jackrabbit Core library, which is generally not available to client applications - unless running in the same VM and class loader hierarchy as the Repository. Version 2 of the JCR Specification currently being developped as JSR-283 should fix this issue by providing an official node type management API. Until then, this approach is about the only solution we have.

Initial Content Loading

Bundles provide initial content, which is loaded into the repository when the bundle has entered the resolved state. Such content is expected to be contained in the bundles accessible through the Bundle entry API methods. Content to be loaded is declared in the Sling-Initial-Content bundle manifest header. This header takes a comma-separated list of bundle entry paths. Each entry and all its child entries are accessed and entered into starting with the child entries of the listed entries.

Adding this content preserves the paths of the entries as show in this table, which assumes a Sling-Initial-Content header entry of SLING-INF/content:


Repository Path





Bundle entries are installed as follows:

Entry Type

Installation method


Created as a node of type nt:folder unless a content definition file of the same name exists in the same directory as the directory to be installed. Example: A directory SLING-INF/content/dir is installed as node /dir of type nt:folder unless a SLING-INF/content/dir.xml or SLING-INF/content/dir.json file exists which defines the content for the /dir node.


Unless the file is a content definition file (see below) an nt:file node is created for the file and an nt:resource node is created as its jcr:content child node to take the contents of the bundle file. The properties nt:resource node are set from file information as available. If the file is a content definition file, the content is created as defined in the file. See below for the content definition file specification.

Content Definition File Specification

Structured content may be specified in content specification file in JSON or XML format which define subtrees of content. A content definition file contains the definition of a single node with optional properties and child nodes. Each child node may again have its properties and child nodes. The definition of a node is as follows:


{{{Node Object: {


Properties Object: {


Value Object: {




... *TODO* ...

Remarks on JSON:

TODO: Specify JSON Format

TODO: Specify XML format

ApacheSling/SlingContent (last edited 2009-09-20 23:45:32 by localhost)