/** * 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; } } }
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; }
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...");
@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); } }
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);
/** * 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"); } } }
/** * 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); } }
/** * 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; } }
@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()) {
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; }
@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();
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();
/** * <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); } }
@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);
@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(); }
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");
@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; }