Permalink
Browse files

Added Servlets#isFacesResourceRequest() and filled Servlets javadoc.

  • Loading branch information...
1 parent 693956d commit 2647e684832a7e3bfa7145050f1aa14cd2d39f49 @BalusC BalusC committed Oct 7, 2014
@@ -16,10 +16,10 @@
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.omnifaces.util.Servlets.isFacesResourceRequest;
import java.io.IOException;
-import javax.faces.application.ResourceHandler;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -219,7 +219,7 @@ public void init() throws ServletException {
(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain)
throws ServletException, IOException
{
- if (!request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
+ if (!isFacesResourceRequest(request)) {
setCacheHeaders(response, expires);
}
@@ -151,7 +151,7 @@ else if (path.contains("?")) {
}
/**
- * Returns <code>true</code> if {@link ExternalContext#getRequestServletPath()} starts with value of
+ * Returns <code>true</code> if {@link ExternalContext#getRequestServletPath()} equals
* {@link ResourceHandler#RESOURCE_IDENTIFIER}.
*/
@Override
@@ -31,6 +31,8 @@
import java.util.Map.Entry;
import java.util.Set;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
@@ -40,7 +42,23 @@
import org.omnifaces.filter.CacheControlFilter;
/**
- * Collection of utility methods for the Servlet API in general.
+ * <p>
+ * Collection of utility methods for the Servlet API in general. Most of them are internally used by {@link Faces}
+ * and {@link FacesLocal}, however they may also be useful in a "plain vanilla" servlet or servlet filter.
+ * <p>
+ * There are as of now also three special methods related to JSF without needing a {@link FacesContext}:
+ * <ul>
+ * <li>The {@link #isFacesAjaxRequest(HttpServletRequest)} which is capable of checking if the current request is a JSF
+ * ajax request.
+ * <li>The {@link #isFacesResourceRequest(HttpServletRequest)} which is capable of checking if the current request is a
+ * JSF resource request.
+ * <li>The {@link #facesRedirect(HttpServletRequest, HttpServletResponse, String, String...)} which is capable
+ * of distinguishing JSF ajax requests from regular requests and altering the redirect logic on it, exactly like as
+ * {@link ExternalContext#redirect(String)} does. In other words, this method behaves exactly the same as
+ * {@link Faces#redirect(String, String...)}.
+ * </ul>
+ * <p>
+ * Those methods can be used in for example a servlet filter.
*
* @author Arjan Tijms
* @author Bauke Scholtz
@@ -425,6 +443,17 @@ public static boolean isFacesAjaxRequest(HttpServletRequest request) {
}
/**
+ * Returns <code>true</code> if the given HTTP servlet request is a JSF resource request. I.e. this request will
+ * trigger the JSF {@link ResourceHandler} for among others CSS/JS/image resources.
+ * @return <code>true</code> if the given HTTP servlet request is a JSF resource request.
+ * @since 2.0
+ * @see ResourceHandler#RESOURCE_IDENTIFIER
+ */
+ public static boolean isFacesResourceRequest(HttpServletRequest request) {
+ return request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER + "/");
+ }
+
+ /**
* Sends a temporary (302) JSF redirect to the given URL, supporting JSF ajax requests. This does exactly the same
* as {@link Faces#redirect(String, String...)}, but without the need for a {@link FacesContext}. The major
* advantage is that you can perform the job inside a servlet filter or even a plain vanilla servlet, where the

0 comments on commit 2647e68

Please sign in to comment.