Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note
titlePage Status

This is obsolete content copied from the Sling website on 2010-02-04.

Default Content Mapping and Request Rendering

Excerpt
hiddentrue

Explains default mapping of repository nodes to Content instances and selection of a default Component.

...

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

path

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.

primaryType

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.

mixinTypes

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.

sling:componentId

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 Content.getComponentId() method.

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:

  1. Let cid be the result of calling Content.getComponentId()
  2. If cid is null, let cid be the result of calling Content.getPath() (this is never null}
  3. Check for a component with the given cid and use it if existing
  4. Otherwise, remove any leading slash from cid and replace slashes by dots and check for a component with this modified cid and use it if existing
  5. Otherwise, let cid be the fully qualified name of the Content object class and check for a component with this modified cid and use it if existing
  6. Otherwise and if cid ends with the string Content, remove that suffix and check for a component with this modified cid and use it if existing
  7. Otherwise, append Component to the end of cid and and check for a component with this modified cid and use it if existing
  8. Otherwise, let cid be the value of the org.apache.sling.components.DefaultComponent.ID field and check for a component with this modified cid and use it if existing
  9. 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, htm

HTML, UTF-8 encoded

xml

XML, UTF-8 encoded

txt

Plain text, UTF-8 encoded

properties

Java Properties file format suitable for a normal properties file

json

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:

...