org.ow2.weblab.repository.file
Class FileRepository

java.lang.Object
  extended by org.ow2.weblab.repository.file.FileRepository

public class FileRepository
extends java.lang.Object

Simple implementation of a file repository Save each resource to a File.

Author:
Jérémie Doucy, EADS DS IPCC

Field Summary
protected  java.io.File currentFolder
           
protected static int DEFAULT_FILE_PER_FOLDER
           
protected static java.lang.String DEFAULT_FILE_PREFIX
           
protected static java.lang.String DEFAULT_REPO_ID
           
protected  int filePerFolder
           
protected  java.lang.String filePrefix
           
protected  java.io.File pathToFS
           
protected  java.lang.String repositoryID
           
protected  org.ow2.weblab.core.extended.jaxb.WebLabMarshaller wlm
           
 
Constructor Summary
FileRepository()
           
 
Method Summary
protected  org.ow2.weblab.core.model.Resource changeUri(org.ow2.weblab.core.model.Resource res)
          check if the resource is already present if not create a unique wlri and change it in the resource
protected  java.io.File createNewFolder()
          Generates a new and unique folder value.
 java.io.File getCurrentFolder()
           
 int getFilePerFolder()
           
 java.lang.String getFilePrefix()
           
 java.io.File getPathToFS()
           
 java.lang.String getRepositoryID()
           
 org.ow2.weblab.core.model.Resource getResource(java.lang.String uri)
           
protected  org.ow2.weblab.core.model.Resource getResourceInside(org.ow2.weblab.core.model.Resource res, java.lang.String uri)
          recursive route which return resource corresponding to the uri
protected  org.ow2.weblab.core.model.Resource getResourceInside(org.ow2.weblab.core.model.Resource res, java.lang.String uri, org.ow2.weblab.core.model.Resource newRes)
          recursive route which replace newRes in res
protected  org.ow2.weblab.core.model.Resource getResourceInside(org.ow2.weblab.core.model.Resource res, java.lang.String uri, org.ow2.weblab.core.model.Resource newRes, org.ow2.weblab.core.model.Resource father)
           
protected  java.lang.String getUniqueResource()
          Use it to get an unique resource identifier
protected  org.ow2.weblab.core.model.Resource loadFile(java.lang.String fileName)
          load the resource corresponding to the file name
static FileRepository newInstance()
           
static FileRepository newInstance(java.net.URL fileUrl)
           
protected  void replaceResource(org.ow2.weblab.core.model.Resource father, org.ow2.weblab.core.model.Resource oldRes, org.ow2.weblab.core.model.Resource newRes)
           
protected  org.ow2.weblab.core.model.Resource replaceUri(org.ow2.weblab.core.model.Resource res, java.lang.String uri)
          Replace the old uri with the new one on a resource
 java.lang.String saveResource(org.ow2.weblab.core.model.Resource resource)
           
 void setCurrentFolder(java.io.File currentFolder)
           
 void setFilePerFolder(int filePerFolder)
           
 void setFilePrefix(java.lang.String filePrefix)
           
 void setPathToFS(java.io.File pathToFS)
          Set the path to the folder file System Creates it if not exist
 void setPathToFS(java.lang.String pathToFS)
          Set the path to the folder file System (calling setPathToFS(File)) Creates it if not exist
 void setRepositoryID(java.lang.String repositoryID)
           
protected  void writeFile(RepoRI wlRi, org.ow2.weblab.core.model.Resource res)
          Write the resource to the file corresponding to the wlRi
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pathToFS

protected java.io.File pathToFS

DEFAULT_REPO_ID

protected static final java.lang.String DEFAULT_REPO_ID
See Also:
Constant Field Values

repositoryID

protected java.lang.String repositoryID

DEFAULT_FILE_PREFIX

protected static final java.lang.String DEFAULT_FILE_PREFIX
See Also:
Constant Field Values

filePrefix

protected java.lang.String filePrefix

DEFAULT_FILE_PER_FOLDER

protected static final int DEFAULT_FILE_PER_FOLDER
See Also:
Constant Field Values

filePerFolder

protected int filePerFolder

currentFolder

protected java.io.File currentFolder

wlm

protected final org.ow2.weblab.core.extended.jaxb.WebLabMarshaller wlm
Constructor Detail

FileRepository

public FileRepository()
Method Detail

getResource

