Author: alexsmirnov
Date: 2010-02-16 18:49:58 -0500 (Tue, 16 Feb 2010)
New Revision: 16464
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/StaticResource.java
Log:
https://jira.jboss.org/jira/browse/JBSEAM-4543, JBIDE-4500
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java 2010-02-16
23:12:41 UTC (rev 16463)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java 2010-02-16
23:49:58 UTC (rev 16464)
@@ -30,7 +30,9 @@
import java.io.StreamCorruptedException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
@@ -443,21 +445,19 @@
throws ResourceNotFoundException, FacesException {
FacesContext context = FacesContext.getCurrentInstance();
if (null != context) {
- if (context.getExternalContext().getContext() instanceof ServletContext) {
- ServletContext servletContext = (ServletContext) context
- .getExternalContext().getContext();
- InputStream in = servletContext.getResourceAsStream(path);
+ try {
+ URL in = context.getExternalContext().getResource(path);
if (null != in) {
InternetResourceBase res = new StaticResource(path);
setRenderer(res, path);
+ // Detect last modification time.
res.setLastModified(new Date(getStartTime()));
addResource(path, res);
- try {
- in.close();
- } catch (IOException e) {
- }
return res;
}
+ } catch (MalformedURLException e) {
+ throw new ResourceNotFoundException(Messages.getMessage(
+ Messages.STATIC_RESOURCE_NOT_FOUND_ERROR, path),e);
}
}
throw new ResourceNotFoundException(Messages.getMessage(
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/StaticResource.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/StaticResource.java 2010-02-16
23:12:41 UTC (rev 16463)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/resource/StaticResource.java 2010-02-16
23:49:58 UTC (rev 16464)
@@ -22,11 +22,17 @@
package org.ajax4jsf.resource;
import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Date;
import javax.faces.context.FacesContext;
import org.ajax4jsf.resource.ResourceContext;
+import com.sun.facelets.FaceletException;
+
/**
* @author asmirnov(a)exadel.com (latest modification by $Author: nick_belaevski $)
* @version $Revision: 1.1.2.2 $ $Date: 2007/01/11 16:52:14 $
@@ -52,6 +58,27 @@
}
+ @Override
+ public Date getLastModified(ResourceContext resourceContext) {
+ InputStream is = null;
+ try {
+ URL url = resourceContext.getResource(path);
+ URLConnection conn = url.openConnection();
+ is = conn.getInputStream();
+ long atl = conn.getLastModified();
+ return new Date(atl);
+ } catch (Exception e) {
+ return super.getLastModified(resourceContext);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (Exception e) {
+ // do nothing
+ }
+ }
+ }
+ }
/* (non-Javadoc)
* @see
org.ajax4jsf.resource.InternetResourceBase#getResourceAsStream(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
@@ -71,11 +98,11 @@
- public String getUri(FacesContext context, Object data) {
- // perform all encodings, suitable for JSF specification.
- String src = context.getApplication().getViewHandler().getResourceURL(context,path);
- return context.getExternalContext().encodeResourceURL(src);
- }
+// public String getUri(FacesContext context, Object data) {
+// // perform all encodings, suitable for JSF specification.
+// String src =
context.getApplication().getViewHandler().getResourceURL(context,path);
+// return context.getExternalContext().encodeResourceURL(src);
+// }