/**
   * This is a complement to the normal webwork execution which allows for a command-based execution
   * of actions.
   */
  private String invokeCommand() throws Exception {
    Timer t = new Timer();

    final StringBuffer methodName = new StringBuffer("do" + this.commandName);
    methodName.setCharAt(2, Character.toUpperCase(methodName.charAt(2)));

    String result = "";

    try {
      final Method method = getClass().getMethod(methodName.toString(), new Class[0]);
      result = (String) method.invoke(this, new Object[0]);
      setStandardResponseHeaders();
    } catch (NoSuchMethodException e) {
      logger.warn("No such method in:" + getRequest().getRequestURI() + ":" + e.getMessage());
    } catch (Exception ie) {
      if (ie.getMessage() != null) logger.error("Exception in top action:" + ie.getMessage(), ie);

      try {
        throw ie.getCause();
      } catch (ResultException e) {
        logger.error("ResultException " + e, e);
        result = e.getResult();
      } catch (AccessConstraintException e) {
        logger.info("AccessConstraintException " + e, e);
        setErrors(e);
        result = ACCESS_DENIED;
      } catch (ConstraintException e) {
        logger.info("ConstraintException " + e, e);
        setErrors(e);
        if (e.getResult() != null && !e.getResult().equals("")) result = e.getResult();
        else result = INPUT;
      } catch (Bug e) {
        logger.error("Bug " + e.getMessage(), e);
        setError(e, e.getCause());
        result = ERROR;
      } catch (ConfigurationError e) {
        logger.error("ConfigurationError " + e);
        setError(e, e.getCause());
        result = ERROR;
      } catch (SystemException e) {
        logger.error("SystemException " + e, e);
        setError(e, e.getCause());
        result = ERROR;
      } catch (Throwable e) {
        logger.error("Throwable " + e.getMessage(), e);
        final Bug bug = new Bug("Uncaught exception!", e);
        setError(bug, bug.getCause());
        result = ERROR;
      }
    }

    try {
      ChangeNotificationController.notifyListeners();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return result;
  }
  /**
   * This is the main execution point for any webwork action. Lately we added statistics on each
   * action for debugging and optimization purposes.
   */
  public String execute() throws Exception {
    Timer t = new Timer();

    String result = "";

    try {
      result = isCommand() ? invokeCommand() : doExecute();
      setStandardResponseHeaders();

      long elapsedTime = t.getElapsedTime();
      long memoryDiff = t.getMemoryDifferenceAsMegaBytes();
      if (elapsedTime > 5000 || memoryDiff > 100) {
        // RequestAnalyser.getRequestAnalyser().registerComponentStatistics("" +
        // this.getUnencodedCurrentURIWithParameters() + " (" + memoryDiff + ")", elapsedTime);
        logger.warn(
            "The "
                + CmsPropertyHandler.getApplicationName()
                + " request: "
                + this.getUnencodedCurrentURIWithParameters()
                + " took "
                + elapsedTime
                + " ms to render and seems to have allocated "
                + memoryDiff
                + " MB of memory)");
      }
      // else
      //	RequestAnalyser.getRequestAnalyser().registerComponentStatistics("" +
      // this.getUnencodedCurrentURI(), elapsedTime);
    } catch (ResultException e) {
      logger.error("ResultException " + e.getMessage());
      logger.warn("ResultException " + e.getMessage(), e);
      result = e.getResult();
    } catch (AccessConstraintException e) {
      logger.info("AccessConstraintException " + e, e);
      setErrors(e);
      result = ACCESS_DENIED;
    } catch (ConstraintException e) {
      logger.info("ConstraintException " + e, e);
      setErrors(e);
      if (e.getResult() != null && !e.getResult().equals("")) result = e.getResult();
      else result = INPUT;
    } catch (Bug e) {
      logger.error("Bug " + e.getMessage());
      logger.warn("Bug  " + e.getMessage(), e);
      setError(e, e.getCause());
      result = ERROR;
    } catch (ConfigurationError e) {
      logger.error("ConfigurationError " + e.getMessage());
      logger.warn("ConfigurationError " + e.getMessage(), e);
      setError(e, e.getCause());
      result = ERROR;
    } catch (SystemException e) {
      logger.error("SystemException " + e.getMessage());
      logger.warn("SystemException " + e.getMessage(), e);
      setError(e, e.getCause());
      result = ERROR;
    } catch (ThreadDeath e) {
      logger.error("Thread died: " + e);
      logger.warn("Thread died: " + e.getMessage(), e);
      final SystemException exception =
          new SystemException("Page took to long to load! Please try again later.");
      setError(exception, e);
      result = ERROR;
    } catch (Throwable e) {
      logger.error("Throwable " + e.getMessage());
      logger.warn("Throwable " + e.getMessage(), new Exception(e));
      final Bug bug = new Bug("Uncaught exception!", e);
      setError(bug, bug.getCause());
      result = ERROR;
    }

    try {
      if (CmsPropertyHandler.getApplicationName().equalsIgnoreCase("cms"))
        ChangeNotificationController.notifyListeners();
    } catch (Exception e) {
      logger.error("Error notifying listener " + e.getMessage());
      logger.warn("Error notifying listener " + e.getMessage(), e);
    }

    return result;
  }