dev@javaserverfaces.java.net

[REVIEW] Remove WebXmlParser and related logic

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Tue, 20 Jul 2004 12:24:49 -0400

Removed WebXmlParser and related logic from Configuration system
and ViewHandlerImpl.

RI, Demo, and related TCK tests pass.

SECTION: Modified Files
------------------------------------
M jsf-ri/src/com/sun/faces/application/ViewHandlerImpl.java
  - Removed logic in getMappingFromRequest that compared
    the incoming serlvet path and path info with that parsed
    from the web.xml
  - Removed setFacesMapping(List) method.
   
M jsf-ri/src/com/sun/faces/config/ConfigureListener.java
  - Removed usage of WebXmlParser.
  - Removed List argument from configure(Application, List)

M jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java
M jsf-ri/test/com/sun/faces/application/TestViewHandlerImpl.java
M jsf-ri/test/com/sun/faces/config/ConfigFileTestCase.java
M jsf-ri/test/com/sun/faces/renderkit/html_basic/TestRenderers_1.java
  - changes to reflect removal of setFacesMapping(List)

R jsf-ri/src/com/sun/faces/config/ServletBean.java
R jsf-ri/src/com/sun/faces/config/ServletMappingBean.java
R jsf-ri/src/com/sun/faces/config/WebXmlParser.java
 - No longer needed


SECTION: Diffs
-----------------------------------
Index: src/com/sun/faces/application/ViewHandlerImpl.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ViewHandlerImpl.java,v
retrieving revision 1.43
diff -u -r1.43 ViewHandlerImpl.java
--- src/com/sun/faces/application/ViewHandlerImpl.java 17 Jul 2004
01:37:12 -0000 1.43
+++ src/com/sun/faces/application/ViewHandlerImpl.java 20 Jul 2004
16:17:53 -0000
@@ -19,7 +19,6 @@
 import org.apache.commons.logging.LogFactory;
 
 import javax.faces.FacesException;
-import javax.faces.application.Application;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
@@ -27,14 +26,10 @@
 import javax.faces.render.RenderKitFactory;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
 import javax.servlet.jsp.jstl.core.Config;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -61,19 +56,7 @@
 
     //
     // Relationship Instance Variables
