|
Page Edited :
SLING :
Sling API Redesign
Sling API Redesign has been edited by Felix Meschberger (Oct 10, 2007). Change summary: intermediate checkpoint Redesign of the Sling APIThere have been a number of threads on the Sling Dev Mailing List on simplifying the current Component API and turn it into a new Sling API. This page starts at the current state of the discussion as of Oct. 10, 2007, and tries to summarize what has been discussed and to resolve this into a modified proposal. [ Redesign of the Sling API ] [ References ] [ Current State ] [ Update Modified Content ] [ JCR based Operations ] [ Replace Content by Resource ] [ Extensions to the Resource interface ] [ Open Issues ] [ Resolving the Servlet ] [ ]
References
Current StateCurrently, request processing is controlled by the sling-core bundle using two sets of filters: one set called at the time the client request enters Sling - so called request level filters - and the other set called for each Content object processed during request processing - so called content level filters. Amongst the request level filters is the ContentResolverFilter which takes the request URL and finds a Content object for the URL. This filter implements the ContentResolver interface and is also registered as this service. So other parts of the system may use the same mechanism to resolve paths to Content objects. The ContentResolver also implements the default content loading described here. Amongst the content level filters is the ComponentResolverFilter which asks the Content object for its component ID and resolves this ID using the registered {{Component}}s. This filter also implements the default component resolution described here. To manage content Sling provides two interfaces:
If components would want to create, update and delete content, they would access the ContentManager by retrieving the org.apache.sling.jcr.content_manager request attribute. If JCR tasks would have to be executed, that retrieved object would be cast to JcrContentManager and the session retrieved. Examples: Update Modified ContentAfter having modified the content, a component might do the following to persisted the modified content: Content content = componentRequest.getContent(); // modify content ContentManager contentManager = (ContentManager) componentRequest.getAttribute("org.apache.sling.jcr.content_manager"); contentManager.store(content); contentManager.save();
public interface ComponentRequest extends HttpServletRequest { ... // Returns the Resource to which the getRequestURL method maps Resource getResource(); // Returns a Resource to which the given URI String maps // Implicit: getResource().equals(getResource(getRequestURL())) Resource getResource(String uri); // Returns an Enumeration child Resources of the given Resource // If resource parameter is null, getResource() is used as parent // (use Enumeration to stay in line with the HttpServletRequest) Enumeration<Resource> getChildren(Resource resource); // Gets a RequestDispatcher to include the given resource RequestDispatcher getRequestDispatcher(Resource resource); ... } Extensions to the Resource interfaceThe Resource interface may be extended depending on the way, the resource is acquired. For example, there might be a MappedContentResource which would return an object mapped from any persistence layer, a JcrResource may encapsulate a JCR based resource. A resolver loading content from a JCR repository using Jackrabbit OCM might return a resource which implements both the MappedContentResource and the JcrResource interfaces. MappedContentResource public interface MappedContentResource extends Resource { // Returns the mapped data object Object getObject(); } JcrResource public interface JcrResource extends Resource { // Returns the JCR session used to acquire the Node // (this is actually convenience as getNode().getSession() // must return the same session) Session getSession(); // Returns the JCR Node addressed by the Resource URI // this is the same as getSession().getItem(getURI()); Node getNode(); } The existing ContentResolver will be retargeted to the Resource interface and return an object implementing the MappedContentResource and the JcrResource interfaces if a mapping exists. Otherwise an object just implementing the JcrResource interface is returned providing just the resolved node. Open IssuesThis above definition leaves a series of issues open. Resolving the Servlet
Currently the Content interface defines a method getComponentId() which returns the identifier of a Component to which processing of the request is dispatched. With the new Resource interface, no such method exists any more. The intent is, that Servlet resolver would know about the concrete implementations of the Resource interface and could handle the respective resources. For example the Sling standard servlet resolver could try the following:
Alternatively, the Resource interface might have a getServletId() method providing the identifier of the servlet to use. It might well be that the first solution is the better one. |
Unsubscribe or edit your notifications preferences
