This project has retired. For details please refer to its Attic page.
CachingLocaleUrlDefinitionDAO (Tiles 2 2.1.4 API)

org.apache.tiles.definition.dao
Class CachingLocaleUrlDefinitionDAO

Package class diagram package CachingLocaleUrlDefinitionDAO
java.lang.Object
  extended by org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO
      extended by org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO
All Implemented Interfaces:
TilesApplicationContextAware, DefinitionDAO<Locale>, URLReader, Refreshable, RefreshMonitor, Initializable
Direct Known Subclasses:
ResolvingLocaleUrlDefinitionDAO

public class CachingLocaleUrlDefinitionDAO
extends BaseLocaleUrlDefinitionDAO
implements Refreshable

A definitions DAO (loading URLs and using Locale as a customization key) that caches definitions that have been loaded in a raw way (i.e. with inheritance that is not resolved).

It can check if the URLs change, but by default this feature is turned off.

Since:
2.1.0
Version:
$Rev: 814502 $ $Date: 2009-09-14 09:14:57 +0200 (lun, 14 set 2009) $

Nested Class Summary
protected  class CachingLocaleUrlDefinitionDAO.WildcardMapping
          Maps a pattern with a definition in cache.
 
Field Summary
static String CHECK_REFRESH_INIT_PARAMETER
          Initialization parameter to set whether we want to refresh URLs when they change.
protected  boolean checkRefresh
          Flag that, when true, enables automatic checking of URLs changing.
protected  Map<Locale,Map<String,Definition>> locale2definitionMap
          The locale-specific set of definitions objects.
protected  Map<Locale,List<CachingLocaleUrlDefinitionDAO.WildcardMapping>> localePatternPaths
          Stores patterns depending on the locale they refer to.
protected  WildcardHelper wildcardHelper
          An object that helps in resolving definitions with wildcards.
 
Fields inherited from class org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO
applicationContext, lastModifiedDates, reader, sourceURLs
 
Constructor Summary
CachingLocaleUrlDefinitionDAO()
          Constructor.
 
Method Summary
protected  void addWildcardPaths(List<CachingLocaleUrlDefinitionDAO.WildcardMapping> paths, Map<String,Definition> defsMap)
          Adds wildcard paths that are stored inside a normal definition map.
protected  Map<String,Definition> checkAndloadDefinitions(Locale customizationKey)
          Checks if URLs have changed.
protected  Map<String,Definition> copyDefinitionMap(Map<String,Definition> localeDefsMap)
          Copies the definition map to be passed to a higher level of customization key.
 Definition getDefinition(String name, Locale customizationKey)
          Returns a definition, given its name and the customization key.
 Map<String,Definition> getDefinitions(Locale customizationKey)
          Returns all the definitions used of a customization key.
 void init(Map<String,String> params)
          Initializes the object.
protected  Map<String,Definition> loadDefinitions(Locale customizationKey)
          Tries to load definitions if necessary.
protected  Map<String,Definition> loadDefinitionsFromURLs(Locale customizationKey)
          Loads definitions from the URLs.
protected  Map<String,Definition> loadParentDefinitions(Locale parentLocale)
          Loads parent definitions, i.e. definitions mapped to a parent locale.
protected  Map<String,Definition> loadRawDefinitionsFromURLs(Locale customizationKey)
          Deprecated. Use loadDefinitionsFromURLs(Locale).
protected  void postDefinitionLoadOperations(Map<String,Definition> localeDefsMap, Locale customizationKey)
          Operations to be done after definitions are loaded.
 void refresh()
          Refreshes the stored definitions, reloading them.
protected  String replace(String st, Map<Integer,String> vars)
          Replaces a string with placeholders using values of a variable map.
protected  Definition replaceDefinition(Definition d, String name, Map<Integer,String> vars)
          Creates a definition given its representation with wildcards.
protected  Definition resolveWildcardDefinition(List<CachingLocaleUrlDefinitionDAO.WildcardMapping> paths, String name)
          Try to resolve a wildcard definition.
 void setCheckRefresh(boolean checkRefresh)
          Sets the flag to check URL refresh.
 
Methods inherited from class org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO
addSourceURL, getResourceNames, getResourceString, identifySources, loadDefinitionsFromURL, refreshRequired, setApplicationContext, setReader, setSourceURLs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.tiles.definition.RefreshMonitor
refreshRequired
 

Field Detail

CHECK_REFRESH_INIT_PARAMETER

public static final String CHECK_REFRESH_INIT_PARAMETER
Initialization parameter to set whether we want to refresh URLs when they change.

Since:
2.1.0
See Also:
Constant Field Values

locale2definitionMap

protected Map<Locale,Map<String,Definition>> locale2definitionMap
The locale-specific set of definitions objects.

Since:
2.1.0

checkRefresh

protected boolean checkRefresh
Flag that, when true, enables automatic checking of URLs changing.

Since:
2.1.0

wildcardHelper

protected WildcardHelper wildcardHelper
An object that helps in resolving definitions with wildcards.

Since:
2.1.0

localePatternPaths

