pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.vfs
Class VirtualFileSystem

java.lang.Object
  extended by org.torweg.pulse.vfs.VirtualFileSystem

public final class VirtualFileSystem
extends java.lang.Object

the VirtualFileSystem is a singleton providing access to VirtualFiles.

The VirtualFileSystem actually uses VFSProviders to access the individual VirtualFiles. The VirtualFileSystem consists of two stores: a private and a public store. VirtualFiles stored in the public store will also be available via HTTP. Moreover, each store may have a different VFSProvider.

A VirtualFile is identified via its URI. URIs for VirtualFiles must contain a scheme and a path. The scheme may either be public for public files, or private for private files. The URIs must not contain authority, host or port information as well as fragments or queries.

Example for a URI identifying a private file file.txt in a top level directory directory:
private:///directory/file.txt

Example for a URI identifying a public file something.txt in the root directory:
public:///something.txt

Version:
$Revision: 2071 $
Author:
Thomas Weber

Method Summary
 boolean delete(VirtualFile file)
          deletes the given VirtualFile and purges it from the VirtualFileSystems full text search index.
protected  boolean distribute(VirtualFile file, User user)
          distributes the VirtualFile.
 boolean exists(java.net.URI uri)
          returns whether the URI identifies an existing object.
 VirtualFile fromHttpURI(java.net.URI uri)
          checks if the given HTTP URI denotes a VirtualFile.
 java.util.Collection<DeadProperty> getAllDeadProperties()
          returns prototypes of all known dead properties.
 java.util.Collection<DeadProperty> getAllDeadProperties(org.hibernate.Session s)
          returns prototypes of all known dead properties using the given session.
 long getCreated(java.net.URI uri, User user)
          returns the creation date of the VirtualFile identified by the given URI.
 long getFileSize(java.net.URI uri, User user)
          returns the size of the VirtualFile identified by the given URI.
 java.net.URI getHttpURI(VirtualFile file)
          resolves the HTTP path to the given VirtualFile.
 VFInputStream getInputStream(VirtualFile file)
          provides an InputStream to read the VirtualFile .
static VirtualFileSystem getInstance()
          provides access to the VirtualFileSystem.
 long getLastModified(java.net.URI uri, User user)
          returns the last modification date of the VirtualFile identified by the given URI.
 VFOutputStream getOutputStream(VirtualFile file, User user)
          provides an OutputStream to write the VirtualFile.
 java.lang.String getPrivateHTTPBase()
          return the private HTTP base URI.
protected  VFSProvider getPrivateProvider()
          returns the private provider.
protected  VFSProvider getProvider(java.net.URI uri)
          returns the VFSProvider for the given URI.
 VFSProvider getProvider(VirtualFile f)
          returns the VFSProvider for the given VirtualFile.
 java.lang.String getPublicHTTPBase()
          return the public HTTP base URI.
protected  VFSProvider getPublicProvider()
          returns the public provider.
 VirtualFile getVirtualFile(java.lang.String path, User user)
          returns a VirtualFile for the given path.
 VirtualFile getVirtualFile(java.net.URI uri, User user)
          returns a VirtualFile for the given path.
protected  void index(VirtualFile file)
          indexes the given VirtualFile for full text search.
static VirtualFileSystem init(org.jdom.Element conf)
          initialises and configures the VirtualFileSystem.
 boolean isCollection(java.net.URI uri)
          returns whether the URI identifies a collection.
 boolean isResource(java.net.URI uri)
          returns whether the URI identifies a resource.
protected  VirtualFile loadVirtualFile(java.net.URI path)
          tries to load a VirtualFile for the given path.
 VirtualFile loadVirtualFile(java.net.URI path, org.hibernate.Session s)
          tries to load a VirtualFile for the given path.
protected  void markModified(VirtualFile file, User user)
          updates the modification tokens for the file.
 boolean mkdir(VirtualFile dir, User user)
          creates a new directory.
protected  void setPrivateProvider(VFSProvider p)
           
protected  void setPublicProvider(VFSProvider p)
           
 void updateFileSize(VirtualFile file)
          updates the file size for the given file but does not save the changes in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadVirtualFile

protected VirtualFile loadVirtualFile(java.net.URI path)
                               throws java.io.IOException
tries to load a VirtualFile for the given path.

Utility method for an atomic load.

Parameters:
path - the path
Returns:
the VirtualFile or null, if no such file exists.
Throws:
java.io.IOException - on errors loading the file

loadVirtualFile

public VirtualFile loadVirtualFile(java.net.URI path,
                                   org.hibernate.Session s)
                            throws java.io.IOException
tries to load a VirtualFile for the given path.

Parameters:
path - the path
s - the session with current transaction
Returns:
the VirtualFile or null, if no such file exists.
Throws:
java.io.IOException - on errors loading the file

getPrivateProvider

protected VFSProvider getPrivateProvider()
returns the private provider.

Returns:
the private provider

setPrivateProvider

protected void setPrivateProvider(VFSProvider p)
Parameters:
p - the private provider to set

getPublicProvider

protected VFSProvider getPublicProvider()
returns the public provider.

Returns:
the public provider

setPublicProvider

protected void setPublicProvider(VFSProvider p)
Parameters:
p - the public provider to set

getProvider

protected VFSProvider getProvider(java.net.URI uri)
returns the VFSProvider for the given URI.

Parameters:
uri - the URI
Returns:
the provider or null, if no such provider exists

getProvider

public VFSProvider getProvider(VirtualFile f)
returns the VFSProvider for the given VirtualFile.

Parameters:
f - the file
Returns:
the provider

markModified

protected void markModified(VirtualFile file, User user)
updates the modification tokens for the file.

Parameters:
file - the file
user - the user

distribute

