Note | ||
---|---|---|
| ||
This is obsolete content copied from the Sling website on 2010-02-04. |
Default Content Mapping and Request Rendering
Excerpt | ||
---|---|---|
| ||
Explains default mapping of repository nodes to |
...
While these steps make sense in an ideal world we all know does not exist (with the exception of Utopia, but there are no computers in Utopia), helpers for rapid development are needed. These helpers come in the form of usefull defaults on various levels.
Default Content Mapping
When a request is processed by Sling, one step is to resolve the request URL into a Content
object. This works by checking the request URL for the longest match with an existing JCR repository node. The path of this node is then used to load the Content
object through the ContentManager.load(String)
method. If no mapping exists for the given node, an exception is thrown and the request fails.
...
Property | Type | Description |
---|---|---|
| String | The path of the node from which the content was loaded. This must not be modified by application programs, unless you are prepared for unexpected behaviour when storing the object. |
| String | The primary node type of the (existing) node. This property is purely informational and will never be used when inserting new content or writing back content. |
| List of String | The mixin node types of the (existing) node. This property is purely informational and will never be used when inserting new content or writing back content. If the node has no mixin node types, this property does not exist. |
| String | The component ID of the component used to handle requests to this content. This property may be modified by application programs (though you should be aware of the consequences) and is used as the result of the |
Default Component Selection
After having mapped the JCR repository node into the Content
object the Component
to actually handle the request must be resolved. This is done by calling the Content.getComponentId()
method and looking up this component ID in an internal table. If either the Content.getComponentId()
method returns null
or no component is registered with the requested component ID a default resolution processing takes place as follows:
- Let
cid
be the result of callingContent.getComponentId()
- If
cid
isnull
, letcid
be the result of callingContent.getPath()
(this is nevernull
} - Check for a component with the given
cid
and use it if existing - Otherwise, remove any leading slash from
cid
and replace slashes by dots and check for a component with this modifiedcid
and use it if existing - Otherwise, let
cid
be the fully qualified name of theContent
object class and check for a component with this modifiedcid
and use it if existing - Otherwise and if
cid
ends with the string Content, remove that suffix and check for a component with this modifiedcid
and use it if existing - Otherwise, append
Component
to the end ofcid
and and check for a component with this modifiedcid
and use it if existing - Otherwise, let
cid
be the value of theorg.apache.sling.components.DefaultComponent.ID
field and check for a component with this modifiedcid
and use it if existing - Finally, fail without having found a component to use - this is highly unlikely, though, because the default component is part of the Sling Core bundle and should always be available.
DefaultComponent
The default component first checks whether the request is sent with parameters and will update the Content
object with the parameters as follows:
...
Extension | Format |
---|---|
| HTML, UTF-8 encoded |
| XML, UTF-8 encoded |
| Plain text, UTF-8 encoded |
| Java Properties file format suitable for a normal properties file |
| JSON, UTF-8 encoded |
Default Script
The easiest way to develop and deploy a component is to create a scripted component in the repository by just creating a node of type sling:scriptedComponent
and creating a single JSP script at jsp/start.jsp
below the component node. After that you can refer to that component by the path of the component node and get the start.jsp
script called.
For more more elaborate script selection you may of course create more scripts and refer to them below the sling:scripts
node of the component node.
Rapid Development Primer
To summarize, for rapid development you will have to execute the following steps:
...