|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.file.CmsRequestContext
public final class CmsRequestContext
Stores the information about the current users OpenCms context, for example the requested URI, the current project, the selected site and more.
Field Summary | |
---|---|
static String |
ATTRIBUTE_EDITOR
Request context attribute for indicating that an editor is currently open. |
static String |
ATTRIBUTE_FULLLINKS
Request context attribute for indicating we want full links generated for HTML fields. |
static String |
ATTRIBUTE_MODEL
Request context attribute for indicating the model file for a create resource operation. |
static String |
ATTRIBUTE_NEW_RESOURCE_LOCALE
Request context attribute for indicating content locale for a create resource operation. |
Constructor Summary | |
---|---|
CmsRequestContext(CmsUser user,
CmsProject project,
String requestedUri,
String siteRoot,
Locale locale,
String encoding,
String remoteAddr,
long requestTime,
CmsResourceTranslator directoryTranslator,
CmsResourceTranslator fileTranslator,
String ouFqn)
Constructs a new request context. |
Method Summary | |
---|---|
String |
addSiteRoot(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. |
String |
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. |
CmsProject |
currentProject()
Deprecated. use getCurrentProject() instead |
CmsUser |
currentUser()
Deprecated. use getCurrentUser() instead |
String |
getAdjustedSiteRoot(String resourcename)
Returns the adjusted site root for a resoure 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. |
Object |
getAttribute(String attributeName)
Gets the value of an attribute from the OpenCms request context attribute list. |
CmsProject |
getCurrentProject()
Returns the current project of the current user. |
CmsUser |
getCurrentUser()
Returns the current user object. |
CmsResourceTranslator |
getDirectoryTranslator()
Returns the directory name translator this context was initialized with. |
String |
getEncoding()
Returns the current content encoding to be used in HTTP response. |
CmsResourceTranslator |
getFileTranslator()
Returns the file name translator this context was initialized with. |
String |
getFolderUri()
Gets the name of the parent folder of the requested file. |
Locale |
getLocale()
Returns the locale used by this request context. |
String |
getOuFqn()
Returns the fully qualified name of the organizational unit. |
String |
getRemoteAddress()
Returns the remote ip address. |
long |
getRequestTime()
Returns the current request time. |
String |
getRootUri()
Returns this request contexts uri extended with the current site root path. |
String |
getSitePath(CmsResource resource)
Adjusts the absolute resource root path for the current site. |
String |
getSiteRoot()
Returns the current root directory in the virtual file system. |
String |
getUri()
Returns the OpenCms VFS URI of the requested resource. |
boolean |
isUpdateSessionEnabled()
Check if this request context will update the session. |
Object |
removeAttribute(String key)
Removes an attribute from the request context. |
String |
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. |
CmsProject |
setCurrentProject(CmsProject project)
Sets the current project for the user. |
void |
setEncoding(String encoding)
Sets the current content encoding to be used in HTTP response. |
void |
setLocale(Locale locale)
Sets the locale used by this request context. |
void |
setOuFqn(String ouFqn)
Sets the organizational unit fully qualified name. |
void |
setRequestTime(long time)
Sets the current request time. |
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 |
setUri(String value)
Set the requested resource OpenCms VFS URI, that is the value returned by getUri() . |
protected void |
switchUser(CmsUser user,
CmsProject project,
String ouFqn)
Switches the user in the context, required after a login. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ATTRIBUTE_EDITOR
public static final String ATTRIBUTE_FULLLINKS
public static final String ATTRIBUTE_MODEL
public static final String ATTRIBUTE_NEW_RESOURCE_LOCALE
Constructor Detail |
---|
public CmsRequestContext(CmsUser user, CmsProject project, String requestedUri, String siteRoot, Locale locale, String encoding, String remoteAddr, long requestTime, CmsResourceTranslator directoryTranslator, CmsResourceTranslator fileTranslator, String ouFqn)
user
- the current userproject
- the current projectrequestedUri
- the requested OpenCms VFS URIsiteRoot
- the users current site rootlocale
- 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 unitMethod Detail |
---|
public static String getAdjustedSiteRoot(String siteRoot, String resourcename)
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.
siteRoot
- the site root of the current siteresourcename
- the resource name to get the adjusted site root for
public String addSiteRoot(String resourcename)
resourcename
- the resource name
addSiteRoot(String, String)
public String addSiteRoot(String siteRoot, String resourcename)
siteRoot
- the site root to addresourcename
- the resource name
@Deprecated public CmsProject currentProject()
getCurrentProject()
instead
@Deprecated public CmsUser currentUser()
getCurrentUser()
instead
public String getAdjustedSiteRoot(String resourcename)
resourcename
- the resource name to get the adjusted site root for
getAdjustedSiteRoot(String, String)
public Object getAttribute(String attributeName)
attributeName
- the attribute name
null
if the attribute was not foundpublic CmsProject getCurrentProject()
public CmsUser getCurrentUser()
public CmsResourceTranslator getDirectoryTranslator()
The directory translator is used to translate old VFS path information
to a new location. Example: /bodys/index.html --> /system/bodies/
.
public String getEncoding()
public CmsResourceTranslator getFileTranslator()
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
.
public String getFolderUri()
public Locale getLocale()
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.
I_CmsLocaleHandler.getI18nInfo(javax.servlet.http.HttpServletRequest, CmsUser, CmsProject, String)
,
CmsLocaleManager.getDefaultLocale(CmsObject, String)
public String getOuFqn()
public String getRemoteAddress()
public long getRequestTime()
public String getRootUri()
getUri()
,
addSiteRoot(String)
public String getSitePath(CmsResource resource)
The full root path of a resource is always available using
. From this name this method cuts
of the current site root using
CmsResource.getRootPath()
.removeSiteRoot(String)
If the resource root path does not start with the current site root, it is left untouched.
resource
- the resource to get the adjusted site root path for
removeSiteRoot(String)
,
CmsResource.getRootPath()
,
CmsObject.getSitePath(CmsResource)
public String getSiteRoot()
public String getUri()
public boolean isUpdateSessionEnabled()
This is used mainly for CmsReports that continue to use the users context, even after the http request is already finished.
public Object removeAttribute(String key)
key
- the name of the attribute to remove
null
if no attribute was set with this namepublic String removeSiteRoot(String resourcename)
If the resource name does not start with the current site root, it is left untouched.
resourcename
- the resource name
getSitePath(CmsResource)
public void setAttribute(String key, Object value)
key
- the attribute namevalue
- the attribute valuepublic CmsProject setCurrentProject(CmsProject project)
project
- the project to be set as current project
public void setEncoding(String encoding)
encoding
- the encodingpublic void setLocale(Locale locale)
locale
- the locale to setfor more information about how the locale is set in normal operation
public void setOuFqn(String ouFqn)
ouFqn
- the organizational unit fully qualified namepublic void setRequestTime(long time)
time
- the request timepublic void setSiteRoot(String root)
root
- the name of the new root directorypublic void setUpdateSessionEnabled(boolean value)
value
- true if this request context will update the session, false otherwisepublic void setUri(String value)
getUri()
.
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.
value
- the value to set the Uri to, must be a complete OpenCms path name like /system/workplace/style.cssprotected void switchUser(CmsUser user, CmsProject project, String ouFqn)
user
- the new user to useproject
- the new users current projectouFqn
- the organizational unit
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |