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:
jdoucy, ymombrun - Cassidian

Field Summary
protected  java.io.File currentFolder
           
protected  int filePerFolder
           
protected  java.lang.String filePrefix
           
protected  org.apache.commons.logging.Log log
           
protected  java.io.File pathToFS
           
protected  java.lang.String repositoryID
           
protected  org.ow2.weblab.core.extended.jaxb.WebLabMarshaller wlm
           
 
Constructor Summary
FileRepository(java.lang.String pathToTheRepository, int filePerFolder, java.lang.String repositoryID, java.lang.String filePrefix)
           
 
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  void createNewSubFolder()
          Generates a new and unique folder value.
 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  java.io.File initPathToFS(java.lang.String pathToTheRepository)
           
protected  org.ow2.weblab.core.model.Resource loadFile(java.lang.String fileName)
          Load the resource corresponding to the file name
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)
           
protected  void setCurrentFolder(java.io.File currentFolder)
           
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 final java.io.File pathToFS

filePrefix

protected final java.lang.String filePrefix

repositoryID

protected final java.lang.String repositoryID

filePerFolder

protected final int filePerFolder

log

protected final org.apache.commons.logging.Log log

currentFolder

protected java.io.File currentFolder

wlm

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

FileRepository

public FileRepository(java.lang.String pathToTheRepository,
                      int filePerFolder,
                      java.lang.String repositoryID,
                      java.lang.String filePrefix)
               throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getResource

public org.ow2.weblab.core.model.Resource getResource(java.lang.String uri)
                                               throws org.ow2.weblab.core.extended.exception.WebLabCheckedException,
                                                      java.io.FileNotFoundException
Parameters:
uri - The URI of the resource to retrieve
Returns:
The Resource
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException - If the resource is not found
java.io.FileNotFoundException

saveResource

public java.lang.String saveResource(org.ow2.weblab.core.model.Resource resource)
                              throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Parameters:
resource - The resource to save
Returns:
The new (might be identical if the resource has already been save in this repo)
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:
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,
                                                               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

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

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

initPathToFS

protected java.io.File initPathToFS(java.lang.String pathToTheRepository)
                             throws java.io.IOException
Parameters:
pathToTheRepository - The path to the root folder of the repository
Returns:
A File on this folder
Throws:
java.io.IOException - If the folder cannot be created

createNewSubFolder

protected void createNewSubFolder()
Generates a new and unique folder value.


setCurrentFolder

protected void setCurrentFolder(java.io.File currentFolder)


Copyright © 2004-2012. All Rights Reserved.