本文整理汇总了Java中com.opensymphony.xwork2.util.ValueStack类的典型用法代码示例。如果您正苦于以下问题:Java ValueStack类的具体用法?Java ValueStack怎么用?Java ValueStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueStack类属于com.opensymphony.xwork2.util包,在下文中一共展示了ValueStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDispatcher
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
public static Dispatcher initDispatcher(ServletContext ctx, Map<String,String> params) {
if (params == null) {
params = new HashMap<>();
}
Dispatcher du = new DispatcherWrapper(ctx, params);
du.init();
Dispatcher.setInstance(du);
// Reset the value stack
Container container = du.getContainer();
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
stack.getContext().put(ActionContext.CONTAINER, container);
ActionContext.setContext(new ActionContext(stack.getContext()));
return du;
}
示例2: determineNamespace
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
/**
* Determines the namespace of the current page being renderdd. Useful for Form, URL, and href generations.
* @param namespace the namespace
* @param stack OGNL value stack
* @param req HTTP request
* @return the namepsace of the current page being rendered, is never <tt>null</tt>.
*/
protected String determineNamespace(String namespace, ValueStack stack, HttpServletRequest req) {
String result;
if (namespace == null) {
result = TagUtils.buildNamespace(actionMapper, stack, req);
} else {
result = findString(namespace);
}
if (result == null) {
result = "";
}
return result;
}
示例3: getText
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
/**
* Gets a message based on a key using the supplied args, as defined in
* {@link java.text.MessageFormat}, or, if the message is not found, a supplied
* default value is returned. Instead of using the value stack in the ActionContext
* this version of the getText() method uses the provided value stack.
*
* @param key the resource bundle key that is to be searched for
* @param defaultValue the default value which will be returned if no message is found
* @param args a list args to be used in a {@link java.text.MessageFormat} message
* @param stack the value stack to use for finding the text
* @return the message as found in the resource bundle, or defaultValue if none is found
*/
public String getText(String key, String defaultValue, List<?> args, ValueStack stack) {
Object[] argsArray = ((args != null) ? args.toArray() : null);
Locale locale;
if (stack == null){
locale = getLocale();
}else{
locale = (Locale) stack.getContext().get(ActionContext.LOCALE);
}
if (locale == null) {
locale = getLocale();
}
if (clazz != null) {
return LocalizedTextUtil.findText(clazz, key, locale, defaultValue, argsArray, stack);
} else {
return LocalizedTextUtil.findText(bundle, key, locale, defaultValue, argsArray, stack);
}
}
示例4: safeTextParseUtil
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
public void safeTextParseUtil(ValueStack stack, TextParseUtil.ParsedValueEvaluator parsedValueEvaluator, Class type) {
String input = "1+1";
TextParseUtil.translateVariables(input, stack);
TextParseUtil.translateVariables(input, stack, parsedValueEvaluator);
TextParseUtil.translateVariables('a', input, stack);
TextParseUtil.translateVariables('a', input, stack, type);
TextParseUtil.translateVariables(new char[]{'a'}, input, stack, type, parsedValueEvaluator);
TextParseUtil.translateVariables(new char[]{'a'}, input, stack, type, parsedValueEvaluator, 0);
TextParseUtil.translateVariables('a', input, stack, type, parsedValueEvaluator, 0);
}
示例5: handleInvalidToken
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
@Override
protected String handleInvalidToken(ActionInvocation invocation) throws Exception {
ActionContext ac = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ac.get(ServletActionContext.HTTP_RESPONSE);
String tokenName = TokenHelper.getTokenName();
String token = TokenHelper.getToken(tokenName);
if ((tokenName != null) && (token != null)) {
Map params = ac.getParameters();
params.remove(tokenName);
params.remove(TokenHelper.TOKEN_NAME_FIELD);
String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
ActionInvocation savedInvocation = InvocationSessionStore.loadInvocation(sessionTokenName, token);
if (savedInvocation != null) {
// set the valuestack to the request scope
ValueStack stack = savedInvocation.getStack();
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
ActionContext savedContext = savedInvocation.getInvocationContext();
savedContext.getContextMap().put(ServletActionContext.HTTP_REQUEST, request);
savedContext.getContextMap().put(ServletActionContext.HTTP_RESPONSE, response);
Result result = savedInvocation.getResult();
if ((result != null) && (savedInvocation.getProxy().getExecuteResult())) {
result.execute(savedInvocation);
}
// turn off execution of this invocations result
invocation.getProxy().setExecuteResult(false);
return savedInvocation.getResultCode();
}
}
return INVALID_TOKEN_CODE;
}
示例6: OptGroup
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
public OptGroup(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
super(stack);
this.req = req;
this.res = res;
internalUiBean = new ListUIBean(stack, req, res) {
protected String getDefaultTemplate() {
return "empty";
}
};
}
示例7: getFormatted
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
/**
* 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));
}
}
示例8: intercept
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ValueStack stack = invocation.getStack();
CompoundRoot root = stack.getRoot();
if (shouldCopyStack(invocation, root)) {
copyStack(invocation, root);
}
return invocation.invoke();
}
示例9: renderTemplate
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
public void renderTemplate(TemplateRenderingContext templateContext) throws Exception {
Template template = templateContext.getTemplate();
LOG.debug("Trying to render template [{}], repeating through parents until we succeed", template);
UIBean tag = templateContext.getTag();
ValueStack stack = templateContext.getStack();
stack.push(tag);
PageContext pageContext = (PageContext) stack.getContext().get(ServletActionContext.PAGE_CONTEXT);
List<Template> templates = template.getPossibleTemplates(this);
Exception exception = null;
boolean success = false;
for (Template t : templates) {
try {
Include.include(getFinalTemplateName(t), pageContext.getOut(),
pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(), encoding);
success = true;
break;
} catch (Exception e) {
if (exception == null) {
exception = e;
}
}
}
if (!success) {
LOG.error("Could not render JSP template {}", templateContext.getTemplate());
if (exception != null) {
throw exception;
} else {
return;
}
}
stack.pop();
}
示例10: buildTemplateModel
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
public ScopesHashModel buildTemplateModel(ValueStack stack, Object action, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, ObjectWrapper wrapper) {
ScopesHashModel model = buildScopesHashModel(servletContext, request, response, wrapper, stack);
populateContext(model, stack, action, request, response);
if (tagLibraries != null) {
for (String prefix : tagLibraries.keySet()) {
model.put(prefix, tagLibraries.get(prefix).getModels(stack, request, response));
}
}
//place the model in the request using the special parameter. This can be retrieved for freemarker and velocity.
request.setAttribute(ATTR_TEMPLATE_MODEL, model);
return model;
}
示例11: 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;
}
示例12: createContext
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
/**
* <p>
* This method is responsible for creating the standard VelocityContext used by all WW2 velocity views. The
* following context parameters are defined:
* </p>
*
* <ul>
* <li><strong>request</strong> - the current HttpServletRequest</li>
* <li><strong>response</strong> - the current HttpServletResponse</li>
* <li><strong>stack</strong> - the current {@link ValueStack}</li>
* <li><strong>ognl</strong> - an {@link OgnlTool}</li>
* <li><strong>struts</strong> - an instance of {@link org.apache.struts2.util.StrutsUtil}</li>
* <li><strong>action</strong> - the current Struts action</li>
* </ul>
*
* @param stack the current {@link ValueStack}
* @param req the current HttpServletRequest
* @param res the current HttpServletResponse
* @return a new StrutsVelocityContext
*/
public Context createContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
Context result = null;
VelocityContext[] chainedContexts = prepareChainedContexts(req, res, stack.getContext());
StrutsVelocityContext context = new StrutsVelocityContext(chainedContexts, stack);
Map standardMap = ContextUtil.getStandardContext(stack, req, res);
for (Iterator iterator = standardMap.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
context.put((String) entry.getKey(), entry.getValue());
}
context.put(STRUTS, new VelocityStrutsUtil(velocityEngine, context, stack, req, res));
ServletContext ctx = null;
try {
ctx = ServletActionContext.getServletContext();
} catch (NullPointerException npe) {
// in case this was used outside the lifecycle of struts servlet
LOG.debug("internal toolbox context ignored");
}
if (toolboxManager != null && ctx != null) {
ChainedContext chained = new ChainedContext(context, velocityEngine, req, res, ctx);
chained.setToolbox(toolboxManager.getToolbox(chained));
result = chained;
} else {
result = context;
}
req.setAttribute(KEY_VELOCITY_STRUTS_CONTEXT, result);
return result;
}
示例13: StrutsUtil
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
public StrutsUtil(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
this.stack = stack;
this.request = request;
this.response = response;
this.ognl = ((Container)stack.getContext().get(ActionContext.CONTAINER)).getInstance(OgnlTool.class);
this.urlHelper = ((Container)stack.getContext().get(ActionContext.CONTAINER)).getInstance(UrlHelper.class);
this.objectFactory = ((Container)stack.getContext().get(ActionContext.CONTAINER)).getInstance(ObjectFactory.class);
}
示例14: populateCookieValueIntoStack
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
/**
* Hook that populate cookie value into value stack (hence the action)
* if the criteria is satisfied (if the cookie value matches with those configured).
*
* @param cookieName cookie name
* @param cookieValue cookie value
* @param cookiesMap map of cookies
* @param stack value stack
*/
protected void populateCookieValueIntoStack(String cookieName, String cookieValue, Map<String, String> cookiesMap, ValueStack stack) {
if (cookiesValueSet.isEmpty() || cookiesValueSet.contains("*")) {
// If the interceptor is configured to accept any cookie value
// OR
// no cookiesValue is defined, so as long as the cookie name match
// we'll inject it into Struts' action
if (LOG.isDebugEnabled()) {
if (cookiesValueSet.isEmpty())
LOG.debug("no cookie value is configured, cookie with name [{}] with value [{}] will be injected", cookieName, cookieValue);
else if (cookiesValueSet.contains("*"))
LOG.debug("interceptor is configured to accept any value, cookie with name [{}] with value [{}] will be injected", cookieName, cookieValue);
}
cookiesMap.put(cookieName, cookieValue);
stack.setValue(cookieName, cookieValue);
}
else {
// if cookiesValues is specified, the cookie's value must match before we
// inject them into Struts' action
if (cookiesValueSet.contains(cookieValue)) {
LOG.debug("both configured cookie name and value matched, cookie [{}] with value [{}] will be injected", cookieName, cookieValue);
cookiesMap.put(cookieName, cookieValue);
stack.setValue(cookieName, cookieValue);
}
}
}
示例15: execute
import com.opensymphony.xwork2.util.ValueStack; //导入依赖的package包/类
/**
* @param invocation the DefaultActionInvocation calling the action call stack
*/
public void execute(ActionInvocation invocation) throws Exception {
// if the finalNamespace wasn't explicitly defined, assume the current one
if (this.namespace == null) {
this.namespace = invocation.getProxy().getNamespace();
}
ValueStack stack = ActionContext.getContext().getValueStack();
String finalNamespace = TextParseUtil.translateVariables(namespace, stack);
String finalActionName = TextParseUtil.translateVariables(actionName, stack);
String finalMethodName = this.methodName != null
? TextParseUtil.translateVariables(this.methodName, stack)
: null;
if (isInChainHistory(finalNamespace, finalActionName, finalMethodName)) {
addToHistory(finalNamespace, finalActionName, finalMethodName);
throw new XWorkException("Infinite recursion detected: " + ActionChainResult.getChainHistory().toString());
}
if (ActionChainResult.getChainHistory().isEmpty() && invocation != null && invocation.getProxy() != null) {
addToHistory(finalNamespace, invocation.getProxy().getActionName(), invocation.getProxy().getMethod());
}
addToHistory(finalNamespace, finalActionName, finalMethodName);
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.VALUE_STACK, ActionContext.getContext().getValueStack());
extraContext.put(ActionContext.PARAMETERS, ActionContext.getContext().getParameters());
extraContext.put(CHAIN_HISTORY, ActionChainResult.getChainHistory());
LOG.debug("Chaining to action {}", finalActionName);
proxy = actionProxyFactory.createActionProxy(finalNamespace, finalActionName, finalMethodName, extraContext);
proxy.execute();
}