Class CmsRequestContext
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Request context attribute for the ADE context path (should be a root path).static final String
Request context attribute for indicating that an editor is currently open.static final String
Request context attribute for indicating we want full links generated for HTML fields.static final String
Request context attribute for indicating the model file for a create resource operation.static final String
Request context attribute for indicating content locale for a create resource operation. -
Constructor Summary
ConstructorDescriptionCmsRequestContext
(CmsUser user, CmsProject project, String requestedUri, CmsSiteMatcher requestMatcher, String siteRoot, boolean isSecureRequest, Locale locale, String encoding, String remoteAddr, long requestTime, CmsResourceTranslator directoryTranslator, CmsResourceTranslator fileTranslator, String ouFqn, boolean forceAbsoluteLinks) Constructs a new request context. -
Method Summary
Modifier and TypeMethodDescriptionaddSiteRoot
(String resourcename) Adds the current site root of this context to the given resource name, and also translates the resource name with the configured the directory translator.addSiteRoot
(String siteRoot, String resourcename) Adds the given site root of this context to the given resource name, taking into account special folders like "/system" where no site root must be added, and also translates the resource name with the configured the directory translator.Deprecated.Deprecated.usegetCurrentUser()
insteadgetAdjustedSiteRoot
(String resourcename) Returns the adjusted site root for a resource this context current site root.static String
getAdjustedSiteRoot
(String siteRoot, String resourcename) Returns the adjusted site root for a resource using the provided site root as a base.getAttribute
(String attributeName) Gets the value of an attribute from the OpenCms request context attribute list.Returns the current project of the current user.Returns the current user object.Gets the detail content structure id (or null if no detail content has been loaded).Gets the detail content resource (or null if no detail content has been loaded).Returns the directory name translator this context was initialized with.Returns the current content encoding to be used in HTTP response.Returns the file name translator this context was initialized with.Gets the name of the parent folder of the requested file.Returns the locale used by this request context.getOuFqn()
Returns the fully qualified name of the organizational unit.Returns the remote ip address.Returns the matcher for the current request, that is the host part of the URI from the original http request.long
Returns the current request time.Returns this request contexts uri extended with the current site root path.getSitePath
(CmsResource resource) Adjusts the absolute resource root path for the current site.Returns the current root directory in the virtual file system.getUri()
Returns the OpenCms VFS URI of the requested resource.boolean
Returns true if links to the current site should be generated as absolute links, i.e.boolean
Checks if we are currently either in the Online project or the 'direct edit disabled' mode.boolean
Returns true if this is a secure request.boolean
Check if this request context will update the session.removeAttribute
(String key) Removes an attribute from the request context.removeSiteRoot
(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
setAttribute
(String key, Object value) Sets an attribute in the request context.setCurrentProject
(CmsProject project) Sets the current project for the user.void
setDetailResource
(CmsResource detailResource) Sets the detail content resource.void
setEncoding
(String encoding) Sets the current content encoding to be used in HTTP response.void
setForceAbsoluteLinks
(boolean forceAbsoluteLinks) Enables/disables link generation with full server prefix for the current site.void
Sets the locale used by this request context.void
Sets the organizational unit fully qualified name.void
setRequestTime
(long time) Sets the current request time.void
setSecureRequest
(boolean secureRequest) Sets the 'secure request' status.void
setSiteRoot
(String root) Sets the current root directory in the virtual file system.void
setUpdateSessionEnabled
(boolean value) Mark this request context to update the session or not.void
Set the requested resource OpenCms VFS URI, that is the value returned bygetUri()
.protected void
switchUser
(CmsUser user, CmsProject project, String ouFqn) Switches the user in the context, required after a login.
-
Field Details
-
ATTRIBUTE_ADE_CONTEXT_PATH
Request context attribute for the ADE context path (should be a root path). -
ATTRIBUTE_EDITOR
Request context attribute for indicating that an editor is currently open. -
ATTRIBUTE_FULLLINKS
Request context attribute for indicating we want full links generated for HTML fields. -
ATTRIBUTE_MODEL
Request context attribute for indicating the model file for a create resource operation. -
ATTRIBUTE_NEW_RESOURCE_LOCALE
Request context attribute for indicating content locale for a create resource operation.
-
-
Constructor Details
-
CmsRequestContext
public CmsRequestContext(CmsUser user, CmsProject project, String requestedUri, CmsSiteMatcher requestMatcher, String siteRoot, boolean isSecureRequest, Locale locale, String encoding, String remoteAddr, long requestTime, CmsResourceTranslator directoryTranslator, CmsResourceTranslator fileTranslator, String ouFqn, boolean forceAbsoluteLinks) Constructs a new request context.- Parameters:
user
- the current userproject
- the current projectrequestedUri
- the requested OpenCms VFS URIrequestMatcher
- the matcher for the current request, that is the host part of the URI from the original http requestsiteRoot
- the users current site rootisSecureRequest
- true if this is a secure requestlocale
- the users current localeencoding
- the encoding to use for this requestremoteAddr
- the remote IP address of the userrequestTime
- the time of the request (used for resource publication / expiration date)directoryTranslator
- the directory translatorfileTranslator
- the file translatorouFqn
- the fully qualified name of the organizational unitforceAbsoluteLinks
- if true, links should be generated with a server prefix even if we're linking to the current site
-
-
Method Details
-
getAdjustedSiteRoot
Returns the adjusted site root for a resource using the provided site root as a base.Usually, this would be the site root for the current site. However, if a resource from the
/system/
folder is requested, this will be the empty String.- Parameters:
siteRoot
- the site root of the current siteresourcename
- the resource name to get the adjusted site root for- Returns:
- the adjusted site root for the resource
-
addSiteRoot
Adds the current site root of this context to the given resource name, and also translates the resource name with the configured the directory translator.- Parameters:
resourcename
- the resource name- Returns:
- the translated resource name including site root
- See Also:
-
addSiteRoot
Adds the given site root of this context to the given resource name, taking into account special folders like "/system" where no site root must be added, and also translates the resource name with the configured the directory translator.- Parameters:
siteRoot
- the site root to addresourcename
- the resource name- Returns:
- the translated resource name including site root
-
currentProject
Deprecated.usegetCurrentProject()
insteadReturns the current project of the current user.- Returns:
- the current project of the current user
-
currentUser
Deprecated.usegetCurrentUser()
insteadReturns the current user object.- Returns:
- the current user object
-
getAdjustedSiteRoot
Returns the adjusted site root for a resource this context current site root.- Parameters:
resourcename
- the resource name to get the adjusted site root for- Returns:
- the adjusted site root for the resource
- See Also:
-
getAttribute
Gets the value of an attribute from the OpenCms request context attribute list.- Parameters:
attributeName
- the attribute name- Returns:
- Object the attribute value, or
null
if the attribute was not found
-
getCurrentProject
Returns the current project of the current user.- Returns:
- the current project of the current user
-
getCurrentUser
Returns the current user object.- Returns:
- the current user object
-
getDetailContentId
Gets the detail content structure id (or null if no detail content has been loaded).- Returns:
- the detail content id
-
getDetailResource
Gets the detail content resource (or null if no detail content has been loaded).- Returns:
- the detail content resource
-
getDirectoryTranslator
Returns the directory name translator this context was initialized with.The directory translator is used to translate old VFS path information to a new location. Example:
/bodys/index.html --> /system/bodies/
.- Returns:
- the directory name translator this context was initialized with
-
getEncoding
Returns the current content encoding to be used in HTTP response.- Returns:
- the encoding
-
getFileTranslator
Returns the file name translator this context was initialized with.The file name translator is used to translate filenames from uploaded files to valid OpenCms filenames. Example:
Wüste Wörter.doc --> Wueste_Woerter.doc
.- Returns:
- the file name translator this context was initialized with
-
getFolderUri
Gets the name of the parent folder of the requested file.- Returns:
- the name of the parent folder of the requested file
-
getLocale
Returns the locale used by this request context.In normal operation, the request context locale is initialized using
I_CmsLocaleHandler.getI18nInfo(javax.servlet.http.HttpServletRequest, CmsUser, CmsProject, String)
depending on the requested resource URI.- Returns:
- the locale used by this request context
- See Also:
-
getOuFqn
Returns the fully qualified name of the organizational unit.- Returns:
- the fully qualified name of the organizational unit
-
getRemoteAddress
Returns the remote ip address.- Returns:
- the remote ip address as string
-
getRequestMatcher
Returns the matcher for the current request, that is the host part of the URI from the original http request.- Returns:
- the matcher for the current request, that is the host part of the URI from the original http request
-
getRequestTime
Returns the current request time.- Returns:
- the current request time
-
getRootUri
Returns this request contexts uri extended with the current site root path.- Returns:
- this request contexts uri extended with the current site root path
- See Also:
-
getSitePath
Adjusts the absolute resource root path for the current site.The full root path of a resource is always available using
. From this name this method cuts of the current site root usingCmsResource.getRootPath()
.removeSiteRoot(String)
If the resource root path does not start with the current site root, it is left untouched.
- Parameters:
resource
- the resource to get the adjusted site root path for- Returns:
- the absolute resource path adjusted for the current site
- See Also:
-
getSiteRoot
Returns the current root directory in the virtual file system.- Returns:
- the current root directory in the virtual file system
-
getUri
Returns the OpenCms VFS URI of the requested resource.- Returns:
- the OpenCms VFS URI of the requested resource
-
isForceAbsoluteLinks
Returns true if links to the current site should be generated as absolute links, i.e. with a server prefix.- Returns:
- true if links to the current site should be absolute
-
isOnlineOrEditDisabled
Checks if we are currently either in the Online project or the 'direct edit disabled' mode.- Returns:
- true if we are online or in 'direct edit enabled' mode
-
isSecureRequest
Returns true if this is a secure request.- Returns:
- true if this is secure
-
isUpdateSessionEnabled
Check if this request context will update the session.This is used mainly for CmsReports that continue to use the users context, even after the http request is already finished.
- Returns:
- true if this request context will update the session, false otherwise
-
removeAttribute
Removes an attribute from the request context.- Parameters:
key
- the name of the attribute to remove- Returns:
- the removed attribute, or
null
if no attribute was set with this name
-
removeSiteRoot
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 the resource name does not start with the current site root, it is left untouched.
- Parameters:
resourcename
- the resource name- Returns:
- the resource name adjusted for the current site root
- See Also:
-
setAttribute
Sets an attribute in the request context.- Parameters:
key
- the attribute namevalue
- the attribute value
-
setCurrentProject
Sets the current project for the user.- Parameters:
project
- the project to be set as current project- Returns:
- the CmsProject instance
-
setDetailResource
Sets the detail content resource.- Parameters:
detailResource
- the detail content resource
-
setEncoding
Sets the current content encoding to be used in HTTP response.- Parameters:
encoding
- the encoding
-
setForceAbsoluteLinks
Enables/disables link generation with full server prefix for the current site.- Parameters:
forceAbsoluteLinks
- true if links to the current site should be generated with server prefix
-
setLocale
Sets the locale used by this request context.- Parameters:
locale
- the locale to set- See Also:
-
setOuFqn
Sets the organizational unit fully qualified name.- Parameters:
ouFqn
- the organizational unit fully qualified name
-
setRequestTime
Sets the current request time.- Parameters:
time
- the request time
-
setSecureRequest
Sets the 'secure request' status.- Parameters:
secureRequest
- the new value
-
setSiteRoot
Sets the current root directory in the virtual file system.- Parameters:
root
- the name of the new root directory
-
setUpdateSessionEnabled
Mark this request context to update the session or not.- Parameters:
value
- true if this request context will update the session, false otherwise
-
setUri
Set the requested resource OpenCms VFS URI, that is the value returned bygetUri()
.Use this with caution! Many things (caches etc.) depend on this value. If you change this value, better make sure that you change it only temporarily and reset it in a
try { // do something // } finally { // reset URI // }
statement.- Parameters:
value
- the value to set the Uri to, must be a complete OpenCms path name like /system/workplace/style.css
-
switchUser
Switches the user in the context, required after a login.- Parameters:
user
- the new user to useproject
- the new users current projectouFqn
- the organizational unit
-
getCurrentProject()
instead