protected List < ServletDefinition > getWebXmlServletDefinitions ( Document webXmlDoc , ServletContext servletContext , List < String > servletsToInitialize , ClassLoader webAppClassLoader ) throws ClassNotFoundException { // Parse the servlet configuration NodeList servletNodes = webXmlDoc . getElementsByTagName ( SERVLET_TAG_NAME ) ; List < ServletDefinition > servletDefinitions = new ArrayList < ServletDefinition > ( ) ; for ( int i = 0 ; i < servletNodes . getLength ( ) ; i ++ ) { String servletName = null ; Class < ? > servletClass = null ; MockServletConfig config = new MockServletConfig ( servletContext ) ; int order = i ; Node servletNode = servletNodes . item ( i ) ; Map < String , Object > initParameters = new HashMap < String , Object > ( ) ; NodeList childNodes = servletNode . getChildNodes ( ) ; for ( int j = 0 ; j < childNodes . getLength ( ) ; j ++ ) { Node servletChildNode = childNodes . item ( j ) ; if ( servletChildNode . getNodeName ( ) . equals ( SERVLET_NAME_TAG_NAME ) ) { servletName = getTextValue ( servletChildNode ) ; config . setServletName ( servletName ) ; } else if ( servletChildNode . getNodeName ( ) . equals ( SERVLET_CLASS_TAG_NAME ) ) { String servletClassName = getTextValue ( servletChildNode ) ; servletClass = webAppClassLoader . loadClass ( servletClassName ) ; } else if ( servletChildNode . getNodeName ( ) . equals ( INIT_PARAM_TAG_NAME ) ) { initializeInitParams ( servletChildNode , initParameters ) ; } else if ( servletChildNode . getNodeName ( ) . equals ( LOAD_ON_STARTUP_TAG_NAME ) ) { order = Integer . parseInt ( getTextValue ( servletChildNode ) ) ; } } // Initialize the servlet config with the init parameters config . setInitParameters ( initParameters ) ; // If the servlet name is part of the list of servlet to initialized // Set the flag accordingly if ( servletsToInitialize . contains ( servletName ) || JawrServlet . class . isAssignableFrom ( servletClass ) ) { ServletDefinition servletDef = new ServletDefinition ( servletClass , config , order ) ; servletDefinitions . add ( servletDef ) ; } // Handle Spring MVC servlet definition if ( servletContext . getInitParameter ( CONFIG_LOCATION_PARAM ) == null && servletClass . getName ( ) . equals ( "org.springframework.web.servlet.DispatcherServlet" ) ) { ( ( MockServletContext ) servletContext ) . putInitParameter ( CONFIG_LOCATION_PARAM , "/WEB-INF/" + servletName + "-servlet.xml" ) ; } } return servletDefinitions ; }
Returns the list of servlet definition which must be initialize