ro.isdc.wro.model.resource.locator
Class ServletContextUriLocator

java.lang.Object
  extended by ro.isdc.wro.model.resource.locator.wildcard.WildcardUriLocatorSupport
      extended by ro.isdc.wro.model.resource.locator.ServletContextUriLocator
All Implemented Interfaces:
UriLocator

public class ServletContextUriLocator
extends WildcardUriLocatorSupport

UriLocator capable to read the resources relative to servlet context. The resource reader will attempt to locate a physic resource under the servlet context and if the resource does not exist, will try to use requestDispatcher. This kind of resources will be accepted if their prefix is '/'.

Author:
Alex Objelean, Ivar Conradi Ă˜sthus

Nested Class Summary
static class ServletContextUriLocator.LocatorStrategy
          Available LocatorStrategies.
 
Field Summary
static String ALIAS
          Alias used to register this locator with LocatorProvider.
static String ALIAS_DISPATCHER_FIRST
          Same as default Alias (exist for explicit configuration).
static String ALIAS_SERVLET_CONTEXT_FIRST
          Uses SERVLET_CONTEXT_FIRST strategy, meaning that, for example, a jsp will be served with its raw content, instead of processed by container.
static String PREFIX
          Prefix for url resources.
 
Constructor Summary
ServletContextUriLocator()
           
 
Method Summary
 boolean accept(String uri)
          Check if this uri can be located by concrete implementation.
static boolean isProtectedResource(String uri)
          Check If the uri of the resource is protected: it cannot be accessed by accessing the url directly (WEB-INF folder).
static boolean isValid(String uri)
          Check if a uri is a servletContext resource.
 InputStream locate(String uri)
          Locates the uri by retrieving the InputStream.
 ServletContextUriLocator setLocatorStrategy(ServletContextUriLocator.LocatorStrategy locatorStrategy)
          Sets the locator strategy to use.
 
Methods inherited from class ro.isdc.wro.model.resource.locator.wildcard.WildcardUriLocatorSupport
getWildcardStreamLocator, isEnableWildcards, newWildcardStreamLocator, setEnableWildcards
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIAS

public static final String ALIAS
Alias used to register this locator with LocatorProvider.

See Also:
Constant Field Values

ALIAS_DISPATCHER_FIRST

public static final String ALIAS_DISPATCHER_FIRST
Same as default Alias (exist for explicit configuration). Uses DISPATCHER_FIRST strategy. Meaning that, for example, a jsp resource will be served in its final state (processed by servlet container), rather than in its raw variant.

See Also:
Constant Field Values

ALIAS_SERVLET_CONTEXT_FIRST

public static final String ALIAS_SERVLET_CONTEXT_FIRST
Uses SERVLET_CONTEXT_FIRST strategy, meaning that, for example, a jsp will be served with its raw content, instead of processed by container.

See Also:
Constant Field Values

PREFIX

public static final String PREFIX
Prefix for url resources.

See Also:
Constant Field Values
Constructor Detail

ServletContextUriLocator

public ServletContextUriLocator()
Method Detail

setLocatorStrategy

public ServletContextUriLocator setLocatorStrategy(ServletContextUriLocator.LocatorStrategy locatorStrategy)
Sets the locator strategy to use.


accept

public boolean accept(String uri)
Check if this uri can be located by concrete implementation.

Parameters:
uri - to read.
Returns:
true if UriLocator is able to return an InputStream of this uri.

isValid

public static boolean isValid(String uri)
Check if a uri is a servletContext resource.

Parameters:
uri - to check.
Returns:
true if the uri is a servletContext resource.

isProtectedResource

public static boolean isProtectedResource(String uri)
Check If the uri of the resource is protected: it cannot be accessed by accessing the url directly (WEB-INF folder).

Parameters:
uri - the uri to check.
Returns:
true if the uri is a protected resource.

locate

public InputStream locate(String uri)
                   throws IOException
Locates the uri by retrieving the InputStream. The client is responsible for closing the InputStream.

Parameters:
uri - uri to read.
Returns:
InputStream for the provided uri.
Throws:
IOException - if the resource cannot be read for some reason.


Copyright © 2008-2013. All Rights Reserved.