// FIXME hack
URL url = cl.getResource(locationAttr);
if (url != null) {
return new UrlResource(url);
}
throw new MissingResourceException(locationFile.toString());
}
if (locationFile.isDirectory()) {
try {
manifestFile = new File(locationFile, "META-INF/MANIFEST.MF");
if (manifestFile.exists()) {
Manifest mf = new Manifest(new FileInputStream(manifestFile));
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
if (appCtxPath != null) {
appXmlFile = new File(locationFile, appCtxPath);
if (appXmlFile.exists()) {
return new UrlResource(appXmlFile.toURL());
}
}
}
// no manifest-specified Spring context, use default
appXmlFile = new File(locationFile, APPLICATION_CONTEXT);
if (appXmlFile.exists()) {
return new UrlResource(appXmlFile.toURL());
}
} catch (IOException e) {
throw new LoaderException("Error reading manifest " + manifestFile);
}
} else {
try {
JarFile jf = new JarFile(locationFile);
JarEntry je;
Manifest mf = jf.getManifest();
if (mf != null) {
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
if (appCtxPath != null) {
je = jf.getJarEntry(appCtxPath);
if (je != null) {
// TODO return a Spring specific Resouce type for jars
return new UrlResource(new URL("jar:" + locationFile.toURL() + "!/" + appCtxPath));
}
}
}
je = jf.getJarEntry(APPLICATION_CONTEXT);
if (je != null) {
return new UrlResource(new URL("jar:" + locationFile.toURI().toURL() + "!" + APPLICATION_CONTEXT));
}
} catch (IOException e) {
// bad archive
// TODO: create a more appropriate exception type
throw new MissingResourceException(locationAttr, e);
}
}
throw new MissingResourceException(APPLICATION_CONTEXT);
}