/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 ****************************************************************/
package org.apache.james.container.spring.adaptor;

import java.io.File;
import java.io.FileNotFoundException;

import org.apache.james.services.FileSystem;

public class FileSystemBridge implements FileSystem {

	public File getBasedir() throws FileNotFoundException {
		return new File(".");
	}

    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));
            } else {
            	return new File("./"+fileURL.substring(7));
            }
        } else {
            throw new UnsupportedOperationException("getFile: "+fileURL);
        }
    }

}

@@ -1292,16 +1292,104 @@
 ception;
+%0Aimport java.io.InputStream;%0Aimport java.io.IOException;%0Aimport java.io.FileInputStream;
 %0A%0Aimport
@@ -1486,93 +1486,907 @@
 m %7B%0A
-%0A%09public File getBasedir() throws FileNotFoundException %7B%0A%09%09return new File(%22.%22);%0A%09%7D%0A
+    private static final String FILE_PROTOCOL = %22file://%22;%0A    private static final String FILE_PROTOCOL_AND_CONF = %22file://conf/%22;%0A%0A    public File getBasedir() throws FileNotFoundException %7B%0A%09%09return new File(%22.%22);%0A%09%7D%0A%0A    /**%0A     * loads resources from classpath or file system %0A     */%0A    public InputStream getResource(String url) throws IOException %7B%0A    %09if (url.startsWith(%22classpath:%22)) %7B%0A    %09%09String resourceName = url.substring(%22classpath:%22.length());%0A%09%09%09InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);%0A    %09%09if (resourceAsStream==null) %7B%0A    %09%09%09throw new IOException(%22Resource '%22 + resourceName + %22' not found in the classpath!%22);%0A    %09%09%7D%0A    %09%09return resourceAsStream;%0A    %09%7D%0A    %09return new FileInputStream(getFile(url));%0A    %7D%0A%0A    /**%0A     * @see org.apache.james.services.FileSystem#getFile(String filURL) %0A     */
 %0A   
@@ -2484,25 +2484,29 @@
 rtsWith(
-%22file://%22
+FILE_PROTOCOL
 )) %7B%0A   
@@ -2537,30 +2537,38 @@
 rtsWith(
-%22file://conf/%22
+FILE_PROTOCOL_AND_CONF
 )) %7B%0A   
@@ -2607,13 +2607,12 @@
 src/
-trunk
+main
 /con
@@ -2616,24 +2616,41 @@
 config/%22
-+fileURL
+ + FILE_PROTOCOL_AND_CONF
 .substri
@@ -2712,23 +2712,31 @@
 ile(%22./%22
-+fileUR
+ + FILE_PROTOCO
 L.substr
@@ -2838,17 +2838,19 @@
 tFile: %22
-+
+ + 
 fileURL)

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)