private static Action getCurrentAction() { ActionContext ctx = ActionContext.getContext(); if ( ctx != null ) { ActionInvocation ai = ctx.getActionInvocation(); if ( ai != null ) return ai.getAction(); } return null; }
protected TemplateModel createModel(ObjectWrapper wrapper, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws TemplateModelException { OgnlValueStack stack = ServletActionContext.getContext().getValueStack(); Object action = null; if (ServletActionContext.getContext().getActionInvocation() != null) { action = ServletActionContext.getContext().getActionInvocation().getAction(); } TemplateModel model = FreemarkerManager.getInstance().buildTemplateModel(stack, action, servletContext, request, response, wrapper); return model; }
public static String buildNamespace(OgnlValueStack stack, HttpServletRequest request) { ActionContext context = new ActionContext(stack.getContext()); ActionInvocation invocation = context.getActionInvocation(); if (invocation == null) { ActionMapper mapper = ActionMapperFactory.getMapper(); ActionMapping mapping = mapper.getMapping(request); if (mapping != null) { return mapping.getNamespace(); } else { // well, if the ActionMapper can't tell us, and there is no existing action invocation, // let's just go with a default guess that the namespace is the last the path minus the // last part (/foo/bar/baz.xyz -> /foo/bar) String path = RequestUtils.getServletPath(request); return path.substring(0, path.lastIndexOf("/")); } } else { return invocation.getProxy().getNamespace(); } } }
/** * Retrieves the 'real' {@link ActionConfig) for the current context. This is different * to what is available in via the {@link com.opensymphony.xwork.ActionContext#getContext()} * method because that come from the 'runtime' configuration which has been generated separately. * * @return The original {@link ActionConfig} for the current context. */ public ActionConfig getCurrentActionConfig() { if ( ActionContext.getContext() != null && ActionContext.getContext().getActionInvocation() != null && ActionContext.getContext().getActionInvocation().getProxy() != null ) { ActionConfig currentAction = ActionContext.getContext().getActionInvocation().getProxy().getConfig(); ActionRequest request = null; try { request = ActionRequest.parse( ActionContext.getContext().getName() ); PackageConfig packageConfig = ConfigurationManager.getConfiguration().getPackageConfig( currentAction.getPackageName() ); if ( packageConfig != null ) return (ActionConfig) packageConfig.getActionConfigs().get( request.getActionName() ); } catch ( ConveyorException e ) { } } return null; }
ActionInvocation ai = ActionContext.getContext().getActionInvocation();
Template template = config.getTemplate(decorator.getPage(), getLocale(ctx.getActionInvocation(), config)); // WW-1181
/** * Applies the decorator, creating the relevent contexts and delegating to * the extended applyDecorator(). * * @param page The page * @param decorator The decorator * @param req The servlet request * @param res The servlet response */ protected void applyDecorator(Page page, Decorator decorator, HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletContext servletContext = filterConfig.getServletContext(); ActionContext ctx = ServletActionContext.getActionContext(req); if (ctx == null) { // ok, one isn't associated with the request, so let's get a ThreadLocal one (which will create one if needed) OgnlValueStack vs = new OgnlValueStack(); vs.getContext().putAll(DispatcherUtils.getInstance().createContextMap(req, res, null, servletContext)); ctx = new ActionContext(vs.getContext()); if (ctx.getActionInvocation() == null) { // put in a dummy ActionSupport so basic functionality still works ActionSupport action = new ActionSupport(); vs.push(action); ctx.setActionInvocation(new DummyActionInvocation(action)); } } // delegate to the actual page decorator applyDecorator(page, decorator, req, res, servletContext, ctx); }
/** * Create a Freemarker's Model through {@link FreemarkerManager#buildTemplateModel(OgnlValueStack, Object, ServletContext, HttpServletRequest, HttpServletResponse, ObjectWrapper)}. * * @return * @throws TemplateException */ protected SimpleHash createModel() throws TemplateException { FreemarkerManager freemarkerManager = FreemarkerManager.getInstance(); ActionInvocation invocation = ActionContext.getContext().getActionInvocation(); ServletContext servletContext = JspSupportServlet.jspSupportServlet.getServletContext(); OgnlValueStack stack = ActionContext.getContext().getValueStack(); ObjectWrapper wrapper = freemarkerManager.getConfiguration(servletContext).getObjectWrapper(); Object action = null; if(invocation!= null ) action = invocation.getAction(); //Added for NullPointException return freemarkerManager.buildTemplateModel(stack, action, servletContext, request, response, wrapper); } }
Action action = (Action) context.getActionInvocation().getAction();