org.liquidsite.core.content
Class ContentManager

java.lang.Object
  extended byorg.liquidsite.core.content.ContentManager

public class ContentManager
extends java.lang.Object

The content manager. This class provides an interface for retrieving objects from the database. The content manager guarantees that security considerations are taken into account before returning object (if a method comment does not explicitly say otherwise). The content manager also makes sure not to return unpublished content if it's policy does not allow that (only used by the web administration).


Constructor Summary
ContentManager(ContentManager manager, boolean admin)
          Creates a new content manager.
ContentManager(DatabaseConnector db, java.io.File baseDir, boolean admin)
          Creates a new content manager.
 
Method Summary
 void close()
          Closes this content manager and frees all resources.
 ContentSite findSite(java.lang.String protocol, java.lang.String hostname, int port, java.lang.String path)
          Finds the site corresponding to a web request.
 java.io.File getBaseDir()
          Returns the content base directory.
 Content getContent(User user, int id)
          Returns the content object with the specified identifier and highest revision readable by the user.
 Content getContentChild(User user, Content parent, java.lang.String name)
          Returns the child content object with the specified name and highest revision readable by the user.
 Content getContentChild(User user, Domain domain, java.lang.String name)
          Returns the domain root content object with the specified name and highest revision readable by the user.
 Content[] getContentChildren(User user, Content parent)
          Returns the user readable child content objects.
 Content[] getContentChildren(User user, Content parent, int category)
          Returns the user readable child content objects in the specified category.
 Content[] getContentChildren(User user, Domain domain)
          Returns the user readable domain root content objects.
 Content[] getContentChildren(User user, Domain domain, int category)
          Returns the user readable domain root content objects in the specified category.
 int getContentCount(ContentSelector selector)
          Returns the number of content objects matching the selector.
 Content[] getContentObjects(User user, ContentSelector selector)
          Returns the user readable content objects matching the selector.
 DatabaseConnector getDatabase()
          Returns the database connector for this content manager.
 Domain getDomain(User user, java.lang.String name)
          Returns a domain with the specified name readable by a user.
 Domain[] getDomains(User user)
          Returns an array of all domains readable by a user.
 Group getGroup(Domain domain, java.lang.String name)
          Returns a group with a specified name.
 Group[] getGroups(Domain domain, java.lang.String filter)
          Returns an array of groups in a specified domain.
 PermissionList getPermissions(Content content, boolean inherit)
          Returns the permission list applicable to a content object.
 PermissionList getPermissions(Domain domain)
          Returns the permission list applicable to a domain object.
 User getUser(Domain domain, java.lang.String name)
          Returns a user with a specified name.
 int getUserCount(Domain domain, java.lang.String filter)
          Returns the number of users in a specified domain.
 User[] getUsers(Domain domain, java.lang.String filter, int startPos, int maxLength)
          Returns an array of users in a specified domain.
 boolean isAdmin()
          Checks if the admin flag is set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentManager

public ContentManager(DatabaseConnector db,
                      java.io.File baseDir,
                      boolean admin)
Creates a new content manager. If the admin content manager flag is set, the content manager will NOT cache content objects and the latest revision returned will always be a work revision if one is available.

Parameters:
db - the database connector
baseDir - the content base directory
admin - the admin content manager flag

ContentManager

public ContentManager(ContentManager manager,
                      boolean admin)
Creates a new content manager. If the admin content manager flag is set, the content manager will NOT cache content objects and the latest revision returned will always be a work revision if one is available.

Parameters:
manager - the content manager to modify
admin - the admin content manager flag
Method Detail

isAdmin

public boolean isAdmin()
Checks if the admin flag is set.

Returns:
true if the admin flag is set, or false otherwise

getDatabase

public DatabaseConnector getDatabase()
Returns the database connector for this content manager.

Returns:
the database connector for this content manager.

getBaseDir

public java.io.File getBaseDir()
Returns the content base directory.

Returns:
the content base directory.

getDomains

public Domain[] getDomains(User user)
                    throws ContentException
Returns an array of all domains readable by a user.

Parameters:
user - the user requesting the list
Returns:
an array of all user readable domains
Throws:
ContentException - if the database couldn't be accessed properly

getDomain

public Domain getDomain(User user,
                        java.lang.String name)
                 throws ContentException,
                        ContentSecurityException
Returns a domain with the specified name readable by a user.

Parameters:
user - the user requesting the domain
name - the domain name
Returns:
the domain found, or null if no such domain exists
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the specified domain wasn't readable by the user

getContent

public Content getContent(User user,
                          int id)
                   throws ContentException,
                          ContentSecurityException
Returns the content object with the specified identifier and highest revision readable by the user.

Parameters:
user - the user requesting the content
id - the content identifier
Returns:
the content object found, or null if no matching content existed
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the specified content object wasn't readable by the user

getContentChild

public Content getContentChild(User user,
                               Domain domain,
                               java.lang.String name)
                        throws ContentException,
                               ContentSecurityException
Returns the domain root content object with the specified name and highest revision readable by the user.

Parameters:
user - the user requesting the content
domain - the domain
name - the child name
Returns:
the content object found, or null if no matching content existed
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the specified content object wasn't readable by the user

getContentChild

public Content getContentChild(User user,
                               Content parent,
                               java.lang.String name)
                        throws ContentException,
                               ContentSecurityException
Returns the child content object with the specified name and highest revision readable by the user.

