SWF-1388 Move Spring JS resources to META-INF/web-resources

This commit is contained in:
Rossen Stoyanchev
2010-08-31 22:39:08 +00:00
parent 08dedb822c
commit 9dc9a6eb45
17 changed files with 26 additions and 19 deletions

View File

@@ -31,7 +31,7 @@
<antcall target="minify-spring-js" inheritAll="false"/>
<unzip src="${basedir}/../spring-js/dojo-build/dojo-build.zip"
dest="${main.output.dir}/META-INF"/>
dest="${main.output.dir}/META-INF/web-resources"/>
<jar destfile="${jar.output.file}" basedir="${main.output.dir}" index="true" filesetmanifest="merge">
<manifest>
@@ -80,8 +80,8 @@
</sequential>
</macrodef>
<compress file="/META-INF/spring/Spring.js"/>
<compress file="/META-INF/spring/Spring-Dojo.js"/>
<compress file="/META-INF/web-resources/spring/Spring.js"/>
<compress file="/META-INF/web-resources/spring/Spring-Dojo.js"/>
</target>

View File

@@ -65,6 +65,8 @@ public class ResourceServlet extends HttpServletBean {
private String jarPathPrefix = "META-INF";
private String springJsJarPathPrefix = "META-INF/web-resources";
private boolean gzipEnabled = true;
private Set allowedResourcePaths = new HashSet();
@@ -254,22 +256,10 @@ public class ResourceServlet extends HttpServletBean {
}
URL resource = getServletContext().getResource(localResourcePath);
if (resource == null) {
String jarResourcePath = jarPathPrefix + localResourcePath;
if (!isAllowed(jarResourcePath)) {
if (log.isWarnEnabled()) {
log
.warn("An attempt to access a protected resource at " + jarResourcePath
+ " was disallowed.");
}
return null;
}
if (jarResourcePath.startsWith("/")) {
jarResourcePath = jarResourcePath.substring(1);
}
if (log.isDebugEnabled()) {
log.debug("Searching classpath for resource: " + jarResourcePath);
}
resource = ClassUtils.getDefaultClassLoader().getResource(jarResourcePath);
resource = getJarResource(springJsJarPathPrefix, localResourcePath);
}
if (resource == null) {
resource = getJarResource(jarPathPrefix, localResourcePath);
}
if (resource == null) {
if (resources.length > 1) {
@@ -283,6 +273,23 @@ public class ResourceServlet extends HttpServletBean {
return resources;
}
private URL getJarResource(String jarPrefix, String resourcePath) {
String jarResourcePath = jarPrefix + resourcePath;
if (!isAllowed(jarResourcePath)) {
if (log.isWarnEnabled()) {
log.warn("An attempt to access a protected resource at " + jarResourcePath + " was disallowed.");
}
return null;
}
if (jarResourcePath.startsWith("/")) {
jarResourcePath = jarResourcePath.substring(1);
}
if (log.isDebugEnabled()) {
log.debug("Searching classpath for resource: " + jarResourcePath);
}
return ClassUtils.getDefaultClassLoader().getResource(jarResourcePath);
}
private boolean isAllowed(String resourcePath) {
if (resourcePath.matches(protectedPath)) {
return false;