org.liquidsite.app.template
Class BeanContext

java.lang.Object
  extended byorg.liquidsite.app.template.BeanContext

public class BeanContext
extends java.lang.Object

A template bean context. This class holds contains references to common objects used by all beans. It also contains several utility methods to simplify the code in the various beans.


Method Summary
 int countContent(ContentSelector selector)
          Counts the number of content objects matching a content selector.
 int countDocuments(ContentSection section)
          Counts the number of documents under the specified section (and subsections).
 int countDocuments(java.lang.String path)
          Counts the number of documents under the specified absolute path.
 User createUser(java.lang.String name)
          Creates a new user with the specified name in the current environment domain.
 Content[] findContent(ContentSelector selector)
          Finds a set of content objects with a content selector.
 Content findContent(int id)
          Finds a content object from a specified content id.
 Content findContent(java.lang.Object parent, java.lang.String path)
          Finds a content object from a relative path.
 Content findContent(java.lang.String path)
          Finds a content object from an absolute path.
 DocumentBean findDocument(java.lang.Object parent, java.lang.String path)
          Finds a document corresponding to the specified relative path.
 DocumentBean findDocument(java.lang.String path)
          Finds a document corresponding to the specified absolute path.
 java.util.ArrayList findDocuments(ContentSection section, java.lang.String sorting, int offset, int count)
          Finds all documents under the specified section (and subsections).
 java.util.ArrayList findDocuments(java.lang.String path, java.lang.String sorting, int offset, int count)
          Finds all documents under the specified absolute path.
 ForumBean findForum(ContentSection section, java.lang.String name)
          Finds a named forum in a section.
 Group findGroup(java.lang.String name)
          Finds a specified group.
 SectionBean findSection(java.lang.Object parent, java.lang.String path)
          Finds a section corresponding to the specified relative path.
 SectionBean findSection(java.lang.String path)
          Finds a section corresponding to the specified absolute path.
 UserBean findUser(java.lang.String name)
          Finds a specified user.
 UserBean findUserByEmail(java.lang.String email)
          Finds a specified user by email address.
 java.lang.String getContentPath(Content content)
          Returns the absolute path to a content object.
 java.lang.String getMimeType()
          Returns the response content MIME type.
 java.lang.String getRelativePath(java.lang.String basePath)
          Returns the relative path to a specified base path.
 Request getRequest()
          Returns the request object.
 java.lang.String getSitePath()
          Returns the relative path to the site root directory.
 boolean sendMail(Group receiver, java.lang.String subject, java.lang.String text)
          Sends an email to all the members in a group.
 boolean sendMail(java.lang.String receiver, java.lang.String subject, java.lang.String text)
          Sends an email to the specified receiver.
 void setMimeType(java.lang.String mimeType)
          Sets the response content MIME type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMimeType

public java.lang.String getMimeType()
Returns the response content MIME type. By default the content type is set to "text/html".

Returns:
the response content MIME type

setMimeType

public void setMimeType(java.lang.String mimeType)
Sets the response content MIME type.

Parameters:
mimeType - the new MIME type

getRequest

public Request getRequest()
Returns the request object.

Returns:
the request object

getSitePath

public java.lang.String getSitePath()
Returns the relative path to the site root directory. The path is relative to the request URL and may be empty if the request refers to an object in the site root directory. Otherwise the path ends with an "/" character. The result of this method will be stored in an instance variable to avoid calculations on further requests.

Returns:
the relative path to the site root directory

getRelativePath

public java.lang.String getRelativePath(java.lang.String basePath)
Returns the relative path to a specified base path. The specified path is assumed to be a part of the complete request path. This method will return an empty string if the request refers to a object in the specified directory.

Parameters:
basePath - the absolute base path
Returns:
the relative path to the base path for the request

getContentPath

public java.lang.String getContentPath(Content content)
Returns the absolute path to a content object.

Parameters:
content - the content object
Returns:
the absolute path to a content object

countContent

public int countContent(ContentSelector selector)
                 throws ContentException
Counts the number of content objects matching a content selector.

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

countDocuments

public int countDocuments(java.lang.String path)
Counts the number of documents under the specified absolute path.

Parameters:
path - the section path
Returns:
the number of documents found

countDocuments

public int countDocuments(ContentSection section)
Counts the number of documents under the specified section (and subsections).

Parameters:
section - the parent section
Returns:
the number of documents found

findContent

public Content findContent(int id)
                    throws ContentException,
                           ContentSecurityException
Finds a content object from a specified content id.