public org.ow2.weblab.core.model.Resource getResource(java.lang.String uri)
                                               throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

saveResource

public java.lang.String saveResource(org.ow2.weblab.core.model.Resource resource)
                              throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getResourceInside

protected org.ow2.weblab.core.model.Resource getResourceInside(org.ow2.weblab.core.model.Resource res,
                                                               java.lang.String uri)
                                                        throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
recursive route which return resource corresponding to the uri

Parameters:
res - main resource
uri - uri to find
Returns:
res corresponding to the uri
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getResourceInside

protected org.ow2.weblab.core.model.Resource getResourceInside(org.ow2.weblab.core.model.Resource res,
                                                               java.lang.String uri,
                                                               org.ow2.weblab.core.model.Resource newRes)
                                                        throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
recursive route which replace newRes in res

Parameters:
res - main resource
uri - uri to find (the same as in newRes)
newRes - new resource which going to replace the funded one
Returns:
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getResourceInside

protected org.ow2.weblab.core.model.Resource getResourceInside(org.ow2.weblab.core.model.Resource res,
                                                               java.lang.String uri,
                                                               org.ow2.weblab.core.model.Resource newRes,
                                                               org.ow2.weblab.core.model.Resource father)
                                                        throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

replaceResource

protected void replaceResource(org.ow2.weblab.core.model.Resource father,
                               org.ow2.weblab.core.model.Resource oldRes,
                               org.ow2.weblab.core.model.Resource newRes)
                        throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

loadFile

protected org.ow2.weblab.core.model.Resource loadFile(java.lang.String fileName)
                                               throws org.ow2.weblab.core.extended.exception.WebLabCheckedException,
                                                      java.io.FileNotFoundException
load the resource corresponding to the file name

Parameters:
fileName -
Returns:
the loaded resource
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException
java.io.FileNotFoundException

setPathToFS

public void setPathToFS(java.io.File pathToFS)
                 throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Set the path to the folder file System Creates it if not exist

Parameters:
pathToFS - path to the folder file system
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

changeUri

protected org.ow2.weblab.core.model.Resource changeUri(org.ow2.weblab.core.model.Resource res)
                                                throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
check if the resource is already present if not create a unique wlri and change it in the resource

Parameters:
res - resource
Returns:
new unique wlri
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getUniqueResource

protected java.lang.String getUniqueResource()
Use it to get an unique resource identifier

Returns:
An unique resource id

createNewFolder

protected java.io.File createNewFolder()
Generates a new and unique folder value.

Returns:
the new folder

replaceUri

protected org.ow2.weblab.core.model.Resource replaceUri(org.ow2.weblab.core.model.Resource res,
                                                        java.lang.String uri)
                                                 throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Replace the old uri with the new one on a resource

Parameters:
res - the resource to be changed
newUri - the new uri
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

writeFile

protected void writeFile(RepoRI wlRi,
                         org.ow2.weblab.core.model.Resource res)
                  throws java.io.FileNotFoundException,
                         org.ow2.weblab.core.extended.exception.WebLabCheckedException
Write the resource to the file corresponding to the wlRi

Parameters:
wlRi - resource ri
res - resource to write
Throws:
java.io.FileNotFoundException
org.ow2.weblab.core.extended.exception.WebLabCheckedException

setPathToFS

public void setPathToFS(java.lang.String pathToFS)
                 throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Set the path to the folder file System (calling setPathToFS(File)) Creates it if not exist

Parameters:
pathToFS - String containing the path to the folder file system
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getRepositoryID

public java.lang.String getRepositoryID()

setRepositoryID

public void setRepositoryID(java.lang.String repositoryID)

getFilePrefix

public java.lang.String getFilePrefix()

setFilePrefix

public void setFilePrefix(java.lang.String filePrefix)

getPathToFS

public java.io.File getPathToFS()

newInstance

public static FileRepository newInstance()
                                  throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

newInstance

public static FileRepository newInstance(java.net.URL fileUrl)
                                  throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getFilePerFolder

public int getFilePerFolder()

setFilePerFolder

public void setFilePerFolder(int filePerFolder)

getCurrentFolder

public java.io.File getCurrentFolder()

setCurrentFolder

public void setCurrentFolder(java.io.File currentFolder)


Copyright © 2004-2010. All Rights Reserved.