com.opensymphony.xwork2.util.ValueStack类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(14.6k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中com.opensymphony.xwork2.util.ValueStack类的一些代码示例,展示了ValueStack类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ValueStack类的具体详情如下:
包路径:com.opensymphony.xwork2.util.ValueStack
类名称:ValueStack

ValueStack介绍

[英]ValueStack allows multiple beans to be pushed in and dynamic EL expressions to be evaluated against it. When evaluating an expression, the stack will be searched down the stack, from the latest objects pushed in to the earliest, looking for a bean with a getter or setter for the given property or a method of the given name (depending on the expression being evaluated).
[中]ValueStack允许推入多个bean,并根据它计算动态EL表达式。在计算表达式时,堆栈将沿着堆栈向下搜索,从推入的最新对象到最早的对象,查找具有给定属性或给定名称的方法(取决于正在计算的表达式)的getter或setter的bean。

代码示例

代码示例来源:origin: org.apache.struts/struts2-jasperreports-plugin

/**
   * Is there any more data
   *
   * @return <code>true</code> if there are more elements to iterate over and
   *         <code>false</code> otherwise
   * @throws JRException if there is a problem determining whether there
   *                     is more data
   */
  public boolean next() throws JRException {
    if (firstTimeThrough) {
      firstTimeThrough = false;
    } else {
      valueStack.pop();
    }

    if ((iterator != null) && (iterator.hasNext())) {
      valueStack.push(iterator.next());
      if (LOG.isDebugEnabled()) {
        LOG.debug("Pushed next value: {}", valueStack.findValue("."));
      }

      return true;
    } else {
      LOG.debug("No more values");

      return false;
    }
  }
}

代码示例来源:origin: org.apache.struts.xwork/xwork-core

public void testNullIsReturnedWhenCreateNullObjectsIsSpecifiedAsFalse() {
  ValueStack vs = ActionContext.getContext().getValueStack();
  vs.push(new MapHolder(Collections.emptyMap()));
  ReflectionContextState.setCreatingNullObjects(vs.getContext(), false);
  assertNull(vs.findValue("map['key']"));
}

代码示例来源:origin: org.apache.struts.xwork/xwork-core

/**
 * 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;
}

代码示例来源:origin: org.beangle.struts2/beangle-struts2-view

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();
 }
}

代码示例来源:origin: org.apache.struts/struts2-json-plugin

protected Object findRootObject(ActionInvocation invocation) {
  Object rootObject;
  if (this.root != null) {
    ValueStack stack = invocation.getStack();
    rootObject = stack.findValue(root);
  } else {
    rootObject = invocation.getStack().peek(); // model overrides action
  }
  return rootObject;
}

代码示例来源:origin: org.apache.struts/struts2-jasperreports-plugin

LOG.debug("Creating JasperReport for dataSource = {}, format = {}", dataSource, format);
HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(ServletActionContext.HTTP_RESPONSE);
ValueStack stack = invocation.getStack();
ValueStackDataSource stackDataSource = null;
Connection conn = (Connection) stack.findValue(connection);
if (conn == null)
  stackDataSource = new ValueStackDataSource(stack, dataSource, wrapField);
ServletContext servletContext = (ServletContext) invocation.getInvocationContext().get(ServletActionContext.SERVLET_CONTEXT);
String systemId = servletContext.getRealPath(finalLocation);
Map parameters = new ValueStackShadowMap(stack);
Map reportParams = (Map) stack.findValue(reportParameters);
if (reportParams != null) {
  LOG.debug("Found report parameters; adding to parameters...");
  parameters.putAll(reportParams);
  Map exportParams = (Map) stack.findValue(exportParameters);
  if (exportParams != null) {
    LOG.debug("Found export parameters; adding to exporter parameters...");

代码示例来源:origin: org.apache.struts/struts2-tiles-plugin

@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);
  }
}

代码示例来源:origin: org.apache.struts/struts2-json-plugin

final ValueStack stack = invocation.getStack();
if (this.root != null) {
  rootObject = stack.findValue(this.root);
      mapKey = this.root.substring(this.root.lastIndexOf('.') + 1);
      rootObject = stack.findValue(this.root.substring(0, this.root.lastIndexOf('.')));
      if (rootObject == null) {
        throw new RuntimeException("JSON array: Invalid root expression: '" + this.root + "'.");
      rootObject = invocation.getStack().peek();
    LOG.error("Unable to deserialize JSON object from request");
    throw new JSONException("Unable to deserialize JSON object from request");
        rootObject = invocation.getAction();
  LOG.debug("Accept header parameter must be '{}' or '{}'. Ignoring request with Content Type '{}'", jsonContentType, jsonRpcContentType, requestContentType);

代码示例来源:origin: org.apache.struts/struts2-jasperreports-plugin

/**
 * Create a value stack data source on the given iterable property
 *
 * @param valueStack      The value stack to base the data source on
 * @param dataSourceParam The property to iterate over for the report
 */
