/** * Default implementation to handle ExceptionHolder publishing. Pushes given ExceptionHolder on the stack. * Subclasses may override this to customize publishing. * * @param invocation The invocation to publish Exception for. * @param exceptionHolder The exceptionHolder wrapping the Exception to publish. */ protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) { invocation.getStack().push(exceptionHolder); }
protected Object getValue(Object obj, String property) { stack.push(obj); try { Object value = stack.findValue(property); if (value instanceof Number) { return MessageFormat.format(NumberFormat, value); } return value; } finally { stack.pop(); } }
@Override public boolean end(Writer writer, String body) { ValueStack stack = getStack(); if (_iterator != null) { Object value = stack.pop(); if (_lastKey == null || !_lastKey.equals(body)) { _currentGroup = new ArrayList<Object>(); _groups.add(_currentGroup); } _currentGroup.add(value); _lastKey = body; } if (_iterator != null && _iterator.hasNext()) { Object currentValue = _iterator.next(); stack.push(currentValue); return true; } else { putInContext(_groups); return super.end(writer, ""); } } }
@Override public boolean start(Writer writer) { ValueStack stack = getStack(); if (_value == null) _value = "top"; _iterator = MakeIterator.convert(findValue(_value)); // get the first if ((_iterator != null) && _iterator.hasNext()) { Object currentValue = _iterator.next(); stack.push(currentValue); return true; } else { super.end(writer, ""); return false; } }
@Override protected AgiActionName executeTemplate(ActionContext context, AgiTemplate template) throws Exception { if (_message != null) { ValueStack stack = context.getValueStack(); MessageSource source = new MessageSource(_message,_nextAction); stack.push(source); } return super.executeTemplate(context, template); }
@Override public boolean start(Writer writer) { ValueStack stack = getStack(); if (_value == null) _value = "top"; _iterator = MakeIterator.convert(findValue(_value)); // get the first if ((_iterator != null) && _iterator.hasNext()) { Object currentValue = _iterator.next(); stack.push(currentValue); return true; } else { super.end(writer, ""); return false; } }
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']")); }
@Override public String getMessage(Object object) { boolean pop = false; if (useSensitiveContext && !stack.getRoot().contains(c)) { stack.push(c); pop = true; } String message = super.getMessage(object); if (pop) { stack.pop(); } return message; }
@Override public String getMessage(Object object) { boolean pop = false; if (useSensitiveContext && !stack.getRoot().contains(c)) { stack.push(c); pop = true; } String message = super.getMessage(object); if (pop) { stack.pop(); } return message; }
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()); }
public void testNullIsReturnedWhenCreateNullObjectsIsSpecifiedAsFalse() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.emptyMap())); ReflectionContextState.setCreatingNullObjects(vs.getContext(), false); assertNull(vs.findValue("map['key']")); }
/** * Return the field value named <code>name</code> from <code>object</code>, * <code>object</code> should have the appropriate getter/setter. * * @param name name of the field * @param object to search field name on * @return Object as field value * @throws ValidationException */ protected Object getFieldValue(String name, Object object) throws ValidationException { boolean pop = false; if (!stack.getRoot().contains(object)) { stack.push(object); pop = true; } Object retVal = stack.findValue(name); if (pop) { stack.pop(); } return retVal; }
@Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof ModelDriven) { ModelDriven modelDriven = (ModelDriven) action; ValueStack stack = invocation.getStack(); Object model = modelDriven.getModel(); if (model != null) { stack.push(model); } if (refreshModelBeforeResult) { invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model)); } } return invocation.invoke(); }
public void init(ActionProxy proxy) { this.proxy = proxy; Map<String, Object> contextMap = createContextMap(); // Setting this so that other classes, like object factories, can use the ActionProxy and other // contextual information to operate ActionContext actionContext = ActionContext.getContext(); if (actionContext != null) { actionContext.setActionInvocation(this); } createAction(contextMap); if (pushAction) { stack.push(action); contextMap.put("action", action); } invocationContext = new ActionContext(contextMap); invocationContext.setName(proxy.getActionName()); createInterceptors(proxy); }
/** * {@inheritDoc} */ public void prepare() { ActionContext actionContext = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST); ConversationContextManager contextManager = scopeContainer.getComponent(HttpConversationContextManagerProvider.class).getManager(request); try { scopeContainer.getComponent(ConversationProcessor.class).processConversations(new StrutsConversationAdapter(actionContext.getActionInvocation(), contextManager)); Map<String, Map<String, String>> stackItem = new HashMap<String, Map<String, String>>(); stackItem.put(StrutsScopeConstants.CONVERSATION_ID_MAP_STACK_KEY, ConversationAdapter.getAdapter().getViewContext()); actionContext.getValueStack().push(stackItem); } catch (ConversationException e) { LOG.error("Programmatic Conversation error in Prepare method", e); } }
public void validate(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = this.getFieldValue(fieldName, object); if (value == null) { log.warn("The visited object is null, VisitorValidator will not be able to handle validation properly. Please make sure the visited object is not null for VisitorValidator to function properly"); return; } ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(object); String visitorContext = (context == null) ? ActionContext.getContext().getName() : context; if (value instanceof Collection) { Collection coll = (Collection) value; Object[] array = coll.toArray(); validateArrayElements(array, fieldName, visitorContext); } else if (value instanceof Object[]) { Object[] array = (Object[]) value; validateArrayElements(array, fieldName, visitorContext); } else { validateObject(fieldName, value, visitorContext); } stack.pop(); }
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(); }
@Override public void validateWhenNotSkip(Object object) throws ValidationException { booleans = initParams(Boolean.class, booleanParams, EXTRA_BOOLEAN_PARAM_ENTRY_PATTERN); shorts = initParams(Short.class, shortParams, EXTRA_SHORT_PARAM_ENTRY_PATTERN); ints = initParams(Integer.class, intParams, EXTRA_INT_PARAM_ENTRY_PATTERN); longs = initParams(Long.class, longParams, EXTRA_LONG_PARAM_ENTRY_PATTERN); doubles = initParams(Double.class, doubleParams, EXTRA_DOUBLE_PARAM_ENTRY_PATTERN); strings = initParams(String.class, stringParams, EXTRA_STRING_PARAM_ENTRY_PATTERN); boolean pop = false; if (!stack.getRoot().contains(this)) { stack.push(this); pop = true; } try { super.validateWhenNotSkip(object); } finally { if (pop) { stack.pop(); } } }
@Override public void validate(Object object) throws ValidationException { booleans = initParams(Boolean.class, booleanParams, EXTRA_BOOLEAN_PARAM_ENTRY_PATTERN); shorts = initParams(Short.class, shortParams, EXTRA_SHORT_PARAM_ENTRY_PATTERN); ints = initParams(Integer.class, intParams, EXTRA_INT_PARAM_ENTRY_PATTERN); longs = initParams(Long.class, longParams, EXTRA_LONG_PARAM_ENTRY_PATTERN); doubles = initParams(Double.class, doubleParams, EXTRA_DOUBLE_PARAM_ENTRY_PATTERN); strings = initParams(String.class, stringParams, EXTRA_STRING_PARAM_ENTRY_PATTERN); boolean pop = false; if (!stack.getRoot().contains(this)) { stack.push(this); pop = true; } try { super.validate(object); } finally { if (pop) { stack.pop(); } } }