You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xang-cvs@xml.apache.org by md...@apache.org on 2001/01/11 02:00:14 UTC
cvs commit: xml-xang/java/src/org/apache/xang/util ServletUtil.java
mdierken 01/01/10 17:00:14
Modified: java/src/org/apache/xang/util ServletUtil.java
Log:
Add getCustomPathInfo() which has code that seems to work for Tomcat.
Revision Changes Path
1.4 +61 -2 xml-xang/java/src/org/apache/xang/util/ServletUtil.java
Index: ServletUtil.java
===================================================================
RCS file: /home/cvs/xml-xang/java/src/org/apache/xang/util/ServletUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServletUtil.java 2000/09/13 18:42:35 1.3
+++ ServletUtil.java 2001/01/11 01:00:13 1.4
@@ -5,9 +5,16 @@
import org.apache.xang.net.http.object.*;
import org.apache.xang.net.http.object.impl.HTTPObjectServer;
+/**
+ * This code sucks. Different servlet engines do different things with reporting the location
+ * of servlets which are mapped to handle files with a certain extension.
+ * Servlets want to get the file location of the 'script', and also support URL paths after the name
+ * of the script. For example: "http://localhost/sample/hello.xap/sub1/sub2"
+ *
+ */
public class ServletUtil
{
- /** This will get the location of the file which the servlet is handling.
+ /** This will get the location on disk of the 'script' file which the servlet is handling.
*/
public static String getRealPath(IHTTPContext context)
{
@@ -49,7 +56,8 @@
return realPath;
}
- /** This will get the location of the file which the servlet is handling.
+
+ /** This tries to get the 'extended path info' - stuff after the 'script' URL path portion.
*/
public static String getPathInfo(IHTTPContext context)
{
@@ -87,6 +95,57 @@
return realPath;
}
+
+ public static String getCustomPathInfo(IHTTPContext context)
+ {
+ String path;
+ String realPath=null;
+ boolean hasServletPath=false;
+
+ path = context.getRequest().getServletPath();
+ path = context.getRequest().getPathInfo();
+ if (path != null && path.startsWith("/servlet"))
+ {
+ hasServletPath=true;
+ }
+
+ // detect odd Servlet API behavior
+ if (null == context.getServletContext().getRealPath(path))
+ {
+ int pos;
+
+ // We'll have to parse stuff out.
+ path = context.getRequest().getPathInfo();
+ realPath = path;
+
+ if (path != null)
+ {
+ if (!hasServletPath)
+ {
+ // this is just evil
+ pos = path.indexOf(".xap");
+ if (pos >= 0)
+ {
+ while (pos < path.length() &&
+ path.charAt(pos) != '/' &&
+ path.charAt(pos) != '\\')
+ {
+ pos++;
+ }
+ realPath = path.substring(pos);
+ }
+ }
+ }
+ }
+ else
+ {
+ // let the API do it.
+ realPath = context.getRequest().getPathInfo();
+ }
+
+ return realPath;
+ }
+
/*
"c:/inetpub/apache/docs/xang/apps/hello/hello.xap/../layouts/xap.xsl"