org.norther.tammi.core.io
Class DefaultPathFinder

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.io.DefaultPathFinder
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, PathFinder

public class DefaultPathFinder
extends Adaptee
implements PathFinder

A default implementation of PathFinder.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static String DEFAULT_BINARY
          The default binary folder.
static String DEFAULT_CGI_BIN
          The default cgi bin folder.
static String DEFAULT_CONFIG
          The default config folder.
static String DEFAULT_DATA
          The default data folder.
static String DEFAULT_LIBRARY
          The default libray folder.
static String DEFAULT_LICENSE
          The default license folder.
static String DEFAULT_LOGS
          The default logs folder.
static String DEFAULT_MEDIA
          The default media folder.
static String DEFAULT_RESOURCE
          The default resource folder.
static String DEFAULT_SCRIPT
          The default script folder.
static String DEFAULT_SECURITY
          The default security folder.
static String DEFAULT_START
          The default start folder.
static String DEFAULT_STOP
          The default stop folder.
static String DEFAULT_TAMMI
          The default tammi folder.
static String DEFAULT_TEMP
          The default temp folder.
static String DEFAULT_TEMPLATE
          The default template folder.
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.io.PathFinder
BINARY, CGI_BIN, CONFIG, CONTEXT, CSV_EXTENSION, DATA, DEFAULT_DATA_PROPERTY, DEFAULT_LOGS_PROPERTY, DEFAULT_TEMP_PROPERTY, LIBRARY, LICENSE, LOGS, MEDIA, PROPERTIES_EXTENSION, RESOURCE, SCRIPT, SECURITY, START, STOP, TEMP, TEMPLATE, XML_EXTENSION
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultPathFinder()
          Constructs a new finder.
DefaultPathFinder(String root)
          Constructs a new finder with a specified root.
 
Method Summary
 void addContextPath(int index, String path)
          Adds a context path to the specified index.
 void addContextPath(String path)
          Adds a context path if not already specified.
 void addFolderPath(String key, int index, String path)
          Adds a key folder path to the specified index.
 void addFolderPath(String key, String path)
          Adds a key folder path if not already specified.
 void clearContext()
          Clears all context paths.
 void clearFolder(String key)
          Clears a key folder.
 void clearFolders()
          Clears all key folders.
 boolean deleteFile(File file)
          Deletes a file or folder and its contents.
 File findFile(String path)
          Finds a file relative to the root folder.
 File findFile(String key, String path)
          Finds a file relative to a key folder.
 File findFile(String key, String path, Locale locale)
          Finds a localized file relative to a key folder.
 File findFile(String key, String path, Locale locale, String variant)
          Finds a localized file with an optional variant relative to a key folder.
 OrderedSet findFolders(String key)
          Finds all existing folders corresponding to the specified key by applying the context paths of this path finder.
 URL findResource(String path)
          Finds a root resource using a local class loader.
 URL findResource(String key, String path)
          Finds a key resource using a local class loader.
 URL findResource(String key, String path, Locale locale)
          Finds a localized key resource using a local class loader.
 URL findResource(String key, String path, Locale locale, String variant)
          Finds a localized key resource with an optional variant using a local class loader.
 URL findURL(String path)
          Finds a file relative to the root folder or a root resource using a local class loader.
 URL findURL(String key, String path)
          Finds a file relative to a key folder or a key resource using a local class loader.
 URL findURL(String key, String path, Locale locale)
          Finds a localized file relative to a key folder or a localized key resource using a local class loader.
 URL findURL(String key, String path, Locale locale, String variant)
          Finds a localized file relative to a key folder or a localized key resource, with an optional variant, using a local class loader.
 Set folderKeySet()
          Returns a read-only set of specified folder keys.
 ClassLoader getContextClassLoader()
          Gets a context class loader loading resources from context paths of this path finder.
 String[] getContextPaths()
          Gets the context paths.
 String[] getFolderPaths(String key)
          Gets the specified key folder paths.
 File getRootFolder()
          Gets the root folder.
 String getRootPath()
          Gets the root path.
 File getSystemFolder()
          Gets the operating system folder.
 boolean isNormalizedPaths()
          Checks whether requested paths are normalized before search to reject absolute search paths and references outside context paths folders.
 void removeContextPath(String path)
          Removes a context path.
 void removeFolderPath(String key, String path)
          Removes a key folder path.
 void setContextPaths(String[] paths)
          Sets the context paths..
 void setFolderPaths(String key, String[] paths)
          Sets the specified key folder paths.
 void setNormalizedPaths(boolean flag)
          Sets whether requested paths are normalized before search to reject absolute search paths and references outside context paths folders.
 void setRootPath(String path)
          Sets the root path.
 URL toURL(String path)
          Converts a URL path, local path or jar path relative to the root folder to a URL instance.
 URL toURL(String key, String path)
          Converts a URL path, local path or jar path relative to the key folder to a URL instance.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BINARY

