Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BEE94DA5E for ; Wed, 12 Dec 2012 09:18:07 +0000 (UTC) Received: (qmail 42439 invoked by uid 500); 12 Dec 2012 09:18:06 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 42397 invoked by uid 500); 12 Dec 2012 09:18:06 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 42382 invoked by uid 99); 12 Dec 2012 09:18:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2012 09:18:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2012 09:17:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 47CE42388BCD for ; Wed, 12 Dec 2012 09:17:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r841833 [5/28] - in /websites/staging/sling/trunk/content: ./ site/ site/46-line-blog.data/ site/authentication.data/ site/documentation.data/ site/first-steps.data/ site/getting-and-building-sling.data/ site/how-to-manage-events-in-sling.d... Date: Wed, 12 Dec 2012 09:17:17 -0000 To: commits@sling.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121212091731.47CE42388BCD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: websites/staging/sling/trunk/content/site/configuration.html ============================================================================== --- websites/staging/sling/trunk/content/site/configuration.html (added) +++ websites/staging/sling/trunk/content/site/configuration.html Wed Dec 12 09:16:44 2012 @@ -0,0 +1,353 @@ + + + + + Apache Sling - Configuration + + + + + +
+ +
+ + Apache + +
+
+ +
+ +

Configuration Support

+ + +

Introduction

+ +

Configuration in Sling is aligned with respective support by the OSGi specification:

+ +
    +
  • Framework and Java system properties are available through the BundleContext.getProperty(String) method. These properties are provided in Sling through the Sling launcher.
  • +
  • Bundle Header values are available through the Bundle.getHeaders() and Bundle.getHeaders(String) methods. These header values are set by the bundle developer in the META-INF/MANIFEST.MF file. In fact, all main manifest attributes are available through these methods.
  • +
  • Components managed by the Service Component Runtime and declared in component descriptor files listed in the Service-Component manifest header access configuration properties through the ComponentContext.getProperties() method. These properties have three sources: +
      +
    1. Configuration specified specifically for factory components
    2. +
    3. Properties retrieved from the Configuration Admin Service
    4. +
    5. Properties set in the component descriptor
    6. +
    +
  • +
  • Configuration properties provided to ManagedService and ManagedServiceFactory instances by the Configuration Admin Service.
  • +
+ + +

For the discussion to follow we differentiate between intial configuration provided by Framework and system properties and managed configuration provided by the Configuration Admin Service.

+ +

Components managed by the Service Component Runtime are generally configured (as listed above) through the descriptor properties and configuration set by Configuration Admin Service configuration. The descriptor property values may be seen as configuration default values set by the component developer, which may be overwritten by user configuration through the Configuration Admin Service. Components may but are not required to make use of Framework properties by accessing the BundleContext through the ComponentContext given to the activate(ComponentContext) method of the component.

+ + + +

Initial Configuration

+ +

The lifecycle of the OSGi framework implemented by an instance of the org.apache.felix.framework.Felix class is managed by the Sling launcher class org.apache.sling.launcher.Sling. This class is used by the standalone main class (org.apache.sling.launcher.main.Main) and the Sling Servlet (org.apache.sling.launcher.servlet.SlingServlet) to control the lifecycle.

+ +

The Sling launcher is responsible to provide the Framework properties to the OSGi framework. The properties are prepared as a java.util.Map<String, String> instance as follows (later steps may overwrite properties defined in earlier steps) :

