* during expansion
*/
public static String expand(Host host, URL war, String pathname) throws IOException {
int debug = 0;
Logger logger = host.getLogger();
if (host instanceof StandardHost) {
debug = ((StandardHost) host).getDebug();
}
// Make sure that there is no such directory already existing
File appBase = new File(host.getAppBase());
if (!appBase.isAbsolute()) {
appBase = new File(System.getProperty("catalina.base"),
host.getAppBase());
}
if (!appBase.exists() || !appBase.isDirectory()) {
throw new IOException
(sm.getString("hostConfig.appBase",
appBase.getAbsolutePath()));
}
File docBase = new File(appBase, pathname);
if (docBase.exists()) {
// War file is already installed
return (docBase.getAbsolutePath());
}
// Create the new document base directory
docBase.mkdir();
if (debug >= 2) {
logger.log(" Have created expansion directory " +
docBase.getAbsolutePath());
}
// Expand the WAR into the new document base directory
JarURLConnection juc = (JarURLConnection) war.openConnection();
juc.setUseCaches(false);
JarFile jarFile = null;
InputStream input = null;
try {
jarFile = juc.getJarFile();
if (debug >= 2) {
logger.log(" Have opened JAR file successfully");
}
Enumeration jarEntries = jarFile.entries();
if (debug >= 2) {
logger.log(" Have retrieved entries enumeration");
}
while (jarEntries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
String name = jarEntry.getName();
if (debug >= 2) {
logger.log(" Am processing entry " + name);
}
int last = name.lastIndexOf('/');
if (last >= 0) {
File parent = new File(docBase,
name.substring(0, last));
if (debug >= 2) {
logger.log(" Creating parent directory " + parent);
}
parent.mkdirs();
}
if (name.endsWith("/")) {
continue;
}
if (debug >= 2) {
logger.log(" Creating expanded file " + name);
}
input = jarFile.getInputStream(jarEntry);
File expandedFile = expand(input, docBase, name);
long lastModified = jarEntry.getTime();