cmsrequestcontext.java
来自「找了很久才找到到源代码」· Java 代码 · 共 613 行 · 第 1/2 页
JAVA
613 行
return m_locale;
}
/**
* Returns the fully qualified name of the organizational unit.<p>
*
* @return the fully qualified name of the organizational unit
*/
public String getOuFqn() {
return m_ouFqn;
}
/**
* Returns the remote ip address.<p>
*
* @return the remote ip address as string
*/
public String getRemoteAddress() {
return m_remoteAddr;
}
/**
* Returns the current request time.<p>
*
* @return the current request time
*/
public long getRequestTime() {
return m_requestTime;
}
/**
* Adjusts the absolute resource root path for the current site.<p>
*
* The full root path of a resource is always available using
* <code>{@link CmsResource#getRootPath()}</code>. From this name this method cuts
* of the current site root using
* <code>{@link CmsRequestContext#removeSiteRoot(String)}</code>.<p>
*
* If the resource root path does not start with the current site root,
* it is left untouched.<p>
*
* @param resource the resource to get the adjusted site root path for
*
* @return the absolute resource path adjusted for the current site
*
* @see #removeSiteRoot(String)
* @see CmsResource#getRootPath()
* @see CmsObject#getSitePath(CmsResource)
*/
public String getSitePath(CmsResource resource) {
return removeSiteRoot(resource.getRootPath());
}
/**
* Returns the current root directory in the virtual file system.<p>
*
* @return the current root directory in the virtual file system
*/
public String getSiteRoot() {
return m_siteRoot;
}
/**
* Returns the OpenCms VFS URI of the requested resource.<p>
*
* @return the OpenCms VFS URI of the requested resource
*/
public String getUri() {
return m_uri;
}
/**
* Check if this request context will update the session.<p>
*
* This is used mainly for CmsReports that continue to use the
* users context, even after the http request is already finished.<p>
*
* @return true if this request context will update the session, false otherwise
*/
public boolean isUpdateSessionEnabled() {
return m_updateSession;
}
/**
* Removes an attribute from the request context.<p>
*
* @param key the name of the attribute to remove
*
* @return the removed attribute, or <code>null</code> if no attribute was set with this name
*/
public Object removeAttribute(String key) {
if (m_attributeMap != null) {
return m_attributeMap.remove(key);
}
return null;
}
/**
* 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.<p>
*
* If the resource name does not start with the current site root,
* it is left untouched.<p>
*
* @param resourcename the resource name
*
* @return the resource name adjusted for the current site root
*
* @see #getSitePath(CmsResource)
*/
public String removeSiteRoot(String resourcename) {
String siteRoot = getAdjustedSiteRoot(m_siteRoot, resourcename);
if ((siteRoot == m_siteRoot)
&& resourcename.startsWith(siteRoot)
&& ((resourcename.length() == siteRoot.length()) || (resourcename.charAt(siteRoot.length()) == '/'))) {
resourcename = resourcename.substring(siteRoot.length());
}
return resourcename;
}
/**
* Restores the saved site root.<p>
*
* @throws RuntimeException in case there is no site root saved
*
* @deprecated store the current site root locally before switching
* to another site, and set it back again at the end, like:
* <pre>
* String storedSite = context.getSiteRoot();
* try {
* context.setSiteRoot("");
* // do something with the context
* } finally {
* context.setSiteRoot(storedSite);
* }
* </pre>
*/
public void restoreSiteRoot() throws RuntimeException {
if (m_savedSiteRoot == null) {
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_EMPTY_SITEROOT_0));
}
m_siteRoot = m_savedSiteRoot;
m_savedSiteRoot = null;
}
/**
* Saves the current site root.<p>
*
* @throws RuntimeException in case there is already a site root saved
*
* @deprecated store the current site root locally before switching
* to another site, and set it back again at the end, like:
* <pre>
* String storedSite = context.getSiteRoot();
* try {
* context.setSiteRoot("");
* // do something with the context
* } finally {
* context.setSiteRoot(storedSite);
* }
* </pre>
*/
public void saveSiteRoot() throws RuntimeException {
if (m_savedSiteRoot != null) {
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_NONEMPTY_SITEROOT_1, m_savedSiteRoot));
}
m_savedSiteRoot = m_siteRoot;
}
/**
* Sets an attribute in the request context.<p>
*
* @param key the attribute name
* @param value the attribute value
*/
public void setAttribute(String key, Object value) {
if (m_attributeMap == null) {
// hash table is still the most efficient form of a synchronized Map
m_attributeMap = new Hashtable();
}
m_attributeMap.put(key, value);
}
/**
* Sets the current project for the user.<p>
*
* @param project the project to be set as current project
*
* @return the CmsProject instance
*/
public CmsProject setCurrentProject(CmsProject project) {
if (project != null) {
m_currentProject = project;
}
return m_currentProject;
}
/**
* Sets the current content encoding to be used in HTTP response.<p>
*
* @param encoding the encoding
*/
public void setEncoding(String encoding) {
m_encoding = encoding;
}
/**
* Sets the current request time.<p>
*
* @param time the request time
*/
public void setRequestTime(long time) {
m_requestTime = time;
}
/**
* Sets the current root directory in the virtual file system.<p>
*
* @param root the name of the new root directory
*/
public void setSiteRoot(String root) {
// site roots must never end with a "/"
if (root.endsWith("/")) {
m_siteRoot = root.substring(0, root.length() - 1);
} else {
m_siteRoot = root;
}
}
/**
* Mark this request context to update the session or not.<p>
*
* @param value true if this request context will update the session, false otherwise
*/
public void setUpdateSessionEnabled(boolean value) {
m_updateSession = value;
}
/**
* Set the requested resource OpenCms VFS URI, that is the value returned by {@link #getUri()}.<p>
*
* 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 <code>try { // do something // } finally { // reset URI // }</code> statement.<p>
*
* @param value the value to set the Uri to, must be a complete OpenCms path name like /system/workplace/style.css
*/
public void setUri(String value) {
m_uri = value;
}
/**
* Switches the user in the context, required after a login.<p>
*
* @param user the new user to use
* @param project the new users current project
* @param ouFqn the organizational unit
*/
protected void switchUser(CmsUser user, CmsProject project, String ouFqn) {
m_user = user;
m_currentProject = project;
setOuFqn(ouFqn);
}
/**
* Sets the organizational unit fully qualified name.<p>
*
* @param ouFqn the organizational unit fully qualified name
*/
private void setOuFqn(String ouFqn) {
String userOu = CmsOrganizationalUnit.getParentFqn(m_user.getName());
if (ouFqn != null) {
if (!ouFqn.startsWith(userOu) && !ouFqn.substring(1).startsWith(userOu)) {
throw new CmsIllegalArgumentException(Messages.get().container(
Messages.ERR_BAD_ORGUNIT_2,
ouFqn,
userOu));
}
m_ouFqn = ouFqn;
} else {
m_ouFqn = userOu;
}
m_ouFqn = CmsOrganizationalUnit.removeLeadingSeparator(m_ouFqn);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?