package org.restexpress.plugin.content.adapter;

import java.io.File;
import java.io.IOException;

import org.restexpress.plugin.content.ContextAdapter;
import org.restexpress.plugin.content.resolver.Resolver;

public class FileContextAdapter implements ContextAdapter {

    /**
     * {@link Resolver}.
     */
    protected final Resolver resolver;

    /**
     * {@link File} as root directory
     */
    protected final File rootDirectory;

    public FileContextAdapter(Resolver resolver, File rootDirectory) {
        super();
        this.resolver = resolver;
        this.rootDirectory = rootDirectory;
    }

    @Override
    public Boolean match(String name) {
        return resolver.match(name);
    }

    @Override
    public File retrieve(String name) throws IOException {
        // extract path name
        String pathname = resolver.resolve(name);
        // locate file under root directory
        File file = new File(rootDirectory, pathname);
        // return file if exists
        return file.exists() ? file : null;
    }

}

@@ -1047,10 +1047,164 @@
 %0A    %7D%0A%0A
+    @Override%0A    public String toString() %7B%0A        return %22FileContextAdapter %5Bresolver=%22 + resolver + %22, rootDirectory=%22 + rootDirectory + %22%5D%22;%0A    %7D%0A%0A
 %7D%0A

add toString information