001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.webengine.jaxrs.servlet.config; 013 014import java.io.File; 015import java.io.IOException; 016import java.net.URL; 017 018import org.nuxeo.runtime.api.Framework; 019 020/** 021 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 022 */ 023public class FileResourceResolver implements ResourceResolver { 024 025 protected File file; 026 027 public FileResourceResolver(String path) { 028 file = new File(Framework.expandVars(path)); 029 } 030 031 public FileResourceResolver(File file) { 032 this.file = file; 033 } 034 035 @Override 036 public URL getResource(String name) { 037 File f = new File(file, name); 038 if (f.isFile()) { 039 try { 040 return f.toURI().toURL(); 041 } catch (IOException e) { 042 return null; 043 } 044 } 045 return null; 046 } 047 048}