public ValueStackDataSource(ValueStack valueStack, String dataSourceParam, boolean wrapField) {
  this.valueStack = valueStack;
  this.dataSource = dataSourceParam;
  this.wrapField = wrapField;
  Object dataSourceValue = valueStack.findValue(dataSource);
  if (dataSourceValue != null) {
    if (MakeIterator.isIterable(dataSourceValue)) {
      iterator = MakeIterator.convert(dataSourceValue);
    } else {
      Object[] array = new Object[1];
      array[0] = dataSourceValue;
      iterator = MakeIterator.convert(array);
    }
  } else {
    if (LOG.isWarnEnabled()) {
      LOG.warn("Data source value for data source " + dataSource + " was null");
    }
  }
}

代码示例来源:origin: org.apache.struts/struts2-jasperreports-plugin

/**
 * Move to the first item.
 *
 * @throws JRException if there is a problem with moving to the first
 *                     data element
 */
public void moveFirst() throws JRException {
  Object dataSourceValue = valueStack.findValue(dataSource);
  if (dataSourceValue != null) {
    if (MakeIterator.isIterable(dataSourceValue)) {
      iterator = MakeIterator.convert(dataSourceValue);
    } else {
      Object[] array = new Object[1];
      array[0] = dataSourceValue;
      iterator = MakeIterator.convert(array);
    }
  } else {
    LOG.warn("Data source value for data source [{}] was null", dataSource);
  }
}

代码示例来源:origin: org.apache.struts/struts2-jasperreports-plugin

/**
 * Get the value of a given field
 *
 * @param field The field to get the value for. The expression language to get the value
 *              of the field is either taken from the description property or from the name of the field
 *              if the description is <code>null</code>.
 * @return an <code>Object</code> containing the field value or a new
 *         <code>ValueStackDataSource</code> object if the field value evaluates to
 *         an object that can be iterated over.
 * @throws JRException if there is a problem obtaining the value
 */
public Object getFieldValue(JRField field) throws JRException {
  //TODO: move the code to return a ValueStackDataSource to a seperate
  //      method when and if the JRDataSource interface is updated to support
  //      this.
  String expression = field.getName();
  Object value = valueStack.findValue(expression);
  LOG.debug("Field [{}] = [{}]", field.getName(), value);
  if (!wrapField && MakeIterator.isIterable(value) && field.getValueClass().isInstance(value)) {
    return value;
  } else if (MakeIterator.isIterable(value)) {
    // wrap value with ValueStackDataSource if not already wrapped
    return new ValueStackDataSource(this.valueStack, expression, wrapField);
  } else {
    return value;
  }
}

代码示例来源:origin: org.apache.struts.xwork/xwork-core

