use of org.apache.catalina.WebResourceRoot in project tomcat by apache.
the class ResolverImpl method resolveResource.
@Override
public boolean resolveResource(int type, String name) {
WebResourceRoot resources = request.getContext().getResources();
WebResource resource = resources.getResource(name);
if (!resource.exists()) {
return false;
} else {
switch(type) {
case 0:
return (resource.isDirectory());
case 1:
return (resource.isFile());
case 2:
return (resource.isFile() && resource.getContentLength() > 0);
default:
return false;
}
}
}
use of org.apache.catalina.WebResourceRoot in project tomcat by apache.
the class DirResourceSet method getResource.
@Override
public WebResource getResource(String path) {
checkPath(path);
String webAppMount = getWebAppMount();
WebResourceRoot root = getRoot();
if (path.startsWith(webAppMount)) {
File f = file(path.substring(webAppMount.length()), false);
if (f == null) {
return new EmptyResource(root, path);
}
if (!f.exists()) {
return new EmptyResource(root, path, f);
}
if (f.isDirectory() && path.charAt(path.length() - 1) != '/') {
path = path + '/';
}
return new FileResource(root, path, f, isReadOnly(), getManifest());
} else {
return new EmptyResource(root, path);
}
}
use of org.apache.catalina.WebResourceRoot in project Synthese_2BIN by TheYoungSensei.
the class Main method main.
public static void main(String[] args) throws Exception {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File("./web").getAbsolutePath());
WebResourceRoot resources = new StandardRoot(ctx);
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
use of org.apache.catalina.WebResourceRoot in project tomee by apache.
the class TomcatWebAppBuilder method configuredClasspath.
private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
Loader loader = standardContext.getLoader();
if (loader != null && LazyStopLoader.class.isInstance(loader)) {
loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
}
if (loader != null) {
final ClassLoader cl = standardContext.getLoader().getClassLoader();
if (cl == null) {
return null;
}
final Collection<String> cp = new LinkedList<>();
final WebResourceRoot webResources = standardContext.getResources();
if (webResources != null) {
// to enhance
for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
for (final WebResourceSet wr : sets) {
final URL base = wr.getBaseUrl();
if (base != null) {
final File baseFile = URLs.toFile(base);
if (baseFile.isDirectory()) {
final String[] libs = wr.list("/WEB-INF/lib/");
if (libs != null) {
for (final String resource : libs) {
cp.add(new File(baseFile, resource).getAbsolutePath());
}
}
final WebResource classes = wr.getResource("/WEB-INF/classes/");
if (classes != null) {
final String path = classes.getCanonicalPath();
if (path != null) {
cp.add(path);
}
}
} else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
try {
cp.add(baseFile.getCanonicalPath());
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
}
}
}
}
if (!cp.isEmpty()) {
return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null);
}
}
return null;
}
use of org.apache.catalina.WebResourceRoot in project tomee by apache.
the class TomcatWebAppBuilder method addConfiguredDocBases.
private void addConfiguredDocBases(final StandardContext standardContext, final ContextInfo contextInfo) {
if (contextInfo.appInfo.path != null) {
// add external web resources
final String contextPath = standardContext.getServletContext().getContextPath();
final String name = contextPath.isEmpty() ? "ROOT" : contextPath.substring(1);
final String webResources = SystemInstance.get().getProperty("tomee." + name + ".docBases", contextInfo.appInfo.properties.getProperty("docBases"));
if (webResources != null) {
for (final String alt : webResources.trim().split(",")) {
final String trim = alt.trim();
if (trim.isEmpty()) {
continue;
}
if (!new File(trim).isDirectory()) {
logger.warning("Can't add docBase which are not directory: " + trim);
continue;
}
final WebResourceRoot root = standardContext.getResources();
root.addPreResources(new DirResourceSet(root, "/", trim, "/"));
}
}
}
}
Aggregations