+ +
    +
  1. Load core properties from the embedded sling.properties file.
  2. +
  3. Resolve any property file inclusions. This is mainly used to resolve the correct JRE package definitions for the JRE version used.
  4. +
  5. Overwrite with any properties provided by the main class or the Sling Servlet.
  6. +
  7. Make sure the sling.home property is set defining a sensible default value if missing
  8. +
  9. Load the contents of the ${sling.home}/sling.properties file
  10. +
  11. Overwrite properties with Java system properties. This step only considers system properties of the same names as properties already existing. That is, the system properties are not just copied into the properties here. Additionally this step my be omitted if the sling.ignoreSystemProperties property is set to true.
  12. +
  13. Resolve any property file inclusions. This may be used to provide more configurability depending on the integration.
  14. +
  15. Handle OSGi boot delegation support (see below).
  16. +
  17. Resolve property references of the form ${propName}
  18. +
  19. For each property value starting with ontext:/ do the following, assuming the value to be an URL with scheme context:: +
      +
    • Copy the application resource to ${sling.home} preserving the URL path unless such a file already exists.
    • +
    • Replace the property value with the path to the newly created file. The path has the form ${sling.home}/relpath.
    • +
    +
  20. +
  21. Store the properties as ${sling.home}/sling.properties to be re-used on next startup
  22. +
  23. Setup Bundle auto installation for the Felix Framework
  24. +
+ + +

Using file system copies of the initial configuration and referred files, it is easy to modify this configuration without the need to unpack and repackage the web application archive.

+ +

The only property really required is actually the sling.home property, which defines the file system location where runtime files will be placed. The default if this property is missing will be sling in the current working directory as defined the user.dir system property.

+ + + +

Standalone Application

+ +

When launching Sling as a standalone application the sling-app.jar file is used. This is an executable JAR File. The sling.properties file as well as the sling_install.properties and JRE specific properties files are located at the root of the JAR file hierarchy.

+ +

The standalone application currently sets properties for the third step of the configuration setup to ensure the HTTP Servlet integration is using the Apache Felix http.jetty bundle. Additionally system properties may be set using the -D command line switch of the Java binary.

+ +

In addition the following command line arguments are accepted:

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Argument Sling property Description
-l loglevel org.apache.sling.osgi.log.level The initial loglevel (0..4, FATAL, ERROR, WARN, INFO, DEBUG)
-f logfile org.apache.sling.osgi.log.file The log file, "-" for stdout
-c slinghome sling.home the sling context directory
-a address the interfact to bind to (use 0.0.0.0 for any) (not supported yet)
-p port org.osgi.service.http.port the port to listen to (default 8080)
-h Prints a simple usage message and exits.
+
+ + +

The standalone application exits with status code 0 (zero) if Sling terminates normally, that is if the OSGi framework is stopped or if just the usage note has been displayed. If any error occurrs during command line parsing, the cause is printed to the error output and the application exists with status code 1 (one). If the OSGi framework fails to start, the cause is printed to the error output and the application exists with status code 2.

+ + +

Web Application

+ +

When launching Sling as a web application using the sling-servlet.war or any derived Web Application archive file, the sling.properties file is located in the WEB-INF folder along with the sling_install.properties and JRE specific properties files.

+ +

The Sling Servlet uses the Servlet Context and Servlet init-param configurations to prepare the properties for the third step of the configuration setup.

+ +

If the OSGi framework fails to startup for any reason a javax.servlet.UnavailableException.

+ + + +

Property File Inclusions

+ +

Twice in the configuration setup (second and seventh step) any property file inclusions will be handled. Property files may be included by defining one or more properties containing a comma-separated list of properties files to include. Property file inclusion looks at the sling.include property and any other property whose prefix is sling.include.. When such properties exist, the files listed in those properties are included.

+ +

The order of handling the property file inclusion properties is defined as natural sort order of the actual property names. So the properties of the files listed in the sling.include.first property will be loaded before the files listed in the sling.include.second but after the files listed in the sling.include.a property.

+ +

Any file which does not exist is silently ignored.

+ +

The names of the files are resolved as follows:

+ +
    +
  1. If a resource exists at the same location as the initial sling.properties file packaged with the application, that resource is used
  2. +
  3. If the name is a relative file name, it is looked for in the sling.home directory
  4. +
  5. If the name is an absolute file name, it is used as is
  6. +
+ + +

Example

+ +

The packaged sling.properties file contains the following properties file inclusion setting:

+ +
+
sling.include.jre = jre-${java.specification.version}.properties
+
+
+ +

This is used to include the JRE package list to be made visible inside the OSGi framework.

+ + + +

OSGi Boot Delegation Support

