|
||||||
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 java.lang.String |
ATTRIBUTE_EDITOR
Request context attribute for indicating that an editor is currently open. |
static java.lang.String |
ATTRIBUTE_FULLLINKS
Request context attribute for indicating we want full links generated for HTML fields. |
static java.lang.String |
ATTRIBUTE_MODEL
Request context attribute for indicating the model file for a create resource operation. |
Constructor Summary | |
---|---|
CmsRequestContext(CmsUser user,
CmsProject project,
java.lang.String requestedUri,
java.lang.String siteRoot,
java.util.Locale locale,
java.lang.String encoding,
java.lang.String remoteAddr,
long requestTime,
CmsResourceTranslator directoryTranslator,
CmsResourceTranslator fileTranslator,
java.lang.String ouFqn)
Constructs a new request context. |
Method Summary | |
---|---|
java.lang.String |
addSiteRoot(java.lang.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. |
java.lang.String |
addSiteRoot(java.lang.String siteRoot,
java.lang.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()
Returns the current project of the current user. |
CmsUser |
currentUser()
Returns the current user object. |
java.lang.String |
getAdjustedSiteRoot(java.lang.String resourcename)
Returns the adjusted site root for a resoure this context current site root. |
static java.lang.String |
getAdjustedSiteRoot(java.lang.String siteRoot,
java.lang.String resourcename)
Returns the adjusted site root for a resoure using the provided site root as a base. |
java.lang.Object |
getAttribute(java.lang.String attributeName)
Gets the value of an attribute from the OpenCms request context attribute list. |
CmsResourceTranslator |
getDirectoryTranslator()
Returns the directory name translator this context was initialized with. |
java.lang.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. |
java.lang.String |
getFolderUri()
Gets the name of the parent folder of the requested file. |
java.util.Locale |
getLocale()
Returns the locale used by this request context. |
java.lang.String |
getOuFqn()
Returns the fully qualified name of the organizational unit. |
java.lang.String |
getRemoteAddress()
Returns the remote ip address. |
long |
getRequestTime()
Returns the current request time. |
java.lang.String |
getSitePath(CmsResource resource)
Adjusts the absolute resource root path for the current site. |
java.lang.String |
getSiteRoot()
Returns the current root directory in the virtual file system. |
java.lang.String |
getUri()
Returns the OpenCms VFS URI of the requested resource. |
boolean |
isUpdateSessionEnabled()
Check if this request context will update the session. |
java.lang.Object |
removeAttribute(java.lang.String key)
Removes an attribute from the request 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 |
restoreSiteRoot()
Deprecated. store the current site root locally before switching to another site, and set it back again at the end, like: String storedSite = context.getSiteRoot(); try { context.setSiteRoot(""); // do something with the context } finally { context.setSiteRoot(storedSite); } |
void |
saveSiteRoot()
Deprecated. store the current site root locally before switching to another site, and set it back again at the end, like: String storedSite = context.getSiteRoot(); try { context.setSiteRoot(""); // do something with the context } finally { context.setSiteRoot(storedSite); } |
void |
setAttribute(java.lang.String key,
java.lang.Object value)
Sets an attribute in the request context. |
CmsProject |
setCurrentProject(CmsProject project)
Sets the current project for the user. |
void |
setEncoding(java.lang.String encoding)
Sets the current content encoding to be used in HTTP response. |
void |
setLocale(java.util.Locale locale)
Sets the locale used by this request context. |
void |
setOuFqn(java.lang.String ouFqn)
Sets the organizational unit fully qualified name. |
void |
setRequestTime(long time)
Sets the current request time. |
void |
setSiteRoot(java.lang.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(java.lang.String value)
Set the requested resource OpenCms VFS URI, that is the value returned by getUri() . |
protected void |
switchUser(CmsUser user,
CmsProject project,
java.lang.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 java.lang.String ATTRIBUTE_EDITOR
public static final java.lang.String ATTRIBUTE_FULLLINKS
public static final java.lang.String ATTRIBUTE_MODEL
Constructor Detail |
---|
public CmsRequestContext(CmsUser user, CmsProject project, java.lang.String requestedUri, java.lang.String siteRoot, java.util.Locale locale, java.lang.String encoding, java.lang.String remoteAddr, long requestTime, CmsResourceTranslator directoryTranslator, CmsResourceTranslator fileTranslator, java.lang.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 java.lang.String getAdjustedSiteRoot(java.lang.String siteRoot, java.lang.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 java.lang.String addSiteRoot(java.lang.String resourcename)
resourcename
- the resource name
addSiteRoot(String, String)
public java.lang.String addSiteRoot(java.lang.String siteRoot, java.lang.String resourcename)
siteRoot
- the site root to addresourcename
- the resource name
public CmsProject currentProject()
public CmsUser currentUser()
public java.lang.String getAdjustedSiteRoot(java.lang.String resourcename)
resourcename
- the resource name to get the adjusted site root for
getAdjustedSiteRoot(String, String)
public java.lang.Object getAttribute(java.lang.String attributeName)
attributeName
- the attribute name
null
if the attribute was not foundpublic CmsResourceTranslator getDirectoryTranslator()
The directory translator is used to translate old VFS path information
to a new location. Example: /bodys/index.html --> /system/bodies/
.
public java.lang.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 java.lang.String getFolderUri()
public java.util.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 java.lang.String getOuFqn()
public java.lang.String getRemoteAddress()
public long getRequestTime()
public java.lang.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 java.lang.String getSiteRoot()
public java.lang.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 java.lang.Object removeAttribute(java.lang.String key)
key
- the name of the attribute to remove
null
if no attribute was set with this namepublic java.lang.String removeSiteRoot(java.lang.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 restoreSiteRoot() throws java.lang.RuntimeException
String storedSite = context.getSiteRoot(); try { context.setSiteRoot(""); // do something with the context } finally { context.setSiteRoot(storedSite); }
java.lang.RuntimeException
- in case there is no site root savedpublic void saveSiteRoot() throws java.lang.RuntimeException
String storedSite = context.getSiteRoot(); try { context.setSiteRoot(""); // do something with the context } finally { context.setSiteRoot(storedSite); }
java.lang.RuntimeException
- in case there is already a site root savedpublic void setAttribute(java.lang.String key, java.lang.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(java.lang.String encoding)
encoding
- the encodingpublic void setLocale(java.util.Locale locale)
locale
- the locale to setfor more information about how the locale is set in normal operation
public void setOuFqn(java.lang.String ouFqn)
ouFqn
- the organizational unit fully qualified namepublic void setRequestTime(long time)
time
- the request timepublic void setSiteRoot(java.lang.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(java.lang.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, java.lang.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 |