- //
-
- /**
- * <p>List of url-patterns defined for the FacesServlet.</p>
- */
- protected List facesServletMappings;
-
- /**
- * <p>If there are multiple extension mappings, then the
- * mapping returned will be arbitrary. Return this value
- * in that case.</p>
- */
- private String defaultMappingExtension;
+ //
 
     /**
      * <p>Store the value of <code>DEFAULT_SUFFIX_PARAM_NAME</code>
@@ -164,7 +147,7 @@
 
         // set the request character encoding. NOTE! This MUST be done
         // before any request praameter is accessed.
- HttpSession session = null;
+
         /*
         HttpServletRequest request =
             (HttpServletRequest) extContext.getRequest();
@@ -228,7 +211,6 @@
             // this was probably an initial request
             // send them off to the root of the web application
             try {
- Object response = extContext.getResponse();
                 context.responseComplete();
                 if (log.isDebugEnabled()) {
                     log.debug("Response Complete for" + viewId);
@@ -505,45 +487,6 @@
 
 
     /**
- * <p>Specifies a <code>List</code> of one or more URL patterns
- * mapped to one or more {_at_link javax.faces.webapp.FacesServlet}
- * instances.</p>
- *
- * @param mappings the URL patterns of the
- * defined {_at_link javax.faces.webapp.FacesServlet}
- * @throws NullPointerException if <code>mappings</code> is null
- */
- public void setFacesMapping(List mappings) {
-
- if (mappings == null) {
- String message = Util.getExceptionMessageString
- (Util.NULL_PARAMETERS_ERROR_MESSAGE_ID);
- message = message +"mappings " + mappings;
- throw new NullPointerException(message);
- }
-
- if (log.isTraceEnabled()) {
- log.debug("Setting a list of URL patterns mappings");
- }
- synchronized (this) {
- facesServletMappings =
- Collections.unmodifiableList(new ArrayList(mappings));
-
- int size = facesServletMappings.size();
- if (facesServletMappings.size() > 1) {
- for (int i = 0; i < size; i++) {
- String mapping = (String) facesServletMappings.get(i);
- if (mapping.charAt(0) == '.') {
- defaultMappingExtension = mapping;
- break;
- }
- }
- }
- }
- }
-
-
- /**
      * <p>Returns the URL pattern of the
      * {_at_link javax.faces.webapp.FacesServlet} that
      * is executing the current request. If there are multiple
@@ -566,7 +509,7 @@
         if (context == null) {
             String message = Util.getExceptionMessageString
                 (Util.NULL_PARAMETERS_ERROR_MESSAGE_ID);
- message = message +"context " + context;
+ message = message +" context " + context;
             throw new NullPointerException(message);
         }
        
@@ -632,69 +575,28 @@
             log.trace("servletPath " + servletPath);
             log.trace("pathInfo " + pathInfo);
         }
- String mapping = null;
-
+
         // If the path returned by HttpServletRequest.getServletPath()
         // returns a zero-length String, then the FacesServlet has
         // been mapped to '/*'.
         if (servletPath.length() == 0) {
- int idx = facesServletMappings.indexOf("/*");
- if (idx != -1) {
                 return "/*";
- } else {
- // Shouldn't happen...
- if (log.isWarnEnabled()) {
- log.warn(
- "Error: FacesServlet mapping does not contain
\"/*\" ");
- }
- return null;
- }
         }
        
         // presence of path info means we were invoked
         // using a prefix path mapping
         if (pathInfo != null) {
- for (int i = 0, size = facesServletMappings.size();
- i < size; i++) {
-
- String temp = (String) facesServletMappings.get(i);
-
- if (servletPath.equals(temp)) {
- mapping = temp;
- break;
- }
- }
+ return servletPath;
+ } else if (pathInfo == null && servletPath.indexOf('.') < 0) {
+ // if pathInfo is null and no '.' is present, assume the
+ // FacesServlet was invoked using prefix path but without
+ // any pathInfo - i.e. GET /contextroot/faces or
+ // GET /contextroot/faces/
+ return servletPath;
         } else {
- // Servlet could have been invoked using extension mapping.
- // Check the mappings in our List for a matching
- // extension mapping.
- for (int i = 0, size = facesServletMappings.size();
- i < size; i++) {
- String temp = (String) facesServletMappings.get(i);
- if (servletPath.endsWith(temp)) {
- mapping = temp;
- break;
- } else if (servletPath.equals(temp)) {
- // The request that came in was in fact
- // prefix path matched, but was sent to the
- // servlet with no path info, i.e.
- // /<context_root>/faces or /<context_root>/faces/
- mapping = temp;
- break;
- }
- }
-
- // no exact extension mapping found, return the
- // default mapping extension.
- if (mapping == null) {
- mapping = defaultMappingExtension;
- if (log.isDebugEnabled()) {
- log.debug("Using default mapping extension " +
mapping);
- }
- }
+ // Servlet invoked using extension mapping
+ return servletPath.substring(servletPath.lastIndexOf('.'));
         }
-
- return mapping;
     }
 
 
Index: src/com/sun/faces/config/ConfigureListener.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/config/ConfigureListener.java,v
retrieving revision 1.22
diff -u -r1.22 ConfigureListener.java
--- src/com/sun/faces/config/ConfigureListener.java 17 Jul 2004
01:37:12 -0000 1.22
+++ src/com/sun/faces/config/ConfigureListener.java 20 Jul 2004
16:17:53 -0000
@@ -176,12 +176,6 @@
             return;
         }
 
- // Step 0, parse the url-pattern information for the
- // FacesServlet. This information is passed onto the
- // ConfigParser for later use.
- WebXmlParser webXmlParser = new WebXmlParser(context);
- List mappings = webXmlParser.getFacesServletMappings();
-
         // Step 1, configure a Digester instance we can use
         try {
             boolean validateXml = validateTheXml(context);
@@ -332,7 +326,7 @@
 
         // Step 7, use the accumulated configuration beans to configure
the RI
         try {
- configure(context, fcb, mappings);
+ configure(context, fcb);
         } catch (FacesException e) {
             e.printStackTrace();
             throw e;
@@ -399,12 +393,12 @@
      * @param config <code>FacesConfigBean</code> that is the root of the
      * tree of configuration information
      */
