Package org.apache.struts.chain.contexts

Examples of org.apache.struts.chain.contexts.ServletActionContext


  }

  @Override
  public boolean execute(ActionContext context) throws Exception
  {
    ServletActionContext sc = (ServletActionContext) context;
    preProcessor.preprocessRequest(sc.getRequest());
    return false;
  }
View Full Code Here


    ActionForm form = actionContext.getActionForm();

    if (form != null)
    {

      ServletActionContext sc = (ServletActionContext) actionContext;
      HttpServletRequest request = sc.getRequest();
      form = formHandler.wrapForm(form, request);

      if (form instanceof BindingForm)
      {
        formHandler.handleBindingForm((BindingForm) form, request);
View Full Code Here

      {
      delegate = newControllerProcessorDelegate();
      }
    }
   
    ServletActionContext sc = (ServletActionContext) context;
    HttpServletRequest request = sc.getRequest();
    HttpServletResponse response = sc.getResponse();
    ServletContext servletContext = sc.getContext();
   
    ActionContext actionContext = actionContextFactory.createActionContext(request, response, servletContext,
        actionForm, (ActionMapping) actionConfig);

    ActionForward forward = null;
View Full Code Here

   * @param context our context
   * @throws ServletException
   * @throws IOException
   */
  public boolean execute(Context ctx) throws ServletException, IOException {
    ServletActionContext context = (ServletActionContext)ctx;
    ForwardConfig forward = context.getForwardConfig();
    if (forward == null || forward.getPath() == null || forward.getRedirect()) {
      return false;
    }
    if (forward.getModule() != null && !forward.getModule().equals(context.getModuleConfig().getPrefix())) {
      return false;
    }
    HttpServletRequest request = context.getRequest();
    PanelsSupport support = PanelsSupport.getInstance(request);
    Locale locale = I18nSupport.getInstance(request).getLocale(request);
    PanelConfig panel = support.findPanelConfig(forward.getPath(), locale);
    if (panel != null) {
      String template = panel.findTemplate(locale);
      if (template == null) {
        throw new ServletException("Cannot find template for panel " + panel.getName());
      }
      PanelsContext panels = support.getOrCreateContext(request, locale);
      boolean include = !panels.isEmpty() || context.getResponse().isCommitted();

      panels.push(panel);
      try {
        RequestDispatcher rd = context.getContext().getRequestDispatcher(template);
        if (include) {
          rd.include(request, context.getResponse());
        } else {
          rd.forward(request, context.getResponse());
        }
      } finally {
        panels.pop();
      }

View Full Code Here

     * that we're processing in "include" mode.
     */
    public boolean execute(Context context) throws Exception {

        // Is there a Tiles Definition to be processed?
        ServletActionContext sacontext = (ServletActionContext) context;
        ForwardConfig forwardConfig = sacontext.getForwardConfig();
        if (forwardConfig == null || forwardConfig.getPath() == null)
        {
            log.debug("No forwardConfig or no path, so pass to next command.");
            return (false);
        }


        ComponentDefinition definition = null;
        try
        {
            definition = TilesUtil.getDefinition(forwardConfig.getPath(),
                    sacontext.getRequest(),
                    sacontext.getContext());
        }
        catch (FactoryNotFoundException ex)
        {
            // this is not a serious error, so log at low priority
            log.debug("Tiles DefinitionFactory not found, so pass to next command.");
            return false;
        }
        catch (NoSuchDefinitionException ex)
        {
            // ignore not found
            log.debug("NoSuchDefinitionException " + ex.getMessage());
        }

        // Do we do a forward (original behavior) or an include ?
        boolean doInclude = false;
        ComponentContext tileContext = null;

        // Get current tile context if any.
        // If context exists, or if the response has already been committed we will do an include
        tileContext = ComponentContext.getContext(sacontext.getRequest());
        doInclude = (tileContext != null || sacontext.getResponse().isCommitted());

        // Controller associated to a definition, if any
        Controller controller = null;

        // Computed uri to include
        String uri = null;

        if (definition != null)
        {
            // We have a "forward config" definition.
            // We use it to complete missing attribute in context.
            // We also get uri, controller.
            uri = definition.getPath();
            controller = definition.getOrCreateController();

            if (tileContext == null) {
                tileContext =
                        new ComponentContext(definition.getAttributes());
                ComponentContext.setContext(tileContext, sacontext.getRequest());

            } else {
                tileContext.addMissing(definition.getAttributes());
            }
        }

        // Process definition set in Action, if any.  This may override the
        // values for uri or controller found using the ForwardConfig, and
        // may augment the tileContext with additional attributes.
        // :FIXME: the class DefinitionsUtil is deprecated, but I can't find
        // the intended alternative to use.
        definition = DefinitionsUtil.getActionDefinition(sacontext.getRequest());
        if (definition != null) { // We have a definition.
                // We use it to complete missing attribute in context.
                // We also overload uri and controller if set in definition.
                if (definition.getPath() != null) {
                    log.debug("Override forward uri "
                              + uri
                              + " with action uri "
                              + definition.getPath());
                        uri = definition.getPath();
                }

                if (definition.getOrCreateController() != null) {
                    log.debug("Override forward controller with action controller");
                        controller = definition.getOrCreateController();
                }

                if (tileContext == null) {
                        tileContext =
                                new ComponentContext(definition.getAttributes());
                        ComponentContext.setContext(tileContext, sacontext.getRequest());
                } else {
                        tileContext.addMissing(definition.getAttributes());
                }
        }


        if (uri == null) {
            log.debug("no uri computed, so pass to next command");
            return false;
        }

        // Execute controller associated to definition, if any.
        if (controller != null) {
            log.trace("Execute controller: " + controller);
            controller.execute(
                    tileContext,
                    sacontext.getRequest(),
                    sacontext.getResponse(),
                    sacontext.getContext());
        }

        // If request comes from a previous Tile, do an include.
        // This allows to insert an action in a Tile.

        if (doInclude) {
            log.info("Tiles process complete; doInclude with " + uri);
            doInclude(sacontext, uri);
        } else {
            log.info("Tiles process complete; forward to " + uri);
            doForward(sacontext, uri);
        }

        log.debug("Tiles processed, so clearing forward config from context.");
        sacontext.setForwardConfig( null );
        return (false);
    }
View Full Code Here

    protected ActionContext createActionContextInstance(
        ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException {
        if (this.actionContextClass == null) {
            return new ServletActionContext(servletContext, request, response);
        }

        try {
            if (this.servletActionContextConstructor == null) {
                return (ActionContext) this.actionContextClass.newInstance();
View Full Code Here

    public ActionForm createActionForm(ActionContext context)
        throws IllegalAccessException, InstantiationException {
        ActionServlet actionServlet = null;

        if (context instanceof ServletActionContext) {
            ServletActionContext saContext = (ServletActionContext) context;

            actionServlet = saContext.getActionServlet();
        }

        return createActionForm(actionServlet);
    }
View Full Code Here

        //  directly depends on ActionServlet
        if (actionCtx instanceof ServletActionContext) {
            // The servlet property of ActionForm is transient, so
            // ActionForms which are restored from a serialized state
            // need to have their servlet restored.
            ServletActionContext sac = (ServletActionContext) actionCtx;

            instance.setServlet(sac.getActionServlet());
        }

        actionCtx.setActionForm(instance);

        scope.put(actionConfig.getAttribute(), instance);
View Full Code Here

                actions.put(type, action);
            }
        }

        if (action.getServlet() == null) {
            ServletActionContext saContext = (ServletActionContext) context;
            ActionServlet actionServlet = saContext.getActionServlet();

            action.setServlet(actionServlet);
        }

        return (action);
View Full Code Here

            new MockActionServlet(servletContext, servletConfig);

        servlet.initInternal();

        this.saContext =
            new ServletActionContext(servletContext, request,
                new MockHttpServletResponse());

        this.saContext.setActionServlet(servlet);
        this.command = new AuthorizeAction();
    }
View Full Code Here

TOP

Related Classes of org.apache.struts.chain.contexts.ServletActionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.