+ +

Some packages may have to be shared between bundles in an OSGi framework and the rest of Java VM in which the framework has been launched. This is especially true for OSGi framework instances launched in embedding such as Servlet Containers. In the case of a Sling Application accessing a JCR Repository launched in a different Web Application, this mainly concerns an API packages as well as the JNDI Initial Factory package(s).

+ +

To cope with this sharing issue, the OSGi core specification defines two properties, which may list packages to be used from the environment:

+ + +
    +
  • org.osgi.framework.system.packages - This property lists package names which are added to the list of exported packages of the system bundle of the OSGi framework. These packages are used in the resolution process just as any package listed in an Export-Package bundle manifest header.
  • +
  • org.osgi.framework.bootdelegation - This property lists packages, which are always used from the environment. As such, these packages will never be looked up in package wirings as are packages imported by listing them in the Import-Package bundle manifest header.
  • +
+ + + +

Sometimes, especially in the Servlet Container case, it is important to use the shared classes from the container and not resolve using standard OSGi resolution. In such cases, the packages of these shared classes must be listed in the org.osgi.framework.bootdelegation property. Sling provides a mechanism to extend the default setting of the org.osgi.framework.bootdelegation property by adding properties prefixed with sling.bootdelegation.. The value of each of these prefixed properties is conditionally appended to the org.osgi.framework.bootdelegation property. Conditionally means, that the property name may contain the fully qualified name of a class, which is checked to see whether to add the property value or not.

+ +

Examples

+ +
+ + + + + + + + + +
sling.bootdelegation.simple = com.some.package This setting unconditionally adds the com.some.package package to the org.osgi.framework.bootdelegation property
sling.bootdelegation.class.com.some.other.Main = com.some.other This setting checks whether the com.some.other.Main class is known. If so, the com.some.other package is added to the org.osgi.framework.bootdelegation property. Otherwise the com.some.other package is not added - and therefore must be exported by a bundle if required for use inside the framework.
+
+ + + +

Note Even though packages listed in the org.osgi.framework.bootdelegation property will always be loaded from the environment, any bundles using these packages must still import them (through Import-Package or DynamicImport-Package) and the bundles must resolve for being usable.

+ + + +

OSGi System Packages Support

+ +

As listed in the above section on OSGi Boot Delegation Support, the org.osgi.framework.system.packages property may be used to extend the export list of the system bundle. Similar to the support for extending the boot delegation packages list, Sling supports extending the system packages list. The mechanism to extend the default setting of the org.osgi.framework.system.packages property by adding properties prefixed with sling.system.packages.. The value of each of these prefixed properties is conditionally appended to the org.osgi.framework.system.packages property. Conditionally means, that the property name may contain the fully qualified name of a class, which is checked to see whether to add the property value or not.

+ +

Examples

+ +
+ + + + + + + + + +
sling.system.packages.simple = com.some.package This setting unconditionally adds the com.some.package package to the org.osgi.framework.system.packages property
sling.system.packages.class.com.some.other.Main = com.some.other This setting checks whether the com.some.other.Main class is known. If so, the com.some.other package is added to the org.osgi.framework.system.packages property. Otherwise the com.some.other package is not added - and therefore must be exported by a bundle if required for use inside the framework.
+
+ + + +

Note Packages listed in the org.osgi.framework.system.packages required by any bundles must be imported by those bundles by listing them in the Import-Package or DynamicImport-Package manifest header.

+ + + +

Recommendations for property names

+ +

The following system property names are reserved:

+ +
    +
  • Names starting with org.osgi. are reserved for OSGi defined Framework properties
  • +
  • Names starting with org.apache.felix. are reserved for the Felix Framework
  • +
  • Names starting with sling. and org.apache.sling. are reserved for Sling
  • +
+ + +

To prevent property name collisions, I suggest the following convention:

+ +
    +
  • Use fully qualified property names for initial configuration through Framework properties
  • +
  • Use unqualified property names for configuration through the Configuration Admin Service
  • +
+ + + +

Well Known Properties

