use of grails.core.GrailsControllerClass in project grails-core by grails.
the class GrailsConventionGroovyPageLocator method findView.
/**
* <p>Finds a view for the given controller and view name. For example specifying a controller with a class name of HomeController and a view name of "index" will search for
* /WEB-INF/grails-app/views/home/index.gsp in production and grails-app/views/home/index.gsp in development</p>
*
* <p>If the view is not found in the application then a scan is executed that searches through binary and source plugins looking for the first matching view name</p>
*
* @param controller The controller
* @param viewName The view name
* @return The GroovyPageScriptSource
*/
public GroovyPageScriptSource findView(Object controller, String viewName) {
if (controller == null || viewName == null) {
return null;
}
String controllerName = getNameForController(controller);
String viewNameWithFormat = resolveViewFormat(viewName);
GroovyPageScriptSource scriptSource = null;
final String controllerClassName = GrailsNameUtils.getFullClassName(controller.getClass());
Object controllerArtefact = grailsApplication != null ? grailsApplication.getArtefact(ControllerArtefactHandler.TYPE, controllerClassName) : null;
if (controllerArtefact instanceof GrailsControllerClass) {
GrailsControllerClass gcc = (GrailsControllerClass) controllerArtefact;
String namespace = gcc.getNamespace();
if (namespace != null) {
scriptSource = findPage("/" + namespace + uriService.getViewURI(controllerName, viewNameWithFormat));
if (scriptSource == null) {
scriptSource = findPage("/" + namespace + uriService.getViewURI(controllerName, viewName));
}
}
}
if (scriptSource == null) {
scriptSource = findPage(uriService.getViewURI(controllerName, viewNameWithFormat));
}
if (scriptSource == null) {
scriptSource = findPage(uriService.getViewURI(controllerName, viewName));
}
if (scriptSource == null && pluginManager != null) {
String pathToView = pluginManager.getPluginViewsPathForInstance(controller);
if (pathToView != null) {
scriptSource = findViewByPath(GrailsResourceUtils.appendPiecesForUri(pathToView, viewName));
}
}
// if all else fails do a full search
if (scriptSource == null) {
scriptSource = findView(controllerName, viewName);
}
return scriptSource;
}
use of grails.core.GrailsControllerClass in project grails-core by grails.
the class GrailsConventionGroovyPageLocator method findTemplate.
/**
* Finds a template for the given controller name and template name
*
* @param controller The controller n
* @param templateName The view name
* @return The GroovyPageScriptSource
*/
public GroovyPageScriptSource findTemplate(Object controller, String templateName) {
String controllerName = getNameForController(controller);
GroovyPageScriptSource scriptSource = null;
final String templateURI = uriService.getTemplateURI(controllerName, templateName);
final String fullClassName = GrailsNameUtils.getFullClassName(controller.getClass());
Object controllerArtefact = grailsApplication != null ? grailsApplication.getArtefact(ControllerArtefactHandler.TYPE, fullClassName) : null;
if (controllerArtefact instanceof GrailsControllerClass) {
GrailsControllerClass gcc = (GrailsControllerClass) controllerArtefact;
String namespace = gcc.getNamespace();
if (namespace != null) {
scriptSource = findPage("/" + namespace + templateURI);
}
}
if (scriptSource == null) {
scriptSource = findPage(templateURI);
}
return scriptSource;
}
use of grails.core.GrailsControllerClass in project grails-core by grails.
the class GrailsWebRequest method getControllerClass.
/**
* @return the controllerClass
*/
public GrailsControllerClass getControllerClass() {
HttpServletRequest currentRequest = getCurrentRequest();
GrailsControllerClass controllerClass = (GrailsControllerClass) currentRequest.getAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS);
if (controllerClass == null) {
Object controllerNameObject = currentRequest.getAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE);
if (controllerNameObject != null) {
controllerClass = (GrailsControllerClass) getAttributes().getGrailsApplication().getArtefactByLogicalPropertyName(ControllerArtefactHandler.TYPE, controllerNameObject.toString());
if (controllerClass != null) {
currentRequest.setAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS, controllerClass);
}
}
}
return controllerClass;
}
use of grails.core.GrailsControllerClass 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 grails.core.GrailsControllerClass in project grails-core by grails.
the class GrailsWebRequest method isFlowRequest.
/**
* Returns true if the current executing request is a flow request
*
* @return true if it is a flow request
*/
public boolean isFlowRequest() {
GrailsApplication application = getAttributes().getGrailsApplication();
Object controllerClassObject = getControllerClass();
GrailsControllerClass controllerClass = null;
if (controllerClassObject instanceof GrailsControllerClass) {
controllerClass = (GrailsControllerClass) controllerClassObject;
}
if (controllerClass == null)
return false;
String actionName = getActionName();
if (actionName == null)
actionName = controllerClass.getDefaultAction();
if (actionName == null)
return false;
return false;
}
Aggregations