Project Wonder 5.0

er.extensions.foundation
Class ERXFileRepository

java.lang.Object
  extended by er.extensions.foundation.ERXFileRepository

public class ERXFileRepository
extends java.lang.Object

Allows you to store a large amount of files and folders without the hassles of directory size limitations. The files are stored by an abstract "key" which is by default a ERXRandomGUID.
It uses a factory to create the folder structure under the root directory. With the default factory there will be directories for the first two characters and under these again directories for the next two characters of the GUID.

Author:
ak (original version by Dominik Westner)

Nested Class Summary
static class ERXFileRepository.DefaultFactory
          Default implementation of the Factory interface.
static interface ERXFileRepository.Factory
           
 
Field Summary
protected  ERXFileRepository.Factory _factory
           
protected  java.io.File _root
           
 
Constructor Summary
protected ERXFileRepository(java.io.File root, ERXFileRepository.Factory factory)
          Private constructor, as we use the factory methods to create instances.
 
Method Summary
static ERXFileRepository addRepository(java.lang.String name, ERXFileRepository repository)
          Adds an existing repository under the given name.
static ERXFileRepository addRepository(java.lang.String name, java.io.File root)
          Adds a repository under the given name and the given root directory that uses the default factory.
static ERXFileRepository addRepository(java.lang.String name, java.io.File root, ERXFileRepository.Factory factory)
          Adds a repository under the given name and the given root directory that uses the given factory.
 java.io.File createFile()
          Returns a new file in the repository.
 java.io.File getFile(java.lang.String id)
          Returns a file for a given id
 java.io.File getRoot()
          Returns the root directory for the repository.
 boolean hasFile(java.lang.String id)
          Returns true if the file is present in the repository and also exists.
static ERXFileRepository respository(java.lang.String name)
          Returns the repository that is registered under the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_root

protected java.io.File _root

_factory

protected final ERXFileRepository.Factory _factory
Constructor Detail

ERXFileRepository

protected ERXFileRepository(java.io.File root,
                            ERXFileRepository.Factory factory)
Private constructor, as we use the factory methods to create instances.

Parameters:
root -
factory -
Method Detail

createFile

public java.io.File createFile()
Returns a new file in the repository. As you can also create directories it does not really create the file, only the path to the file. You can use file.getName() to get at the GUID which is the key to the file.

Returns:
the new file

getFile

public java.io.File getFile(java.lang.String id)
Returns a file for a given id

Parameters:
id - the id of the file
Returns:
a file for the given id

hasFile

public boolean hasFile(java.lang.String id)
Returns true if the file is present in the repository and also exists.

Parameters:
id - the id of the file
Returns:
true if the file exists in the repository

getRoot

public java.io.File getRoot()
Returns the root directory for the repository.

Returns:
the root directory for the repository

respository

public static ERXFileRepository respository(java.lang.String name)
Returns the repository that is registered under the given name.

Parameters:
name - the name under which the respository is registered
Returns:
the repository that is registered under the given name or null

addRepository

public static ERXFileRepository addRepository(java.lang.String name,
                                              java.io.File root)
Adds a repository under the given name and the given root directory that uses the default factory.

Parameters:
name - the name under which the repository should be added
root - the root directory of the repository
Returns:
the new repository

addRepository

public static ERXFileRepository addRepository(java.lang.String name,
                                              java.io.File root,
                                              ERXFileRepository.Factory factory)
Adds a repository under the given name and the given root directory that uses the given factory.

Parameters:
name - the name under which the repository should be added
root - the root directory of the repository
factory - the factory to determine the directory from the id for this repository
Returns:
the new repository

addRepository

public static ERXFileRepository addRepository(java.lang.String name,
                                              ERXFileRepository repository)
Adds an existing repository under the given name.

Parameters:
name - the name under which the repository should be added
repository - the repository to register
Returns:
the repository

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.