roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r415377 - /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/RequestMappingFilter.java
Date Mon, 19 Jun 2006 17:25:52 GMT
Author: agilliland
Date: Mon Jun 19 10:25:52 2006
New Revision: 415377

URL: http://svn.apache.org/viewvc?rev=415377&view=rev
Log:
new request mapping filter.


Added:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/RequestMappingFilter.java

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/RequestMappingFilter.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/RequestMappingFilter.java?rev=415377&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/RequestMappingFilter.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/RequestMappingFilter.java
Mon Jun 19 10:25:52 2006
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.rendering.filters;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.ui.rendering.RequestMapper;
+import org.apache.roller.ui.rendering.WeblogRequestMapper;
+
+
+/**
+ * Provides generalized request mapping capablilites.
+ *
+ * Incoming requests can be inspected by a series of RequestMappers and can
+ * potentially be re-routed to different places within the application.
+ *
+ * @web.filter name="RequestMappingFilter"
+ */
+public class RequestMappingFilter implements Filter {
+    
+    private static Log log = LogFactory.getLog(RequestMappingFilter.class);
+    
+    // list of RequestMappers that want to inspect the request
+    List requestMappers = null;
+    
+    
+    public void init(FilterConfig filterConfig) {
+        
+        this.requestMappers = new ArrayList();
+        
+        // TODO 3.0: configurable set of request mappers
+        this.requestMappers.add(new WeblogRequestMapper());
+    }
+    
+    
+    /**
+     * Inspect incoming urls and see if they should be routed.
+     */
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+            throws IOException, ServletException {
+        
+        HttpServletRequest request = (HttpServletRequest) req;
+        HttpServletResponse response = (HttpServletResponse) res;
+        
+        log.debug("entering");
+        
+        // give each mapper a chance to handle the request
+        RequestMapper mapper = null;
+        Iterator mappersIT = this.requestMappers.iterator();
+        while(mappersIT.hasNext()) {
+            mapper = (RequestMapper) mappersIT.next();
+            
+            log.debug("trying mapper "+mapper.getClass().getName());
+            
+            boolean wasHandled = mapper.handleRequest(request, response);
+            if(wasHandled) {
+                // if mapper has handled the request then we are done
+                log.debug("request handled by "+mapper.getClass().getName());
+                log.debug("exiting");
+                return;
+            }
+        }
+        
+        log.debug("request not mapped");
+        
+        // nobody handled the request, so let it continue as usual
+        chain.doFilter(request, response);
+        
+        log.debug("exiting");
+    }
+    
+    
+    public void destroy() {}
+    
+}



Mime
View raw message