final ActionContext context = actionInvocation.getInvocationContext(); com.opensymphony.xwork2.util.ValueStack vs=context.getValueStack(); ((ActionMapping)vs.getContext().get("struts.actionMapping")).getExtension();
private int getBackCount(ActionContext context) { int count = 1; Object value = context.get("count"); if (value != null) count = Integer.parseInt(value.toString()); Map<String, Object> params = context.getParameters(); value = params.get("count"); if (value != null) count = Integer.parseInt(value.toString()); ValueStack stack = context.getValueStack(); value = stack.findValue("count"); if (value != null) count = Integer.parseInt(value.toString()); return count; } }
/** * <p>Creates and returns an initialized Velocity context.</p> * * @param request servlet request from client * @param response servlet reponse to client */ protected Context createContext(HttpServletRequest request, HttpServletResponse response) { Context context = (Context) request.getAttribute(VelocityManager.KEY_VELOCITY_STRUTS_CONTEXT); if (context == null) { ActionContext ctx = ServletActionContext.getActionContext(request); context = velocityManager.createContext(ctx.getValueStack(), request, response); } return context; }
public void beforeResult(ActionInvocation invocation, String resultCode) { ValueStack stack = ActionContext.getContext().getValueStack(); stack.setExprOverrides(fakeParams); } });
public char execute(ActionContext context, AgiOperations opts) throws IOException, AgiException { Locale locale = context.getLocale(); ValueStack valueStack = context.getValueStack(); String text = LocalizedTextUtil.findText( AbstractAgiTemplate.this.getClass(), _message, locale, _message, _args, valueStack); return _textToSpeechFactory.getAudio(opts, text, ALL_DIGITS); } }
private boolean isInChainHistory(String namespace, String actionName, String methodName) { LinkedList<? extends String> chainHistory = ActionChainResult.getChainHistory(); if (chainHistory == null) { return false; } else { // Actions to skip Set<String> skipActionsList = new HashSet<String>(); if (skipActions != null && skipActions.length() > 0) { ValueStack stack = ActionContext.getContext().getValueStack(); String finalSkipActions = TextParseUtil.translateVariables(this.skipActions, stack); skipActionsList.addAll(TextParseUtil.commaDelimitedStringToSet(finalSkipActions)); } if (!skipActionsList.contains(actionName)) { // Get if key is in the chain history return chainHistory.contains(makeKey(namespace, actionName, methodName)); } 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); }
/** * Dedicated method to support I10N and conversion errors * * @param key message which contains formatting string * @param expr that should be formatted * @return formatted expr with format specified by key */ public String getFormatted(String key, String expr) { Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors(); if (conversionErrors.containsKey(expr)) { String[] vals = (String[]) conversionErrors.get(expr); return vals[0]; } else { final ValueStack valueStack = ActionContext.getContext().getValueStack(); final Object val = valueStack.findValue(expr); return getText(key, Arrays.asList(val)); } }
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()); }
/** * The validation implementation must guarantee that setValidatorContext will * be called with a non-null ValidatorContext before validate is called. * * @param object * @throws ValidationException */ @Override public void doValidate(Object object) throws ValidationException { String fieldName = getFieldName(); String fullFieldName = getValidatorContext().getFullFieldName(fieldName); ActionContext context = ActionContext.getContext(); Map<String, Object> conversionErrors = context.getConversionErrors(); if (conversionErrors.containsKey(fullFieldName)) { if ((defaultMessage == null) || ("".equals(defaultMessage.trim()))) { defaultMessage = XWorkConverter.getConversionErrorMessage(fullFieldName, context.getValueStack()); } addFieldError(fieldName, object); } }
@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); } }
public void testNullIsReturnedWhenCreateNullObjectsIsSpecifiedAsFalse() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.emptyMap())); ReflectionContextState.setCreatingNullObjects(vs.getContext(), false); assertNull(vs.findValue("map['key']")); }
/** * S2ComponentMapをValueStackに追加します。 * */ public String intercept(ActionInvocation invocation) throws Exception { if (container == null && SingletonS2ContainerFactory.hasContainer()) { container = SingletonS2ContainerFactory.getContainer(); } Map map = new S2ComponentMap(container.getRoot()); ActionContext.getContext().getValueStack().getRoot().add(map); return invocation.invoke(); }
@Override public void buildTemplate(ActionContext context) { ValueStack stack = context.getValueStack(); String message = stack.findString("message"); String nextAction = stack.findString("nextAction"); if (message != null) addMessage(message); else System.err.println("no message specified"); if (nextAction != null) { setNextAction(nextAction); } else { addAction(".*\\*", "/back"); setNextAction("/back"); } } }
@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); }
/** * {@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); } }
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 buildTemplate(ActionContext context) { ValueStack valueStack = context.getValueStack(); PhoneArrivalsAndDeparturesModel model = (PhoneArrivalsAndDeparturesModel) valueStack.findValue("model"); StopsWithArrivalsAndDeparturesBean result = model.getResult(); buildPredictedArrivalsTemplate(result.getArrivalsAndDepartures()); addMessage(Messages.ARRIVAL_INFO_ON_SPECIFIC_ROUTE); AgiActionName byRouteAction = addActionWithParameterFromMatch("1(\\d+)#", "/stop/arrivalsAndDeparturesForRoute", "route", 1); byRouteAction.putParam("model", model); addMessage(Messages.ARRIVAL_INFO_BOOKMARK_THIS_LOCATION); AgiActionName bookmarkAction = addAction("2", "/stop/bookmark"); bookmarkAction.putParam("stops", result.getStops()); addMessage(Messages.ARRIVAL_INFO_RETURN_TO_MAIN_MENU); addAction("3", "/index"); addAction("(#|[04-9]|1.*\\*)", "/repeat"); addMessage(Messages.HOW_TO_GO_BACK); addAction("\\*", "/back"); addMessage(Messages.TO_REPEAT); }