@SuppressWarnings({ "unchecked", "rawtypes" })
public static IncludedContent includeForUrlMappingInfo(HttpServletRequest request,
HttpServletResponse response, UrlMappingInfo info, Map model) {
String includeUrl = buildDispatchUrlForMapping(info, true);
final GrailsWebRequest webRequest = GrailsWebRequest.lookup(request);
String currentController = null;
String currentAction = null;
String currentId = null;
ModelAndView currentMv = null;
Binding currentPageBinding = null;
Map currentParams = null;
Object currentLayoutAttribute = null;
Object currentRenderingView = null;
if (webRequest != null) {
currentPageBinding = (Binding) webRequest.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE, 0);
webRequest.removeAttribute(GrailsApplicationAttributes.PAGE_SCOPE, 0);
currentLayoutAttribute = webRequest.getAttribute(WebUtils.LAYOUT_ATTRIBUTE, 0);
if (currentLayoutAttribute != null) {
webRequest.removeAttribute(WebUtils.LAYOUT_ATTRIBUTE, 0);
}
currentRenderingView = webRequest.getAttribute(WebUtils.RENDERING_VIEW, 0);
if (currentRenderingView != null) {
webRequest.removeAttribute(WebUtils.RENDERING_VIEW, 0);
}
currentController = webRequest.getControllerName();
currentAction = webRequest.getActionName();
currentId = webRequest.getId();
currentParams = new HashMap();
currentParams.putAll(webRequest.getParameterMap());
currentMv = (ModelAndView)webRequest.getAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW, 0);
}
try {
if (webRequest!=null) {
webRequest.getParameterMap().clear();
info.configure(webRequest);
webRequest.getParameterMap().putAll(info.getParameters());
webRequest.removeAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW, 0);
}
return includeForUrl(includeUrl, request, response, model);
}
finally {
if (webRequest!=null) {
webRequest.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE,currentPageBinding, 0);
if (currentLayoutAttribute != null) {
webRequest.setAttribute(WebUtils.LAYOUT_ATTRIBUTE, currentLayoutAttribute, 0);
}
if (currentRenderingView != null) {
webRequest.setAttribute(WebUtils.RENDERING_VIEW, currentRenderingView, 0);
}
webRequest.getParameterMap().clear();
webRequest.getParameterMap().putAll(currentParams);
webRequest.setId(currentId);
webRequest.setControllerName(currentController);
webRequest.setActionName(currentAction);
if (currentMv != null) {
webRequest.setAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW, currentMv, 0);
}
}
}
}