protected boolean distribute(VirtualFile file, User user)
distributes the VirtualFile.

Parameters:
file - the VirtualFile to be distributed
user - the user who modified the file
Returns:
true if the distribution has been successful; otherwise false

index

protected void index(VirtualFile file)
indexes the given VirtualFile for full text search.

This method is called upon VFOutputStream.close() to start the indexing.

TODO: has to be implemented yet

Parameters:
file - the file to be indexed

getInputStream

public VFInputStream getInputStream(VirtualFile file)
                             throws VFIOException
provides an InputStream to read the VirtualFile .

Parameters:
file - the VirtualFile to be read from the InputStream
Returns:
an InputStream to read from the VirtualFile
Throws:
VFIOException - on errors aquiring the InputStream

getOutputStream

public VFOutputStream getOutputStream(VirtualFile file, User user)
                               throws VFIOException
provides an OutputStream to write the VirtualFile.

Parameters:
file - the VirtualFile to be written to by the OutputStream
user - the user used to access the file
Returns:
an OutputStream to read from the VirtualFile
Throws:
VFIOException - on errors aquiring the OutputStream

updateFileSize

public void updateFileSize(VirtualFile file)
updates the file size for the given file but does not save the changes in the database.

Parameters:
file - the file

delete

public boolean delete(VirtualFile file)
deletes the given VirtualFile and purges it from the VirtualFileSystems full text search index.

Parameters:
file - the VirtualFile to be deleted
Returns:
true, if successful. Otherwise false.

getInstance

public static VirtualFileSystem getInstance()
provides access to the VirtualFileSystem.

Returns:
the VirtualFileSystem singleton

getVirtualFile

public VirtualFile getVirtualFile(java.lang.String path, User user)
                           throws java.io.IOException,
                                  java.net.URISyntaxException
returns a VirtualFile for the given path.

Parameters:
path - the path locating the VirtualFile
user - the User to be used for access checks
Returns:
a VirtualFile for the given path.
Throws:
java.io.IOException - on errors accessing the VirtualFile
java.net.URISyntaxException - on errors parsing the URI

getVirtualFile

public VirtualFile getVirtualFile(java.net.URI uri, User user)
                           throws java.io.IOException
returns a VirtualFile for the given path.

Parameters:
uri - the path locating the VirtualFile
user - the User to be used for access checks
Returns:
a VirtualFile for the given path.
Throws:
java.io.IOException - on errors accessing the VirtualFile

getAllDeadProperties

public java.util.Collection<DeadProperty> getAllDeadProperties()
returns prototypes of all known dead properties.

Returns:
prototypes of all known dead properties

getAllDeadProperties

public java.util.Collection<DeadProperty> getAllDeadProperties(org.hibernate.Session s)
returns prototypes of all known dead properties using the given session.

It is assumed that the transaction is controlled by the caller.

Parameters:
s - the HibernateTM session
Returns:
prototypes of all known dead properties

getHttpURI

public java.net.URI getHttpURI(VirtualFile file)
resolves the HTTP path to the given VirtualFile.

Parameters:
file - the VirtualFile to be resolved
Returns:
the URI to the VirtualFile or null, if the VirtualFile is private

fromHttpURI

public VirtualFile fromHttpURI(java.net.URI uri)
checks if the given HTTP URI denotes a VirtualFile.

Parameters:
uri - the HTTP uri
Returns:
the VirtualFile or null, if the URI does not denote a VirtualFile

getFileSize

public long getFileSize(java.net.URI uri, User user)
                 throws java.io.IOException
returns the size of the VirtualFile identified by the given URI.

Parameters:
uri - the uri
user - the user
Returns:
the size
Throws:
java.io.IOException - on errors

getCreated

public long getCreated(java.net.URI uri, User user)
                throws java.io.IOException
returns the creation date of the VirtualFile identified by the given URI.

Parameters:
uri - the uri
user - the user
Returns:
the creation date
Throws:
java.io.IOException - on errors

getLastModified

public long getLastModified(java.net.URI uri, User user)
                     throws java.io.IOException
returns the last modification date of the VirtualFile identified by the given URI.

Parameters:
uri - the uri
user - the user
Returns:
the last modification date
Throws:
java.io.IOException - on errors

isCollection

public boolean isCollection(java.net.URI uri)
                     throws java.io.IOException
returns whether the URI identifies a collection.

Parameters:
uri - the URI
Returns:
true, if and only if the URI identifies a collection. Otherwise false.
Throws:
java.io.IOException - on errors

isResource

public boolean isResource(java.net.URI uri)
                   throws java.io.IOException
returns whether the URI identifies a resource.

Parameters:
uri - the URI
Returns:
true, if and only if the URI identifies a resource. Otherwise false.
Throws:
java.io.IOException - on errors

exists

public boolean exists(java.net.URI uri)
               throws java.io.IOException
returns whether the URI identifies an existing object.

Parameters:
uri - the URI
Returns:
true, if and only if the URI identifies an existing object. Otherwise false.
Throws:
java.io.IOException - on errors

mkdir

public boolean mkdir(VirtualFile dir, User user)
              throws VFIOException
creates a new directory.

Parameters:
dir - the directory to be created
user - the user who creates the directory
Returns:
true, if and only if the directory has been created
Throws:
VFIOException - on errors creating the directory

getPublicHTTPBase

public java.lang.String getPublicHTTPBase()
return the public HTTP base URI.

Returns:
the public HTTP base URI

getPrivateHTTPBase

public java.lang.String getPrivateHTTPBase()
return the private HTTP base URI.

Returns:
the private HTTP base URI

init

public static VirtualFileSystem init(org.jdom.Element conf)
initialises and configures the VirtualFileSystem.

Parameters:
conf - the configuration element
Returns:
the configured singleton