+ +

The following table is a collection of well known property names from different parts of Project Sling.

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Property Description
sling.home Defines the file system location where Project Sling will write copies of the initial configuration. This property should also be used to define other local file system locations such as the directory to use for the Apache Felix Bundle Cache (${sling.home}/felix by default). If this property is not set it defaults to ${user.dir}/sling.
sling.home.url Contains the Sling directory set in the sling.home property as a valid URL. This property may be used in situations where the Sling directory is required as an URL. This property is automatically set by the Sling application and may not be modified by configuration files.
sling.ignoreSystemProperties Whether to overwrite any configuration properties with Java system properties or not. By default this property is set to true by the Sling Servlet but not set by the Sling main class. The reason to set this by default in the Sling Servlet is to not induce values from the environment, which may not be appropriate in the Web Application case.
obr.repository.url A comma-separated list of OSGi Bundle Repository URLs. See Important Properties on the page Initial Provisioning and Startup.
sling.install.bundles A comma-separated list of start level numbers. See Important Properties on the page Initial Provisioning and Startup.
sling.install.<n> A comma-separated list of bundle specifications. See Important Properties on the page Initial Provisioning and Startup.
org.apache.sling.osgi.log.* Properties providing initial configuration to the Sling Log Service. See 'Important Properties' on the page Initial Provisioning and Startup.
+
+ + + + +

Configuration Admin Service

+ +

Configuration of the system entities, such as services and components, by the system administrator is supported the Configuration Admin Service. The Configuration Admin Service acts as the center for the management of the configuration data, to which GUI-based tools will connect to retrieve and update configuration data. The Configuration Admin Service is responsible for persisting the configuration data and for providing configuration consumers with the configuration data. Specifically services registered with the ManagedService or ManagedServiceFactory interfaces are updated with the configuration upon updated. The Service Component Runtime on the other hand recognizes updated configuration and provides it to the managed components as defined in the OSGi Declarative Services Specification.

+ +

By default the Configuration Admin Service is installed when Sling is started for the first time. This service is used by the Service Component Runtime launching the OSGi components declared in the bundles with configuration values. The Sling Management Console provides a simple GUI to manage these configuration elements on the 'Configuration' page.

+ +

For more information on the Configuration Admin Service refer to the OSGi Configuration Admin Service Specification in the OSGi Service Platform Service Compendium book.

+
+Last modified by mykee on 2009-06-01 07:40:41.0 +
+
+Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners. +
+
+ + + Added: websites/staging/sling/trunk/content/site/content-loading-and-nodetype-support-jcrcontentloader.html ============================================================================== --- websites/staging/sling/trunk/content/site/content-loading-and-nodetype-support-jcrcontentloader.html (added) +++ websites/staging/sling/trunk/content/site/content-loading-and-nodetype-support-jcrcontentloader.html Wed Dec 12 09:16:44 2012 @@ -0,0 +1,343 @@ + + + + + Apache Sling - Content Loading and Nodetype Support (jcr.contentloader) + + + + + +
+ +
+ + Apache Incubator + +
+
+ +
+ +

Content Loading and Nodetype Support

+ +

Apache Sling provides support for initial content loading into a repository and for registering node types. The sling-jcr-contentloader bundle provides loading of content from a bundle into the repository and the sling-jcr-base bundle provides node type registration.

+ +

Initial Content Loading

+ +

Bundles can provide initial content, which is loaded into the repository when the bundle has entered the started 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:

+ + + + + + + + + + + + + +
Entry Repository Path
SLING-INF/content/home /home
SLING-INF/content/content/playground/en/home /content/playground/en/home
+

Bundle entries are installed as follows:

+ + + + + + + + + + + + + +
Entry Type Installation method
Directory 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.
File 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 of the 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.
+

