List of usage examples for javax.el ExpressionFactory createValueExpression
public abstract ValueExpression createValueExpression(ELContext context, String expression, Class<?> expectedType);
From source file:inti.ws.spring.resource.template.TemplateResource.java
protected String applyTemplate(ExpressionFactory factory, String templateName, String templateFile) { ValueExpression var; Object val; SimpleContext templateContext = new SimpleContext(); ValueExpression templateContent;/* ww w . j ava2 s . c o m*/ templateContent = factory.createValueExpression(templateContext, template, String.class); var = factory.createValueExpression(templateContext, "${content}", String.class); var.setValue(templateContext, templateFile.replaceAll("\"", "\\\\\"")); for (Map.Entry<String, Object> parameter : parameters.entrySet()) { var = factory.createValueExpression(templateContext, "${" + parameter.getKey() + '}', String.class); val = parameter.getValue(); if ("$filename".equals(val)) { val = templateName; } else if ("$modulename".equals(val)) { val = moduleName; } var.setValue(templateContext, val); } return (String) templateContent.getValue(templateContext); }
From source file:com.googlecode.jsfFlex.taglib.AbstractFlexUIComponentTagBase.java
protected void setProperties(UIComponent component) { super.setProperties(component); FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); if (_value != null) { component.setValueExpression(VALUE_ATTR, _value); }/*from ww w .j a v a2s .c o m*/ if (_converter != null) { if (component instanceof ValueHolder) { ValueExpression ve = expressionFactory.createValueExpression(context.getELContext(), _converter, Object.class); if (ve != null) { component.setValueExpression(CONVERTER_ATTR, ve); } else { Converter converter = context.getApplication().createConverter(_converter); ((ValueHolder) component).setConverter(converter); } } else { _log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set value."); } } }
From source file:inti.ws.spring.resource.FilteredWebResource.java
@Override public void update() throws Exception { ExpressionFactory factory; ValueExpression var; Object val; StringBuilder builder = new StringBuilder(32); MessageDigest digest = DIGESTS.get(); for (WebResource dependency : dependencies) { dependency.updateIfNeeded();/* w w w . jav a 2s .c om*/ } super.update(); factory = ExpressionFactory.newInstance(); content = factory.createValueExpression(context, compressedFile, String.class); for (Map.Entry<String, Object> parameter : parameters.entrySet()) { var = factory.createValueExpression(context, "${" + parameter.getKey() + '}', String.class); val = parameter.getValue(); if (val instanceof WebResource) { ((WebResource) val).updateIfNeeded(); val = ((WebResource) val).getContent().hashCode(); } var.setValue(context, val); } compressedFile = (String) content.getValue(context); digest.reset(); builder.append(Hex.encodeHexString(digest.digest(compressedFile.getBytes(StandardCharsets.UTF_8)))); messageDigest = builder.toString(); builder.delete(0, builder.length()); DATE_FORMATTER.formatDate(lastModified, builder); lastModifiedString = builder.toString(); }
From source file:inti.ws.spring.resource.template.TemplateResource.java
@Override public void update() throws Exception { ExpressionFactory factory; ValueExpression var; Object val; StringBuilder builder = new StringBuilder(2048); MessageDigest digest = DIGESTS.get(); factory = ExpressionFactory.newInstance(); for (WebResource file : files) { if (file.hasChanged()) { file.update();// ww w.j a va2 s .com } builder.append(applyTemplate(factory, file.getName(), file.getContent().replaceAll("\\s+", " "))); builder.append(','); } builder.delete(builder.length() - 1, builder.length()); super.update(); content = factory.createValueExpression(context, compressedFile, String.class); var = factory.createValueExpression(context, "${files}", String.class); var.setValue(context, builder.toString()); if (parameters != null) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { var = factory.createValueExpression(context, "${" + parameter.getKey() + '}', String.class); val = parameter.getValue(); if ("$filename".equals(val)) { val = resource.getFile(); } else if ("$modulename".equals(val)) { val = moduleName; } var.setValue(context, val); } } compressedFile = (String) content.getValue(context); builder.delete(0, builder.length()); digest.reset(); builder.append(Hex.encodeHexString(digest.digest(compressedFile.getBytes(StandardCharsets.UTF_8)))); messageDigest = builder.toString(); builder.delete(0, builder.length()); DATE_FORMATTER.formatDate(lastModified, builder); lastModifiedString = builder.toString(); }
From source file:net.vpc.common.jsf.FacesUtils.java
public static Object evaluateEL(String p_expression) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, String.class); return vex.getValue(elContext); }
From source file:org.ajax4jsf.context.ViewResources.java
private static String getInitParameterValue(FacesContext context, String parameterName) { String key = INIT_PARAMETER_PREFIX + parameterName; ExternalContext externalContext = context.getExternalContext(); Map<String, Object> applicationMap = externalContext.getApplicationMap(); Object mutex = externalContext.getRequest(); Object parameterValue = null; synchronized (mutex) { parameterValue = applicationMap.get(key); if (parameterValue == null) { String initParameter = externalContext.getInitParameter(parameterName); if (initParameter != null) { if (ELUtils.isValueReference(initParameter)) { Application application = context.getApplication(); ExpressionFactory expressionFactory = application.getExpressionFactory(); parameterValue = expressionFactory.createValueExpression(context.getELContext(), initParameter, String.class); } else { parameterValue = initParameter; }//w w w .ja v a 2 s .co m } else { parameterValue = NULL; } applicationMap.put(key, parameterValue); } } return evaluate(context, parameterValue); }
From source file:org.apache.camel.language.juel.JuelExpression.java
public <T> T evaluate(Exchange exchange, Class<T> tClass) { // TODO we could use caching here but then we'd have possible concurrency issues // so lets assume that the provider caches // Create (if needed) the ExpressionFactory first from the CamelContext using FactoryFinder ExpressionFactory factory = getExpressionFactory(exchange.getContext()); ELContext context = populateContext(createContext(), exchange); ValueExpression valueExpression = factory.createValueExpression(context, expression, type); Object value = valueExpression.getValue(context); return exchange.getContext().getTypeConverter().convertTo(tClass, value); }
From source file:org.apache.myfaces.application.ApplicationImpl.java
@SuppressWarnings("unchecked") @Override//from ww w. j a v a 2s .co m public final <T> T evaluateExpressionGet(final FacesContext context, final String expression, final Class<? extends T> expectedType) throws ELException { ELContext elContext = context.getELContext(); ExpressionFactory factory = getExpressionFactory(); return (T) factory.createValueExpression(elContext, expression, expectedType).getValue(elContext); }
From source file:org.apache.myfaces.config.ManagedBeanBuilder.java
private void initializeMap(FacesContext facesContext, MapEntries mapEntries, Map<? super Object, ? super Object> map) { Application application = facesContext.getApplication(); Class<?> keyClass = (mapEntries.getKeyClass() == null) ? String.class : ClassUtils.simpleJavaTypeToClass(mapEntries.getKeyClass()); Class<?> valueClass = (mapEntries.getValueClass() == null) ? String.class : ClassUtils.simpleJavaTypeToClass(mapEntries.getValueClass()); ValueExpression valueExpression;//from ww w. ja va2s . c om ExpressionFactory expFactory = application.getExpressionFactory(); ELContext elContext = facesContext.getELContext(); for (Iterator<? extends MapEntry> iterator = mapEntries.getMapEntries(); iterator.hasNext();) { MapEntry entry = iterator.next(); Object key = entry.getKey(); if (ContainerUtils.isValueReference((String) key)) { valueExpression = expFactory.createValueExpression(elContext, (String) key, Object.class); key = valueExpression.getValue(elContext); } if (entry.isNullValue()) { map.put(coerceToType(facesContext, key, keyClass), null); } else { Object value = entry.getValue(); if (ContainerUtils.isValueReference((String) value)) { valueExpression = expFactory.createValueExpression(elContext, (String) value, Object.class); value = valueExpression.getValue(elContext); } map.put(coerceToType(facesContext, key, keyClass), coerceToType(facesContext, value, valueClass)); } } }
From source file:org.apache.myfaces.config.ManagedBeanBuilder.java
private void initializeList(FacesContext facesContext, ListEntries listEntries, List<? super Object> list) { Application application = facesContext.getApplication(); Class<?> valueClass = (listEntries.getValueClass() == null) ? String.class : ClassUtils.simpleJavaTypeToClass(listEntries.getValueClass()); ExpressionFactory expFactory = application.getExpressionFactory(); ELContext elContext = facesContext.getELContext(); for (Iterator<? extends ListEntry> iterator = listEntries.getListEntries(); iterator.hasNext();) { ListEntry entry = iterator.next(); if (entry.isNullValue()) { list.add(null);/*from w w w . j av a 2 s. co m*/ } else { Object value = entry.getValue(); if (ContainerUtils.isValueReference((String) value)) { ValueExpression valueExpression = expFactory.createValueExpression(elContext, (String) value, Object.class); value = valueExpression.getValue(elContext); } list.add(coerceToType(facesContext, value, valueClass)); } } }