[utilities COMMIT] /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/UriSupport.java

noreply at shibboleth.net noreply at shibboleth.net
Tue Aug 13 12:18:45 EDT 2013


Author: rdw
Date: Tue Aug 13 12:18:45 2013
New Revision: 423

URL: http://svn.shibboleth.net/view/utilities?rev=423&view=rev
Log:
Fix an issue with absolute file paths, URIs and windows

Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/UriSupport.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/UriSupport.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/UriSupport.java?rev=423&r1=422&r2=423&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/UriSupport.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/UriSupport.java Tue Aug 13 12:18:45 2013
@@ -157,6 +157,29 @@
             throw new IllegalArgumentException("Illegal scheme", e);
         }
     }
+    
+    /**
+     * Create a file: URI from an absolute path, dealing with the Windows, non leading "/" issue.
+     * <br/>
+     * Windows absolute paths have a habit of starting with a "DosDeviceName" (such as <code>C:\absolute\path</code>
+     * if we blindly convert that to a file URI by prepending "file://", then we end up with a URI which has "C:" as 
+     * the network segment.  So if we need to have an absolute file path based URI (JAAS is the example) we call this
+     * method which hides the hideous implementation
+     * @param path the absolute file path to convert
+     * @return a suitable URI
+     * @throws URISyntaxException if the URI contructor fails
+     */
+    public static URI fileURIFromAbsolutePath(String path) throws URISyntaxException {
+        final StringBuilder uriPath = new StringBuilder(path.length()+8);
+        
+        uriPath.append("file://");
+        if (!path.startsWith("/")) {
+            // it's windows
+            uriPath.append('/');
+        }
+        uriPath.append(path);
+        return new URI(uriPath.toString());
+    }
 
     /**
      * Builds an RFC-3968 encoded URL query component from a collection of parameters.



More information about the commits mailing list