Author: berndf
Date: Mon Aug 13 07:10:08 2007
New Revision: 565357

URL: http://svn.apache.org/viewvc?view=rev&rev=565357
Log:
implement extended interface FileManager and add classpath loading capabilities.
see JAMES-803, thanks for the initial patch to Zsombor.
also, fix the hardcoded file loading behavior for conf files (which will be 
made configurable in another step)

Modified:
    
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/FileSystemBridge.java

Modified: 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/FileSystemBridge.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/FileSystemBridge.java?view=diff&rev=565357&r1=565356&r2=565357
==============================================================================
--- 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/FileSystemBridge.java
 (original)
+++ 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/FileSystemBridge.java
 Mon Aug 13 07:10:08 2007
@@ -20,24 +20,47 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.FileInputStream;
 
 import org.apache.james.services.FileSystem;
 
 public class FileSystemBridge implements FileSystem {
+    private static final String FILE_PROTOCOL = "file://";
+    private static final String FILE_PROTOCOL_AND_CONF = "file://conf/";
 
-       public File getBasedir() throws FileNotFoundException {
+    public File getBasedir() throws FileNotFoundException {
                return new File(".");
        }
 
+    /**
+     * loads resources from classpath or file system 
+     */
+    public InputStream getResource(String url) throws IOException {
+       if (url.startsWith("classpath:")) {
+               String resourceName = url.substring("classpath:".length());
+                       InputStream resourceAsStream = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
+               if (resourceAsStream==null) {
+                       throw new IOException("Resource '" + resourceName + "' 
not found in the classpath!");
+               }
+               return resourceAsStream;
+       }
+       return new FileInputStream(getFile(url));
+    }
+
+    /**
+     * @see org.apache.james.services.FileSystem#getFile(String filURL) 
+     */
     public File getFile(String fileURL) throws FileNotFoundException {
-        if (fileURL.startsWith("file://")) {
-            if (fileURL.startsWith("file://conf/")) {
-                return new File("./src/trunk/config/"+fileURL.substring(12));
+        if (fileURL.startsWith(FILE_PROTOCOL)) {
+            if (fileURL.startsWith(FILE_PROTOCOL_AND_CONF)) {
+                return new File("./src/main/config/" + 
FILE_PROTOCOL_AND_CONF.substring(12));
             } else {
-               return new File("./"+fileURL.substring(7));
+               return new File("./" + FILE_PROTOCOL.substring(7));
             }
         } else {
-            throw new UnsupportedOperationException("getFile: "+fileURL);
+            throw new UnsupportedOperationException("getFile: " + fileURL);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to