xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r662487 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java status.xml
Date Mon, 02 Jun 2008 16:54:59 GMT
Author: jeremias
Date: Mon Jun  2 09:54:59 2008
New Revision: 662487

URL: http://svn.apache.org/viewvc?rev=662487&view=rev
Log:
Bugzilla #44902:
Made file URLs with a host (as happens when using UNC paths) work when loading images.
Commons IO's FileUtils.toFile(URL) actually doesn't support UNC paths, so I copied the method
into AbstractImageSessionContext for a quickfix and changed it as necessary.

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
    xmlgraphics/commons/trunk/status.xml

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java?rev=662487&r1=662486&r2=662487&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
Mon Jun  2 09:54:59 2008
@@ -33,7 +33,6 @@
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -93,7 +92,7 @@
         } catch (MalformedURLException e) {
             url = null;
         } 
-        File f = FileUtils.toFile(url);
+        File f = /*FileUtils.*/toFile(url);
         if (f != null) {
             boolean directFileAccess = true;
             assert (source instanceof StreamSource) || (source instanceof SAXSource);
@@ -174,6 +173,44 @@
         return imageSource;
     }
     
+    /**
+     * Convert from a <code>URL</code> to a <code>File</code>.
+     * <p>
+     * This method will decode the URL.
+     * Syntax such as <code>file:///my%20docs/file.txt</code> will be
+     * correctly decoded to <code>/my docs/file.txt</code>.
+     * <p>
+     * Note: this method has been copied over from Apache Commons IO and enhanced to support
+     * UNC paths.
+     *
+     * @param url  the file URL to convert, <code>null</code> returns <code>null</code>
+     * @return the equivalent <code>File</code> object, or <code>null</code>
+     *  if the URL's protocol is not <code>file</code>
+     * @throws IllegalArgumentException if the file is incorrectly encoded
+     */
+    public static File toFile(URL url) {
+        if (url == null || !url.getProtocol().equals("file")) {
+            return null;
+        } else {
+            String filename = "";
+            if (url.getHost() != null) {
+                filename += Character.toString(File.separatorChar)
+                        + Character.toString(File.separatorChar)
+                        + url.getHost();
+            }
+            filename += url.getFile().replace('/', File.separatorChar);
+            int pos = 0;
+            while ((pos = filename.indexOf('%', pos)) >= 0) {
+                if (pos + 2 < filename.length()) {
+                    String hexStr = filename.substring(pos + 1, pos + 3);
+                    char ch = (char) Integer.parseInt(hexStr, 16);
+                    filename = filename.substring(0, pos) + ch + filename.substring(pos +
3);
+                }
+            }
+            return new File(filename);
+        }
+    }
+    
     private SoftMapCache sessionSources = new SoftMapCache(false); //no need for synchronization
     
     /** {@inheritDoc} */

Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?rev=662487&r1=662486&r2=662487&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Mon Jun  2 09:54:59 2008
@@ -40,6 +40,9 @@
   </contexts>
   <changes>
     <release version="Trunk" date="n/a">
+      <action context="Code" dev="JM" type="fix" fixes-bug="44902">
+        Made file URLs with a host (as happens when using UNC paths) work when loading images.
+      </action>
       <action context="Code" dev="MB" type="fix">
         Bugfix for classpath resources: the code doesn't just check the system class loader
anymore.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message