protected Map<Locale,List<CachingLocaleUrlDefinitionDAO.WildcardMapping>> localePatternPaths
Stores patterns depending on the locale they refer to.

Since:
2.1.0
Constructor Detail

CachingLocaleUrlDefinitionDAO

public CachingLocaleUrlDefinitionDAO()
Constructor.

Since:
2.1.0
Method Detail

init

public void init(Map<String,String> params)
Initializes the object.

Specified by:
init in interface Initializable
Overrides:
init in class BaseLocaleUrlDefinitionDAO
Parameters:
params - The map of parameters.

getDefinition

public Definition getDefinition(String name,
                                Locale customizationKey)
Returns a definition, given its name and the customization key.

Specified by:
getDefinition in interface DefinitionDAO<Locale>
Parameters:
name - The name of the definition.
customizationKey - The customization key.
Returns:
The requested definition, if found, otherwise null. The inheritance of the definition must not be resolved.

getDefinitions

public Map<String,Definition> getDefinitions(Locale customizationKey)
Returns all the definitions used of a customization key.

Specified by:
getDefinitions in interface DefinitionDAO<Locale>
Parameters:
customizationKey - The customization key.
Returns:
All the definitions that are connected to the customization key. The inheritance of the definitions must not be resolved.

refresh

public void refresh()
Refreshes the stored definitions, reloading them.

Specified by:
refresh in interface Refreshable

setCheckRefresh

public void setCheckRefresh(boolean checkRefresh)
Sets the flag to check URL refresh. If not called, the default is false.

Parameters:
checkRefresh - When true, enables automatic checking of URLs changing.
Since:
2.1.0

checkAndloadDefinitions

protected Map<String,Definition> checkAndloadDefinitions(Locale customizationKey)
Checks if URLs have changed. If yes, it clears the cache. Then continues loading definitions.

Parameters:
customizationKey - The locale to use when loading URLs.
Returns:
The loaded definitions.
Since:
2.1.0

loadDefinitions

protected Map<String,Definition> loadDefinitions(Locale customizationKey)
Tries to load definitions if necessary.

Parameters:
customizationKey - The locale to use when loading URLs.
Returns:
The loaded definitions.
Since:
2.1.0

loadDefinitionsFromURLs

protected Map<String,Definition> loadDefinitionsFromURLs(Locale customizationKey)
Loads definitions from the URLs.

Parameters:
customizationKey - The locale to use when loading URLs.
Returns:
The loaded definitions.
Since:
2.1.0

loadRawDefinitionsFromURLs

protected Map<String,Definition> loadRawDefinitionsFromURLs(Locale customizationKey)
Deprecated. Use loadDefinitionsFromURLs(Locale).

Loads the raw definitions from the URLs associated with a locale.

Parameters:
customizationKey - The locale to use when loading URLs.
Returns:
The loaded definitions.
Since:
2.1.3

loadParentDefinitions

protected Map<String,Definition> loadParentDefinitions(Locale parentLocale)
Loads parent definitions, i.e. definitions mapped to a parent locale.

Parameters:
parentLocale - The locale to use when loading URLs.
Returns:
The loaded parent definitions.
Since:
2.1.0

postDefinitionLoadOperations

protected void postDefinitionLoadOperations(Map<String,Definition> localeDefsMap,
                                            Locale customizationKey)
Operations to be done after definitions are loaded.

Parameters:
localeDefsMap - The loaded definitions.
customizationKey - The locale to use when loading URLs.
Since:
2.1.0

addWildcardPaths

protected void addWildcardPaths(List<CachingLocaleUrlDefinitionDAO.WildcardMapping> paths,
                                Map<String,Definition> defsMap)
Adds wildcard paths that are stored inside a normal definition map.

Parameters:
paths - The list containing the currently stored paths.
defsMap - The definition map to parse.
Since:
2.1.0

resolveWildcardDefinition

protected Definition resolveWildcardDefinition(List<CachingLocaleUrlDefinitionDAO.WildcardMapping> paths,
                                               String name)
Try to resolve a wildcard definition.

Parameters:
paths - The list containing the currently stored paths.
name - The name of the definition to resolve.
Returns:
A definition, if found, or null if not.
Since:
2.1.0

replaceDefinition

protected Definition replaceDefinition(Definition d,
                                       String name,
                                       Map<Integer,String> vars)
Creates a definition given its representation with wildcards.

Parameters:
d - The definition to replace.
name - The name of the definition to be created.
vars - The variables to be substituted.
Returns:
The definition that can be rendered.
Since:
2.1.0

replace

protected String replace(String st,
                         Map<Integer,String> vars)
Replaces a string with placeholders using values of a variable map.

Parameters:
st - The string to replace.
vars - The variables.
Returns:
The replaced string.
Since:
2.1.0

copyDefinitionMap

protected Map<String,Definition> copyDefinitionMap(Map<String,Definition> localeDefsMap)
Copies the definition map to be passed to a higher level of customization key.

Parameters:
localeDefsMap - The map of definition to be copied.
Returns:
The copy of the definition map. This particular implementation return the localeDefsMap itself.
Since:
2.1.4


Copyright © 2001-2009 Apache Software Foundation. All Rights Reserved.