org.norther.tammi.spray.engine.tool
Class PathTool

java.lang.Object
  extended by org.norther.tammi.core.pool.RecyclableSupport
      extended by org.norther.tammi.core.pool.PoolableSupport
          extended by org.norther.tammi.spray.engine.tool.GlobalTool
              extended by org.norther.tammi.spray.engine.tool.PathTool
All Implemented Interfaces:
Serializable, Cloneable, EventListener, Poolable, Recyclable, ContextBindingListener

public class PathTool
extends GlobalTool

A global context tool for file path operations.

Version:
$Id: PathTool.java,v 1.10 2009/09/28 15:08:29 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
PathTool()
          Constructs a new tool.
 
Method Summary
 boolean deleteFile(File file)
          Deletes a file or folder and its contents.
 File findFile(String path)
          Finds a file relative to the current root directory.
 File findFile(String key, String path)
          Finds a file relative to the specified key directory.
 File findFile(String key, String path, Locale locale)
          Finds a localized file relative to the specified key directory.
 File findFile(String key, String path, Locale locale, String variant)
          Finds a localized file relative to the specified key directory.
 URL findResource(String path)
          Finds a resource relative to the current root folder.
 URL findResource(String key, String path)
          Finds a resource relative to the specified key folder.
 URL findResource(String key, String path, Locale locale)
          Finds a localized resource relative to the specified key folder.
 URL findResource(String key, String path, Locale locale, String variant)
          Finds a localized resource relative to the specified key folder.
 URL findURL(String path)
          Finds a file or resource relative to the current root folder.
 URL findURL(String key, String path)
          Finds a file or resource relative to the specified key folder.
 URL findURL(String key, String path, Locale locale)
          Finds a localized file or resource relative to the specified key folder.
 URL findURL(String key, String path, Locale locale, String variant)
          Finds a localized file or resource relative to the specified key folder.
 CharSequence read(File file, String encoding)
          Reads the contents of the specified file.
 CharSequence read(InputStream input, String encoding)
          Reads the contents of the specified stream.
 CharSequence read(URL url, String encoding)
          Reads the contents of the specified URL.
 Set<File> sortByDate(File[] files)
          Sorts an array of files based on their modification date.
 Set<File> sortByName(File[] files)
          Sorts an array of files based on their name.
 void write(File file, CharSequence contents, String encoding)
          Writes the contents of the specified file.
 void write(OutputStream output, CharSequence contents, String encoding)
          Writes the contents of the specified stream.
 
Methods inherited from class org.norther.tammi.spray.engine.tool.GlobalTool
clone, dispose, getContext, getContextToolFilter, getMBeanServer, isBound, nop, toString, valueBound, valueUnbound
 
Methods inherited from class org.norther.tammi.core.pool.PoolableSupport
disposed, recycled
 
Methods inherited from class org.norther.tammi.core.pool.RecyclableSupport
isDisposed, recycle
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.pool.Recyclable
isDisposed, recycle
 

Constructor Detail

PathTool

public PathTool()
Constructs a new tool.

Method Detail

deleteFile

public boolean deleteFile(File file)
Deletes a file or folder and its contents.

Parameters:
file - the file to delete.
Returns:
the true if successful, false otherwise.

findURL

public URL findURL(String path)
Finds a file or resource relative to the current root folder.

Parameters:
path - the pathname of the file.
Returns:
the found URL or null.

findURL

public URL findURL(String key,
                   String path)
Finds a file or resource relative to the specified key folder.

Parameters:
key - a folder key.
path - the pathname of the file.
Returns:
the found URL or null.

findURL

public URL findURL(String key,
                   String path,
                   Locale locale)
Finds a localized file or resource relative to the specified key folder.

Parameters:
key - a folder key.
path - the pathname of the file.
locale - the locale of the file.
Returns:
the found URL or null.

findURL

public URL findURL(String key,
                   String path,
                   Locale locale,
                   String variant)
Finds a localized file or resource relative to the specified key folder.

Parameters:
key - a folder key.
path - the pathname of the file.
locale - the locale of the file.
variant - an optional locale variant.
Returns:
the found URL or null.

findFile

public File findFile(String path)
Finds a file relative to the current root directory.

Parameters:
path - the pathname of the file.
Returns:
the found file.

findFile

public File findFile(String key,
                     String path)
Finds a file relative to the specified key directory.

Parameters:
key - the directory key.
path - the pathname of the file.
Returns:
the found file.

findFile

public File findFile(String key,
                     String path,
                     Locale locale)
Finds a localized file relative to the specified key directory.

Parameters:
key - the directory key.
path - the pathname of the file.
locale - the locale of the file.
Returns:
the found file.

findFile

public File findFile(String key,
                     String path,
                     Locale locale,
                     String variant)
Finds a localized file relative to the specified key directory.

Parameters:
key - the directory key.
path - the pathname of the file.
locale - the locale of the file.
variant - an optional locale variant.
Returns:
the found file.

findResource

public URL findResource(String path)
Finds a resource relative to the current root folder.

Parameters:
path - the pathname of the file.
Returns:
the found URL or null.

findResource

public URL findResource(String key,
                        String path)
Finds a resource relative to the specified key folder.

Parameters:
key - a folder key.
path - the pathname of the file.
Returns:
the found URL or null.

findResource

public URL findResource(String key,
                        String path,
                        Locale locale)
Finds a localized resource relative to the specified key folder.

Parameters:
key - a folder key.
path - the pathname of the file.
locale - the locale of the file.
Returns:
the found URL or null.

findResource

public URL findResource(String key,
                        String path,
                        Locale locale,
                        String variant)
Finds a localized resource relative to the specified key folder.

Parameters:
key - a folder key.
path - the pathname of the file.
locale - the locale of the file.
variant - an optional locale variant.
Returns:
the found URL or null.

sortByName

public Set<File> sortByName(File[] files)
Sorts an array of files based on their name.

Parameters:
files - an array of files.
Returns:
a set of sorted files.

sortByDate

public Set<File> sortByDate(File[] files)
Sorts an array of files based on their modification date.

Parameters:
files - an array of files.
Returns:
a set of sorted files.

read

public CharSequence read(File file,
                         String encoding)
Reads the contents of the specified file.

Parameters:
file - the file.
encoding - the encoding.
Returns:
the contents.

read

public CharSequence read(URL url,
                         String encoding)
Reads the contents of the specified URL.

Parameters:
url - the URL.
encoding - the encoding.
Returns:
the contents.

read

public CharSequence read(InputStream input,
                         String encoding)
Reads the contents of the specified stream.

Parameters:
input - the stream.
encoding - the encoding.
Returns:
the contents.

write

public void write(File file,
                  CharSequence contents,
                  String encoding)
Writes the contents of the specified file.

Parameters:
file - the file.
contents - the contents.
encoding - the encoding.

write

public void write(OutputStream output,
                  CharSequence contents,
                  String encoding)
Writes the contents of the specified stream.

Parameters:
output - the stream.
contents - the contents.
encoding - the encoding.


Copyright © 2004 The Norther Organization. All rights reserved.