use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method createMainResourceSet.
protected WebResourceSet createMainResourceSet() {
String docBase = context.getDocBase();
WebResourceSet mainResourceSet;
if (docBase == null) {
mainResourceSet = new EmptyResourceSet(this);
} else {
File f = new File(docBase);
if (!f.isAbsolute()) {
f = new File(((Host) context.getParent()).getAppBaseFile(), f.getPath());
}
if (f.isDirectory()) {
mainResourceSet = new DirResourceSet(this, "/", f.getAbsolutePath(), "/");
} else if (f.isFile() && docBase.endsWith(".war")) {
mainResourceSet = new WarResourceSet(this, "/", f.getAbsolutePath());
} else {
throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", f.getAbsolutePath()));
}
}
return mainResourceSet;
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method getResourceInternal.
protected final WebResource getResourceInternal(String path, boolean useClassLoaderResources) {
WebResource result = null;
WebResource virtual = null;
WebResource mainEmpty = null;
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
if (!useClassLoaderResources && !webResourceSet.getClassLoaderOnly() || useClassLoaderResources && !webResourceSet.getStaticOnly()) {
result = webResourceSet.getResource(path);
if (result.exists()) {
return result;
}
if (virtual == null) {
if (result.isVirtual()) {
virtual = result;
} else if (main.equals(webResourceSet)) {
mainEmpty = result;
}
}
}
}
}
// Use the first virtual result if no real result was found
if (virtual != null) {
return virtual;
}
// Default is empty resource in main resources
return mainEmpty;
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method stopInternal.
@Override
protected void stopInternal() throws LifecycleException {
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
webResourceSet.stop();
}
}
if (main != null) {
main.destroy();
}
mainResources.clear();
for (WebResourceSet webResourceSet : jarResources) {
webResourceSet.destroy();
}
jarResources.clear();
for (WebResourceSet webResourceSet : classResources) {
webResourceSet.destroy();
}
classResources.clear();
for (TrackedWebResource trackedResource : trackedResources) {
log.error(sm.getString("standardRoot.lockedFile", context.getName(), trackedResource.getName()), trackedResource.getCreatedBy());
try {
trackedResource.close();
} catch (IOException e) {
// Ignore
}
}
cache.clear();
setState(LifecycleState.STOPPING);
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method createWebResourceSet.
@Override
public void createWebResourceSet(ResourceSetType type, String webAppMount, String base, String archivePath, String internalPath) {
List<WebResourceSet> resourceList;
WebResourceSet resourceSet;
switch(type) {
case PRE:
resourceList = preResources;
break;
case CLASSES_JAR:
resourceList = classResources;
break;
case RESOURCE_JAR:
resourceList = jarResources;
break;
case POST:
resourceList = postResources;
break;
default:
throw new IllegalArgumentException(sm.getString("standardRoot.createUnknownType", type));
}
// This implementation assumes that the base for all resources will be a
// file.
File file = new File(base);
if (file.isFile()) {
if (archivePath != null) {
// Must be a JAR nested inside a WAR if archivePath is non-null
resourceSet = new JarWarResourceSet(this, webAppMount, base, archivePath, internalPath);
} else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
resourceSet = new JarResourceSet(this, webAppMount, base, internalPath);
} else {
resourceSet = new FileResourceSet(this, webAppMount, base, internalPath);
}
} else if (file.isDirectory()) {
resourceSet = new DirResourceSet(this, webAppMount, base, internalPath);
} else {
throw new IllegalArgumentException(sm.getString("standardRoot.createInvalidFile", file));
}
if (type.equals(ResourceSetType.CLASSES_JAR)) {
resourceSet.setClassLoaderOnly(true);
} else if (type.equals(ResourceSetType.RESOURCE_JAR)) {
resourceSet.setStaticOnly(true);
}
resourceList.add(resourceSet);
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method initInternal.
// --------------------------------------------------------------- Lifecycle
@Override
protected void initInternal() throws LifecycleException {
super.initInternal();
cacheJmxName = register(cache, getObjectNameKeyProperties() + ",name=Cache");
registerURLStreamHandlerFactory();
if (context == null) {
throw new IllegalStateException(sm.getString("standardRoot.noContext"));
}
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
webResourceSet.init();
}
}
}
Aggregations