net.sourceforge.pavlov.user
Class LocalUserFile

java.lang.Object
  extended by net.sourceforge.pavlov.user.LocalUserFile
All Implemented Interfaces:
UserFile

public final class LocalUserFile
extends Object
implements UserFile

A user file that resides on the same computer the application is running on.


Constructor Summary
LocalUserFile(String userName)
          Creates a new LocalUserFile instance named for this user in the subdirectory "users/".
LocalUserFile(String userName, String userDir)
          Creates a new LocalUserFile named for the user in the given directory.
 
Method Summary
 boolean canRead()
          Returns true if the file exists and is readable.
 boolean canWrite()
          If the file exists, return if it is writable.
 boolean exists()
          Returns true if the file exists and is readable.
protected  String getFileName(String userName)
          Converts the userDir and the userName into a file path.
 User read(String password)
          Attempts to read the given user file.
 void save(User user)
          Saves the given user information to this file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalUserFile

public LocalUserFile(String userName,
                     String userDir)
              throws IOException
Creates a new LocalUserFile named for the user in the given directory.

Parameters:
userName - a String value
newUserDir - a String value
Throws:
IOException - if an error occurs

LocalUserFile

public LocalUserFile(String userName)
              throws IOException
Creates a new LocalUserFile instance named for this user in the subdirectory "users/".

Parameters:
userName - a String value
Throws:
IOException - if an error occurs
Method Detail

exists

public boolean exists()
Returns true if the file exists and is readable.

Specified by:
exists in interface UserFile
Returns:
a boolean value

save

public void save(User user)
          throws FileNotFoundException,
                 IOException
Saves the given user information to this file.

Specified by:
save in interface UserFile
Parameters:
user - an User value
Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

read

public User read(String password)
          throws SAXException,
                 FileNotFoundException,
                 IOException
Attempts to read the given user file. Will not return the User if the password is incorrect.

Specified by:
read in interface UserFile
Parameters:
password - a String value
Returns:
an User value
Throws:
SAXException - if an error occurs
FileNotFoundException - if an error occurs
IOException - if an error occurs

canRead

public boolean canRead()
Returns true if the file exists and is readable.

Specified by:
canRead in interface UserFile
Returns:
a boolean value

canWrite

public boolean canWrite()
If the file exists, return if it is writable. If not, create it, and try to write to it.

Specified by:
canWrite in interface UserFile
Returns:
a boolean value

getFileName

protected String getFileName(String userName)
Converts the userDir and the userName into a file path.

Parameters:
userName - a String value
Returns:
a String value