You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/02/10 23:28:24 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util MimeMap.java
costin 00/02/10 14:28:24
Modified: . build.xml
src/share/org/apache/tomcat/context
BaseContextInterceptor.java
src/share/org/apache/tomcat/core Context.java
ContextInterceptor.java
src/share/org/apache/tomcat/request SimpleMapper.java
src/share/org/apache/tomcat/servlets WarFileServlet.java
src/share/org/apache/tomcat/util MimeMap.java
Log:
- Added servlet init and destroy notification in ContextInterceptor
- Context.getMimeMap() will return java.net.FileNameMap instead of internal
MimeMap
- added ServletMap - all maps will be in one hashtable, and the
request interceptor will manage it's internal representation ( prefix, etc)
- small change in MimeMap ( reduce GC: -1 string allocation )
Revision Changes Path
1.30 +2 -0 jakarta-tomcat/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/build.xml,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- build.xml 2000/02/09 23:26:27 1.29
+++ build.xml 2000/02/10 22:28:21 1.30
@@ -46,6 +46,8 @@
<target name="tomcat" depends="prepare">
<javac srcdir="src/share" destdir="${tomcat.build}/classes"
classpath="${tomcat.build}/lib/xml.jar" debug="on"/>
+ <javac srcdir="src/j2ee" destdir="${tomcat.build}/classes"
+ classpath="${tomcat.build}/lib/xml.jar" debug="on"/>
<rmic base="${tomcat.build}/classes"
class="org.apache.tomcat.shell.AdminImpl"/>
</target>
1.4 +20 -0 jakarta-tomcat/src/share/org/apache/tomcat/context/BaseContextInterceptor.java
Index: BaseContextInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/BaseContextInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseContextInterceptor.java 2000/02/09 20:36:09 1.3
+++ BaseContextInterceptor.java 2000/02/10 22:28:22 1.4
@@ -133,6 +133,26 @@
return 0;
}
+ /** Servlet Init notification
+ */
+ public int preServletInit( Context ctx, ServletWrapper sw ) {
+ return 0;
+ }
+
+ public int postServletInit( Context ctx, ServletWrapper sw ) {
+ return 0;
+ }
+
+ /** Servlet Destroy notification
+ */
+ public int preServletDestroy( Context ctx, ServletWrapper sw ) {
+ return 0;
+ }
+
+
+ public int postServletDestroy( Context ctx, ServletWrapper sw ) {
+ return 0;
+ }
}
1.46 +65 -47 jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- Context.java 2000/02/10 18:55:54 1.45
+++ Context.java 2000/02/10 22:28:22 1.46
@@ -154,6 +154,9 @@
// Env entries
Hashtable envEntryTypes=new Hashtable();
Hashtable envEntryValues=new Hashtable();
+
+ // Maps specified in web.xml ( String url -> ServletWrapper )
+ private Hashtable mappings = new Hashtable();
// Maps specified in web.xml ( String->ServletWrapper )
private Hashtable prefixMappedServlets = new Hashtable();
@@ -554,6 +557,10 @@
return welcomeFiles.elements();
}
+ /** @deprecated It is used as a hack to allow web.xml override default
+ welcome files.
+ Tomcat will first load the "default" web.xml and then this file.
+ */
public void removeWelcomeFiles() {
if( ! this.welcomeFiles.isEmpty() )
this.welcomeFiles.removeAllElements();
@@ -646,6 +653,8 @@
attributes.remove(name);
}
+ /** @deprecated - use getDocBase and URLUtil if you need it as URL
+ */
public URL getDocumentBase() {
if( documentBase == null ) {
if( docBase != null)
@@ -658,6 +667,8 @@
return documentBase;
}
+ /** @deprecated - use setDocBase
+ */
public void setDocumentBase(URL s) {
// Used only by startup, will be removed
this.documentBase=s;
@@ -692,7 +703,7 @@
this.sessionTimeOut = sessionTimeOut;
}
- public MimeMap getMimeMap() {
+ public FileNameMap getMimeMap() {
return mimeTypes;
}
@@ -821,6 +832,59 @@
}
}
+
+ /**
+ * Maps a named servlet to a particular path or extension.
+ * If the named servlet is unregistered, it will be added
+ * and subsequently mapped.
+ *
+ * Note that the order of resolution to handle a request is:
+ *
+ * exact mapped servlet (eg /catalog)
+ * prefix mapped servlets (eg /foo/bar/*)
+ * extension mapped servlets (eg *jsp)
+ * default servlet
+ *
+ */
+ public void addServletMapping(String servletName, String path) {
+ ServletWrapper sw = (ServletWrapper)servlets.get(servletName);
+
+ if (sw == null) {
+ log("Servlet not registered " + servletName );
+ return;
+ // or throw an exception !
+ }
+ mappings.put( path, sw );
+ }
+
+ public Enumeration getServletMappings() {
+ return mappings.keys();
+ }
+
+ public ServletWrapper getServletMapping( String path ) {
+ return mappings.get(path);
+ }
+
+ public void removeMapping( String path ) {
+ log( "Removing " + path + " -> " + mappings.get(path) );
+ mappings.remove( path );
+ }
+
+ public void removeMappingsFor( ServletWrapper sw ) {
+ Enumeration enum = mappings.keys();
+
+ while (enum.hasMoreElements()) {
+ String key = (String)enum.nextElement();
+
+ if (mappings.get(key).equals(sw)) {
+ log( "Removing " + key + " -> " + sw );
+ mappings.remove(key);
+ }
+ }
+ }
+
+ // -------------------- deprecated code
+
// XXX only one mapping, the mapper should do it's own optimizations
/**
* Maps a named servlet to a particular path or extension.
@@ -1002,52 +1066,6 @@
public ServletLoader getServletLoader() {
return servletL;
}
-
-// /** @deprecated
-// */
-// public void setLoader(ServletClassLoader loader ) {
-// this.servletLoader=loader;
-// }
-
-// /** @deprecated
-// */
-// public ServletClassLoader getLoader() {
-// return servletLoader;
-// }
-
-// public Enumeration getClassPaths() {
-// return this.classPaths.elements();
-// }
-
-// public void addClassPath(String path) {
-// this.classPaths.addElement(path);
-// }
-
-// public Enumeration getLibPaths() {
-// return this.libPaths.elements();
-// }
-
-// public void addLibPath(String path) {
-// this.libPaths.addElement(path);
-// }
-
-// // XXX XXX XXX ugly, need rewrite ( servletLoader will call getClassPaths and getLibPaths
-// // and will concatenate the "file" part of them ).
-// /** Returns the classpath as a string
-// */
-// public String getClassPath() {
-// String cp = this.classPath.trim();
-// String servletLoaderClassPath =
-// this.getLoader().getClassPath();
-
-// if (servletLoaderClassPath != null &&
-// servletLoaderClassPath.trim().length() > 0) {
-// cp += ((cp.length() > 0) ? File.pathSeparator : "") +
-// servletLoaderClassPath;
-// }
-
-// return cp;
-// }
/* -------------------- Utils -------------------- */
public void setDebug( int level ) {
1.5 +15 -5 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java
Index: ContextInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ContextInterceptor.java 2000/02/09 20:36:10 1.4
+++ ContextInterceptor.java 2000/02/10 22:28:22 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.4 2000/02/09 20:36:10 costin Exp $
- * $Revision: 1.4 $
- * $Date: 2000/02/09 20:36:10 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.5 2000/02/10 22:28:22 costin Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/02/10 22:28:22 $
*
* ====================================================================
*
@@ -85,7 +85,6 @@
*/
public int engineShutdown(ContextManager cm);
-
/** Called when a context is added to a CM
*/
public int addContext( ContextManager cm, Context ctx );
@@ -94,7 +93,6 @@
*/
public int removeContext( ContextManager cm, Context ctx );
-
/** Notification when a context is initialized
*/
public int contextInit(Context ctx);
@@ -120,4 +118,16 @@
*/
public int removeMapping( Context ctx, String path );
+ /** Servlet Init notification
+ */
+ public int preServletInit( Context ctx, ServletWrapper sw );
+
+ public int postServletInit( Context ctx, ServletWrapper sw );
+
+
+ /** Servlet Destroy notification
+ */
+ public int preServletDestroy( Context ctx, ServletWrapper sw );
+
+ public int postServletDestroy( Context ctx, ServletWrapper sw );
}
1.8 +0 -1 jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java
Index: SimpleMapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SimpleMapper.java 2000/02/03 23:41:29 1.7
+++ SimpleMapper.java 2000/02/10 22:28:23 1.8
@@ -339,6 +339,5 @@
return ctx;
}
-
}
1.2 +1 -1 jakarta-tomcat/src/share/org/apache/tomcat/servlets/WarFileServlet.java
Index: WarFileServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/servlets/WarFileServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WarFileServlet.java 2000/01/30 04:22:47 1.1
+++ WarFileServlet.java 2000/02/10 22:28:23 1.2
@@ -79,7 +79,7 @@
private ServletContextFacade facade;
private String servletInfo = "DefaultServlet";
private Context context;
- private MimeMap mimeTypes;
+ private FileNameMap mimeTypes;
private String datePattern = "EEE, dd MMM yyyyy HH:mm z";
private DateFormat dateFormat = new SimpleDateFormat(datePattern);
1.2 +26 -12 jakarta-tomcat/src/share/org/apache/tomcat/util/MimeMap.java
Index: MimeMap.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeMap.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MimeMap.java 1999/10/09 00:20:56 1.1
+++ MimeMap.java 2000/02/10 22:28:24 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeMap.java,v 1.1 1999/10/09 00:20:56 duncan Exp $
- * $Revision: 1.1 $
- * $Date: 1999/10/09 00:20:56 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeMap.java,v 1.2 2000/02/10 22:28:24 costin Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/02/10 22:28:24 $
*
* ====================================================================
*
@@ -95,19 +95,33 @@
public void removeContentType(String extn) {
map.remove(extn.toLowerCase());
}
-
- public String getContentTypeFor(String fileName) {
+
+ /** Get extension of file, without fragment id
+ */
+ public static String getExtension( String fileName ) {
// play it safe and get rid of any fragment id
// that might be there
- int i = fileName.lastIndexOf('#');
+ int length=fileName.length();
+
+ int newEnd = fileName.lastIndexOf('#');
+ if( newEnd== -1 ) newEnd=length;
+ // Instead of creating a new string.
+ // if (i != -1) {
+ // fileName = fileName.substring(0, i);
+ // }
+ int i = fileName.lastIndexOf('.', newEnd );
if (i != -1) {
- fileName = fileName.substring(0, i);
+ return fileName.substring(i + 1, newEnd );
+ } else {
+ // no extension, no content type
+ return null;
}
- i = fileName.lastIndexOf('.');
- if (i != -1) {
- String extn = fileName.substring(i + 1, fileName.length());
- String type = getContentType(extn.toLowerCase());
- return type;
+ }
+
+ public String getContentTypeFor(String fileName) {
+ String extn=getExtension( fileName );
+ if (extn!=null) {
+ return getContentType(extn.toLowerCase());
} else {
// no extension, no content type
return null;