targetFile.setLastModified(sourceFile.lastModified());
if (isLogDebugEnabled()) logDebug("Copying static file from filename::" + sourceFile, null);
}
} else if (sourceFile.getName().endsWith(".jar")) {
JarFile jar;
jar = new JarFile(sourceFile);
Enumeration<JarEntry> jarEntries = jar.entries();
// Check in all jars - maybe we have static resources in custom jars
// as well (not only in core)
while (jarEntries.hasMoreElements()) {
JarEntry jarEntry = jarEntries.nextElement();
String jarEntryName = jarEntry.getName();
if (jarEntryName.indexOf(File.separator + ClassPathStaticDispatcher.STATIC_DIR_NAME + File.separator) != -1) {
if (!jarEntry.isDirectory()) {
// Copy file from jar to static place
// extract class name without trailing slashes
staticDirPos = jarEntryName.indexOf(ClassPathStaticDispatcher.STATIC_DIR_NAME);
String packageName = jarEntryName.substring(0, staticDirPos - 1);
packageName = packageName.replace(File.separator, ".");
String fileName = jarEntryName.substring(staticDirPos + ClassPathStaticDispatcher.STATIC_DIR_NAME.length());
File targetFile = new File(classPathStaticDir, packageName + fileName);
// Only do this if it does not already exist.
// Use jar file last modified instead of jarEntry.getTime, seems to be unpredictable
if (targetFile.exists() && targetFile.lastModified() >= sourceFile.lastModified()) {
if (isLogDebugEnabled()) logDebug("Skipping static file from jar, filename::" + jarEntryName + " in jar::" + jar.getName()
+ " - does already exist", null);
} else {
targetFile.getParentFile().mkdirs();
BufferedInputStream inputStream = new BufferedInputStream(jar.getInputStream(jarEntry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(targetFile));
FileUtils.copy(inputStream, outputStream, jarEntry.getSize());
inputStream.close();
outputStream.close();
targetFile.setLastModified(sourceFile.lastModified());
if (isLogDebugEnabled()) logDebug("Copying static file from jar, filename::" + jarEntryName + " in jar::" + jar.getName(),
null);
}
}
}
}