📄 context.java
字号:
return url;
} catch( IOException ex ) {
ex.printStackTrace();
return null;
}
}
/** According to Servlet 2.2 the real path is interpreted as
* relative to the current web app and _cannot_ go outside the
* box. If your intention is different or want the "other" behavior
* you'll have to first call getContext(path) and call getRealPath()
* on the result context ( if any - the server may disable that from
* security reasons !).
* XXX find out how can we find the context path in order to remove it
* from the path - that's the only way a user can do that unless he have
* prior knowledge of the mappings !
*/
public String getRealPath( String path) {
String base=getAbsolutePath();
if( path==null ) path="";
String realPath=FileUtil.safePath( base, path );
// No need for a sub-request, that's a great simplification
// in servlet space.
// Important: that's different from what some people might
// expect and how other server APIs work, but that's how it's
// specified in 2.2. From a security point of view that's very
// good, it keeps inter-webapp communication under control.
if( debug>5) {
log("Get real path " + path + " " + realPath + " " + base );
}
return realPath;
}
/** method to return the Localized version of the file whose
* name is passed as an argument. This corresponds to "file" type
* localization resource lookup mechanism.
*
* The method performs a resource lookup in a manner similar to the
* one specified by java.util.ResourceBundle.
*
* In the case of 'typed' files (files whose name is [file].[ftype])
* search for localized versions of the file are looked for:
*
* file + "_" + language1 + "_" + country1 + "_" + variant1 + "." + ftype
* file + "_" + language1 + "_" + country1 + "." + ftype
* file + "_" + language1 + "." + ftype
* file + "_" + language2 + "_" + country2 + "_" + variant2 "." + ftype
* file + "_" + language2 + "_" + country2 "." + ftype
* file + "_" + language2 + "." + ftype
* file + "." + ftype
*
* Where language1, country1, variant1 are associated with the Locale
* passed as an argument and language2, country2, variant are associated
* with the default Locale passed as argument.
*
* For example, if the preferred Locale is <CODE>es_AR_POSIX</CODE> and
* the default Locale passed is <CODE>fr_CA_WIN</CODE>, and the requested
* pathname is <CODE>/foo/bar/index.html</CODE>, then a search for
* the following localized versions of that file will be done, in order:
*<UL>
*<LI>/foo/bar/index_es_AR_POSIX.html</LI>
*<LI>/foo/bar/index_es_AR.html</LI>
*<LI>/foo/bar/index_es.html</LI>
*<LI>/foo/bar/index_fr_CA_WIN.html</LI>
*<LI>/foo/bar/index_fr.html</LI>
*<LI>/foo/bar/index.html</LI>
*</UL>
*
* If the resource passed has no 'ftype' component, then the same
* rules above apply, with the exception that '.' + ftype are not
* concatenated.
*
* @param path the pathname for the resource whose localized version
* we are seeking
* @param loc the Locale we are interested in.
* @param fbLoc the fallback Locale to use if unsuccessful
*
* @return a String with the path of the "best localized match" for
* the file whose path has been passed as argument.
*/
public String getRealPath (String path, Locale reqLocale, Locale fbLocale)
{
return getRealPath (path, reqLocale, fbLocale, "file");
}
/** method to return the Localized version of the file whose
* name is passed as an argument. The localization is done based
* on localization subdirectories under the docBase.
*
* The method performs a resource lookup in a manner similar to the
* one used for JavaHelp resources.
*
* Search for localized versions of the file are looked for:
*
* <docBase> + "/" + language1 + "_" + country1 + "_" + variant1 + file
* <docBase> + "/" + language1 + "_" + country1 + file
* <docBase> + "/" + language1 + file
* <docBase> + "/" + language2 + "_" + country2 + "_" + variant1 + file
* <docBase> + "/" + language2 + "_" + country2 + file
* <docBase> + "/" + language2 + file
* <docBase> + file
*
* Where language1, country1, variant1 are associated with the Locale
* passed as an argument and language2, country2, variant are associated
* with the fallback Locale passed as argument.
*
*
* @param path the pathname for the resource whose localized version
* we are seeking
* @param loc the Locale we are interested in.
* @param fbLoc the fallback Locale to use if unsuccessful
* @param locType the type of localization required "file", "docbase"
*
* @return a String with the path of the "best localized match" for
* the file whose path has been passed as argument.
*/
public String getRealPath (String path, Locale reqLocale, Locale fbLocale,
String locType)
{
String base = getAbsolutePath();
if (path == null) path = "";
String realPath = null;
if ("file".equals (locType))
realPath = FileUtil.getLocalizedFile (base, path,
reqLocale, fbLocale);
else if ("docbase".equals (locType))
realPath = FileUtil.getDocBaseLocalizedFile (base, path,
reqLocale, fbLocale);
if( debug>5) {
log("Get real path " + path + " " + realPath + " " + base
+ reqLocale.toString() + " " + fbLocale.toString() );
}
return realPath;
}
// -------------------- Deprecated
// tomcat specific properties
private boolean isWorkDirPersistent = false;
private String engineHeader = null;
private URL documentBase;
private URL servletBase = null;
private boolean isInvokerEnabled = false;
// for serving WARs directly
private File warDir = null;
private boolean isWARExpanded = false;
private boolean isWARValidated = false;
/** @deprecated
*/
public boolean isInvokerEnabled() {
return isInvokerEnabled;
}
/** @deprecated
*/
public void setInvokerEnabled(boolean isInvokerEnabled) {
this.isInvokerEnabled = isInvokerEnabled;
}
/** @deprecated
*/
public boolean isWorkDirPersistent() {
return this.isWorkDirPersistent;
}
/** @deprecated
*/
public void setWorkDirPersistent( boolean b ) {
isWorkDirPersistent=b;
}
/** @deprecated
*/
public File getWorkDir() {
return workDir;
}
/** @deprecated
*/
public void setWorkDir(File workDir) {
this.workDir = workDir;
}
/** Set work dir using a String property
* @deprecated
*/
public void setWorkDirPath(String workDir) {
this.workDir=new File(workDir);
}
/** @deprecated
*/
public String getEngineHeader() {
return engineHeader;
}
/** @deprecated
*/
public void setEngineHeader(String s) {
engineHeader=s;
}
// /** @deprecated
// */
// public void setRequestSecurityProvider(RequestSecurityProvider rsProvider) {
// this.rsProvider = rsProvider;
// }
// /** @deprecated
// */
// public RequestSecurityProvider getRequestSecurityProvider() {
// return this.rsProvider;
// }
/** @deprecated
*/
public File getWARDir() {
return this.warDir;
}
/** @deprecated
*/
public void setWARDir( File f ) {
warDir=f;
}
/** @deprecated
*/
public boolean isWARExpanded() {
return this.isWARExpanded;
}
/** @deprecated
*/
public void setIsWARExpanded(boolean isWARExpanded) {
this.isWARExpanded = isWARExpanded;
}
/** @deprecated
*/
public boolean isWARValidated() {
return this.isWARValidated;
}
/** @deprecated
*/
public void setIsWARValidated(boolean isWARValidated) {
this.isWARValidated = isWARValidated;
}
/** @deprecated
*/
public void addContextInterceptor( ContextInterceptor ci) {
getContainer().addContextInterceptor(ci);
}
/** @deprecated
*/
public ContextInterceptor[] getContextInterceptors() {
return getContainer().getContextInterceptors();
}
/** @deprecated
*/
public void addRequestInterceptor( RequestInterceptor ci) {
getContainer().addRequestInterceptor(ci);
}
/** @deprecated
*/
public RequestInterceptor[] getRequestInterceptors() {
return getContainer().getRequestInterceptors();
}
/**
* Get the SecurityManager Permissions for this Context.
*/
public Object getPermissions() {
return perms;
}
public void setPermissions( Object o ) {
perms=o;
}
public Object getProtectionDomain() {
return protectionDomain;
}
public void setProtectionDomain(Object o) {
protectionDomain=o;
}
/** @deprecated - use getDocBase and URLUtil if you need it as URL
* NOT USED INSIDE TOMCAT - ONLY IN OLD J2EE CONNECTORS !
*/
public URL getDocumentBase() {
if( documentBase == null ) {
if( docBase == null)
return null;
try {
String absPath=docBase;
// detect absolute path ( use the same logic in all tomcat )
if (FileUtil.isAbsolute( docBase ) )
absPath=docBase;
else
absPath = contextM.getHome() + File.separator + docBase;
try {
absPath = new File(absPath).getCanonicalPath();
} catch (IOException npe) {
}
documentBase = new URL("file", "", absPath);
} catch( MalformedURLException ex ) {
ex.printStackTrace();
}
}
return documentBase;
}
/** @deprecated - use setDocBase
*/
public void setDocumentBase(URL s) {
// Used only by startup, will be removed
this.documentBase=s;
}
// -------------------- Virtual host support --------------------
/** Make this context visible as part of a virtual host
*/
public void setHost( String h ) {
vhost=h;
}
/** Return the virtual host name, or null if we are in the
default context
*/
public String getHost() {
return vhost;
}
/** Virtual host support - this context will be part of
* a virtual host with the specified name. You should
* set all the aliases. XXX Not implemented
*/
public void addHostAlias( String alias ) {
vhostAliases.addElement( alias );
}
public Enumeration getHostAliases() {
return vhostAliases.elements();
}
// -------------------- Security - trusted code --------------------
public void setTrusted( boolean t ) {
trusted=t;
}
public boolean isTrusted() {
return trusted;
}
public boolean allowAttribute( String name ) {
// check if we can access this attribute.
if( isTrusted() ) return true;
log( "Illegal access to internal attribute ", null, Logger.ERROR);
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -