protected ServletContext initServletContext ( Document webXmlDoc , String baseDirPath , String tmpDirPath , String springConfigFiles , String servletAPIversion ) { // Parse the context parameters MockServletContext servletContext = new MockServletContext ( servletAPIversion , baseDirPath , tmpDirPath ) ; Map < String , Object > servletContextInitParams = new HashMap < String , Object > ( ) ; NodeList contextParamsNodes = webXmlDoc . getElementsByTagName ( CONTEXT_TAG_NAME ) ; for ( int i = 0 ; i < contextParamsNodes . getLength ( ) ; i ++ ) { Node node = contextParamsNodes . item ( i ) ; initializeInitParams ( node , servletContextInitParams ) ; } // Override spring config file if needed if ( StringUtils . isNotEmpty ( springConfigFiles ) ) { servletContextInitParams . put ( CONFIG_LOCATION_PARAM , springConfigFiles . replace ( " " , "%20" ) ) ; } servletContext . setInitParameters ( servletContextInitParams ) ; return servletContext ; }
Initalize the servlet context