예제 #1
0
 private final StackTraceElement getStackTraceElementForActionMapping(
     HttpServletRequest request, ActionMapping mapping, StackTraceElement[] elements) {
   Class<?> actionClass = actionClass(mapping.getType());
   setActionErrorClass(actionClass);
   String methodName =
       DispatchAction.class.isAssignableFrom(actionClass)
           ? request.getParameter(mapping.getParameter())
           : "execute";
   setActionErrorMethod(methodName);
   for (StackTraceElement element : elements) {
     if (element.getClassName().equals(mapping.getType())
         && element.getMethodName().equals(methodName)) {
       return element;
     }
   }
   return null;
 }
예제 #2
0
  /**
   * Gets the <code>Action</code> specified by the mapping type from a PicoContainer. The action
   * will be instantiated if necessary, and its dependencies will be injected. The action will be
   * instantiated via a special PicoContainer that just contains actions. If this container already
   * exists in the request attribute, this method will use it. If no such container exists, this
   * method will create a new Pico container and place it in the request. The parent container will
   * either be the request container, or if that container can not be found the session container,
   * or if that container can not be found, the application container. If no parent container can be
   * found, a <code>PicoInitializationException</code> will be thrown. The action path specified in
   * the mapping is used as the component key for the action.
   *
   * @param request the Http servlet request.
   * @param mapping the Struts mapping object, whose type property tells us what Action class is
   *     required.
   * @param servlet the Struts <code>ActionServlet</code>.
   * @return the <code>Action</code> instance.
   * @throws PicoIntrospectionException if the mapping type does not specify a valid action.
   * @throws PicoInitializationException if no request, session, or application scoped Pico
   *     container can be found.
   */
  public Action processAction(
      HttpServletRequest request, ActionMapping mapping, ActionServlet servlet)
      throws PicoIntrospectionException, PicoInitializationException {
    Object actionKey = mapping.getPath();
    Class actionType = getActionClass(mapping.getType());

    Action action = (Action) sf.getService(actionKey);
    if (action == null) {
      sf.registerService(actionKey, actionType);
      action = (Action) sf.getService(actionKey);
    }

    action.setServlet(servlet);
    return action;
  }
예제 #3
0
  /**
   * Register a given ActionMapping
   *
   * @param actionMapping
   * @throws Exception
   */
  protected void registerActionMapping(ActionMapping actionMapping) throws Exception {

    if (actions == null) {
      actions = new ArrayList<ActionConfig>();
    }

    String actionClassType = actionMapping.getType();

    // Will inject the action classes inside the dotCMS context
    injectContext(actionClassType);

    ModuleConfig moduleConfig = activatorUtil.getModuleConfig();
    // We need to unfreeze this module in order to add new action mappings
    activatorUtil.unfreeze(moduleConfig);

    // Adding the ActionConfig to the ForwardConfig
    moduleConfig.addActionConfig(actionMapping);
    // moduleConfig.freeze();

    actions.add(actionMapping);
    Logger.info(this, "Added Struts Action Mapping: " + actionClassType);
  }