Refactored SpringFaces.js to have Ext and Dojo implementations.
Fixed resource support to properly send a 404 status when resource is not found.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package org.springframework.faces.ui;
|
||||
|
||||
import javax.faces.component.UIComponentBase;
|
||||
|
||||
public class DojoAdvisor extends UIComponentBase {
|
||||
|
||||
public String getFamily() {
|
||||
|
||||
return "spring.faces.DojoAdvisor";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springframework.faces.ui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.render.Renderer;
|
||||
|
||||
import org.springframework.faces.ui.resource.FlowResourceHelper;
|
||||
|
||||
public class DojoRenderer extends Renderer {
|
||||
|
||||
private String dojoJsResourceUri = "/dojo/dojo.js";
|
||||
|
||||
private String dojoStyleResourceUri = "/dojo/dojo.css";
|
||||
|
||||
private String dijitThemePath = "/dijit/themes/";
|
||||
|
||||
private String dijitTheme = "tundra";
|
||||
|
||||
private String springFacesJsResourceUri = "/spring-faces/SpringFaces.js";
|
||||
|
||||
private String springFacesDojoJsResourceUri = "/spring-faces/SpringFaces-Dojo.js";
|
||||
|
||||
private FlowResourceHelper resourceHelper = new FlowResourceHelper();
|
||||
|
||||
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
|
||||
|
||||
resourceHelper.renderStyleLink(context, dijitThemePath + "/" + dijitTheme + "/" + dijitTheme + ".css");
|
||||
|
||||
resourceHelper.renderStyleLink(context, dojoStyleResourceUri);
|
||||
|
||||
resourceHelper.renderScriptLink(context, dojoJsResourceUri);
|
||||
|
||||
resourceHelper.renderScriptLink(context, springFacesJsResourceUri);
|
||||
|
||||
resourceHelper.renderScriptLink(context, springFacesDojoJsResourceUri);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ public class ExtJsRenderer extends Renderer {
|
||||
|
||||
private static final String SPRING_FACES_SCRIPT = "/spring-faces/SpringFaces.js";
|
||||
|
||||
private static final String SPRING_FACES_EXT_SCRIPT = "/spring-faces/SpringFaces-Ext.js";
|
||||
|
||||
private FlowResourceHelper resourceHelper = new FlowResourceHelper();
|
||||
|
||||
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
|
||||
@@ -31,5 +33,7 @@ public class ExtJsRenderer extends Renderer {
|
||||
}
|
||||
|
||||
resourceHelper.renderScriptLink(context, SPRING_FACES_SCRIPT);
|
||||
|
||||
resourceHelper.renderScriptLink(context, SPRING_FACES_EXT_SCRIPT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.springframework.faces.ui.resource;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,14 +42,22 @@ public class ResolveAndRenderResourceAction implements Action {
|
||||
|
||||
public Event execute(RequestContext context) throws Exception {
|
||||
|
||||
String resourcePath = "META-INF" + context.getExternalContext().getRequestPath().toString();
|
||||
URLConnection resourceConn = ClassUtils.getDefaultClassLoader().getResource(resourcePath).openConnection();
|
||||
long lastModified = resourceConn.getLastModified();
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
|
||||
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
|
||||
ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();
|
||||
|
||||
String resourcePath = "META-INF" + context.getExternalContext().getRequestPath().toString();
|
||||
|
||||
URL resource = ClassUtils.getDefaultClassLoader().getResource(resourcePath);
|
||||
|
||||
if (resource == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return new Event(this, "success");
|
||||
}
|
||||
|
||||
URLConnection resourceConn = resource.openConnection();
|
||||
long lastModified = resourceConn.getLastModified();
|
||||
|
||||
long ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
|
||||
if (ifModifiedSince > 0 && lastModified / 1000 <= ifModifiedSince / 1000) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
|
||||
Reference in New Issue
Block a user