public static final String DEFAULT_BINARY
The default binary folder.

See Also:
Constant Field Values

DEFAULT_LIBRARY

public static final String DEFAULT_LIBRARY
The default libray folder.

See Also:
Constant Field Values

DEFAULT_LICENSE

public static final String DEFAULT_LICENSE
The default license folder.

See Also:
Constant Field Values

DEFAULT_MEDIA

public static final String DEFAULT_MEDIA
The default media folder.

See Also:
Constant Field Values

DEFAULT_CGI_BIN

public static final String DEFAULT_CGI_BIN
The default cgi bin folder.

See Also:
Constant Field Values

DEFAULT_RESOURCE

public static final String DEFAULT_RESOURCE
The default resource folder.

See Also:
Constant Field Values

DEFAULT_TEMPLATE

public static final String DEFAULT_TEMPLATE
The default template folder.

See Also:
Constant Field Values

DEFAULT_START

public static final String DEFAULT_START
The default start folder.

See Also:
Constant Field Values

DEFAULT_STOP

public static final String DEFAULT_STOP
The default stop folder.

See Also:
Constant Field Values

DEFAULT_SCRIPT

public static final String DEFAULT_SCRIPT
The default script folder.

See Also:
Constant Field Values

DEFAULT_CONFIG

public static final String DEFAULT_CONFIG
The default config folder.

See Also:
Constant Field Values

DEFAULT_SECURITY

public static final String DEFAULT_SECURITY
The default security folder.

See Also:
Constant Field Values

DEFAULT_TEMP

public static final String DEFAULT_TEMP
The default temp folder.

See Also:
Constant Field Values

DEFAULT_DATA

public static final String DEFAULT_DATA
The default data folder.

See Also:
Constant Field Values

DEFAULT_LOGS

public static final String DEFAULT_LOGS
The default logs folder.

See Also:
Constant Field Values

DEFAULT_TAMMI

public static final String DEFAULT_TAMMI
The default tammi folder.

See Also:
Constant Field Values
Constructor Detail

DefaultPathFinder

public DefaultPathFinder()
Constructs a new finder.


DefaultPathFinder

public DefaultPathFinder(String root)
Constructs a new finder with a specified root.

Parameters:
root - a root folder.
Method Detail

isNormalizedPaths

public boolean isNormalizedPaths()
Description copied from interface: PathFinder
Checks whether requested paths are normalized before search to reject absolute search paths and references outside context paths folders.

Specified by:
isNormalizedPaths in interface PathFinder
Returns:
true if normalized, false otherwise.

setNormalizedPaths

public void setNormalizedPaths(boolean flag)
Description copied from interface: PathFinder
Sets whether requested paths are normalized before search to reject absolute search paths and references outside context paths folders.

Specified by:
setNormalizedPaths in interface PathFinder
Parameters:
flag - true if normalized, false otherwise.

getRootFolder

public File getRootFolder()
Description copied from interface: PathFinder
Gets the root folder.

Specified by:
getRootFolder in interface PathFinder
Returns:
the root folder.

getRootPath

public String getRootPath()
Description copied from interface: PathFinder
Gets the root path. The path of the root folder is the first context path of this path finder.

Specified by:
getRootPath in interface PathFinder
Returns:
the root path.

setRootPath

public void setRootPath(String path)
Description copied from interface: PathFinder
Sets the root path. The path of the root folder is the first context path of this path finder. If the specified path already exists among context paths, it is moved to be the first one in the list, otherwise the first context path is replaced with the specified path.

Specified by:
setRootPath in interface PathFinder
Parameters:
path - the root path.

getContextPaths

