List of usage examples for org.springframework.expression.spel.support StandardEvaluationContext StandardEvaluationContext
public StandardEvaluationContext(Object rootObject)
From source file:com.vedri.mtp.frontend.support.stomp.DefaultSubscriptionRegistry.java
private MultiValueMap<String, String> filterSubscriptions(MultiValueMap<String, String> allMatches, Message<?> message) {//from w ww. j a va2 s . c om if (!this.selectorHeaderInUse) { return allMatches; } EvaluationContext context = null; MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(allMatches.size()); for (String sessionId : allMatches.keySet()) { for (String subId : allMatches.get(sessionId)) { SessionSubscriptionInfo info = this.subscriptionRegistry.getSubscriptions(sessionId); if (info == null) { continue; } Subscription sub = info.getSubscription(subId); if (sub == null) { continue; } Expression expression = sub.getSelectorExpression(); if (expression == null) { result.add(sessionId, subId); continue; } if (context == null) { context = new StandardEvaluationContext(message); context.getPropertyAccessors().add(new SimpMessageHeaderPropertyAccessor()); } try { if (expression.getValue(context, boolean.class)) { result.add(sessionId, subId); } } catch (SpelEvaluationException ex) { if (logger.isDebugEnabled()) { logger.debug("Failed to evaluate selector: " + ex.getMessage()); } } catch (Throwable ex) { logger.debug("Failed to evaluate selector", ex); } } } return result; }
From source file:org.synyx.hera.si.PluginRegistryAwareMessageHandler.java
/** * Returns the actual arguments to be used for the plugin method invocation. Will apply the configured invocation * argument expression to the given {@link Message}. * /*from ww w .j a va 2 s . c o m*/ * @param message * @return */ private Object[] getInvocationArguments(Message<?> message) { if (invocationArgumentsExpression == null) { return new Object[] { message }; } StandardEvaluationContext context = new StandardEvaluationContext(message); Object result = delimiterExpression.getValue(context); return ObjectUtils.isArray(result) ? ObjectUtils.toObjectArray(result) : new Object[] { result }; }
From source file:es.logongas.ix3.security.model.ACE.java
/** * Evalua una expresin de un ACE//from ww w. j a va 2 s . c om * * @param ace El ACE a evaluar * @param identity El usuario que est haciando la peticin * @param secureResourceName El recurso * @param arguments Los argumentos de la peticin * @param mg Los MathcherGroups de la "secureResourceName" si el "secureResourceName" era una expresin regular. * @return El resultado de evaluarlo */ private boolean evaluateConditionalExpression(ACE ace, Identity identity, String secureResourceName, Object arguments, List<String> mg) { try { Object result; //Si no hay Script retornamos 'null' if ((ace.getConditionalExpression() == null) || (ace.getConditionalExpression().trim().length() == 0)) { throw new RuntimeException("No podemos evaluar una expresion vacia del ACE:" + ace.getIdACE()); } EvaluationContext context = new StandardEvaluationContext( new ConditionalExpressionSpelContext(ace, identity, secureResourceName, arguments, mg)); result = expressionParser.parseExpression(ace.getConditionalExpression()).getValue(context, Object.class); if (result == null) { throw new RuntimeException("La expresion no puede retornar null en el ACE:" + ace.getIdACE()); } if (!(result instanceof Boolean)) { throw new RuntimeException("La expresion no es un boolean en el ACE:" + ace.getIdACE()); } return (Boolean) result; } catch (Exception ex) { throw new RuntimeException("ACE:" + ace.toString(), ex); } }
From source file:gov.nih.nci.calims2.ui.generic.crud.CRUDTableDecorator.java
/** * Compute the datastore and the column lengths. *///from w w w .ja v a2 s .c om private void computeDataStore() { List<Column> columns = getDisplayableColumns(); lengths = new HashMap<String, ColumnLength>(); for (Column column : columns) { String header = messageSource.getMessage(config.getViewPrefix() + "list." + column.getName(), null, locale); ColumnLength length = new ColumnLength(header.length()); lengths.put(column.getName(), length); } Map<String, Expression> expressions = getColumnExpressions(columns); dataStore = new TreeMap<String, Object>(); dataStore.put("identifier", "id"); List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(); for (T row : rows) { EvaluationContext context = new StandardEvaluationContext(row); Map<String, Object> item = new TreeMap<String, Object>(); List<Boolean> flags = getItemCommandFlags(securityFlags, row); item.put("id", row.getId().toString() + convertItemCommandFlags(flags)); for (Column column : columns) { Expression expression = expressions.get(column.getName()); Object value = evaluateExpression(expression, context); String displayedValue = getValue(row, column, value); item.put(column.getName(), displayedValue); ColumnLength length = lengths.get(column.getName()); length.adjustLength(displayedValue); } items.add(item); } dataStore.put("items", items); }
From source file:gov.nih.nci.calims2.taglib.form.SingleSelectTag.java
@SuppressWarnings("unchecked") private List<Option> getOptionsFromEntities(Collection<?> entities) { List<Option> result = new ArrayList<Option>(); if (optionCreatorCallback != null) { OptionCreatorCallback<Object> callback = (OptionCreatorCallback<Object>) optionCreatorCallback; for (Object entity : entities) { result.add(new Option(callback.getId(entity), callback.getLabel(entity))); }// w w w . j a v a 2 s . co m } else { Expression idProperty = propertyMap.get("id"); if (idProperty == null) { throw new IllegalArgumentException("Missing id property"); } Expression labelProperty = propertyMap.get("label"); if (labelProperty == null) { throw new IllegalArgumentException("Missing label property"); } for (Object entity : entities) { EvaluationContext context = new StandardEvaluationContext(entity); result.add(new Option(SingleSelectHelper.evaluateExpression(idProperty, context), SingleSelectHelper.evaluateExpression(labelProperty, context))); } } return result; }
From source file:com.springinpractice.ch11.web.sitemap.Sitemap.java
public String resolve(String exprStr, Map<String, Object> context) { log.debug("Resolving expression: {}", exprStr); Expression expr = exprParser.parseExpression(exprStr); EvaluationContext evalContext = new StandardEvaluationContext(context); return (String) expr.getValue(evalContext); }
From source file:net.abhinavsarkar.spelhelper.SpelHelper.java
private EvaluationContext getEvaluationContext(final Object rootObject) { StandardEvaluationContext newContext = new StandardEvaluationContext(rootObject); newContext.getMethodResolvers().add(new ImplicitMethodResolver()); newContext.getPropertyAccessors().add(new ImplicitPropertyAccessor()); newContext.setConstructorResolvers(asList((ConstructorResolver) new ImplicitConstructorResolver())); for (Method method : registeredFunctions) { newContext.setVariable(method.getName(), method); }// ww w. jav a 2s . com newContext.setVariable(CONTEXT_LOOKUP_KEY, this); return newContext; }
From source file:org.apereo.portal.portlet.PortletSpELServiceImpl.java
/** * Return a SpEL evaluation context for the supplied portlet request. * * @param request PortletRequest//from w w w. j a va 2 s .c o m * @return SpEL evaluation context for the supplied portlet request */ protected EvaluationContext getEvaluationContext(PortletRequest request) { Map<String, String> userInfo = (Map<String, String>) request.getAttribute(PortletRequest.USER_INFO); final SpELEnvironmentRoot root = new SpELEnvironmentRoot(new PortletWebRequest(request), userInfo); final StandardEvaluationContext context = new StandardEvaluationContext(root); // Allows for @myBeanName replacements context.setBeanResolver(this.beanResolver); return context; }
From source file:org.apereo.portal.spring.spel.PortalSpELServiceImpl.java
@Override public String getValue(String expressionString, Object spelEnvironment) { final StandardEvaluationContext context = new StandardEvaluationContext(spelEnvironment); context.setBeanResolver(this.beanResolver); final Expression expression = this.parseCachedExpression(expressionString, TemplateParserContext.INSTANCE); return expression.getValue(context, String.class); }
From source file:org.apereo.portal.spring.spel.PortalSpELServiceImpl.java
/** * Return a SpEL evaluation context for the supplied web request. * //from ww w .j a va 2s . com * @param request * @return */ protected EvaluationContext getEvaluationContext(WebRequest request) { final HttpServletRequest httpRequest = this.portalRequestUtils.getOriginalPortalRequest(request); final IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpRequest); final IPerson person = userInstance.getPerson(); final SpELEnvironmentRoot root = new SpELEnvironmentRoot(request, person); final StandardEvaluationContext context = new StandardEvaluationContext(root); context.setBeanResolver(this.beanResolver); return context; }