Ejemplo n.º 1
0
  /**
   * 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();
    GrailsControllerClass controllerClass =
        (GrailsControllerClass)
            application.getArtefactByLogicalPropertyName(
                ControllerArtefactHandler.TYPE, getControllerName());

    if (controllerClass == null) return false;

    String actionName = getActionName();
    if (actionName == null) actionName = controllerClass.getDefaultAction();
    if (actionName == null) return false;

    if (controllerClass != null && controllerClass.isFlowAction(actionName)) return true;
    return false;
  }
  /**
   * Overrides the default behaviour to establish the handler from the GrailsApplication instance
   *
   * @param request The request
   * @param cache Whether to cache the Handler in the request
   * @return The HandlerExecutionChain
   * @throws Exception
   */
  protected HandlerExecutionChain getHandler(HttpServletRequest request, boolean cache)
      throws Exception {
    String uri = urlHelper.getPathWithinApplication(request);
    if (logger.isDebugEnabled()) {
      logger.debug("Looking up Grails controller for URI [" + uri + "]");
    }
    GrailsControllerClass controllerClass =
        (GrailsControllerClass)
            application.getArtefactForFeature(ControllerArtefactHandler.TYPE, uri);
    final String actionName =
        (String) request.getAttribute(GrailsApplicationAttributes.ACTION_NAME_ATTRIBUTE);

    if (controllerClass != null) {
      HandlerInterceptor[] interceptors;
      // if we're in a development environment we want to re-establish interceptors just in case
      // they
      // have changed at runtime

      if (GrailsUtil.isDevelopmentEnv()) {
        interceptors = establishInterceptors(getWebApplicationContext());
      } else {
        interceptors = this.interceptors;
      }
      if (controllerClass.isFlowAction(actionName)) {
        FlowHandler flowHandler =
            new AbstractFlowHandler() {
              public String getFlowId() {
                return actionName;
              }
            };
        return new HandlerExecutionChain(flowHandler, interceptors);
      } else {
        return new HandlerExecutionChain(mainController, interceptors);
      }
    }
    return null;
  }