org.liquidsite.core.content
Class PersistentObject

java.lang.Object
  extended byorg.liquidsite.core.content.PersistentObject
Direct Known Subclasses:
Content, Domain, Group, Host, Lock, PermissionList, User

public abstract class PersistentObject
extends java.lang.Object

A persistent object.


Field Summary
protected static java.lang.String BINDERS
          The ASCII binding separator characters.
protected static java.lang.String LOWER_CASE
          The ASCII lower-case characters.
protected static java.lang.String NUMBERS
          The ASCII numerical characters.
protected static java.lang.String UPPER_CASE
          The ASCII upper-case characters.
 
Constructor Summary
protected PersistentObject(ContentManager manager, boolean persistent)
          Creates a new persistent object.
 
Method Summary
protected static java.util.HashMap decodeMap(java.lang.String str)
          Decodes a string into a map.
 void delete(DataSource src, User user)
          Deletes this object from the database.
 void delete(User user)
          Deletes this object from the database.
protected abstract  void doDelete(DataSource src, User user)
          Deletes the object data from the database.
protected abstract  void doInsert(DataSource src, User user, boolean restore)
          Inserts the object data into the database.
protected abstract  void doUpdate(DataSource src, User user)
          Updates the object data in the database.
protected abstract  void doValidate()
          Validates the object data before writing to the database.
protected static java.lang.String encodeMap(java.util.HashMap map)
          Encodes a map into a string.
 ContentManager getContentManager()
          Returns the content manager used by this object.
 boolean hasAdminAccess(User user)
          Checks the admin access for a user.
 boolean hasPublishAccess(User user)
          Checks the publish access for a user.
 boolean hasReadAccess(User user)
          Checks the read access for a user.
 boolean hasWriteAccess(User user)
          Checks the write access for a user.
 boolean isPersistent()
          Checks if this object is persistent.
 void restore(DataSource src, User user)
          Restores this object to the database.
 void restore(User user)
          Restores this object to the database.
 void save(DataSource src, User user)
          Saves this object to the database.
 void save(User user)
          Saves this object to the database.
protected static void validateChars(java.lang.String name, java.lang.String value, java.lang.String chars)
          Checks a field value for invalid characters.
protected static void validateSize(java.lang.String name, java.lang.String value, int minLength, int maxLength)
          Checks a field value size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UPPER_CASE

protected static final java.lang.String UPPER_CASE
The ASCII upper-case characters.

See Also:
Constant Field Values

LOWER_CASE

protected static final java.lang.String LOWER_CASE
The ASCII lower-case characters.

See Also:
Constant Field Values

NUMBERS

protected static final java.lang.String NUMBERS
The ASCII numerical characters.

See Also:
Constant Field Values

BINDERS

protected static final java.lang.String BINDERS
The ASCII binding separator characters.

See Also:
Constant Field Values
Constructor Detail

PersistentObject

protected PersistentObject(ContentManager manager,
                           boolean persistent)
Creates a new persistent object.

Parameters:
manager - the content manager to use
persistent - the persistent flag
Method Detail

encodeMap

protected static java.lang.String encodeMap(java.util.HashMap map)
Encodes a map into a string. The map values or keys must consist of normal ASCII characters, and may NOT contain the ':' or '=' characters as they are used in the encoding.

Parameters:
map - the map to encode
Returns:
the encoded map string
See Also:
decodeMap(java.lang.String)

decodeMap

protected static java.util.HashMap decodeMap(java.lang.String str)
Decodes a string into a map. The string must previously have been encoded with the encodeMap method.

Parameters:
str - the encoded string
Returns:
the unencoded map
See Also:
encodeMap(java.util.HashMap)

validateSize

protected static void validateSize(java.lang.String name,
                                   java.lang.String value,
                                   int minLength,
                                   int maxLength)
                            throws ContentException
Checks a field value size.

Parameters:
name - the field name
value - the field value to check
minLength - the minimum length
maxLength - the maximum length
Throws:
ContentException - if the field value was too short or too long

validateChars

protected static void validateChars(java.lang.String name,
                                    java.lang.String value,
                                    java.lang.String chars)
                             throws ContentException
Checks a field value for invalid characters.

Parameters:
name - the field name
value - the field value to check
chars - the allowed characters
Throws:
ContentException - if the field value contained invalid characters

isPersistent

public boolean isPersistent()
Checks if this object is persistent. I.e. if it has been stored to the database.

Returns:
true if the object is persistent, or false otherwise

hasReadAccess

public final boolean hasReadAccess(User user)
                            throws ContentException
Checks the read access for a user.

Parameters:
user - the user to check, or null for none
Returns:
true if the user has read access, or false otherwise
Throws:
ContentException - if the database couldn't be accessed properly

hasWriteAccess

public final boolean hasWriteAccess(User user)
                             throws ContentException
Checks the write access for a user.

Parameters:
user - the user to check, or null for none
Returns:
true if the user has write access, or false otherwise
Throws:
ContentException - if the database couldn't be accessed properly

hasPublishAccess

public final boolean hasPublishAccess(User user)
                               throws ContentException
Checks the publish access for a user.

Parameters:
user - the user to check, or null for none
Returns:
true if the user has publish access, or false otherwise
Throws:
ContentException - if the database couldn't be accessed properly

hasAdminAccess

public final boolean hasAdminAccess(User user)
                             throws ContentException
Checks the admin access for a user.

Parameters:
user - the user to check, or null for none
Returns:
true if the user has admin access, or false otherwise
Throws:
ContentException - if the database couldn't be accessed properly

getContentManager

public ContentManager getContentManager()
Returns the content manager used by this object.

Returns:
the content manager used by this object

save

public final void save(User user)
                throws ContentException,
                       ContentSecurityException
Saves this object to the database.

Parameters:
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

save

public final void save(DataSource src,
                       User user)
                throws ContentException,
                       ContentSecurityException
Saves this object to the database.

Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

restore

public final void restore(User user)
                   throws ContentException,
                          ContentSecurityException
Restores this object to the database. This method is only used when restoring objects from a backup. Superuser permissions are normally required for this operation.

Parameters:
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

restore

public final void restore(DataSource src,
                          User user)
                   throws ContentException,
                          ContentSecurityException
Restores this object to the database. This method is only used when restoring objects from a backup. Superuser permissions are normally required for this operation.

Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

delete

public final void delete(User user)
                  throws ContentException,
                         ContentSecurityException
Deletes this object from the database.

Parameters:
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

delete

public final void delete(DataSource src,
                         User user)
                  throws ContentException,
                         ContentSecurityException
Deletes this object from the database.

Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

doValidate

protected abstract void doValidate()
                            throws ContentException
Validates the object data before writing to the database.

Throws:
ContentException - if the object data wasn't valid

doInsert

protected abstract void doInsert(DataSource src,
                                 User user,
                                 boolean restore)
                          throws ContentException
Inserts the object data into the database. If the restore flag is set, no automatic changes should be made to the data before writing to the database.

Parameters:
src - the data source to use
user - the user performing the operation
restore - the restore flag
Throws:
ContentException - if the database couldn't be accessed properly

doUpdate

protected abstract void doUpdate(DataSource src,
                                 User user)
                          throws ContentException
Updates the object data in the database.

Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly

doDelete

protected abstract void doDelete(DataSource src,
                                 User user)
                          throws ContentException
Deletes the object data from the database.

Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly