[jboss-svn-commits] JBL Code SVN: r15789 - in labs/shotoku/trunk/shotoku-web: src/java/org/jboss/shotoku/web and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 12 03:11:26 EDT 2007
Author: adamw
Date: 2007-10-12 03:11:25 -0400 (Fri, 12 Oct 2007)
New Revision: 15789
Modified:
labs/shotoku/trunk/shotoku-web/example/src/web/WEB-INF/web.xml
labs/shotoku/trunk/shotoku-web/src/java/org/jboss/shotoku/web/ResourcesFilter.java
Log:
Adding Seam support
Modified: labs/shotoku/trunk/shotoku-web/example/src/web/WEB-INF/web.xml
===================================================================
--- labs/shotoku/trunk/shotoku-web/example/src/web/WEB-INF/web.xml 2007-10-12 05:25:17 UTC (rev 15788)
+++ labs/shotoku/trunk/shotoku-web/example/src/web/WEB-INF/web.xml 2007-10-12 07:11:25 UTC (rev 15789)
@@ -18,9 +18,9 @@
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
- <listener>
+ <!-- <listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
- </listener>
+ </listener> -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
Modified: labs/shotoku/trunk/shotoku-web/src/java/org/jboss/shotoku/web/ResourcesFilter.java
===================================================================
--- labs/shotoku/trunk/shotoku-web/src/java/org/jboss/shotoku/web/ResourcesFilter.java 2007-10-12 05:25:17 UTC (rev 15788)
+++ labs/shotoku/trunk/shotoku-web/src/java/org/jboss/shotoku/web/ResourcesFilter.java 2007-10-12 07:11:25 UTC (rev 15789)
@@ -46,22 +46,16 @@
* is prepended to the path. The file referenced by the path is then included
* in the request. To specify for which file extensions the filter is enabled,
* set the <code>extensions</code> init parameter. If not set, it defaults to:
- * <code>jsp,css,html,htm,gif,jpg,jpeg,png,txt</code>.
- *
+ * <code>jsp,css,html,htm,gif,jpg,jpeg,png,txt,xhtml</code>.
+ *
* @author <a href="mailto:adam at warski.org">Adam Warski</a>
*/
public class ResourcesFilter implements Filter {
/**
- * Name of a subdirectory of the exploded deployment to which files
- * will be copied.
- */
- private final static String DEST_RES_DIR = "copied-resources";
-
- /**
* A list of extensions, which are filtered by default, if nothing is
* specified in the filter configuration.
*/
- private final static String DEFAULT_EXTENSIONS = "jsp,css,html,htm,gif,jpg,jpeg,png,txt";
+ private final static String DEFAULT_EXTENSIONS = "jsp,css,html,htm,gif,jpg,jpeg,png,txt,xhtml";
/**
* Base path to a directory where files will
@@ -74,7 +68,7 @@
* Directory in the filesystem from which to read the files.
*/
private String sourceBasePath;
-
+
/**
* A set of <code>java.lang.String</code>s, which are extensions, that are filtered.
*/
@@ -100,33 +94,33 @@
public void init(FilterConfig conf) {
sourceBasePath = conf.getInitParameter("sourceBasePath");
- destBasePath = conf.getServletContext().getRealPath("") + File.separator + DEST_RES_DIR;
-
+ destBasePath = conf.getServletContext().getRealPath("");
+
extensions = new HashSet();
String filteredExtensionsString = conf.getInitParameter("extensions");
-
+
if (filteredExtensionsString == null) {
filteredExtensionsString = DEFAULT_EXTENSIONS;
}
-
+
String[] tokens = filteredExtensionsString.split(",");
-
+
for (int i=0; i<tokens.length; i++) {
extensions.add(tokens[i]);
}
}
-
+
private String safeToString(Object o) {
if (o == null) {
return null;
}
-
+
return o.toString();
}
-
+
private boolean checkExtension(String path) {
int dotIndex = path.lastIndexOf('.');
-
+
if (dotIndex != -1) {
String extension = path.substring(dotIndex + 1);
return extensions.contains(extension);
@@ -139,25 +133,27 @@
FilterChain chain) throws IOException, ServletException {
if (request instanceof HttpServletRequest) {
HttpServletRequest httpRequest = (HttpServletRequest) request;
-
+
/* Getting the name of the requested resource; first checking if
* it is an included, then forwarded resource. Finally, checking
* the request uri itself. */
String requestedResource;
requestedResource = safeToString(httpRequest.getAttribute("javax.servlet.include.servlet_path"));
-
+
if (requestedResource == null) {
requestedResource = httpRequest.getServletPath();
}
-
+
// JSF check - we have to replace .jsf with .jsp.
String realRequestedResource = requestedResource;
if (realRequestedResource.endsWith(".jsf")) {
realRequestedResource = realRequestedResource.replace(".jsf", ".jsp");
+ } else if (realRequestedResource.endsWith(".seam")) {
+ realRequestedResource = realRequestedResource.replace(".seam", ".xhtml");
}
-
- // Filtering only some extensions and preventing a loop.
- if (requestedResource.startsWith("/" + DEST_RES_DIR) || !checkExtension(realRequestedResource)) {
+
+ // Filtering only some file extensions.
+ if (!checkExtension(realRequestedResource)) {
chain.doFilter(request, response);
return;
}
@@ -185,14 +181,11 @@
out.close();
}
}
-
- request.getRequestDispatcher("/" + DEST_RES_DIR + requestedResource).include(request, response);
- } else {
- response.setContentType("text/html");
- response.getWriter().write("Unsupported request class");
}
- }
+ chain.doFilter(request, response);
+ }
+
public void destroy() {
}
More information about the jboss-svn-commits
mailing list