- protected void configure(ServletContext context, FacesConfigBean
config,
- List mappings) throws Exception {
+ protected void configure(ServletContext context, FacesConfigBean
config)
+ throws Exception {
         configure(config.getFactory());
         configure(config.getLifecycle());
 
- configure(config.getApplication(), mappings);
+ configure(config.getApplication());
         configure(config.getComponents());
         configure(config.getConvertersByClass());
         configure(config.getConvertersById());
@@ -421,9 +415,8 @@
      *
      * @param config <code>ApplicationBean</code> that contains our
      * configuration information
- * @param mappings List of mappings for <code>FacesServlet</code>
      */
- private void configure(ApplicationBean config, List mappings)
+ private void configure(ApplicationBean config)
         throws Exception {
 
         if (config == null) {
@@ -543,10 +536,7 @@
                 }
                 instance = Util.createInstance
                     (values[i], ViewHandler.class,
- application.getViewHandler());
- if (instance instanceof ViewHandlerImpl) {
- ((ViewHandlerImpl) instance).setFacesMapping(mappings);
- }
+ application.getViewHandler());
                 if (instance != null) {
                     application.setViewHandler
                         ((ViewHandler) instance);
Index: test/com/sun/faces/application/TestApplicationImpl.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java,v
retrieving revision 1.20
diff -u -r1.20 TestApplicationImpl.java
--- test/com/sun/faces/application/TestApplicationImpl.java 15 Jul
2004 18:08:32 -0000 1.20
+++ test/com/sun/faces/application/TestApplicationImpl.java 20 Jul
2004 16:17:53 -0000
@@ -23,7 +23,6 @@
 import javax.faces.application.NavigationHandler;
 import javax.faces.application.StateManager;
 import javax.faces.application.ViewHandler;
-import javax.faces.application.Application;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.el.PropertyResolver;
@@ -33,9 +32,6 @@
 import javax.faces.event.ActionEvent;
 import javax.faces.event.ActionListener;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * <B>TestApplicationImpl</B> is a class ...
  * <p/>
@@ -424,9 +420,7 @@
             exceptionThrown = true;
         }
         assertTrue(!exceptionThrown);
- List mappings = new ArrayList();
- mappings.add("/faces");
- ((ViewHandlerImpl) handler).setFacesMapping(mappings);
+
         try {
             handler.renderView(getFacesContext(),
                                getFacesContext().getViewRoot());
Index: test/com/sun/faces/application/TestViewHandlerImpl.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/application/TestViewHandlerImpl.java,v
retrieving revision 1.20
diff -u -r1.20 TestViewHandlerImpl.java
--- test/com/sun/faces/application/TestViewHandlerImpl.java 14 Jul
2004 22:05:21 -0000 1.20
+++ test/com/sun/faces/application/TestViewHandlerImpl.java 20 Jul
2004 16:17:53 -0000
@@ -187,16 +187,7 @@
         FacesContext facesContext = new FacesContextImpl(extContext,
lifecycle);
         String contextPath = request.getContextPath();
 
- // Spoof the mappings so we can properly test the different
possible
- // values
- List mappings = new ArrayList();
- // create the same "massaged" mappings that WebXMLParser creates.
- mappings.add("/faces");
- mappings.add(".jsf");
- mappings.add("/*");
         ViewHandlerImpl handler = new ViewHandlerImpl();
- handler.setFacesMapping(mappings);
-
 
         // if getServletPath() returns "" then the viewId path returned
should
         // be the same as what was passed, prefixed by the context path.
Index: test/com/sun/faces/config/ConfigFileTestCase.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/ConfigFileTestCase.java,v
retrieving revision 1.61
diff -u -r1.61 ConfigFileTestCase.java
--- test/com/sun/faces/config/ConfigFileTestCase.java 17 Jul 2004
01:37:14 -0000 1.61
+++ test/com/sun/faces/config/ConfigFileTestCase.java 20 Jul 2004
16:17:53 -0000
@@ -10,15 +10,12 @@
 package com.sun.faces.config;
 
 import com.sun.faces.ServletFacesTestCase;
-import com.sun.faces.config.beans.FacesConfigBean;
-
-import org.apache.commons.digester.Digester;
-
-import com.sun.faces.application.ApplicationImpl;
 import com.sun.faces.application.ApplicationAssociate;
+import com.sun.faces.application.ApplicationImpl;
+import com.sun.faces.config.beans.FacesConfigBean;
 import com.sun.faces.util.Util;
 import org.apache.cactus.WebRequest;
-import org.xml.sax.InputSource;
+import org.apache.commons.digester.Digester;
 
 import javax.faces.FactoryFinder;
 import javax.faces.application.ApplicationFactory;
@@ -26,25 +23,19 @@
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.convert.Converter;
-import javax.faces.el.ValueBinding;
-import javax.faces.lifecycle.Lifecycle;
-import javax.faces.lifecycle.LifecycleFactory;
 import javax.faces.render.RenderKit;
 import javax.faces.render.RenderKitFactory;
 import javax.faces.validator.Validator;
 import javax.servlet.ServletContext;
 
-import java.io.FileNotFoundException;
 import java.io.File;
-import java.io.InputStream;
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import java.net.URL;
-
 
 /**
  * <p>Unit tests for Configuration File processing.</p>
@@ -71,7 +62,7 @@
         url = (new File(System.getProperty("testRootDir"))).toURL();
         url = new URL(url, str);
         parse(digester, url, fcb);
- configure(context, fcb, java.util.Collections.EMPTY_LIST);
+ configure(context, fcb);
     }
     }
    
@@ -104,16 +95,6 @@
 
 
     // ------------------------------------------------ Individual Test
Methods
-
- // Verify the url-patterns for all javax.faces.webapp.FacesServlet
- // entries are found and massaged.
- public void testWebXmlParser() throws Exception {
- WebXmlParser parser = new WebXmlParser(config.getServletContext());
- List mappings = parser.getFacesServletMappings();
-
- assertTrue(mappings.contains("/faces"));
- assertTrue(mappings.contains(".jsf"));
- }
 
 
     protected void parseConfig(String resource,
Index: test/com/sun/faces/renderkit/html_basic/TestRenderers_1.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/renderkit/html_basic/TestRenderers_1.java,v
retrieving revision 1.60
diff -u -r1.60 TestRenderers_1.java
--- test/com/sun/faces/renderkit/html_basic/TestRenderers_1.java 7
Apr 2004 17:52:59 -0000 1.60
+++ test/com/sun/faces/renderkit/html_basic/TestRenderers_1.java 20
Jul 2004 16:17:53 -0000
@@ -157,9 +157,7 @@
         root.setId("root");
         root.setViewId("/root");
         ViewHandlerImpl viewHandler = new ViewHandlerImpl();
- List mappings = new ArrayList();
- mappings.add("/faces");
- viewHandler.setFacesMapping(mappings);
+
         getFacesContext().getApplication().setViewHandler(viewHandler);
         getFacesContext().setViewRoot(root);
         // Call this twice to test the multiple forms in a page logic.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net