public String[] getContextPaths()
Description copied from interface: PathFinder
Gets the context paths.

Specified by:
getContextPaths in interface PathFinder
Returns:
an array of context paths.

setContextPaths

public void setContextPaths(String[] paths)
Description copied from interface: PathFinder
Sets the context paths..

Specified by:
setContextPaths in interface PathFinder
Parameters:
paths - an array of context paths.

addContextPath

public void addContextPath(String path)
Description copied from interface: PathFinder
Adds a context path if not already specified.

Specified by:
addContextPath in interface PathFinder
Parameters:
path - the context path.

addContextPath

public void addContextPath(int index,
                           String path)
Description copied from interface: PathFinder
Adds a context path to the specified index.

Specified by:
addContextPath in interface PathFinder
Parameters:
index - the path index.
path - the context path.

removeContextPath

public void removeContextPath(String path)
Description copied from interface: PathFinder
Removes a context path.

Specified by:
removeContextPath in interface PathFinder
Parameters:
path - the context path.

clearContext

public void clearContext()
Description copied from interface: PathFinder
Clears all context paths.

Specified by:
clearContext in interface PathFinder

getFolderPaths

public String[] getFolderPaths(String key)
Description copied from interface: PathFinder
Gets the specified key folder paths.

Specified by:
getFolderPaths in interface PathFinder
Parameters:
key - the folder key.
Returns:
an array of key folder paths.

setFolderPaths

public void setFolderPaths(String key,
                           String[] paths)
Description copied from interface: PathFinder
Sets the specified key folder paths.

Specified by:
setFolderPaths in interface PathFinder
Parameters:
key - the folder key.
paths - an array of key folder paths.

addFolderPath

public void addFolderPath(String key,
                          String path)
Description copied from interface: PathFinder
Adds a key folder path if not already specified.

Specified by:
addFolderPath in interface PathFinder
Parameters:
key - the folder key.
path - the key folder path.

addFolderPath

public void addFolderPath(String key,
                          int index,
                          String path)
Description copied from interface: PathFinder
Adds a key folder path to the specified index.

Specified by:
addFolderPath in interface PathFinder
Parameters:
key - the folder key.
index - the path index.
path - the key folder path.

removeFolderPath

public void removeFolderPath(String key,
                             String path)
Description copied from interface: PathFinder
Removes a key folder path.

Specified by:
removeFolderPath in interface PathFinder
Parameters:
key - the folder key.
path - the key folder path.

clearFolder

public void clearFolder(String key)
Description copied from interface: PathFinder
Clears a key folder.

Specified by:
clearFolder in interface PathFinder
Parameters:
key - the folder key.

clearFolders

public void clearFolders()
Description copied from interface: PathFinder
Clears all key folders.

Specified by:
clearFolders in interface PathFinder

folderKeySet

public Set folderKeySet()
Description copied from interface: PathFinder
Returns a read-only set of specified folder keys.

Specified by:
folderKeySet in interface PathFinder
Returns:
a set of keys or an empty set.

deleteFile

public boolean deleteFile(File file)
Description copied from interface: PathFinder
Deletes a file or folder and its contents.

Specified by:
deleteFile in interface PathFinder
Parameters:
file - the file to delete.
Returns:
true if successful, false otherwise.

findFolders

public OrderedSet findFolders(String key)
Description copied from interface: PathFinder
Finds all existing folders corresponding to the specified key by applying the context paths of this path finder.

Specified by:
findFolders in interface PathFinder
Parameters:
key - a folder key.
Returns:
folders as a set of java.io.File instances.

findURL

public URL findURL(String path)
Description copied from interface: PathFinder
Finds a file relative to the root folder or a root resource using a local class loader.

Specified by:
findURL in interface PathFinder
Parameters:
path - a path to find.
Returns:
the found file or resource as a URL or null.

findURL

public URL findURL(String key,
                   String path)
Description copied from interface: PathFinder
Finds a file relative to a key folder or a key resource using a local class loader.

Specified by:
findURL in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
Returns:
the found file or resource as a URL or null.

findURL

public URL findURL(String key,
                   String path,
                   Locale locale)
Description copied from interface: PathFinder
Finds a localized file relative to a key folder or a localized key resource using a local class loader. A file having the given locale, or any part of it, embedded into its name is searched for.