Parameters:
user - the user requesting the content
parent - the content parent
name - the child name
Returns:
the content object found, or null if no matching content existed
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the specified content object wasn't readable by the user

getContentChildren

public Content[] getContentChildren(User user,
                                    Domain domain)
                             throws ContentException
Returns the user readable domain root content objects. Only the highest revision of each object will be returned.

Parameters:
user - the user requesting the content
domain - the domain
Returns:
the user readable domain root content objects
Throws:
ContentException - if the database couldn't be accessed properly

getContentChildren

public Content[] getContentChildren(User user,
                                    Domain domain,
                                    int category)
                             throws ContentException
Returns the user readable domain root content objects in the specified category. Only the highest revision of each object will be returned.

Parameters:
user - the user requesting the content
domain - the domain
category - the content category
Returns:
the user readable domain root content objects
Throws:
ContentException - if the database couldn't be accessed properly

getContentChildren

public Content[] getContentChildren(User user,
                                    Content parent)
                             throws ContentException
Returns the user readable child content objects. Only the highest revision of each object will be returned.

Parameters:
user - the user requesting the content
parent - the content parent
Returns:
the user readable child content objects
Throws:
ContentException - if the database couldn't be accessed properly

getContentChildren

public Content[] getContentChildren(User user,
                                    Content parent,
                                    int category)
                             throws ContentException
Returns the user readable child content objects in the specified category. Only the highest revision of each object will be returned.

Parameters:
user - the user requesting the content
parent - the content parent
category - the content category
Returns:
the user readable child content objects
Throws:
ContentException - if the database couldn't be accessed properly

getContentCount

public int getContentCount(ContentSelector selector)
                    throws ContentException
Returns the number of content objects matching the selector. Only the highest revision of each object will be returned. Note that the number returned by this method may in some cases be higher than the number of content object actually visible by the user, due to lacking read permissions.

Parameters:
selector - the content selector
Returns:
the number of matching content objects
Throws:
ContentException - if the database couldn't be accessed properly

getContentObjects

public Content[] getContentObjects(User user,
                                   ContentSelector selector)
                            throws ContentException
Returns the user readable content objects matching the selector. Only the highest revision of each object will be returned.

Parameters:
user - the user requesting the content
selector - the content selector
Returns:
the user readable content objects
Throws:
ContentException - if the database couldn't be accessed properly

getPermissions

public PermissionList getPermissions(Domain domain)
                              throws ContentException
Returns the permission list applicable to a domain object. If the object has no permissions an empty permission list will be returned.

Parameters:
domain - the domain object
Returns:
the permission list for this object
Throws:
ContentException - if the database couldn't be accessed properly

getPermissions

public PermissionList getPermissions(Content content,
                                     boolean inherit)
                              throws ContentException
Returns the permission list applicable to a content object. If the object has no permissions either an empty list or the inherited permission list will be returned.

Parameters:
content - the content object
inherit - the search inherited permissions flag
Returns:
the permission list for this object
Throws:
ContentException - if the database couldn't be accessed properly

getUser

public User getUser(Domain domain,
                    java.lang.String name)
             throws ContentException
Returns a user with a specified name. If the user couldn't be found in the specified domain, this method also checks for superusers with the specified name.

Parameters:
domain - the domain
name - the user name
Returns:
the user found, or null if no matching user existed
Throws:
ContentException - if the database couldn't be accessed properly

getUserCount

public int getUserCount(Domain domain,
                        java.lang.String filter)
                 throws ContentException
Returns the number of users in a specified domain. Only users with matching names will be counted.

Parameters:
domain - the domain, or null for superusers
filter - the user search filter (empty for all)
Returns:
the number of matching users in the domain
Throws:
ContentException - if the database couldn't be accessed properly

getUsers

public User[] getUsers(Domain domain,
                       java.lang.String filter,
                       int startPos,
                       int maxLength)
                throws ContentException
Returns an array of users in a specified domain. Only users with matching names will be returned. Also, only a limited interval of the matching users will be returned.

Parameters:
domain - the domain, or null for superusers
filter - the user search filter (empty for all)
startPos - the list interval start position
maxLength - the list interval maximum length
Returns:
an array of matching users in the domain
Throws:
ContentException - if the database couldn't be accessed properly

getGroup

public Group getGroup(Domain domain,
                      java.lang.String name)
               throws ContentException
Returns a group with a specified name.

Parameters:
domain - the domain
name - the group name
Returns:
the group found, or null if no matching group existed
Throws:
ContentException - if the database couldn't be accessed properly

getGroups

public Group[] getGroups(Domain domain,
                         java.lang.String filter)
                  throws ContentException
Returns an array of groups in a specified domain. Only groups with matching names will be returned.

Parameters:
domain - the domain
filter - the search filter (empty for all)
Returns:
an array of matching groups in the domain
Throws:
ContentException - if the database couldn't be accessed properly

findSite

public ContentSite findSite(java.lang.String protocol,
                            java.lang.String hostname,
                            int port,
                            java.lang.String path)
                     throws ContentException
Finds the site corresponding to a web request. This method does NOT control access permissions and should thus ONLY be used internally in the request processing.

Parameters:
protocol - the request protocol (i.e. "http")
hostname - the request host name
port - the request port number
path - the full request path
Returns:
the site corresponding to the request, or null if no matching site was found
Throws:
ContentException - if the database couldn't be accessed properly

close

public void close()
Closes this content manager and frees all resources. This method should be called in order to garbage collect the resources used by this manager.