org.jproggy.snippetory
Class UriResolver

java.lang.Object
  extended by org.jproggy.snippetory.UriResolver

public abstract class UriResolver
extends Object

The UrlResolver allows a repository-like definition of templates that are available within a template context. This offers different possibilities including switching between template sets.

The User of the configured TemplateContext only needs to know a uri of a template. As the TemplateContext is provided for resolution schemes based on encoding or locale are possible.

Hence the UrlResolver mechanism provides a clearly bordered repository while the Repo class rather provides access to the global repository.

This class already provides some basic implementations. However, for the moment none of them draws the context into account. But more sophisticated algorithms are likely to be based on Locale or Encoding.


Constructor Summary
UriResolver()
           
 
Method Summary
static UriResolver directories(File... dirs)
          Creates a UriResolver that sequentially scans the provided directories for a file that's represented by the uri and returns the content of the first match.
static UriResolver directories(String... dirs)
          Creates a UriResolver that sequentially scans the provided directories for a file that's represented by the uri and returns the content of the first match.
abstract  String resolve(String uri, TemplateContext context)
          Resolves the uri within the repository to the data represented by it.
static UriResolver resource()
          Resolves to a resource.
static UriResolver resource(String prefix)
          Allows resource lookup from packages with a short name as well as organizing template sets in different packages.
static UriResolver url(String base)
          resolves uris relative to the base URL
static UriResolver url(URL base)
          resolves uris relative to the base URL
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UriResolver

public UriResolver()
Method Detail

directories

public static UriResolver directories(String... dirs)
Creates a UriResolver that sequentially scans the provided directories for a file that's represented by the uri and returns the content of the first match.


directories

public static UriResolver directories(File... dirs)
Creates a UriResolver that sequentially scans the provided directories for a file that's represented by the uri and returns the content of the first match.


resource

public static UriResolver resource()
Resolves to a resource. The resource has to be queried as described in ClassLoader.getResource(String). The used Classloader is typically the ContextClassloader


resource

public static UriResolver resource(String prefix)
Allows resource lookup from packages with a short name as well as organizing template sets in different packages.


url

public static UriResolver url(String base)
resolves uris relative to the base URL


url

public static UriResolver url(URL base)
resolves uris relative to the base URL


resolve

public abstract String resolve(String uri,
                               TemplateContext context)
Resolves the uri within the repository to the data represented by it. This data will be parsed to a template. The meaning of the uri may greatly differ depending on the implementation. It may or may not map to a certain location.