OSDN Git Service

* Added case-sensitivity and other "asset name requirements" to ClasspathLocator...
authorshadowislord <shadowislord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sun, 17 Jul 2011 05:20:38 +0000 (05:20 +0000)
committershadowislord <shadowislord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sun, 17 Jul 2011 05:20:38 +0000 (05:20 +0000)
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7868 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java

index 03970cd..6d5e73a 100644 (file)
@@ -34,10 +34,13 @@ package com.jme3.asset.plugins;
 
 import com.jme3.asset.*;
 import com.jme3.system.JmeSystem;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
@@ -103,12 +106,33 @@ public class ClasspathLocator implements AssetLocator {
         if (url == null)
             return null;
         
+        if (url.getProtocol().equals("file")){
+            try {
+                String path = new File(url.toURI()).getCanonicalPath();
+                
+                // convert to / for windows
+                if (File.separatorChar == '\\'){
+                    path = path.replace('\\', '/');
+                }
+                
+                // compare path
+                if (!path.endsWith(name)){
+                    throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+
+                                                     "\"" + path + "\" doesn't match \"" + name + "\"");
+                }
+            } catch (URISyntaxException ex) {
+                throw new AssetLoadException("Error converting URL to URI", ex);
+            } catch (IOException ex){
+                throw new AssetLoadException("Failed to get canonical path for " + url, ex);
+            }
+        }
+        
         try{
             URLConnection conn = url.openConnection();
             conn.setUseCaches(false);
             return new ClasspathAssetInfo(manager, key, conn);
         }catch (IOException ex){
-            return null;
+            throw new AssetLoadException("Failed to read URL " + url, ex);
         }
         
     }