本文整理汇总了Java中org.apache.catalina.util.RequestUtil.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java RequestUtil.normalize方法的具体用法?Java RequestUtil.normalize怎么用?Java RequestUtil.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.util.RequestUtil
的用法示例。
在下文中一共展示了RequestUtil.normalize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourceAsStream
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return the requested resource as an <code>InputStream</code>. The
* path must be specified according to the rules described under
* <code>getResource</code>. If no such resource can be identified,
* return <code>null</code>.
*
* @param path The path to the desired resource.
*/
public InputStream getResourceAsStream(String path) {
if (path == null || (Globals.STRICT_SERVLET_COMPLIANCE && !path.startsWith("/")))
return (null);
path = RequestUtil.normalize(path);
if (path == null)
return (null);
DirContext resources = context.getResources();
if (resources != null) {
try {
Object resource = resources.lookup(path);
if (resource instanceof Resource)
return (((Resource) resource).streamContent());
} catch (Exception e) {
}
}
return (null);
}
示例2: getResourcePaths
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return a Set containing the resource paths of resources member of the
* specified collection. Each path will be a String starting with
* a "/" character. The returned set is immutable.
*
* @param path Collection path
*/
public Set getResourcePaths(String path) {
// Validate the path argument
if (path == null) {
return null;
}
if (!path.startsWith("/")) {
throw new IllegalArgumentException
(sm.getString("applicationContext.resourcePaths.iae", path));
}
path = RequestUtil.normalize(path);
if (path == null)
return (null);
DirContext resources = context.getResources();
if (resources != null) {
return (getResourcePathsInternal(resources, path));
}
return (null);
}
示例3: normalize
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return a context-relative path, beginning with a "/", that represents
* the canonical version of the specified path after ".." and "." elements
* are resolved out. If the specified path attempts to go outside the
* boundaries of the current context (i.e. too many ".." path elements
* are present), return <code>null</code> instead.
*
* This normalize should be the same as DefaultServlet.normalize, which is almost the same
* ( see source code below ) as RequestUtil.normalize. Do we need all this duplication?
*
* @param path Path to be normalized
*/
public static String normalize(String path) {
if (path == null)
return null;
String normalized = path;
//Why doesn't RequestUtil do this??
// Normalize the slashes and add leading slash if necessary
if ( normalized.indexOf('\\') >= 0 )
normalized = normalized.replace( '\\', '/' );
normalized = RequestUtil.normalize( path );
return normalized;
}
示例4: getResourcePaths
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return a Set containing the resource paths of resources member of the
* specified collection. Each path will be a String starting with
* a "/" character. The returned set is immutable.
*
* @param path Collection path
*/
@Override
public Set<String> getResourcePaths(String path) {
// Validate the path argument
if (path == null) {
return null;
}
if (!path.startsWith("/")) {
throw new IllegalArgumentException
(sm.getString("applicationContext.resourcePaths.iae", path));
}
String normalizedPath = RequestUtil.normalize(path);
if (normalizedPath == null)
return (null);
DirContext resources = context.getResources();
if (resources != null) {
return (getResourcePathsInternal(resources, normalizedPath));
}
return (null);
}
示例5: getRequestDispatcher
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return a RequestDispatcher that wraps the resource at the specified
* path, which may be interpreted as relative to the current request path.
*
* @param path Path of the resource to be wrapped
*/
public RequestDispatcher getRequestDispatcher(String path) {
if (context == null)
return (null);
// If the path is already context-relative, just pass it through
if (path == null)
return (null);
else if (path.startsWith("/"))
return (context.getServletContext().getRequestDispatcher(path));
// Convert a request-relative path to a context-relative one
String servletPath = (String) getAttribute(Globals.SERVLET_PATH_ATTR);
if (servletPath == null)
servletPath = getServletPath();
int pos = servletPath.lastIndexOf('/');
String relative = null;
if (pos >= 0) {
relative = RequestUtil.normalize
(servletPath.substring(0, pos + 1) + path);
} else {
relative = RequestUtil.normalize(servletPath + path);
}
return (context.getServletContext().getRequestDispatcher(relative));
}
示例6: getAbsolutePath
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
protected String getAbsolutePath(String path) throws IOException {
String pathWithoutContext = SSIServletRequestUtil.getRelativePath(req);
String prefix = getPathWithoutFileName(pathWithoutContext);
if (prefix == null) {
throw new IOException("Couldn't remove filename from path: "
+ pathWithoutContext);
}
String fullPath = prefix + path;
String retVal = RequestUtil.normalize(fullPath);
if (retVal == null) {
throw new IOException("Normalization yielded null on path: "
+ fullPath);
}
return retVal;
}
示例7: getServletContextAndPathFromVirtualPath
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
protected ServletContextAndPath getServletContextAndPathFromVirtualPath(
String virtualPath) throws IOException {
if (!virtualPath.startsWith("/") && !virtualPath.startsWith("\\")) {
return new ServletContextAndPath(context,
getAbsolutePath(virtualPath));
}
String normalized = RequestUtil.normalize(virtualPath);
if (isVirtualWebappRelative) {
return new ServletContextAndPath(context, normalized);
}
ServletContext normContext = context.getContext(normalized);
if (normContext == null) {
throw new IOException("Couldn't get context for path: "
+ normalized);
}
//If it's the root context, then there is no context element
// to remove,
// ie:
// '/file1.shtml' vs '/appName1/file1.shtml'
if (!isRootContext(normContext)) {
String noContext = getPathWithoutContext(
normContext.getContextPath(), normalized);
if (noContext == null) {
throw new IOException(
"Couldn't remove context from path: "
+ normalized);
}
return new ServletContextAndPath(normContext, noContext);
}
return new ServletContextAndPath(normContext, normalized);
}
示例8: normalize
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
protected static String normalize(String path) {
return RequestUtil.normalize(path, File.separatorChar == '\\');
}
示例9: normalize
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return a context-relative path, beginning with a "/", that represents
* the canonical version of the specified path after ".." and "." elements
* are resolved out. If the specified path attempts to go outside the
* boundaries of the current context (i.e. too many ".." path elements are
* present), return <code>null</code> instead. This normalize should be
* the same as DefaultServlet.normalize, which is almost the same ( see
* source code below ) as RequestUtil.normalize. Do we need all this
* duplication?
*
* @param path
* Path to be normalized
*/
public static String normalize(String path) {
return RequestUtil.normalize(path);
}
示例10: normalize
import org.apache.catalina.util.RequestUtil; //导入方法依赖的package包/类
/**
* Return a context-relative path, beginning with a "/", that represents
* the canonical version of the specified path after ".." and "." elements
* are resolved out. If the specified path attempts to go outside the
* boundaries of the current context (i.e. too many ".." path elements
* are present), return <code>null</code> instead.
*
* @param path Path to be normalized
*/
protected String normalize(String path) {
return RequestUtil.normalize(path, File.separatorChar == '\\');
}