org.olat.core.util.vfs
Class VFSManager

java.lang.Object
  extended by org.olat.core.util.vfs.VFSManager

public class VFSManager
extends java.lang.Object


Constructor Summary
VFSManager()
           
 
Method Summary
static java.lang.String appendNumberAtTheEndOfFilename(java.lang.String name, int number)
          Sticks together a new filename.
static boolean copyContent(java.io.InputStream inStream, VFSLeaf target)
          Copies the stream to the target leaf.
static boolean copyContent(java.io.InputStream inStream, VFSLeaf target, boolean closeInput)
          Copies the stream to the target leaf.
static boolean copyContent(VFSLeaf source, VFSLeaf target)
          Copies the content of the source to the target leaf.
static boolean exists(VFSItem item)
          Check if the file exist or not
static java.lang.String extractChild(java.lang.String path)
          Extract the next subfolder (e.g.
static VFSSecurityCallback findInheritedSecurityCallback(VFSItem vfsItem)
          Get the security callback which affects this item.
static VFSContainer findInheritingSecurityCallbackContainer(VFSItem vfsItem)
          Get the container which security callback affects this item.
static java.lang.Object[] findWritableRootFolderFor(VFSContainer rootDir, java.lang.String relFilePath)
          This method takes a VFSContainer and a relative path to a file that exists within this container.
static long getQuotaLeftKB(VFSContainer container)
          Check the quota usage on this VFSContainer.
static java.lang.String getRealPath(VFSContainer container)
          Returns the real path of the given VFS container.
static long getUsageKB(VFSItem vfsItem)
          Recursively traverse the container and sum up all leafs' sizes.
static boolean isContainerDescendantOrSelf(VFSContainer descendant, VFSContainer root)
          Check if descendant is indeed a descendant of root..
static boolean isSelfOrParent(VFSContainer descendant, VFSContainer parent)
          Check if descendant is child of parent or same as parent.
static Quota isTopLevelQuotaContainer(VFSContainer container)
          Check wether this container has a quota assigned to itself.
static VFSItem resolveFile(VFSContainer rootContainer, java.lang.String path)
           
static java.lang.String sanitizePath(java.lang.String path)
          Make sure we always have a path that starts with a "/".
static java.lang.String similarButNonExistingName(VFSContainer root, java.lang.String name)
          Returns a similar but non existing file name in root based on the given name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VFSManager

public VFSManager()
Method Detail

sanitizePath

public static java.lang.String sanitizePath(java.lang.String path)
Make sure we always have a path that starts with a "/".

Parameters:
path -
Returns:

extractChild

public static java.lang.String extractChild(java.lang.String path)
Extract the next subfolder (e.g. /foo/bla/gnu.txt -> "foo" PRE: a sanitized path, has a child

Parameters:
path -
Returns:
Next child.

isContainerDescendantOrSelf

public static boolean isContainerDescendantOrSelf(VFSContainer descendant,
                                                  VFSContainer root)
Check if descendant is indeed a descendant of root..

Parameters:
parent -
child -
Returns:

isSelfOrParent

public static boolean isSelfOrParent(VFSContainer descendant,
                                     VFSContainer parent)
Check if descendant is child of parent or same as parent.

Parameters:
descendant -
root -
Returns:

resolveFile

public static VFSItem resolveFile(VFSContainer rootContainer,
                                  java.lang.String path)
See Also:
org.olat.core.util.vfs.VFSItem#resolveFile(java.lang.String)

findInheritedSecurityCallback

public static VFSSecurityCallback findInheritedSecurityCallback(VFSItem vfsItem)
Get the security callback which affects this item. This searches up the path of parents to see wether it can find any callback. If no callback can be found, null is returned.

Parameters:
vfsItem -
Returns:

findInheritingSecurityCallbackContainer

public static VFSContainer findInheritingSecurityCallbackContainer(VFSItem vfsItem)
Get the container which security callback affects this item. This searches up the path of parents to see wether it can find any container with a callback. If no callback can be found, null is returned.

Parameters:
vfsItem -
Returns:

isTopLevelQuotaContainer

public static Quota isTopLevelQuotaContainer(VFSContainer container)
Check wether this container has a quota assigned to itself.

Parameters:
container -
Returns:
Quota if this container has a Quota assigned, null otherwise.

getQuotaLeftKB

public static long getQuotaLeftKB(VFSContainer container)
Check the quota usage on this VFSContainer. If no security callback is provided, this returns -1 (meaning no quota on this folder). Similarly, if no quota is defined, VFSSecurityCallback.NO_QUOTA_DEFINED will be returned to signal no quota on this container.

Parameters:
securityCallback -
container -
Returns:

getUsageKB

public static long getUsageKB(VFSItem vfsItem)
Recursively traverse the container and sum up all leafs' sizes.

Parameters:
container -
Returns:

getRealPath

public static java.lang.String getRealPath(VFSContainer container)
Returns the real path of the given VFS container. If the container is a named container, the delegate container is used. If the container is a merge source with a writable root container, then this one is used. In other cases the method returns null since the given container is not writable to any real file.

Parameters:
container -
Returns:
String representing an absolute path for this container

findWritableRootFolderFor

public static java.lang.Object[] findWritableRootFolderFor(VFSContainer rootDir,
                                                           java.lang.String relFilePath)
This method takes a VFSContainer and a relative path to a file that exists within this container. The method checks if the given container is a writable container that can be used e.g. by the HTML editor as a base directory where to store some things. If the method detects that this is not the case it works against the relative file path and checks each directory in the path.
The result will be an object array that contains the corrected container and the new relative path. If no writable container could be found NULL is returned.
Limitations: the method stops at least after 20 iterations returning NULL

Parameters:
rootDir - the container that should be checked
relFilePath - The valid file path within this container
Returns:
Object array that contains 1) a writable rootDir and 2) the corrected relFilePath that mathes to the new rootDir. Can be NULL if no writable root folder could be found.

similarButNonExistingName

public static java.lang.String similarButNonExistingName(VFSContainer root,
                                                         java.lang.String name)
Returns a similar but non existing file name in root based on the given name.

Parameters:
root -
name -
Returns:
A non existing name based on the given name in the root directory

appendNumberAtTheEndOfFilename

public static java.lang.String appendNumberAtTheEndOfFilename(java.lang.String name,
                                                              int number)
Sticks together a new filename. If there's a match with a common filename with extension, add the counter to the end of the filename before the extension. Else just add the counter to the end of the name. E.g.: hello.xml => hello1.xml where 1 is the counter

Parameters:
name -
number -
Returns:
The new name with the counter added

copyContent

public static boolean copyContent(VFSLeaf source,
                                  VFSLeaf target)
Copies the content of the source to the target leaf.

Parameters:
source -
target -
Returns:
True on success, false on failure

copyContent

public static boolean copyContent(java.io.InputStream inStream,
                                  VFSLeaf target)
Copies the stream to the target leaf.

Parameters:
source -
target -
Returns:
True on success, false on failure

copyContent

public static boolean copyContent(java.io.InputStream inStream,
                                  VFSLeaf target,
                                  boolean closeInput)
Copies the stream to the target leaf.

Parameters:
source -
target -
closeInput - set to false if it's a ZipInputStream
Returns:
True on success, false on failure

exists

public static boolean exists(VFSItem item)
Check if the file exist or not

Parameters:
item -
Returns: