use of org.grails.web.servlet.mvc.GrailsWebRequest in project grails-core by grails.
the class GrailsConventionGroovyPageLocator method lookupRequestFormat.
protected String lookupRequestFormat() {
if (mimeTypeResolver != null) {
MimeType mimeType = mimeTypeResolver.resolveResponseMimeType();
if (mimeType != null) {
return mimeType.getExtension();
}
} else {
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
if (webRequest != null) {
HttpServletRequest request = webRequest.getCurrentRequest();
Object format = request.getAttribute(GrailsApplicationAttributes.RESPONSE_FORMAT);
return format == null ? null : format.toString();
}
}
return null;
}
use of org.grails.web.servlet.mvc.GrailsWebRequest in project grails-core by grails.
the class GrailsConventionGroovyPageLocator method findTemplateInBinding.
/**
* Finds a template for the given given template name, looking up the controller from the request as necessary
*
* @param pluginName The plugin
* @param templateName The template name
* @param binding The binding
* @return The GroovyPageScriptSource
*/
public GroovyPageScriptSource findTemplateInBinding(Object controller, String pluginName, String templateName, TemplateVariableBinding binding) {
if (controller == null) {
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
if (webRequest == null) {
return findPageInBinding(pluginName, uriService.getAbsoluteTemplateURI(templateName, true), binding);
}
return findPageInBinding(pluginName, uriService.getTemplateURI(webRequest.getControllerName(), templateName), binding);
}
final GrailsControllerClass controllerClass = (GrailsControllerClass) grailsApplication.getArtefact(ControllerArtefactHandler.TYPE, GrailsNameUtils.getFullClassName(controller.getClass()));
String templateURI;
final String ns = controllerClass.getNamespace();
GroovyPageScriptSource scriptSource = null;
final String controllerName = controllerClass.getLogicalPropertyName();
if (ns != null) {
templateURI = '/' + ns + uriService.getTemplateURI(controllerName, templateName);
scriptSource = findPageInBinding(pluginName, templateURI, binding);
}
if (scriptSource == null) {
templateURI = uriService.getTemplateURI(controllerName, templateName);
scriptSource = findPageInBinding(pluginName, templateURI, binding);
}
return scriptSource;
}
use of org.grails.web.servlet.mvc.GrailsWebRequest in project grails-core by grails.
the class GroovyPagesServlet method createResponseWriter.
/**
* Creates a response writer for the given response object
*
* @param response The HttpServletResponse
* @return The created java.io.Writer
*/
protected GSPResponseWriter createResponseWriter(HttpServletResponse response) {
GSPResponseWriter out = GSPResponseWriter.getInstance(response);
GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.currentRequestAttributes();
webRequest.setOut(out);
return out;
}
use of org.grails.web.servlet.mvc.GrailsWebRequest in project grails-core by grails.
the class GroovyPageViewResolver method resolveCurrentControllerKeyPrefixes.
/**
* @return prefix for cache key that contains current controller's context (currently plugin and namespace)
*/
protected String resolveCurrentControllerKeyPrefixes() {
String pluginContextPath;
String namespace;
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
if (webRequest != null) {
namespace = webRequest.getControllerNamespace();
pluginContextPath = (webRequest.getAttributes() != null && webRequest.getCurrentRequest() != null) ? webRequest.getAttributes().getPluginContextPath(webRequest.getCurrentRequest()) : null;
return (pluginContextPath != null ? pluginContextPath : "-") + "," + (namespace != null ? namespace : "-");
} else {
return null;
}
}
use of org.grails.web.servlet.mvc.GrailsWebRequest in project grails-core by grails.
the class GroovyPageViewResolver method createGrailsView.
protected View createGrailsView(String viewName) throws Exception {
// try GSP if res is null
GroovyObject controller = null;
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
if (webRequest != null) {
HttpServletRequest request = webRequest.getCurrentRequest();
controller = webRequest.getAttributes().getController(request);
}
GroovyPageScriptSource scriptSource;
if (controller == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Locating GSP view for path {}", viewName);
}
scriptSource = groovyPageLocator.findViewByPath(viewName);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Locating GSP view for controller {} and path {}", controller, viewName);
}
scriptSource = groovyPageLocator.findView(controller, viewName);
}
if (scriptSource != null) {
return createGroovyPageView(scriptSource.getURI(), scriptSource);
}
return createFallbackView(viewName);
}
Aggregations