@Override public String intercept(ActionInvocation invocation) throws Exception {
    ValueStack stack = ac.getValueStack();
    Object obj = stack.findValue(aliasExpression);
        Map<String, Object> context = newStack.getContext();
        ReflectionContextState.setCreatingNullObjects(context, true);
        ReflectionContextState.setDenyMethodExecution(context, true);
        context.put(ActionContext.LOCALE, stack.getContext().get(ActionContext.LOCALE));
        String name = entry.getKey().toString();
        String alias = (String) entry.getValue();
        Object value = stack.findValue(name);
        if (null == value) {
          Map<String, Object> contextParameters = ActionContext.getContext().getParameters();
            newStack.setValue(alias, value);
          } catch (RuntimeException e) {
            if (devMode) {
      if (clearableStack && (stack.getContext() != null) && (newStack.getContext() != null))
        stack.getContext().put(ActionContext.CONVERSION_ERRORS, newStack.getContext().get(ActionContext.CONVERSION_ERRORS));
    } else {
      if (LOG.isDebugEnabled()) {

代码示例来源:origin: org.apache.struts.xwork/xwork-core

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;
}

代码示例来源:origin: org.apache.struts.xwork/xwork-core

@Override
public String intercept(ActionInvocation invocation) throws Exception {
  ActionConfig config = invocation.getProxy().getConfig();
  Object action = invocation.getAction();
    ActionContext ac = ActionContext.getContext();
    Map<String, Object> contextMap = ac.getContextMap();
    try {
      ReflectionContextState.setCreatingNullObjects(contextMap, true);
      ReflectionContextState.setReportingConversionErrors(contextMap, true);
      final ValueStack stack = ac.getValueStack();
        Map<String, Object> context = newStack.getContext();
        ReflectionContextState.setCreatingNullObjects(context, true);
        ReflectionContextState.setDenyMethodExecution(context, true);
        context.put(ActionContext.LOCALE, stack.getContext().get(ActionContext.LOCALE));
          newStack.setValue(entry.getKey(), val);
        } catch (RuntimeException e) {
          if (devMode) {
       if (clearableStack && (stack.getContext() != null) && (newStack.getContext() != null))
        stack.getContext().put(ActionContext.CONVERSION_ERRORS, newStack.getContext().get(ActionContext.CONVERSION_ERRORS));
  return invocation.invoke();

代码示例来源:origin: org.apache.struts.xwork/xwork-core

ActionContext context = ActionContext.getContext();
ActionInvocation actionInvocation = context.getActionInvocation();
  Object action = actionInvocation.getAction();
  if (action instanceof ModelDriven) {
    Object model = ((ModelDriven) action).getModel();
  Object obj = valueStack.findValue(prop);
  try {
    Object actionObj = ReflectionProviderFactory.getInstance().getRealTarget(prop, valueStack.getContext(), valueStack.getRoot());
    if (actionObj != null) {
      PropertyDescriptor propertyDescriptor = ReflectionProviderFactory.getInstance().getPropertyDescriptor(actionObj.getClass(), prop);
            valueStack.push(obj);
          msg = findText(clazz, newKey, locale, null, args);
          if (obj != null)
            valueStack.pop();

代码示例来源:origin: org.apache.struts/struts2-jsf-plugin

/**
 * <p>
 * Will return a reference to the current action if the action name matches
 * the requested variable name. Otherwise it will attempt to resolve the
 * name from the value stack. Otherwise it will delegate to the original jsf
 * resolver.
 * </p>
 *
 * @param name
 *            Variable name to be resolved
 */
public Object resolveVariable(FacesContext context, String name)
    throws EvaluationException {
  if (STRUTS_VARIABLE_NAME.equals(name)) {
    return ActionContext.getContext().getActionInvocation().getAction();
  }
  Object obj = ActionContext.getContext().getValueStack().findValue(name);
  if (obj != null) {
    return obj;
  } else {
    return original.resolveVariable(context, name);
  }
}

代码示例来源:origin: org.apache.struts.xwork/xwork-core

@Override
public String intercept(ActionInvocation invocation) throws Exception {
  ActionContext invocationContext = invocation.getInvocationContext();
  Map<String, Object> conversionErrors = invocationContext.getConversionErrors();
  ValueStack stack = invocationContext.getValueStack();
      String message = XWorkConverter.getConversionErrorMessage(propertyName, stack);
      Object action = invocation.getAction();
      if (action instanceof ValidationAware) {
        ValidationAware va = (ValidationAware) action;
    stack.getContext().put(ORIGINAL_PROPERTY_OVERRIDE, fakie);
    invocation.addPreResultListener(new PreResultListener() {
      public void beforeResult(ActionInvocation invocation, String resultCode) {
        Map<Object, Object> fakie = (Map<Object, Object>) invocation.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE);

代码示例来源:origin: org.entando.entando/entando-core-engine

@Override
public String intercept(ActionInvocation invocation) throws Exception {
  ValueStack stack = invocation.getStack();
  CompoundRoot root = stack.getRoot();
  if (root.size() >= this.compoundRootMinSize && isChainResult(invocation)) {
    List<CompoundRoot> list = new ArrayList<CompoundRoot>(root);
    list.remove(0);
    Collections.reverse(list);
    Map<String, Object> ctxMap = invocation.getInvocationContext().getContextMap();
    Iterator<CompoundRoot> iterator = list.iterator();
    int index = 1; // starts with 1, 0 has been removed
    while (iterator.hasNext()) {
      index = index + 1;
      Object o = iterator.next();
      if (o != null) {
        if (!(o instanceof Unchainable)) {
          reflectionProvider.copy(o, invocation.getAction(), ctxMap, excludes, includes);
        }
      } else {
        LOG.warn("compound root element at index " + index + " is null");
      }
    }
  }
  return invocation.invoke();
}

代码示例来源:origin: org.nuiton/nuiton-validator

ActionContext context = ActionContext.getContext();
  context = new ActionContext(vs.getContext());
  ActionContext.setContext(context);
  extraContext.put(ActionContext.VALUE_STACK, vs);
  DefaultActionInvocation invocation = new DefaultActionInvocation(extraContext, false);
  invocation.setObjectFactory(container.getInstance(ObjectFactory.class));
  invocation.setContainer(container);
    container.getInstance(ActionValidatorManager.class, "no-annotations");

代码示例来源:origin: org.apache.struts.xwork/xwork-core

@Override
public String intercept(ActionInvocation invocation) throws Exception {
  if (LOG.isDebugEnabled()) {
    LOG.debug("intercept '#0/#1' {",
      invocation.getProxy().getNamespace(), invocation.getProxy().getActionName());
  }
  LocaleFinder localeFinder = new LocaleFinder(invocation);
  Locale locale = getLocaleFromParam(localeFinder.getRequestedLocale());
  locale = storeLocale(invocation, locale, localeFinder.getStorage());
  saveLocale(invocation, locale);
  if (LOG.isDebugEnabled()) {
    LOG.debug("before Locale=#0", invocation.getStack().findValue("locale"));
  }
  final String result = invocation.invoke();
  if (LOG.isDebugEnabled()) {
    LOG.debug("after Locale=#0", invocation.getStack().findValue("locale"));
    LOG.debug("intercept } ");
  }
  return result;
}

相关文章