本文整理汇总了Java中com.opensymphony.xwork2.util.ValueStack.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java ValueStack.getContext方法的具体用法?Java ValueStack.getContext怎么用?Java ValueStack.getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.opensymphony.xwork2.util.ValueStack
的用法示例。
在下文中一共展示了ValueStack.getContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNamespace
import com.opensymphony.xwork2.util.ValueStack; //导入方法依赖的package包/类
public static String buildNamespace(ActionMapper mapper, ValueStack stack, HttpServletRequest request) {
ActionContext context = new ActionContext(stack.getContext());
ActionInvocation invocation = context.getActionInvocation();
if (invocation == null) {
ActionMapping mapping = mapper.getMapping(request,
Dispatcher.getInstance().getConfigurationManager());
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();
}
}
示例2: getStack
import com.opensymphony.xwork2.util.ValueStack; //导入方法依赖的package包/类
public static ValueStack getStack(PageContext pageContext) {
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
ValueStack stack = (ValueStack) req.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
if (stack == null) {
HttpServletResponse res = (HttpServletResponse) pageContext.getResponse();
Dispatcher du = Dispatcher.getInstance();
if (du == null) {
throw new ConfigurationException("The Struts dispatcher cannot be found. This is usually caused by "+
"using Struts tags without the associated filter. Struts tags are only usable when the request "+
"has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.");
}
stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack();
Map<String, Object> extraContext = du.createContextMap(new RequestMap(req),
req.getParameterMap(),
new SessionMap(req),
new ApplicationMap(pageContext.getServletContext()),
req,
res);
extraContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);
stack.getContext().putAll(extraContext);
req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
// also tie this stack/context to the ThreadLocal
ActionContext.setContext(new ActionContext(stack.getContext()));
} else {
// let's make sure that the current page context is in the action context
Map<String, Object> context = stack.getContext();
context.put(ServletActionContext.PAGE_CONTEXT, pageContext);
AttributeMap attrMap = new AttributeMap(context);
context.put("attr", attrMap);
}
return stack;
}
示例3: getActionContext
import com.opensymphony.xwork2.util.ValueStack; //导入方法依赖的package包/类
/**
* Gets the current action context
*
* @param req The request
* @return The current action context
*/
public static ActionContext getActionContext(HttpServletRequest req) {
ValueStack vs = getValueStack(req);
if (vs != null) {
return new ActionContext(vs.getContext());
} else {
return null;
}
}
示例4: createContextMap
import com.opensymphony.xwork2.util.ValueStack; //导入方法依赖的package包/类
protected Map<String, Object> createContextMap() {
Map<String, Object> contextMap;
if ((extraContext != null) && (extraContext.containsKey(ActionContext.VALUE_STACK))) {
// In case the ValueStack was passed in
stack = (ValueStack) extraContext.get(ActionContext.VALUE_STACK);
if (stack == null) {
throw new IllegalStateException("There was a null Stack set into the extra params.");
}
contextMap = stack.getContext();
} else {
// create the value stack
// this also adds the ValueStack to its context
stack = valueStackFactory.createValueStack();
// create the action context
contextMap = stack.getContext();
}
// put extraContext in
if (extraContext != null) {
contextMap.putAll(extraContext);
}
//put this DefaultActionInvocation into the context map
contextMap.put(ActionContext.ACTION_INVOCATION, this);
contextMap.put(ActionContext.CONTAINER, container);
return contextMap;
}
示例5: intercept
import com.opensymphony.xwork2.util.ValueStack; //导入方法依赖的package包/类
@Override public String intercept(ActionInvocation invocation) throws Exception {
ActionConfig config = invocation.getProxy().getConfig();
ActionContext ac = invocation.getInvocationContext();
Object action = invocation.getAction();
// get the action's parameters
final Map<String, String> parameters = config.getParams();
if (parameters.containsKey(aliasesKey)) {
String aliasExpression = parameters.get(aliasesKey);
ValueStack stack = ac.getValueStack();
Object obj = stack.findValue(aliasExpression);
if (obj != null && obj instanceof Map) {
//get secure stack
ValueStack newStack = valueStackFactory.createValueStack(stack);
boolean clearableStack = newStack instanceof ClearableValueStack;
if (clearableStack) {
//if the stack's context can be cleared, do that to prevent OGNL
//from having access to objects in the stack, see XW-641
((ClearableValueStack)newStack).clearContextValues();
Map<String, Object> context = newStack.getContext();
ReflectionContextState.setCreatingNullObjects(context, true);
ReflectionContextState.setDenyMethodExecution(context, true);
ReflectionContextState.setReportingConversionErrors(context, true);
//keep locale from original context
context.put(ActionContext.LOCALE, stack.getContext().get(ActionContext.LOCALE));
}
// override
Map aliases = (Map) obj;
for (Object o : aliases.entrySet()) {
Map.Entry entry = (Map.Entry) o;
String name = entry.getKey().toString();
String alias = (String) entry.getValue();
Object value = stack.findValue(name);
if (null == value) {
// workaround
Map<String, Object> contextParameters = ActionContext.getContext().getParameters();
if (null != contextParameters) {
value = contextParameters.get(name);
}
}
if (null != value) {
try {
newStack.setValue(alias, value);
} catch (RuntimeException e) {
if (devMode) {
String developerNotification = LocalizedTextUtil.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{
"Unexpected Exception caught setting '" + entry.getKey() + "' on '" + action.getClass() + ": " + e.getMessage()
});
LOG.error(developerNotification);
if (action instanceof ValidationAware) {
((ValidationAware) action).addActionMessage(developerNotification);
}
}
}
}
}
if (clearableStack && (stack.getContext() != null) && (newStack.getContext() != null))
stack.getContext().put(ActionContext.CONVERSION_ERRORS, newStack.getContext().get(ActionContext.CONVERSION_ERRORS));
} else {
LOG.debug("invalid alias expression: {}", aliasesKey);
}
}
return invocation.invoke();
}