org.apache.sling.servlets.resolver.internal
Class SlingServletResolver

java.lang.Object
  extended by org.apache.sling.servlets.resolver.internal.SlingServletResolver
All Implemented Interfaces:
SlingScriptResolver, ServletResolver, ErrorHandler, org.osgi.service.event.EventHandler

public class SlingServletResolver
extends Object
implements ServletResolver, SlingScriptResolver, ErrorHandler, org.osgi.service.event.EventHandler

The SlingServletResolver has two functions: It resolves scripts by implementing the SlingScriptResolver interface and it resolves a servlet for a request by implementing the ServletResolver interface. The resolver uses an own session to find the scripts.


Field Summary
static Integer DEFAULT_CACHE_SIZE
          The default cache size for the script resolution.
static String DEFAULT_SERVLET_ROOT
          The default servlet root is the first search path (which is usally /apps)
static String PROP_CACHE_SIZE
           
static String PROP_DEFAULT_SCRIPT_WORKSPACE
           
static String PROP_PATHS
           
static String PROP_SCRIPT_USER
           
static String PROP_SERVLET_ROOT
           
static String PROP_USE_DEFAULT_WORKSPACE
           
static String PROP_USE_REQUEST_WORKSPACE
           
 
Constructor Summary
SlingServletResolver()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext context)
          Activate this component.
protected  void bindServlet(org.osgi.framework.ServiceReference reference)
           
protected  void deactivate(org.osgi.service.component.ComponentContext context)
          Deactivate this component.
 SlingScript findScript(ResourceResolver resourceResolver, String name)
          Finds the SlingScript for the given name.
 void handleError(int status, String message, SlingHttpServletRequest request, SlingHttpServletResponse response)
          Called to render a response for a HTTP status code.
 void handleError(Throwable throwable, SlingHttpServletRequest request, SlingHttpServletResponse response)
          Called to render a response for an uncaught Throwable.
 void handleEvent(org.osgi.service.event.Event event)
           
 javax.servlet.Servlet resolveServlet(ResourceResolver resolver, String scriptName)
          Resolves a javax.servlet.Servlet whose service method may be used to handle a request.
 javax.servlet.Servlet resolveServlet(Resource resource, String scriptName)
          Resolves a javax.servlet.Servlet whose service method may be used to handle a request.
 javax.servlet.Servlet resolveServlet(SlingHttpServletRequest request)
          Resolves a javax.servlet.Servlet whose service method may be used to handle the given request.
protected  void unbindServlet(org.osgi.framework.ServiceReference reference)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SERVLET_ROOT

public static final String PROP_SERVLET_ROOT
See Also:
Constant Field Values

PROP_SCRIPT_USER

public static final String PROP_SCRIPT_USER
See Also:
Constant Field Values

PROP_CACHE_SIZE

public static final String PROP_CACHE_SIZE
See Also:
Constant Field Values

PROP_DEFAULT_SCRIPT_WORKSPACE

public static final String PROP_DEFAULT_SCRIPT_WORKSPACE
See Also:
Constant Field Values

PROP_USE_REQUEST_WORKSPACE

public static final String PROP_USE_REQUEST_WORKSPACE
See Also:
Constant Field Values

PROP_USE_DEFAULT_WORKSPACE

public static final String PROP_USE_DEFAULT_WORKSPACE
See Also:
Constant Field Values

DEFAULT_SERVLET_ROOT

public static final String DEFAULT_SERVLET_ROOT
The default servlet root is the first search path (which is usally /apps)

See Also:
Constant Field Values

DEFAULT_CACHE_SIZE

public static final Integer DEFAULT_CACHE_SIZE
The default cache size for the script resolution.


PROP_PATHS

public static final String PROP_PATHS
See Also:
Constant Field Values
Constructor Detail

SlingServletResolver

public SlingServletResolver()
Method Detail

resolveServlet

public javax.servlet.Servlet resolveServlet(SlingHttpServletRequest request)
Description copied from interface: ServletResolver
Resolves a javax.servlet.Servlet whose service method may be used to handle the given request.

The returned servlet must be assumed to be initialized and ready to run. That is, the init nor the destroy methods must NOT be called on the returned servlet.

This method must not return a Servlet instance implementing the OptingServlet interface and returning false when the OptingServlet.accepts(SlingHttpServletRequest) method is called.

Specified by:
resolveServlet in interface ServletResolver
Parameters:
request - The SlingHttpServletRequest object used to drive selection of the servlet.
Returns:
The servlet whose service method may be called to handle the request.
See Also:
ServletResolver.resolveServlet(org.apache.sling.api.SlingHttpServletRequest)