It is possible to modify the intial content loading default behaviour by using certain optional directives. Directives should be specified separated by semicolon. They are defined as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Directive Definition Default value Description
overwrite overwrite:=(true|false) false The overwrite directive specifies if content should be overwritten or just initially added.
uninstall uninstall:=(true|false) overwrite The uninstall directive specifies if content should be uninstalled when bundle is unregistered. This value defaults to the value of the overwrite directive.
path path:=/target/location / The path directive specifies the target node where initial content will be loaded. If the path does not exist yet in the repository, it is created by the content loader. The intermediate nodes are of type nt:folder.
checkin checkin:=(true|false) false The checkin directive specifies whether versionable nodes should be checked in.
ignoreImportProviders ignoreImportProviders:=list of extensions empty This directive can be used to not run one of the configured extractors (see below).
+

Examples of these directives uses could be (assumes a Sling-Initial-Content header entry of SLING-INF/content):

+ + + + + + + + + + + + + + + + + +
Entry Behaviour
SLING-INF/content/home;overwrite:=true;uninstall:=true Overwrites already existing content in /home and uninstalls the content when the bundle is unregistered.
SLING-INF/content/home;path:=/sites/sling_website if /sites/sling_website exists it loads the content into it. Otherwise, it loads the content into root node /.
SLING-INF/content/home;checkin:=true After content loading, versionable nodes are checked in.
+ +

Loading initial content from bundles

+ +

Repository items to be loaded into the repository, when the bundle is first installed, may be defined in four ways:

+
    +
  1. Directories
  2. +
  3. Files
  4. +
  5. XML descriptor files
  6. +
  7. JSON descriptor files
  8. +
+ + +

Depending on the bundle entry found in the location indicated by the Sling-Initial-Content bundle manifest header, nodes are created (and/or updated) as follows:

+ +

Directories

+ +

Unless a node with the name of the directory already exists or has been defined in an XML or JSON descriptor file (see below) a directory is created as a node with the primary node type "nt:folder" in the repository.

+ +

Files

+ +

Unless a node with the name of the file already exists or has been defined in an XML or JSON descriptor file (see below) a file is created as two nodes in the repository. The node bearing the name of the file itself is created with the
+primary node type "nt:file". Underneath this file node, a resource node with the primary node type "nt:resource" is created, which is set to the contents of the file.

+ +

The MIME type is derived from the file name extension by first trying to resolve it from the Bundle entry URL. If this does not resolve to a MIME type, the Sling MIME type resolution service is used to try to find a mime type. If all fals, the MIME type is defaulted to "application/octet-stream".  

+ +

XML Descriptor Files

+ +

Nodes, Properties and in fact complete subtrees may be described in XML files using either the JCR SystemView format, or the format described below. In either case, the file must have the .xml extension.

+
+
<node>
+		<!--
+			optional on top level, defaults to XML file name without .xml extension
+	       	required for child nodes
+		-->
+		<name>xyz</name>
+
+		<!--
+	   		optional, defaults to nt:unstructured
+		-->
+		<primaryNodeType>nt:file</primaryNodeType>
+
+		<!--
+		    optional mixin node type
+		    may be repeated for multiple mixin node types
+		-->
+		<mixinNodeType>mix:versionable</mixinNodeType>
+		<mixinNodeType>mix:lockable</mixinNodeType>
+
+		<!--
+			Optional properties for the node. Each <property> element defines
+			a single property of the node. The element may be repeated.
+		-->
+		<property>
+			<!--
+				required property name
+			-->
+			<name>prop</name>
+
+			<!--
+				value of the property.
+				For multi-value properties, the values are defined by multiple
+				<value> elements nested inside a <values> element instead of a
+				single <value> element
+			-->
+			<value>property value as string</value>
+
+			<!--
+				Optional type of the property value, defaults to String.
+				This must be one of the property type strings defined in the
+				JCR PropertyType interface.
+			<type>String</type>
+		</property>
+
+		<!--
+			Additional child nodes. May be further nested.
+		-->
+		<node>
+		....
+		</node>
+	</node>
+
+ +

Using a custom XML format

+

By writing an XSLT stylesheet file, you can use whatever XML format you prefer. The XML file references an XSLT stylesheet by using the xml-stylesheet processing instruction:

