/** * Restoring Container * * @param actionContext current {@link ActionContext} * @return instance which can be used to invoke action */ public ActionInvocation deserialize(ActionContext actionContext) { DefaultActionInvocation that = this; that.container = actionContext.getContainer(); return that; }
/** * @deprecated Since 2.1 */ @Deprecated public static ObjectFactory getObjectFactory() { return ActionContext.getContext().getContainer().getInstance(ObjectFactory.class); }
public <T> T getInstance(Class<T> type) { Container cont = getContainer(); if (cont != null) { return cont.getInstance(type); } else { throw new XWorkException("Cannot find an initialized container for this request."); } }
public static ReflectionProvider getInstance() { return ActionContext.getContext().getContainer().getInstance(ReflectionProvider.class); } }
private TypeConverter getTypeConverter() { return ActionContext.getContext().getContainer().getInstance(XWorkConverter.class); }
/** * Allows for providing custom theme classes (implementations of the org.apache.struts2.views.java.Theme) interface * for custom rendering of tags using the javatemplates engine * * @param themeClasses a comma delimited list of custom theme class names */ @Inject(value = "struts.javatemplates.customThemes", required = false) public void setThemeClasses(String themeClasses) { StringTokenizer customThemes = new StringTokenizer(themeClasses, ","); while (customThemes.hasMoreTokens()) { String themeClass = customThemes.nextToken().trim(); try { LOG.info("Registering custom theme [{}] to javatemplates engine", themeClass); ObjectFactory factory = ActionContext.getContext().getContainer().getInstance(ObjectFactory.class); Theme theme = (Theme) factory.buildBean(themeClass, new HashMap<String, Object>()); themes.add(theme); } catch (ClassCastException cce) { LOG.error("Invalid java them class [{}]. Class does not implement 'org.apache.struts2.views.java.Theme' interface", themeClass, cce); } catch (ClassNotFoundException cnf) { LOG.error("Invalid java theme class [{}]. Class not found!", themeClass, cnf); } catch (Exception e) { LOG.error("Could not find messages file [{}].properties. Skipping!", themeClass, e); } } }
protected AgiTemplate buildTemplateInstance(ActionContext context, Class<?> c) throws Exception { Container container = context.getContainer(); ObjectFactory factory = container.getInstance(ObjectFactory.class); AgiTemplate template = (AgiTemplate) factory.buildBean(c, context.getContextMap()); return template; }
@Override public Object evaluate(String expression, Request request) { Object result = expression; HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest(); ActionContext ctx = ServletActionContext.getActionContext(httpRequest); if (ctx == null) { LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName()); throw new ConfigurationException("There is no ActionContext for current request!"); } TextProviderFactory tpf = ctx.getContainer().getInstance(TextProviderFactory.class); TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass()); if (textProvider != null) { LOG.debug("Trying find text [{}] using TextProvider {}", expression, textProvider); result = textProvider.getText(expression); } return result; }
@Override public Object evaluate(String expression, Request request) { try { HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest(); ActionContext ctx = ServletActionContext.getActionContext(httpRequest); if (ctx == null) { LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName()); throw new ConfigurationException("There is no ActionContext for current request!"); } OgnlUtil ognlUtil = ctx.getContainer().getInstance(OgnlUtil.class); LOG.debug("Trying evaluate expression [{}] using OgnlUtil's getValue", expression); Object result = ognlUtil.getValue(expression, ctx.getContextMap(), ctx.getValueStack().getRoot()); LOG.debug("Final result of evaluating expression [{}] is: {}", expression, result); return result; } catch (OgnlException e) { throw new EvaluationException(e); } }
private Object readResolve() { // TODO: this should be done better ActionContext ac = ActionContext.getContext(); Container cont = ac.getContainer(); XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class); CompoundRootAccessor accessor = (CompoundRootAccessor) cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName()); TextProvider prov = cont.getInstance(TextProvider.class, "system"); boolean allow = "true".equals(cont.getInstance(String.class, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS)); OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, prov, allow); aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class)); aStack.setRoot(xworkConverter, accessor, this.root, allow); return aStack; }
@Override protected ViewPreparer createPreparer(String name) { ActionContext actionContext = ActionContext.getContext(); if (actionContext == null) { LOG.warn("Action context not initialised, request has omitted an action? Fallback to super.createPreparer!"); return super.createPreparer(name); } try { ObjectFactory factory = actionContext.getContainer().getInstance(ObjectFactory.class); return (ViewPreparer) factory.buildBean(name, ActionContext.getContext().getContextMap()); } catch (Exception e) { LOG.error(new ParameterizedMessage("Cannot create a ViewPreparer [{}], fallback to super.createPreparer!", name), e); return super.createPreparer(name); } } }
public XWorkBeanValidator(Class<B> beanClass, String contextName, boolean includeDefaultContext, ValueStack vs) { this.beanClass = beanClass; this.includeDefaultContext = includeDefaultContext; validationSupport = new ValidationAwareSupport(); validationContext = new DelegatingValidatorContext(validationSupport); if (vs == null) { // create a standalone value stack ConfigurationManager confManager = new ConfigurationManager(); Configuration conf = confManager.getConfiguration(); vs = conf.getContainer().getInstance(ValueStackFactory.class).createValueStack(); if (log.isDebugEnabled()) { log.info("create a standalone value stack " + vs); } } else { if (log.isDebugEnabled()) { log.debug("use given value stack " + vs); } } context = new ActionContext(vs.getContext()); ActionContext.setContext(context); // init validator validator = context.getContainer().getInstance(ActionValidatorManager.class, "no-annotations"); // init context setContextName(contextName); }
@Override public void render(String path, Request request) throws IOException { if (path != null) { LOG.trace("Rendering freemarker tile [{}]", path); ActionContext ctx = readActionContext(request); registerTilesBeanModel(ctx); FreemarkerResult result = new FreemarkerResult(path); result.setWriter(request.getWriter()); Container container = ctx.getContainer(); container.inject(result); try { ActionInvocation invocation = ctx.getActionInvocation(); result.doExecute(path, invocation); } catch (TemplateException e) { LOG.error("Exception was thrown during rendering value {}: {}", path, e.getMessage()); throw new InvalidTemplateException(e); } } else { LOG.error("Path is null, cannot render template!"); throw new InvalidTemplateException("Cannot render a null template"); } }
Container container = context.getContainer();