org.metawidget.config.impl.ServletResourceResolver Maven / Gradle / Ivy
// Metawidget
//
// This file is dual licensed under both the LGPL
// (http://www.gnu.org/licenses/lgpl-2.1.html) and the EPL
// (http://www.eclipse.org/org/documents/epl-v10.php). As a
// recipient of Metawidget, you may choose to receive it under either
// the LGPL or the EPL.
//
// Commercial licenses are also available. See http://metawidget.org
// for details.
package org.metawidget.config.impl;
import java.io.InputStream;
import java.net.URL;
import javax.servlet.ServletContext;
import org.metawidget.inspector.iface.InspectorException;
/**
* Specialized ResourceResolver for Servlets.
*
* Resolves references by looking in /WEB-INF/
first. Defined here, rather than in
* org.metawidget.jsp
, because needs to be shared by various Web-based frameworks
* including GWT.
*
* @author Richard Kennard
*/
public class ServletResourceResolver
extends SimpleResourceResolver {
//
// Private members
//
private ServletContext mContext;
//
// Constructor
//
public ServletResourceResolver( ServletContext context ) {
mContext = context;
}
//
// Protected methods
//
/**
* Overridden to try /WEB-INF/
first.
*/
@Override
public InputStream openResource( String resource ) {
try {
URL url = mContext.getResource( "/WEB-INF/" + resource );
if ( url != null ) {
return url.openStream();
}
} catch ( Exception e ) {
throw InspectorException.newException( e );
}
return super.openResource( resource );
}
}