+
+
<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet href="my-transform.xsl" type="text/xsl"?> <!-- The path to my-transform.xsl is relative to this file -->
+
+<your_custom_root_node>
+   <your_custom_element>
+   ...
+   </your_custom_element>
+...
+</your_custom_root_node>
+
+ +

The my-transform.xsl file is then responsible for translating your format into one of the supported XML formats:

+ +
+
<xsl:stylesheet version="1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" 
+  xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+  xmlns:rep="internal" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:template match="your_custom_element">
+    <node>
+      ...
+    </node>
+  </xsl:template>
+  ...
+</xsl:stylesheet>
+
+ +

JSON Descriptor Files

+ +

Nodes, Properties and in fact complete subtrees may be described in JSON files using the following skeleton structure (see http://www.json.org or information on the syntax of JSON) :

+
+
{
+		// optional node name on top level, default is file name without .json ext.
+		"name": "nodename",
+
+		// optional primary node type, default "nt:unstructured"
+		"primaryNodeType": "sling:ScriptedComponent",
+
+		// optional mixin node types as array
+		"mixinNodeTypes": [ ],
+
+	    // the "properties" property is an object indexed by property name whose
+	    // value is either the string property value, array for multi-values or
+	    // an object whose value[s] property denotes the property value(s) and
+	    // whose type property denotes the property type
+	    "properties": {
+	    	"sling:contentClass": "com.day.sling.jcr.test.Test",
+	    	"sampleMulti": [ "v1", "v2" ],
+	    	"sampleStruct": {
+	    		"value": 1,
+	    		"type": "Long"
+	    	}
+	    	"sampleStructMulti": {
+	    		"value": [ 1, 2, 3 ],
+	    		"type": "Long"
+	    	}
+	    },
+
+	    // the "nodes" property is an array of objects denoting child nodes. Nodes
+	    // may be further nested.
+		"nodes": [
+			{
+				// the name property is required on (nested) child nodes
+	            "name": "sling:scripts",
+
+				"primaryNodeType": "sling:ScriptList",
+
+				"nodes": [
+					{
+						"primaryNodeType": "sling:Script",
+						"properties": {
+							"sling:name": "/test/content/jsp/start.jsp",
+							"sling:type": "jsp",
+							"sling:glob": "*"
+						}
+					}
+				]
+			}
+		]
+	}
+
+ +

Extractors

+ +

By default, the sling-jcr-contentloader bundle tries to extract certain file types during content loading. These include json, xml, zip, and jar files. Therefore all available extractors are used for content processing. However if some files should be put into the repository unextracted, the ignoreImportProviders directive can be used with a comma separated list of extensions that should not be extracted, like ignoreImportProviders:=jar,zip.

+ +

Declared Node Type Registration

+ +

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

+
    +
  • Node Type Definitions - The class org.apache.sling.content.jcr.base.NodeTypeLoader 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.
  • +
+ + +

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-jcr-base 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 currently a problematic issue, 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.

+ +

Automated tests

+ +

The initial content found in the sling-test folder of the launchpad initial content is verified by the InitialContentTest when running the launchpad/testing integration tests.

+ +

Those tests can be used as verified examples of initial content loading. Contributions are welcome to improve the coverage of those tests.

+
+Last modified by mykee on Wed May 27 13:51:00 PDT 2009 +
+
+ + + Added: websites/staging/sling/trunk/content/site/content-loading-and-nodetype-support.html ============================================================================== --- websites/staging/sling/trunk/content/site/content-loading-and-nodetype-support.html (added) +++ websites/staging/sling/trunk/content/site/content-loading-and-nodetype-support.html Wed Dec 12 09:16:44 2012 @@ -0,0 +1,343 @@ + + + + + Apache Sling - Content Loading and Nodetype Support + + + + + +
+ +
+ + Apache Incubator + +
+
+ +
+ +

Content Loading and Nodetype Support

+ +

Apache Sling provides support for initial content loading into a repository and for registering node types. The sling-jcr-contentloader bundle provides loading of content from a bundle into the repository and the sling-jcr-base bundle provides node type registration.

+ +

Initial Content Loading

+ +

Bundles can provide initial content, which is loaded into the repository when the bundle has entered the started 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:

+ + + + + + + + + + + + + +
Entry Repository Path
SLING-INF/content/home /home
SLING-INF/content/content/playground/en/home /content/playground/en/home
+

Bundle entries are installed as follows:

+ + + + + + + + + + + + + +
Entry Type Installation method
Directory 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.
File 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 of the 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.
+

It is possible to modify the intial content loading default behaviour by using certain optional directives. Directives should be specified separated by semicolon. They are defined as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Directive Definition Default value Description
overwrite overwrite:=(true|false) false The overwrite directive specifies if content should be overwritten or just initially added.
uninstall uninstall:=(true|false) overwrite The uninstall directive specifies if content should be uninstalled when bundle is unregistered. This value defaults to the value of the overwrite directive.
path path:=/target/location / The path directive specifies the target node where initial content will be loaded. If the path does not exist yet in the repository, it is created by the content loader. The intermediate nodes are of type nt:folder.
checkin checkin:=(true|false) false The checkin directive specifies whether versionable nodes should be checked in.
ignoreImportProviders ignoreImportProviders:=list of extensions empty This directive can be used to not run one of the configured extractors (see below).
+

Examples of these directives uses could be (assumes a Sling-Initial-Content header entry of SLING-INF/content):

+ + + + + + + + + + + + + + + + + +
Entry Behaviour
SLING-INF/content/home;overwrite:=true;uninstall:=true Overwrites already existing content in /home and uninstalls the content when the bundle is unregistered.
SLING-INF/content/home;path:=/sites/sling_website if /sites/sling_website exists it loads the content into it. Otherwise, it loads the content into root node /.
SLING-INF/content/home;checkin:=true After content loading, versionable nodes are checked in.
+ +

Loading initial content from bundles

+ +

Repository items to be loaded into the repository, when the bundle is first installed, may be defined in four ways:

+
    +
  1. Directories
  2. +
  3. Files
  4. +
  5. XML descriptor files
  6. +
  7. JSON descriptor files
  8. +
+ + +

Depending on the bundle entry found in the location indicated by the Sling-Initial-Content bundle manifest header, nodes are created (and/or updated) as follows:

+ +

Directories

+ +

Unless a node with the name of the directory already exists or has been defined in an XML or JSON descriptor file (see below) a directory is created as a node with the primary node type "nt:folder" in the repository.

+ +

Files

+ +

Unless a node with the name of the file already exists or has been defined in an XML or JSON descriptor file (see below) a file is created as two nodes in the repository. The node bearing the name of the file itself is created with the
+primary node type "nt:file". Underneath this file node, a resource node with the primary node type "nt:resource" is created, which is set to the contents of the file.

+ +

The MIME type is derived from the file name extension by first trying to resolve it from the Bundle entry URL. If this does not resolve to a MIME type, the Sling MIME type resolution service is used to try to find a mime type. If all fals, the MIME type is defaulted to "application/octet-stream".  

+ +

XML Descriptor Files

+ +

Nodes, Properties and in fact complete subtrees may be described in XML files using either the JCR SystemView format, or the format described below. In either case, the file must have the .xml extension.

+
+
<node>
+		<!--
+			optional on top level, defaults to XML file name without .xml extension
+	       	required for child nodes
+		-->
+		<name>xyz</name>
+
+		<!--
+	   		optional, defaults to nt:unstructured
+		-->
+		<primaryNodeType>nt:file</primaryNodeType>
+
+		<!--
+		    optional mixin node type
+		    may be repeated for multiple mixin node types
+		-->
+		<mixinNodeType>mix:versionable</mixinNodeType>
+		<mixinNodeType>mix:lockable</mixinNodeType>
+
+		<!--
+			Optional properties for the node. Each <property> element defines
+			a single property of the node. The element may be repeated.
+		-->
+		<property>
+			<!--
+				required property name
+			-->
+			<name>prop</name>
+
+			<!--
+				value of the property.
+				For multi-value properties, the values are defined by multiple
+				<value> elements nested inside a <values> element instead of a
+				single <value> element
+			-->
+			<value>property value as string</value>
+
+			<!--
+				Optional type of the property value, defaults to String.
+				This must be one of the property type strings defined in the
+				JCR PropertyType interface.
+			<type>String</type>
+		</property>
+
+		<!--
+			Additional child nodes. May be further nested.
+		-->
+		<node>
+		....
+		</node>
+	</node>
+
+ +

Using a custom XML format

+

By writing an XSLT stylesheet file, you can use whatever XML format you prefer. The XML file references an XSLT stylesheet by using the xml-stylesheet processing instruction:

+
+
<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet href="my-transform.xsl" type="text/xsl"?> <!-- The path to my-transform.xsl is relative to this file -->
+
+<your_custom_root_node>
+   <your_custom_element>
+   ...
+   </your_custom_element>
+...
+</your_custom_root_node>
+
+ +

The my-transform.xsl file is then responsible for translating your format into one of the supported XML formats:

+ +
+
<xsl:stylesheet version="1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" 
+  xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+  xmlns:rep="internal" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:template match="your_custom_element">
+    <node>
+      ...
+    </node>
+  </xsl:template>
+  ...
+</xsl:stylesheet>
+
+ +

JSON Descriptor Files

+ +

Nodes, Properties and in fact complete subtrees may be described in JSON files using the following skeleton structure (see http://www.json.org or information on the syntax of JSON) :

+
+
{
+		// optional node name on top level, default is file name without .json ext.
+		"name": "nodename",
+
+		// optional primary node type, default "nt:unstructured"
+		"primaryNodeType": "sling:ScriptedComponent",
+
+		// optional mixin node types as array
+		"mixinNodeTypes": [ ],
+
+	    // the "properties" property is an object indexed by property name whose
+	    // value is either the string property value, array for multi-values or
+	    // an object whose value[s] property denotes the property value(s) and
+	    // whose type property denotes the property type
+	    "properties": {
+	    	"sling:contentClass": "com.day.sling.jcr.test.Test",
+	    	"sampleMulti": [ "v1", "v2" ],
+	    	"sampleStruct": {
+	    		"value": 1,
+	    		"type": "Long"
+	    	}
+	    	"sampleStructMulti": {
+	    		"value": [ 1, 2, 3 ],
+	    		"type": "Long"
+	    	}
+	    },
+
+	    // the "nodes" property is an array of objects denoting child nodes. Nodes
+	    // may be further nested.
+		"nodes": [
+			{
+				// the name property is required on (nested) child nodes
+	            "name": "sling:scripts",
+
+				"primaryNodeType": "sling:ScriptList",
+
+				"nodes": [
+					{
+						"primaryNodeType": "sling:Script",
+						"properties": {
+							"sling:name": "/test/content/jsp/start.jsp",
+							"sling:type": "jsp",
+							"sling:glob": "*"
+						}
+					}
+				]
+			}
+		]
+	}
+
+ +

Extractors

+ +

By default, the sling-jcr-contentloader bundle tries to extract certain file types during content loading. These include json, xml, zip, and jar files. Therefore all available extractors are used for content processing. However if some files should be put into the repository unextracted, the ignoreImportProviders directive can be used with a comma separated list of extensions that should not be extracted, like ignoreImportProviders:=jar,zip.

+ +

Declared Node Type Registration

+ +

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

+
    +
  • Node Type Definitions - The class org.apache.sling.content.jcr.base.NodeTypeLoader 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.
  • +
+ + +

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-jcr-base 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 currently a problematic issue, 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.

+ +

Automated tests

+ +

The initial content found in the sling-test folder of the launchpad initial content is verified by the InitialContentTest when running the launchpad/testing integration tests.

+ +

Those tests can be used as verified examples of initial content loading. Contributions are welcome to improve the coverage of those tests.

+
+Last modified by mykee on Wed May 27 13:49:11 PDT 2009 +
+
+ + +