/**
   * Attempts to resolve a view relative to a controller.
   *
   * @param controller The controller to resolve the view relative to
   * @param application The GrailsApplication instance
   * @param viewName The views name
   * @param loader The ResourceLoader to use
   * @return The URI of the view
   */
  protected String resolveViewForController(
      GroovyObject controller,
      GrailsApplication application,
      String viewName,
      ResourceLoader loader) {

    String
        gspView; // try to resolve the view relative to the controller first, this allows us to
                 // support views provided by plugins
    if (controller != null && application != null) {
      String pathToView =
          pluginManager != null ? pluginManager.getPluginViewsPathForInstance(controller) : null;
      if (pathToView != null) {
        gspView = GrailsResourceUtils.WEB_INF + pathToView + viewName + GSP_SUFFIX;
      } else {
        gspView = localPrefix + viewName + GSP_SUFFIX;
      }
    } else {
      gspView = localPrefix + viewName + GSP_SUFFIX;
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "Attempting to resolve view for URI ["
              + gspView
              + "] using ResourceLoader ["
              + loader.getClass().getName()
              + "]");
    }
    return gspView;
  }