cmsflexrequest.java
来自「java 编写的程序」· Java 代码 · 共 408 行 · 第 1/2 页
JAVA
408 行
* and servlet name.
* If this URI is already absolute, return it unchanged.
* Return URI also unchanged if it is not well-formed.
*
* @param location URI to be (possibly) converted and then returned
* @return The location converted to an absolut location
*/
public String toAbsolute(String location) {
if (DEBUG) System.err.println("FlexRequest.toAbsolute(): location=" + location);
if (location == null) return (location);
// Construct a new absolute URL if possible (cribbed from Tomcat)
java.net.URL url = null;
try {
url = new java.net.URL(location);
} catch (java.net.MalformedURLException e1) {
String requrl = getRequestURL().toString();
try {
url = new java.net.URL(new java.net.URL(requrl), location);
} catch (java.net.MalformedURLException e2) {
// Some other method will deal with that sooner or later
return location;
}
}
// Now check if this is a opencms resource and if so remove the context / servlet path
String uri = url.getPath();
String context = getContextPath() + getServletPath();
if (uri.startsWith(context)) {
uri = uri.substring(context.length());
}
if (DEBUG) System.err.println("FlexRequest.toAbsolute(): result=" + uri);
return uri;
}
/**
* Internal replacement for the standard servlet API getRequestDispatcher() method.
* This version is used if an external file (probably JSP) is dispached to.
* This external file must have a "mirror" version, i.e. a file in the OpenCms VFS
* that represents the external file.
*
* @param cms_target The OpenCms file that is a "mirror" version of the external file.
* @param ext_target The external file (outside the OpenCms VFS).
* @return The constructed CmsFlexRequestDispatcher.
*/
public CmsFlexRequestDispatcher getCmsRequestDispatcher(String cms_target, String ext_target) {
return new CmsFlexRequestDispatcher(getCmsTopRequest().getRequestDispatcher(ext_target), toAbsolute(cms_target), ext_target, m_cache, m_cms);
}
/**
* Internal replacement for the standard servlet API getRequestDispatcher() method.
* This version can be used if you know that you are dealing with a CmsFlexRequest,
* so you can avoid casting the result of getRequestDispatcher() to the CmsFlexRequestDispatcher.
*
* @param target The target for the request dispatcher.
* @return The constructed CmsFlexRequestDispatcher.
*/
public CmsFlexRequestDispatcher getCmsRequestDispatcher(String target) {
return new CmsFlexRequestDispatcher(getCmsTopRequest().getRequestDispatcher(toAbsolute(target)), toAbsolute(target), m_cache, m_cms);
}
// ---------------------------- Methods overloading the HttpServletRequest interface
/**
* Overloads the standard servlet API getRequestDispatcher() method.
* The RequestDispatcher is the main point in this wrapper.
*
* @param target The target for the request dispatcher.
* @return The constructed RequestDispatcher.
*/
public javax.servlet.RequestDispatcher getRequestDispatcher(String target) {
return (javax.servlet.RequestDispatcher) getCmsRequestDispatcher(target);
}
/**
* Wraps the request URI, overloading the standard API.
* This ensures that any wrapped request will use the "faked"
* target parameters. Remember that for the real request,
* a mixture of PathInfo and other request information is used to
* idenify the target.
*
* @return A faked URI that will point to the wrapped target in the VFS.
*/
public String getRequestURI() {
StringBuffer buf = new StringBuffer(128);
buf.append(getContextPath());
buf.append(getServletPath());
buf.append(getCmsResource());
return buf.toString();
}
/**
* Makes sure that the target information is really used
* by internal include calls.
*
* @return The faked PathInfo for this request, which will point to the wrapped target
*/
public String getPathInfo() {
return getCmsResource();
}
/**
* Wraps the request URL, overloading the standard API.
* The wrapped URL will always point to the currently included VFS resource.
*
* @return A faked URL that will point to the included target in the VFS.
*/
public StringBuffer getRequestURL() {
StringBuffer buf = new StringBuffer(128);
buf.append(getScheme());
buf.append("://");
buf.append(getServerName());
buf.append(":");
buf.append(getServerPort());
buf.append(getRequestURI());
return buf;
}
/**
* Returns the cache key for this request.
* The key will be calculated if neccessary.
*
* @return The cache key for this request
*/
CmsFlexCacheKey getCmsCacheKey() {
// The key for this request is only calculated if actually requested
if (m_key == null) {
m_key = new CmsFlexCacheKey(this, m_resource, m_isOnline);
}
return m_key;
}
/**
* Indicates that this request belongs to an online project.
* This is required to distinguish between online and offline
* resources in the cache. Since the resources have the same name,
* a suffix [online] or [offline] is added to distinguish the strings
* when building cache keys.
* Any resource from a request that isOnline() will be saved with
* the [online] suffix and vice versa.<p>
*
* The suffixes are used so that we have a simple String name
* for the resources in the cache. This makes it easy to
* use a standard HashMap for storage of the resources.
*
* @return true if an online resource was requested, false otherwise
*/
public boolean isOnline() {
return m_isOnline;
}
/**
* This is needed to decide if this request can be cached or not.
* Using the request to decide if caching is used or not
* makes it possible to set caching to false e.g. on a per-user
* or per-project basis.
*
* @return true if the request is cacheable, false otherwise
*/
boolean isCacheable() {
return m_canCache;
}
/**
* Adds another include call to this wrapper.
* The set of include calls is maintained to dectect
* an endless inclusion loop.
*/
void addInlucdeCall(String target) {
m_includeCalls.add(target);
}
/**
* Removes an include call from this wrapper.
* The set of include calls is maintained to dectect
* an endless inclusion loop.
*/
void removeIncludeCall(String target) {
m_includeCalls.remove(target);
}
/**
* Checks if a given target is already included in a top-layer of this
* wrapped request.
* The set of include calls is maintained to dectect
* an endless inclusion loop.
*/
boolean containsIncludeCall(String target) {
return m_includeCalls.contains(target);
}
/**
* Used to pass the Set of include calls to the next wrapping layer.
* The set of include calls is maintained to dectect
* an endless inclusion loop.
*/
protected java.util.Set getCmsIncludeCalls() {
return m_includeCalls;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?