/** * Sets the action's context map. * * @param contextMap the context map. */ public void setContextMap(Map<String, Object> contextMap) { getContext().context = contextMap; }
private Object convert(Object element) { if ((element != null) && !clazz.isAssignableFrom(element.getClass())) { // convert to correct type if (LOG.isDebugEnabled()) { LOG.debug("Converting from " + element.getClass().getName() + " to " + clazz.getName()); } TypeConverter conv = getTypeConverter(); Map<String, Object> context = ActionContext.getContext().getContextMap(); element = conv.convertValue(context, null, null, null, element, clazz); } return element; }
/** * Get the XWork chain history. * The stack is a list of <code>namespace/action!method</code> keys. */ public static LinkedList<String> getChainHistory() { LinkedList<String> chainHistory = (LinkedList<String>) ActionContext.getContext().get(CHAIN_HISTORY); // Add if not exists if (chainHistory == null) { chainHistory = new LinkedList<String>(); ActionContext.getContext().put(CHAIN_HISTORY, chainHistory); } return chainHistory; }
public void clearSessionValue() { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext() .get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"); for (Enumeration<String> e = request.getSession().getAttributeNames(); e.hasMoreElements();) { String key = e.nextElement(); if (key.indexOf("class") >= 0) { request.getSession().removeAttribute(key); } } }
protected Flash getFlash() { Flash flash = (Flash) ActionContext.getContext().getSession().get("flash"); if (null == flash) { flash = new Flash(); ActionContext.getContext().getSession().put("flash", flash); } return flash; }
private boolean isInsideActionTag() { if(ActionContext.getContext() == null) { LOG.trace("ActionContext is null! Not a user request?"); return false; } Object attribute = ServletActionContext.getRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION); return (Boolean) ObjectUtils.defaultIfNull(attribute, Boolean.FALSE); }
/** * @deprecated Since 2.1 */ @Deprecated public static ObjectFactory getObjectFactory() { return ActionContext.getContext().getContainer().getInstance(ObjectFactory.class); }
public String getText(String key, List<?> args) { Object[] params; if (args != null) { params = args.toArray(); } else { params = EMPTY_ARGS; } return LocalizedTextUtil.findDefaultText(key, ActionContext.getContext().getLocale(), params); }
public void beforeResult(ActionInvocation invocation, String resultCode) { ValueStack stack = ActionContext.getContext().getValueStack(); stack.setExprOverrides(fakeParams); } });
public String getText(String key, String[] args) { Object[] params; if (args != null) { params = args; } else { params = EMPTY_ARGS; } return LocalizedTextUtil.findDefaultText(key, ActionContext.getContext().getLocale(), params); }
protected String getNextActionOrSuccess() { List<NextAction> stack = getNextActionStack(false); if (stack == null || stack.isEmpty()) return SUCCESS; NextAction next = stack.remove(stack.size() - 1); Map<String, String[]> params = next.getParameters(); if (params != null && !params.isEmpty()) { ActionContext context = ActionContext.getContext(); Map<String, Object> contextParameters = context.getParameters(); contextParameters.putAll(params); } return next.getAction(); }
public Locale getLocale() { ActionContext ctx = ActionContext.getContext(); if (ctx != null) { return ctx.getLocale(); } else { if (LOG.isDebugEnabled()) { LOG.debug("Action context not initialized"); } return null; } }
public Locale getLocale() { ActionContext ctx = ActionContext.getContext(); if (ctx != null) { return ctx.getLocale(); } else { if (LOG.isDebugEnabled()) { LOG.debug("Action context not initialized"); } return null; } }
public void testCreateNullObjectsIsFalseByDefault() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.emptyMap())); assertNull(vs.findValue("map[key]")); }
public void testMapContentsAreReturned() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.singletonMap("key", "value"))); assertEquals("value", vs.findValue("map['key']")); }
public void testNullIsNotReturnedWhenCreateNullObjectsIsSpecified() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.emptyMap())); ReflectionContextState.setCreatingNullObjects(vs.getContext(), true); Object value = vs.findValue("map['key']"); assertNotNull(value); assertSame(Object.class, value.getClass()); }
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; }
protected ActionContext setContext(Container cont) { ActionContext context = ActionContext.getContext(); if (context == null) { ValueStack vs = cont.getInstance(ValueStackFactory.class).createValueStack(); context = new ActionContext(vs.getContext()); ActionContext.setContext(context); } return context; }
@Override protected void doExecute(String location, ActionInvocation invocation) throws Exception { ValueStack stack = ActionContext.getContext().getValueStack(); ValueStackMap map = new ValueStackMap(stack); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); WebEngine.setRequestAndResponse(request, response); WebEngine.getEngine().getTemplate(location, request.getLocale(), map).render(map, response); }
private void validateObject(String fieldName, Object o, String visitorContext) throws ValidationException { ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(o); ValidatorContext validatorContext; if (appendPrefix) { validatorContext = new AppendingValidatorContext(getValidatorContext(), o, fieldName, getMessage(o)); } else { ValidatorContext parent = getValidatorContext(); validatorContext = new DelegatingValidatorContext(parent, DelegatingValidatorContext.makeTextProvider(o, parent), parent); } actionValidatorManager.validate(o, visitorContext, validatorContext); stack.pop(); }