resolveServlet

public javax.servlet.Servlet resolveServlet(Resource resource,
                                            String scriptName)
Description copied from interface: ServletResolver
Resolves a javax.servlet.Servlet whose service method may be used to handle a request.

The returned servlet must be assumed to be initialized and ready to run. That is, the init nor the destroy methods must NOT be called on the returned servlet.

This method skips all OptingServlets as there is no request object available. Basically this method searches a script with the scriptName for the resource type defined by the resource

Specified by:
resolveServlet in interface ServletResolver
Parameters:
resource - The Resource object used to drive selection of the servlet.
scriptName - The name of the script - the script might have an extension. In this case only a script with the matching extension is used.
Returns:
The servlet whose service method may be called to handle the request.
See Also:
ServletResolver.resolveServlet(org.apache.sling.api.resource.Resource, java.lang.String)

resolveServlet

public javax.servlet.Servlet resolveServlet(ResourceResolver resolver,
                                            String scriptName)
Description copied from interface: ServletResolver
Resolves a javax.servlet.Servlet whose service method may be used to handle a request.

The returned servlet must be assumed to be initialized and ready to run. That is, the init nor the destroy methods must NOT be called on the returned servlet.

This method skips all OptingServlets as there is no request object available. Basically this method searches a script with the scriptName

Specified by:
resolveServlet in interface ServletResolver
Parameters:
resolver - The ResourceResolver object used to drive selection of the servlet.
scriptName - The name of the script - the script might have an extension. In this case only a script with the matching extension is used.
Returns:
The servlet whose service method may be called to handle the request.
See Also:
ServletResolver.resolveServlet(org.apache.sling.api.resource.ResourceResolver, java.lang.String)

findScript

public SlingScript findScript(ResourceResolver resourceResolver,
                              String name)
                       throws SlingException
Description copied from interface: SlingScriptResolver
Finds the SlingScript for the given name.

The semantic meaning of the name is implementation specific: It may be an absolute path to a Resource providing the script source or it may be a relative path resolved according to some path settings. Finally, the name may also just be used as an identifier to find the script in some registry.

Specified by:
findScript in interface SlingScriptResolver
Parameters:
resourceResolver - The ResourceResolver used to access the script.
name - The script name. Must not be null.
Returns:
The SlingScript to which the name resolved or null otherwise.
Throws:
SlingException - If an error occurrs trying to resolve the name.
See Also:
SlingScriptResolver.findScript(org.apache.sling.api.resource.ResourceResolver, java.lang.String)

handleError

public void handleError(int status,
                        String message,
                        SlingHttpServletRequest request,
                        SlingHttpServletResponse response)
                 throws IOException
Description copied from interface: ErrorHandler
Called to render a response for a HTTP status code. This method should set the response status and print the status code and optional message.

If the response has already been committed, an error message should be logged but no further processing should take place.

Specified by:
handleError in interface ErrorHandler
Parameters:
status - The HTTP status code to set
message - An optional message to write to the response. This message may be null.
request - The request object providing more information on the request.
response - The response object used to send the status and message.
Throws:
IOException - May be thrown if an error occurrs sending the response.
See Also:
ErrorHandler.handleError(int, String, SlingHttpServletRequest, SlingHttpServletResponse)

handleError

public void handleError(Throwable throwable,
                        SlingHttpServletRequest request,
                        SlingHttpServletResponse response)
                 throws IOException
Description copied from interface: ErrorHandler
Called to render a response for an uncaught Throwable.

If the response has already been committed, an error message should be logged but no further processing should take place.

Specified by:
handleError in interface ErrorHandler
Parameters:
throwable - The Throwable causing this method to be called.
request - The request object providing more information on the request.
response - The response object used to send the status and message.
Throws:
IOException - May be thrown if an error occurrs sending the response.

activate

protected void activate(org.osgi.service.component.ComponentContext context)
                 throws LoginException
Activate this component.

Throws:
LoginException

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext context)
Deactivate this component.


bindServlet

protected void bindServlet(org.osgi.framework.ServiceReference reference)

unbindServlet

protected void unbindServlet(org.osgi.framework.ServiceReference reference)

handleEvent

public void handleEvent(org.osgi.service.event.Event event)
Specified by:
handleEvent in interface org.osgi.service.event.EventHandler
See Also:
EventHandler.handleEvent(org.osgi.service.event.Event)


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.