This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getting the JDK built-in web server to set the correct mime type


On 05/11/2013 07:58 PM, Per Bothner wrote:
One thing to consider some tweaks to the gnu.text.Path
API so that given a file: URL we get FilePath rather
than a URLPath (at least by default).

The attached patch attempts this.  I'm thinking combining
with patch with my previous patch might work.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/
Index: gnu/text/Path.java
===================================================================
--- gnu/text/Path.java	(revision 7491)
+++ gnu/text/Path.java	(working copy)
@@ -48,30 +48,42 @@
     /* #endif */
   }
 
-  public static Path coerceToPathOrNull (Object path)
-  {
-    if (path instanceof Path)
-      return (Path) path;
-    if (path instanceof URL)
-      return URLPath.valueOf((URL) path);
-    /* #ifdef use:java.net.URI */
-    if (path instanceof URI)
-      return URIPath.valueOf((URI) path);
-    /* #endif */
-    if (path instanceof File)
-      return FilePath.valueOf((File) path);
-    String str;
-    if (path instanceof gnu.lists.FString) // FIXME: || UntypedAtomic
-      str = path.toString();
-    else if (! (path instanceof String))
-      return null;
-    else
-      str = (String) path;
-    if (Path.uriSchemeSpecified(str))
-      return URIPath.valueOf(str);
-    else
-      return FilePath.valueOf(str);
-  }
+    public static Path coerceToPathOrNull (Object path) {
+        if (path instanceof Path)
+            return (Path) path;
+        if (path instanceof URL) {
+            URL url = (URL) path;
+            if ("file".equals(url.getProtocol())) {
+                try {
+                    return FilePath.valueOf(new File(url.toURI()));
+                } catch (URISyntaxException ex) {
+                    // fall back to generic case
+                }
+            }
+            return URLPath.valueOf(url);
+        }
+        /* #ifdef use:java.net.URI */
+        if (path instanceof URI) {
+            URI uri = (URI) path;
+            if ("file".equals(uri.getScheme()))
+                return FilePath.valueOf(new File(uri));
+            return URIPath.valueOf(uri);
+        }
+        /* #endif */
+        if (path instanceof File)
+            return FilePath.valueOf((File) path);
+        String str;
+        if (path instanceof gnu.lists.FString) // FIXME: || UntypedAtomic
+            str = path.toString();
+        else if (! (path instanceof String))
+            return null;
+        else
+            str = (String) path;
+        if (Path.uriSchemeSpecified(str))
+            return URIPath.valueOf(str);
+        else
+            return FilePath.valueOf(str);
+    }
 
   public static Path valueOf (Object arg)
   {
Index: gnu/kawa/servlet/KawaAutoHandler.java
===================================================================
--- gnu/kawa/servlet/KawaAutoHandler.java	(revision 7491)
+++ gnu/kawa/servlet/KawaAutoHandler.java	(working copy)
@@ -69,7 +69,7 @@
     // If the path matches a directory rather than a file, keep looking.
     URL url = (plen == 0 || path.charAt(plen-1) == '/') ? null
       : hctx.getResourceURL(path);
-    Path absPath = url == null ? null : URLPath.valueOf(url);
+    Path absPath = url == null ? null : Path.valueOf(url);
     String upath = path;
     if (url == null || absPath.isDirectory())
       {
@@ -87,7 +87,7 @@
             if (url != null)
               {
                 hctx.setScriptAndLocalPath(path.substring(0, sl+1), path.substring(sl+1));
-                absPath = URLPath.valueOf(url);
+                absPath = Path.valueOf(url);
                 break;
               }
           }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]