|
Page Edited :
SLINGxSITE :
Content Loading and Nodetype Support
Content Loading and Nodetype Support has been edited by Mike Mueller (May 27, 2009). Content:Content Loading and Nodetype SupportApache 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 LoadingBundles 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:
Bundle entries are installed as follows:
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:
Examples of these directives uses could be (assumes a Sling-Initial-Content header entry of SLING-INF/content):
Loading initial content from bundlesRepository items to be loaded into the repository, when the bundle is first installed, may be defined in four ways:
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: DirectoriesUnless 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. FilesUnless 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 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 FilesNodes, 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 formatBy 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="" class="code-quote">"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 FilesNodes, Properties and in fact complete subtrees may be described in JSON files using the following skeleton structure (see http://www.json.org {
// 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": "*"
}
}
]
}
]
}
ExtractorsBy 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 RegistrationThe sling-jcr-base bundle provides low-level repository operations which are at the heart of the functionality of Sling:
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 testsThe initial content found in the sling-test folder of the launchpad initial content Those tests can be used as verified examples of initial content loading. Contributions are welcome to improve the coverage of those tests. |
Unsubscribe or edit your notifications preferences
