org.opencms.db
Class CmsDbContext

java.lang.Object
  extended by org.opencms.db.CmsDbContext

public class CmsDbContext
extends java.lang.Object

Wraps context information to access the OpenCms database.

Since:
6.0.0
Version:
$Revision: 1.21 $
Author:
Alexander Kandzior

Field Summary
protected  java.util.Map m_attributes
          Context attributes.
protected  CmsFlexRequestContextInfo m_flexRequestContextInfo
          The current Flex request context info (if available).
protected  CmsUUID m_projectId
          The id of the project for the context.
protected  CmsRequestContext m_requestContext
          The wrapped user request context.
 
Constructor Summary
CmsDbContext()
          Creates a new, empty database context.
CmsDbContext(CmsRequestContext context)
          Creates a new database context initialized with the given user request context.
 
Method Summary
 void clear()
          Clears this database context.
 CmsProject currentProject()
          Returns the current users project.
 CmsUser currentUser()
          Returns the current user.
 java.lang.Object getAttribute(java.lang.String key)
          Get an attribute from the dbc.
 CmsFlexRequestContextInfo getFlexRequestContextInfo()
          Returns the current Flex request context info.
 I_CmsHistoryDriver getHistoryDriver(CmsUUID projectId)
          Gets the history driver associated with this database context.
 I_CmsProjectDriver getProjectDriver(CmsUUID projectId)
          Gets the project driver associated with this database context.
 CmsUUID getProjectId()
          Returns the project id of the context.
 CmsRequestContext getRequestContext()
          Returns the request context.
 I_CmsUserDriver getUserDriver(CmsUUID projectId)
          Gets the user driver associated with this database context.
 I_CmsVfsDriver getVfsDriver(CmsUUID projectId)
          Gets the VFS driver associated with this database context.
 boolean isDefaultDbContext()
          Returns true if the database context uses the default implementation.
 void pop()
          Processes the current database context.
 java.lang.String removeSiteRoot(java.lang.String resourcename)
          Removes the current site root prefix from the absolute path in the resource name, that is adjusts the resource name for the current site root.
 void report(I_CmsReport report, CmsMessageContainer message, java.lang.Throwable throwable)
          Reports an error to the given report (if available) and to the OpenCms log file.
 void setAttribute(java.lang.String key, java.lang.Object value)
          Sets an attribute in the dbc.
 void setProjectId(CmsUUID projectId)
          Sets the project id of the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_flexRequestContextInfo

protected CmsFlexRequestContextInfo m_flexRequestContextInfo
The current Flex request context info (if available).


m_projectId

protected CmsUUID m_projectId
The id of the project for the context.


m_requestContext

protected CmsRequestContext m_requestContext
The wrapped user request context.


m_attributes

protected java.util.Map m_attributes
Context attributes.

Constructor Detail

CmsDbContext

public CmsDbContext()
Creates a new, empty database context.


CmsDbContext

public CmsDbContext(CmsRequestContext context)
Creates a new database context initialized with the given user request context.

Parameters:
context - the current users request context
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Get an attribute from the dbc.

Parameters:
key - the attrbute key
Returns:
the attribute value or null if the attribute does not exist

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object value)
Sets an attribute in the dbc.

Parameters:
key - the attribute key
value - the attribute value

clear

public void clear()
Clears this database context.


currentProject

public CmsProject currentProject()
Returns the current users project.

Returns:
the current users project

currentUser

public CmsUser currentUser()
Returns the current user.

Returns:
the current user

getFlexRequestContextInfo

public CmsFlexRequestContextInfo getFlexRequestContextInfo()
Returns the current Flex request context info.

Returns:
the current Flex request context info

getHistoryDriver

public I_CmsHistoryDriver getHistoryDriver(CmsUUID projectId)
Gets the history driver associated with this database context.

Parameters:
projectId - the project id for which the history driver should be retrieved
Returns:
the history driver

getProjectDriver

public I_CmsProjectDriver getProjectDriver(CmsUUID projectId)
Gets the project driver associated with this database context.

Parameters:
projectId - the project id for which the project driver should be retrieved
Returns:
the project driver

getProjectId

public CmsUUID getProjectId()
Returns the project id of the context.

Returns:
the project

getRequestContext

public CmsRequestContext getRequestContext()
Returns the request context.

Returns:
the request context

getUserDriver

public I_CmsUserDriver getUserDriver(CmsUUID projectId)
Gets the user driver associated with this database context.

Parameters:
projectId - the project id for which the user driver should be retrieved
Returns:
the user driver

getVfsDriver

public I_CmsVfsDriver getVfsDriver(CmsUUID projectId)
Gets the VFS driver associated with this database context.

Parameters:
projectId - the project id for which the VFS driver should be retrieved
Returns:
the VFS driver

isDefaultDbContext

public boolean isDefaultDbContext()
Returns true if the database context uses the default implementation.

Returns:
true if the database context uses the default implementation

pop

public void pop()
         throws CmsException
Processes the current database context.

Throws:
CmsException - if something goes wrong

removeSiteRoot

public java.lang.String removeSiteRoot(java.lang.String resourcename)
Removes the current site root prefix from the absolute path in the resource name, that is adjusts the resource name for the current site root.

If no user request context is available, the given resource name is returned unchanged.

Parameters:
resourcename - the resource name
Returns:
the resource name adjusted for the current site root

report

public void report(I_CmsReport report,
                   CmsMessageContainer message,
                   java.lang.Throwable throwable)
            throws CmsVfsException,
                   CmsException
Reports an error to the given report (if available) and to the OpenCms log file.

Parameters:
report - the report to write the error to
message - the message to write to the report / log
throwable - the exception to write to the report / log
Throws:
CmsException - if the throwable parameter is not null and a CmsException
CmsVfsException - if the throwable parameter is not null and no CmsException

setProjectId

public void setProjectId(CmsUUID projectId)
Sets the project id of the context.

Parameters:
projectId - the id of the project to set