DirContext dirContext;
URI uri = URI.create(documentRoot);
if (!"file".equals(uri.getScheme())) {
dirContext = new FileDirContext() {
@Override
public Attributes getAttributes(String name) throws NamingException {
return new BasicAttributes();
}
@Override
public Object lookup(String name) throws NamingException {
try {
final URL url = new URL(TomcatDefaultServlet.this.documentRoot + name);
return new Resource() {
@Override
public InputStream streamContent() throws IOException {
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();
}
};
} catch (MalformedURLException e) {
throw new NamingException(e.toString());
}
}
};
} else {
dirContext = new FileDirContext();
((FileDirContext)dirContext).setDocBase(uri.getPath());
}
proxyDirContext = new ProxyDirContext(new Hashtable(), dirContext);
resources = proxyDirContext;
}