@SuppressWarnings("unchecked")
	private StringBuffer buildEngineScript(StringBuffer engineScript,ServletContext servletContext) {
		List<Container> containers = ContainerUtil.getAllPublishedContainers(servletContext);
		String allowGetForSafariButMakeForgeryEasier = "";
		String scriptTagProtection = DwrConstants.SCRIPT_TAG_PROTECTION;
		String pollWithXhr = "";
		String sessionCookieName = "JSESSIONID";
		

		
		for(Iterator<Container> it = containers.iterator();it.hasNext();) {
			Container container = it.next();
			ServerLoadMonitor monitor = (ServerLoadMonitor) container.getBean(ServerLoadMonitor.class.getName());
			pollWithXhr = monitor.supportsStreaming() ? "false" : "true";
			
			if(null != container.getBean("allowGetForSafariButMakeForgeryEasier")){
				allowGetForSafariButMakeForgeryEasier = (String)container.getBean("allowGetForSafariButMakeForgeryEasier");
			}
			if(null != container.getBean("scriptTagProtection")){
				scriptTagProtection = (String)container.getBean("scriptTagProtection");
			}
			if(null != container.getBean("sessionCookieName")){
				sessionCookieName = (String)container.getBean("sessionCookieName");
			}		
		}
		StringBuffer sb = new StringBuffer();
		Matcher matcher = PARAMS_PATTERN.matcher(engineScript);
		while(matcher.find()) {
			String match = matcher.group();
			if("${allowGetForSafariButMakeForgeryEasier}".equals(match)){
				matcher.appendReplacement(sb, allowGetForSafariButMakeForgeryEasier);				
			}
			else if("${pollWithXhr}".equals(match)){
				matcher.appendReplacement(sb, pollWithXhr);				
			}
			else if("${sessionCookieName}".equals(match)){
				matcher.appendReplacement(sb, sessionCookieName);				
			}
			else if("${scriptTagProtection}".equals(match)){
				matcher.appendReplacement(sb, scriptTagProtection);				
			}
			else if("${scriptSessionId}".equals(match)){
				matcher.appendReplacement(sb, "\"+JAWR.dwr_scriptSessionId+\"");	
			}
			else if("${defaultPath}".equals(match)){

				matcher.appendReplacement(sb, "\"+JAWR.jawr_dwr_path+\"");
			}
		}
		DWRParamWriter.setUseDynamicSessionId(true);
		matcher.appendTail(sb);
		return sb;
	}
@ SuppressWarnings ( "unchecked" ) private StringBuffer buildEngineScript ( StringBuffer engineScript , ServletContext servletContext ) { List < Container > containers = ContainerUtil . getAllPublishedContainers ( servletContext ) ; String allowGetForSafariButMakeForgeryEasier = "" ; String scriptTagProtection = DwrConstants . SCRIPT_TAG_PROTECTION ; String pollWithXhr = "" ; String sessionCookieName = "JSESSIONID" ; for ( Iterator < Container > it = containers . iterator ( ) ; it . hasNext ( ) ; ) { Container container = it . next ( ) ; ServerLoadMonitor monitor = ( ServerLoadMonitor ) container . getBean ( ServerLoadMonitor . class . getName ( ) ) ; pollWithXhr = monitor . supportsStreaming ( ) ? "false" : "true" ; if ( null != container . getBean ( "allowGetForSafariButMakeForgeryEasier" ) ) { allowGetForSafariButMakeForgeryEasier = ( String ) container . getBean ( "allowGetForSafariButMakeForgeryEasier" ) ; } if ( null != container . getBean ( "scriptTagProtection" ) ) { scriptTagProtection = ( String ) container . getBean ( "scriptTagProtection" ) ; } if ( null != container . getBean ( "sessionCookieName" ) ) { sessionCookieName = ( String ) container . getBean ( "sessionCookieName" ) ; } } StringBuffer sb = new StringBuffer ( ) ; Matcher matcher = PARAMS_PATTERN . matcher ( engineScript ) ; while ( matcher . find ( ) ) { String match = matcher . group ( ) ; if ( "${allowGetForSafariButMakeForgeryEasier}" . equals ( match ) ) { matcher . appendReplacement ( sb , allowGetForSafariButMakeForgeryEasier ) ; } else if ( "${pollWithXhr}" . equals ( match ) ) { matcher . appendReplacement ( sb , pollWithXhr ) ; } else if ( "${sessionCookieName}" . equals ( match ) ) { matcher . appendReplacement ( sb , sessionCookieName ) ; } else if ( "${scriptTagProtection}" . equals ( match ) ) { matcher . appendReplacement ( sb , scriptTagProtection ) ; } else if ( "${scriptSessionId}" . equals ( match ) ) { matcher . appendReplacement ( sb , "\"+JAWR.dwr_scriptSessionId+\"" ) ; } else if ( "${defaultPath}" . equals ( match ) ) { matcher . appendReplacement ( sb , "\"+JAWR.jawr_dwr_path+\"" ) ; } } DWRParamWriter . setUseDynamicSessionId ( true ) ; matcher . appendTail ( sb ) ; return sb ; }
Performs replacement on the engine.js script from DWR.
Mainly copies what DWR does, only at startup. A couple params are actually
replaced to references to javascript vars that jawr will create on the page.

@param engineScript
@return