Author: johnh
Date: Tue Nov 24 06:48:31 2009
New Revision: 883605

URL: http://svn.apache.org/viewvc?rev=883605&view=rev
Log:
Accommodate Windows file paths as URIs in Feature loader system. Not the
prettiest patch, but it appears to work.


Modified:
    
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureRegistry.java
    
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureResourceLoader.java
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java

Modified: 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureRegistry.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureRegistry.java?rev=883605&r1=883604&r2=883605&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureRegistry.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureRegistry.java
 Tue Nov 24 06:48:31 2009
@@ -29,6 +29,7 @@
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.common.uri.UriBuilder;
 import org.apache.shindig.common.util.ResourceLoader;
+import org.apache.shindig.common.util.Utf8UrlCoder;
 import org.apache.shindig.gadgets.GadgetContext;
 import org.apache.shindig.gadgets.GadgetException;
 import org.apache.shindig.gadgets.RenderingContext;
@@ -282,6 +283,13 @@
     return uri;
   }
   
+  static File getFile(String filePath) {
+    if (File.separatorChar == '\\') {
+      filePath = Utf8UrlCoder.decode(filePath);
+    }
+    return new File(filePath);
+  }
+  
   private List<FeatureNode> getTransitiveDeps(Collection<String> needed, 
List<String> unsupported) {
     final List<FeatureNode> requested = getRequestedNodes(needed, unsupported);
     
@@ -402,6 +410,10 @@
     }
   }
   
+  private void loadFile(String filePath) throws GadgetException, IOException {
+    loadFile(getFile(filePath));
+  }
+
   private void loadFile(File file) throws GadgetException, IOException {
     if (!file.exists() || !file.canRead()) {
       throw new GadgetException(GadgetException.Code.INVALID_CONFIG,
@@ -421,7 +433,8 @@
         loadFile(featureFile);
       } else if 
(featureFile.getName().toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
         String content = ResourceLoader.getContent(featureFile);
-        Uri parent = Uri.fromJavaUri(featureFile.toURI());
+        Uri parent = new UriBuilder().setScheme(FILE_SCHEME).setAuthority("")
+            .setPath(featureFile.getAbsolutePath()).toUri();
         loadFeature(parent, content);
       } else {
         if (logger.isLoggable(Level.FINEST)) {

Modified: 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureResourceLoader.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureResourceLoader.java?rev=883605&r1=883604&r2=883605&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureResourceLoader.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/features/FeatureResourceLoader.java
 Tue Nov 24 06:48:31 2009
@@ -74,8 +74,8 @@
   }
   
   protected FeatureResource loadFile(String path, Map<String, String> attribs) 
throws IOException {
-    return new DualModeStaticResource(path, getFileContent(new 
File(getOptPath(path))),
-        getFileContent(new File(path)));
+    return new DualModeStaticResource(path, 
getFileContent(FeatureRegistry.getFile(getOptPath(path))),
+        getFileContent(FeatureRegistry.getFile(path)));
   }
   
   protected String getFileContent(File file) {

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java?rev=883605&r1=883604&r2=883605&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java
 Tue Nov 24 06:48:31 2009
@@ -26,6 +26,7 @@
 
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.common.uri.UriBuilder;
+import org.apache.shindig.common.util.Utf8UrlCoder;
 import org.apache.shindig.config.ContainerConfig;
 import org.apache.shindig.gadgets.GadgetContext;
 import org.apache.shindig.gadgets.GadgetException;
@@ -132,9 +133,9 @@
     File featureFile = File.createTempFile("feature", ".xml", featureDir);
     featureFile.deleteOnExit();
     out = new BufferedWriter(new FileWriter(featureFile));
-    out.write(xml(NODEP_TPL, "gadget", resFile.getAbsolutePath(), null));
+    out.write(xml(NODEP_TPL, "gadget", getFileName(resFile), null));
     out.close();
-    registry.register(childDir.getAbsolutePath());
+    registry.register(getFileName(childDir));
     
     // Verify single resource works all the way through.
     List<FeatureResource> resources = registry.getAllFeatures();
@@ -510,7 +511,17 @@
     BufferedWriter out = new BufferedWriter(new FileWriter(file));
     out.write(content);
     out.close();
-    return Uri.fromJavaUri(file.toURI());
+    return new UriBuilder().setScheme("file").setAuthority("").setPath(
+        getFileName(file)).toUri();
+  }
+  
+  private static String getFileName(File input) throws Exception {
+       if (File.separatorChar == '\\') {
+         // Crazy gross special Windows stuff.
+         return 
Utf8UrlCoder.encode(input.getCanonicalPath().replaceAll("\\\\", "/"))
+                  .replaceAll("%2F", "/");
+       }
+       return input.getCanonicalPath();
   }
   
   private static Uri makeResourceUri(String suffix) {
@@ -541,4 +552,4 @@
       return key.startsWith("/") ? key.substring(1) : key;
     }
   }
-}
\ No newline at end of file
+}


Reply via email to