j2ee.permanent.storage
Class File

java.lang.Object
  extended by java.io.File
      extended by j2ee.permanent.storage.File
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class File
extends java.io.File

This class provides methods to connect to a given location (provided by a .properties-file) at the DFS file system at CERN through applications deployed to the J2EE Public Service as a WAR-file

It works under the assumption that a dfs.properties file with correct location/login information has been placed by the application owner in /WEB-INF/classes/ directory in the WAR-file. The class can also be used without having a property file in the WAR-file, and instead using the methods below that provides the location/login information directly through the input parameters of the save/retrieve-methods

How to use this class:

To retrieve or save a file using the save(String location, String username, String password) or the retrieve(String location, String username, String password) you only have to specify the correct input parameters and it should work.

To use the save() or the retrieve() method, you have to place a dfs.properties file inside the /WEB-INF/classes directory of your WAR-file. The dfs.properties file has to have the following keys

It is very important that the key dfs.location in the dfs.properties file is correct, otherwise it will not work

See Also:
File, Serialized Form

Field Summary
private  java.lang.String fileName
           
private  java.lang.String location
           
private  java.lang.String password
           
private  java.lang.String username
           
(package private)  org.apache.webdav.lib.WebdavResource wdr
           
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
File(java.lang.String fileName)
          Standard constructor for the class.
 
Method Summary
private  boolean getLocationInfo()
          This method retrieves the dfs.properties file and populates the member variables that provide the location/login information for the DFS Webdav Connection
private  java.lang.String parse()
          This methods removes (if present) a '/' from the end of the filename.
private  java.lang.String parseLocation(java.lang.String s)
          This method checks if a '/' is present at the start and at the end of the location given in the dfs.properties or through the method call, and removes them if they are there
 boolean retrieve()
          This method retrieves a file from the DFS file system location and places it in the default temporary directory at the J2EEPS container
 boolean retrieve(java.lang.String location, java.lang.String username, java.lang.String password)
          This method is an alternative method where the user don't have to include a dfs.properties-file in his/her's WAR-file.
private  boolean retrieveFile()
          This method creates an HttpsURL to the location at DFS and connects a WebdavResource to this url.
 boolean save()
          Method that saves the given file and its content to the DFS system.
 boolean save(java.lang.String location, java.lang.String username, java.lang.String password)
          This method can be used if the user does not want to provide a dfs.properties file.
private  boolean saveFile()
          This method creates a HttpsURL to the DFS lcoation and then tries to establish a WebdavResource by using the url.
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

location

private java.lang.String location

username

private java.lang.String username

password

private java.lang.String password

fileName

private java.lang.String fileName

wdr

org.apache.webdav.lib.WebdavResource wdr
Constructor Detail

File

public File(java.lang.String fileName)

Standard constructor for the class. Creates an instance of the java.io.File class

Parameters:
fileName - The name of the file
Method Detail

save

public boolean save()
             throws java.io.IOException,
                    java.util.MissingResourceException

Method that saves the given file and its content to the DFS system.

This method checks whether it can find the dfs.properties file and performs the save (through the saveFile()-method) if it can, otherwise it returns false or an exception describing what went wrong

Returns:
true if file is successfully saved, false otherwise
Throws:
java.io.IOException - if something goes wrong during IO
java.util.MissingResourceException - if the dfs.properties can't be found or have bad/missing information

save

public boolean save(java.lang.String location,
                    java.lang.String username,
                    java.lang.String password)
             throws java.io.IOException

This method can be used if the user does not want to provide a dfs.properties file.

Instead, the location/login information can be given as parameters to this method and it will directly try to save the file

Parameters:
location - the location at dfs, of the form /dfs/Users/first-letter-of-username/username/directory-of-choice, e.g. /dfs/Users/t/testuser/J2EEPS/
username - The user's username
password - The user's password
Returns:
true if file is successfully saved, false or an IOexception otherwise
Throws:
java.io.IOException - if something goes wrong during the saving of the file to the DFS Webdav server

retrieve

public boolean retrieve()
                 throws java.io.IOException,
                        java.util.MissingResourceException

This method retrieves a file from the DFS file system location and places it in the default temporary directory at the J2EEPS container

If it can find the dfs.properties file, then it tries to connect and retrieve the specified file from the DFS location given in dfs.properties

Returns:
true if the file could be retrieved
Throws:
java.io.IOException - if something goes wrong during retrieval
MissinResourceException - if the dfs.properties file can't be found
java.util.MissingResourceException

retrieve

public boolean retrieve(java.lang.String location,
                        java.lang.String username,
                        java.lang.String password)
                 throws java.io.IOException

This method is an alternative method where the user don't have to include a dfs.properties-file in his/her's WAR-file.

Instead, by giving the location/login information through the input parameters, this method will try to retrieve the file from DFS

Parameters:
location - the location at dfs, of the form /dfs/Users/first-letter-of-username/username/directory-of-choice, e.g. /dfs/Users/t/testuser/J2EEPS/
username - the user's username
password - the user's password
Returns:
true if file is successfully retrieved
Throws:
java.io.IOException - if something goes wrong during retrieval

getLocationInfo

private boolean getLocationInfo()
                         throws java.util.MissingResourceException

This method retrieves the dfs.properties file and populates the member variables that provide the location/login information for the DFS Webdav Connection

Returns:
true if everything goes ok, throws an MissinResourceException otherwise
Throws:
java.util.MissingResourceException - if dfs.properties can't be found in the container

retrieveFile

private boolean retrieveFile()
                      throws java.io.IOException

This method creates an HttpsURL to the location at DFS and connects a WebdavResource to this url.

It then executes the getMethod() to put the file in the default temporary directory for the container

Returns:
true if everyting goes okay, IOException otherwise
Throws:
java.io.IOException - if an IO error occurs

saveFile

private boolean saveFile()
                  throws java.io.IOException

This method creates a HttpsURL to the DFS lcoation and then tries to establish a WebdavResource by using the url.

If this is successfull, the putMethod()- are used to save the file to the WebdavResource at DFS

Returns:
true if the file is saved, exception throwed otherwise
Throws:
java.io.IOException - if an IO error occurs

parse

private java.lang.String parse()

This methods removes (if present) a '/' from the end of the filename. It also takes away the directory information from the filename (e.g. /home/user/example.file/ will get parsed to only example.file)

Returns:
the parsed string

parseLocation

private java.lang.String parseLocation(java.lang.String s)

This method checks if a '/' is present at the start and at the end of the location given in the dfs.properties or through the method call, and removes them if they are there

Parameters:
s - The location that should be parsed
Returns:
the parsed location without '/' at the start and end