Parameters:
id - the content identifier
Returns:
the content object found, or null for none
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the content couldn't be read by the current user

findContent

public Content findContent(java.lang.String path)
                    throws ContentException,
                           ContentSecurityException
Finds a content object from an absolute path. The object found can be any object present in a section, that is either a section, a document or a forum.

Parameters:
path - the content path (from the domain root)
Returns:
the content object found, or null if not found
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the content couldn't be read by the current user

findContent

public Content findContent(java.lang.Object parent,
                           java.lang.String path)
                    throws ContentException,
                           ContentSecurityException
Finds a content object from a relative path. The object found can be any object present in a section, that is either a section, a document or a forum.

Parameters:
parent - the parent domain or section
path - the content path (relative to the parent)
Returns:
the content object found, or null if not found
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the content couldn't be read by the current user

findContent

public Content[] findContent(ContentSelector selector)
                      throws ContentException
Finds a set of content objects with a content selector.

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

findDocument

public DocumentBean findDocument(java.lang.String path)
Finds a document corresponding to the specified absolute path.

Parameters:
path - the document (and section) path
Returns:
the document found, or an empty document if not found

findDocument

public DocumentBean findDocument(java.lang.Object parent,
                                 java.lang.String path)
Finds a document corresponding to the specified relative path.

Parameters:
parent - the parent domain or section
path - the document (and section) path
Returns:
the document found, or an empty document if not found

findDocuments

public java.util.ArrayList findDocuments(java.lang.String path,
                                         java.lang.String sorting,
                                         int offset,
                                         int count)
Finds all documents under the specified absolute path. The documents will be returned (as document beans) in a list.

Parameters:
path - the section path
sorting - the sorting information
offset - the number of documents to skip
count - the maximum number of documents
Returns:
a list of the documents found (as document beans)

findDocuments

public java.util.ArrayList findDocuments(ContentSection section,
                                         java.lang.String sorting,
                                         int offset,
                                         int count)
Finds all documents under the specified section (and subsections). The documents will be returned (as document beans) in a list.

Parameters:
section - the parent section
sorting - the sorting information
offset - the number of documents to skip
count - the maximum number of documents
Returns:
a list of the documents found (as document beans)

findForum

public ForumBean findForum(ContentSection section,
                           java.lang.String name)
Finds a named forum in a section.

Parameters:
section - the parent section
name - the forum name
Returns:
the forum found, or an empty forum if not found

findSection

public SectionBean findSection(java.lang.String path)
Finds a section corresponding to the specified absolute path.

Parameters:
path - the section path
Returns:
the section found, or an empty section if not found

findSection

public SectionBean findSection(java.lang.Object parent,
                               java.lang.String path)
Finds a section corresponding to the specified relative path.

Parameters:
parent - the parent domain or section
path - the section path
Returns:
the section found, or an empty section if not found

findUser

public UserBean findUser(java.lang.String name)
Finds a specified user. All users found will be added to an internal cache, making repetitive queries efficient.

Parameters:
name - the user name, or "" for the current user
Returns:
the user bean for the specified user, or an empty bean if no such user could be found

findUserByEmail

public UserBean findUserByEmail(java.lang.String email)
Finds a specified user by email address. All users found will be added to an internal cache, making queries for user name efficient.

Parameters:
email - the user email address
Returns:
the user bean for the specified user, or an empty bean if no such user could be found

findGroup

public Group findGroup(java.lang.String name)
Finds a specified group.

Parameters:
name - the group name
Returns:
the group found, or null if not found

createUser

public User createUser(java.lang.String name)
Creates a new user with the specified name in the current environment domain. The user object will not be saved to the database, only instantiated with the correct parameters.

Parameters:
name - the login name
Returns:
the user object create, or null if no such user could be created

sendMail

public boolean sendMail(java.lang.String receiver,
                        java.lang.String subject,
                        java.lang.String text)
Sends an email to the specified receiver. The email will not be sent immediately, but rather queued in the outgoing mail queue.

Parameters:
receiver - the message recipient address
subject - the message subject line
text - the message text
Returns:
true if the mail could be queued correctly, or false otherwise

sendMail

public boolean sendMail(Group receiver,
                        java.lang.String subject,
                        java.lang.String text)
Sends an email to all the members in a group. The email will not be sent immediately, but rather queued in the outgoing mail queue.

Parameters:
receiver - the message recipient group
subject - the message subject line
text - the message text
Returns:
true if the mail could be queued correctly, or false otherwise