You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/01/14 20:58:30 UTC
cvs commit: jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core ApplicationContext.java StandardContext.java
remm 01/01/14 11:58:30
Modified: catalina/src/share/org/apache/catalina/core
ApplicationContext.java StandardContext.java
Log:
- Fix the binding of the resources in the servlet context.
- Fix ServletContext.getRealPath().
- The AppContext cannot accurately generate the base path by itself
anymore, as the new resources do not expose that information. Instead, it's
passed as a parameter in the constructor.
Revision Changes Path
1.12 +13 -6 jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
Index: ApplicationContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ApplicationContext.java 2001/01/13 05:22:40 1.11
+++ ApplicationContext.java 2001/01/14 19:58:30 1.12
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.11 2001/01/13 05:22:40 remm Exp $
- * $Revision: 1.11 $
- * $Date: 2001/01/13 05:22:40 $
+ * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.12 2001/01/14 19:58:30 remm Exp $
+ * $Revision: 1.12 $
+ * $Date: 2001/01/14 19:58:30 $
*
* ====================================================================
*
@@ -105,7 +105,7 @@
*
* @author Craig R. McClanahan
* @author Remy Maucherat
- * @version $Revision: 1.11 $ $Date: 2001/01/13 05:22:40 $
+ * @version $Revision: 1.12 $ $Date: 2001/01/14 19:58:30 $
*/
public final class ApplicationContext
@@ -121,10 +121,11 @@
*
* @param context The associated Context instance
*/
- public ApplicationContext(StandardContext context) {
+ public ApplicationContext(String basePath, StandardContext context) {
super();
this.context = context;
+ this.basePath = basePath;
}
@@ -164,6 +165,12 @@
StringManager.getManager(Constants.Package);
+ /**
+ * Base path.
+ */
+ private String basePath = null;
+
+
// --------------------------------------------------------- Public Methods
@@ -353,7 +360,7 @@
public String getRealPath(String path) {
// Here, we return a fake path
- File file = new File(context.getDocBase(), path);
+ File file = new File(basePath, path);
return (file.getAbsolutePath());
}
1.36 +46 -31 jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- StandardContext.java 2001/01/13 05:20:49 1.35
+++ StandardContext.java 2001/01/14 19:58:30 1.36
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.35 2001/01/13 05:20:49 remm Exp $
- * $Revision: 1.35 $
- * $Date: 2001/01/13 05:20:49 $
+ * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.36 2001/01/14 19:58:30 remm Exp $
+ * $Revision: 1.36 $
+ * $Date: 2001/01/14 19:58:30 $
*
* ====================================================================
*
@@ -136,7 +136,7 @@
*
* @author Craig R. McClanahan
* @author Remy Maucherat
- * @version $Revision: 1.35 $ $Date: 2001/01/13 05:20:49 $
+ * @version $Revision: 1.36 $ $Date: 2001/01/14 19:58:30 $
*/
public class StandardContext
@@ -845,7 +845,7 @@
public synchronized ServletContext getServletContext() {
if (context == null)
- context = new ApplicationContext(this);
+ context = new ApplicationContext(getBasePath(), this);
return (context);
}
@@ -912,33 +912,14 @@
public synchronized void setResources(DirContext resources) {
if (resources instanceof BaseDirContext) {
- String docBase = null;
- Container container = this;
- while (container != null) {
- if (container instanceof Host)
- break;
- container = container.getParent();
- }
- if (container == null) {
- docBase = (new File(engineBase(), getDocBase())).getPath();
- } else {
- File file = new File(getDocBase());
- if (!file.isAbsolute()) {
- // Use the "appBase" property of this container
- String appBase = ((Host) container).getAppBase();
- file = new File(appBase);
- if (!file.isAbsolute())
- file = new File(engineBase(), appBase);
- docBase = (new File(file, getDocBase())).getPath();
- } else {
- docBase = file.getPath();
- }
- }
- ((BaseDirContext) resources).setDocBase(docBase);
+ if (resources instanceof BaseDirContext)
+ ((BaseDirContext) resources).setDocBase(getBasePath());
}
super.setResources(resources);
- // We put the resources into the servlet context
- getServletContext().setAttribute(Globals.RESOURCES_ATTR, resources);
+ if (started)
+ // We put the resources into the servlet context
+ getServletContext().setAttribute
+ (Globals.RESOURCES_ATTR, getResources());
}
@@ -2968,6 +2949,10 @@
}
}
+ // We put the resources into the servlet context
+ getServletContext().setAttribute
+ (Globals.RESOURCES_ATTR, getResources());
+
// Configure and call application event listeners and filters
listenerStart();
filterStart();
@@ -3158,6 +3143,36 @@
/**
+ * Get base path.
+ */
+ private String getBasePath() {
+ String docBase = null;
+ Container container = this;
+ while (container != null) {
+ if (container instanceof Host)
+ break;
+ container = container.getParent();
+ }
+ if (container == null) {
+ docBase = (new File(engineBase(), getDocBase())).getPath();
+ } else {
+ File file = new File(getDocBase());
+ if (!file.isAbsolute()) {
+ // Use the "appBase" property of this container
+ String appBase = ((Host) container).getAppBase();
+ file = new File(appBase);
+ if (!file.isAbsolute())
+ file = new File(engineBase(), appBase);
+ docBase = (new File(file, getDocBase())).getPath();
+ } else {
+ docBase = file.getPath();
+ }
+ }
+ return docBase;
+ }
+
+
+ /**
* Create and initialize the JNDI naming context.
*/
private void createNamingContext()
@@ -3297,7 +3312,7 @@
// Binding the resources directory context
try {
- compCtx.bind("Resources", resources);
+ compCtx.bind("Resources", getResources());
} catch (NamingException e) {
log(sm.getString("standardContext.bindFailed", e));
}