String finalString = script.replace("${webapp}", webapp);
final String classpathPrefix = "classpath:";
if (finalString.startsWith(classpathPrefix)) {
final String resourceString = finalString.substring(classpathPrefix.length());
try {
addScript(new InputStreamResource(getClass().getClassLoader().getResourceAsStream(resourceString)));
} catch (Exception e) {
throw new AssertionError("Failed to load data script as a from the classpath: "+resourceString);
}
} else {
// series of hack for different platforms...
try {
addScript(new InputStreamResource(new URL(finalString).openStream()));
} catch (Exception e) {
String fileUrlPrefix = "file:/";
if (finalString.startsWith(fileUrlPrefix)) {
finalString = finalString.substring(fileUrlPrefix.length());
}
if (!new File(finalString).exists()) {
finalString = finalString.substring(1);
}
if (new File(finalString).exists()) {
addScript(new InputStreamResource(new FileInputStream(finalString)));
} else {
throw new AssertionError("Failed to load data script as a url: "+finalString);
}
}
}