Specified by:
findURL in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
locale - the locale of the path.
Returns:
the found file or resource as a URL or null.

findURL

public URL findURL(String key,
                   String path,
                   Locale locale,
                   String variant)
Description copied from interface: PathFinder
Finds a localized file relative to a key folder or a localized key resource, with an optional variant, using a local class loader. A file having the given locale, or any part of it, embedded into its name is searched for. If the variant is not null, it replaces any variants in the locale.

Specified by:
findURL in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
locale - the locale of the path.
variant - a variant to the locale.
Returns:
the found file or resource as a URL or null.

findFile

public File findFile(String path)
Description copied from interface: PathFinder
Finds a file relative to the root folder.

Specified by:
findFile in interface PathFinder
Parameters:
path - a path to find.
Returns:
the found file.

findFile

public File findFile(String key,
                     String path)
Description copied from interface: PathFinder
Finds a file relative to a key folder.

Specified by:
findFile in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
Returns:
the found file.

findFile

public File findFile(String key,
                     String path,
                     Locale locale)
Description copied from interface: PathFinder
Finds a localized file relative to a key folder. A file having the given locale, or any part of it, embedded into its name is searched for.

Specified by:
findFile in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
locale - the locale of the path.
Returns:
the found file.

findFile

public File findFile(String key,
                     String path,
                     Locale locale,
                     String variant)
Description copied from interface: PathFinder
Finds a localized file with an optional variant relative to a key folder. A file having the given locale, or any part of it, embedded into its name is searched for. If the variant is not null, it replaces any variants in the locale.

Specified by:
findFile in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
locale - the locale of the path.
variant - a variant to the locale.
Returns:
the found file.

findResource

public URL findResource(String path)
Description copied from interface: PathFinder
Finds a root resource using a local class loader.

Specified by:
findResource in interface PathFinder
Parameters:
path - a path to find.
Returns:
the found URL or null.

findResource

public URL findResource(String key,
                        String path)
Description copied from interface: PathFinder
Finds a key resource using a local class loader.

Specified by:
findResource in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
Returns:
the found URL or null.

findResource

public URL findResource(String key,
                        String path,
                        Locale locale)
Description copied from interface: PathFinder
Finds a localized key resource using a local class loader. A resource having the given locale, or any part of it, embedded into its name is searched for.

Specified by:
findResource in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
locale - the locale of the path.
Returns:
the found URL or null.

findResource

public URL findResource(String key,
                        String path,
                        Locale locale,
                        String variant)
Description copied from interface: PathFinder
Finds a localized key resource with an optional variant using a local class loader. A resource having the given locale, or any part of it, embedded into its name is searched for. If the variant is not null, it replaces any variants in the locale.

Specified by:
findResource in interface PathFinder
Parameters:
key - a folder key or null for the root.
path - a path to find.
locale - the locale of the path.
variant - a variant to the locale.
Returns:
the found URL or null.

toURL

public URL toURL(String path)
          throws MalformedURLException
Description copied from interface: PathFinder
Converts a URL path, local path or jar path relative to the root folder to a URL instance. The path must specify the protocol to apply (file:, jar:file:, etc).

Specified by:
toURL in interface PathFinder
Parameters:
path - a path to find.
Returns:
the URL or null.
Throws:
MalformedURLException - for an invalid URL path.

toURL

public URL toURL(String key,
                 String path)
          throws MalformedURLException
Description copied from interface: PathFinder
Converts a URL path, local path or jar path relative to the key folder to a URL instance. The path must specify the protocol to apply (file:, jar:file:, etc).

Specified by:
toURL in interface PathFinder
Parameters:
key - a folder key.
path - a path to find.
Returns:
the URL or null.
Throws:
MalformedURLException - for an invalid URL path.

getContextClassLoader

public ClassLoader getContextClassLoader()
Description copied from interface: PathFinder
Gets a context class loader loading resources from context paths of this path finder.

Specified by:
getContextClassLoader in interface PathFinder
Returns:
the context class loader.

getSystemFolder

public File getSystemFolder()
Description copied from interface: PathFinder
Gets the operating system folder.

Specified by:
getSystemFolder in interface PathFinder
Returns:
the operating system folder.


Copyright © 2004 The Norther Organization. All rights reserved.