|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.File
j2ee.permanent.storage.File
public class 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
File
,
Serialized FormField 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 |
---|
private java.lang.String location
private java.lang.String username
private java.lang.String password
private java.lang.String fileName
org.apache.webdav.lib.WebdavResource wdr
Constructor Detail |
---|
public File(java.lang.String fileName)
Standard constructor for the class. Creates an instance of the java.io.File class
fileName
- The name of the fileMethod Detail |
---|
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
java.io.IOException
- if something goes wrong during IO
java.util.MissingResourceException
- if the dfs.properties can't be found or have bad/missing informationpublic 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
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 usernamepassword
- The user's password
java.io.IOException
- if something goes wrong during the saving of the file to the DFS Webdav serverpublic 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
java.io.IOException
- if something goes wrong during retrieval
MissinResourceException
- if the dfs.properties file can't be found
java.util.MissingResourceException
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
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 usernamepassword
- the user's password
java.io.IOException
- if something goes wrong during retrievalprivate 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
java.util.MissingResourceException
- if dfs.properties can't be found in the containerprivate 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
java.io.IOException
- if an IO error occursprivate 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
java.io.IOException
- if an IO error occursprivate 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)
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
s
- The location that should be parsed
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |