Example usage for javax.el ELContext setPropertyResolved

List of usage examples for javax.el ELContext setPropertyResolved

Introduction

In this page you can find the example usage for javax.el ELContext setPropertyResolved.

Prototype

public void setPropertyResolved(boolean resolved) 

Source Link

Usage

From source file:com.github.htfv.maven.plugins.buildconfigurator.core.el.BuildConfiguratorELResolver.java

/**
 * Resolves value of a property./*from   w w  w  . j  ava 2s.  co m*/
 *
 * @param context
 *            {@link ELContext} used to resolve EL expressions.
 * @param property
 *            name of the property to resolve.
 *
 * @return resolved value of the property.
 */
public Object resolve(final ELContext context, final String property) {
    if (valueCache.containsKey(property)) {
        context.setPropertyResolved(true);
        return valueCache.get(property);
    }

    final Properties userProperties = mavenProject.getProjectBuildingRequest().getUserProperties();

    if (userProperties.containsKey(property)) {
        final String value = userProperties.getProperty(property);

        context.setPropertyResolved(true);

        valueCache.put(property, value);
        return value;
    }

    final Properties projectProperties = mavenProject.getProperties();

    if (projectProperties.containsKey(property)) {
        final String value = projectProperties.getProperty(property);

        context.setPropertyResolved(true);

        valueCache.put(property, value);
        return value;
    }

    if (configuration.containsKey(property)) {
        final Object value = ELUtils.getValue(context, configuration.getString(property), Object.class);

        context.setPropertyResolved(true);

        valueCache.put(property, value);
        return value;
    }

    return null;
}

From source file:com.foreveross.modules.jsf.SpringBeanELResolver.java

@Override
public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        BeanFactory bf = getBeanFactory(elContext);
        if (bf.containsBean(beanName)) {
            elContext.setPropertyResolved(true);
            return bf.getType(beanName);
        }//from w w  w  .  j a v a2  s.  c  o m
    }
    return null;
}

From source file:com.github.htfv.maven.plugins.buildconfigurator.core.el.BuildConfiguratorELResolver.java

@Override
public Object getValue(final ELContext context, final Object base, final Object property) {
    if (base == null) {
        final String key = property.toString();

        if ("env".equals(key)) {
            context.setPropertyResolved(true);
            return System.getenv();
        }//from  w ww .  j  a v a 2s . c o m

        if ("project".equals(key)) {
            context.setPropertyResolved(true);
            return mavenProject;
        }

        if ("prop".equals(key)) {
            context.setPropertyResolved(true);
            return new PropertyAccessor(this, context);
        }

        return resolve(context, key);
    }

    return null;
}

From source file:com.asual.summer.core.faces.FacesELResolver.java

public Object getValue(ELContext elContext, Object base, Object property) throws ELException {

    Object value = super.getValue(elContext, base, property);

    if (value == null) {
        if (property instanceof String) {
            final String current = (String) property;
            if (base == null && MESSAGES.equals(current)) {
                elContext.setPropertyResolved(true);
                RequestUtils.setAttribute(MESSAGE_ATTRIBUTE, null);
                RequestUtils.setAttribute(PROPERTY_ATTRIBUTE, null);
                return current;
            } else if (base == null && PROPERTIES.equals(current)) {
                elContext.setPropertyResolved(true);
                RequestUtils.setAttribute(MESSAGE_ATTRIBUTE, null);
                RequestUtils.setAttribute(PROPERTY_ATTRIBUTE, null);
                return current;
            } else if (MESSAGES.equals(base)) {
                elContext.setPropertyResolved(true);
                RequestUtils.setAttribute(MESSAGE_ATTRIBUTE, current);
                String result = ResourceUtils.getMessage(current);
                return result != null ? result : "";
            } else if (PROPERTIES.equals(base)) {
                elContext.setPropertyResolved(true);
                RequestUtils.setAttribute(PROPERTY_ATTRIBUTE, current);
                Object result = ResourceUtils.getProperty(current);
                return result != null ? result : "";
            } else if (base instanceof String && RequestUtils.getAttribute(MESSAGE_ATTRIBUTE) != null) {
                elContext.setPropertyResolved(true);
                RequestUtils.setAttribute(MESSAGE_ATTRIBUTE,
                        RequestUtils.getAttribute(MESSAGE_ATTRIBUTE) + "." + current);
                Object result = ResourceUtils.getMessage((String) RequestUtils.getAttribute(MESSAGE_ATTRIBUTE));
                return result != null ? result : "";
            } else if (base instanceof String && RequestUtils.getAttribute(PROPERTY_ATTRIBUTE) != null) {
                elContext.setPropertyResolved(true);
                RequestUtils.setAttribute(PROPERTY_ATTRIBUTE,
                        RequestUtils.getAttribute(PROPERTY_ATTRIBUTE) + "." + current);
                Object result = ResourceUtils
                        .getProperty((String) RequestUtils.getAttribute(PROPERTY_ATTRIBUTE));
                return result != null ? result : "";
            }/* w ww.j  a v a 2  s  . com*/
        }
    }

    return value;
}

From source file:com.foreveross.modules.jsf.SpringBeanELResolver.java

@Override
public void setValue(ELContext elContext, Object base, Object property, Object value) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        BeanFactory bf = getBeanFactory(elContext);
        if (bf.containsBean(beanName)) {
            if (value == bf.getBean(beanName)) {
                // Setting the bean reference to the same value is alright - can simply be ignored...
                elContext.setPropertyResolved(true);
            } else {
                throw new PropertyNotWritableException("Variable '" + beanName
                        + "' refers to a Spring bean which by definition is not writable");
            }/*from w  w w  .  j a va2s  . co m*/
        }
    }
}

From source file:com.foreveross.modules.jsf.SpringBeanELResolver.java

@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        BeanFactory bf = getBeanFactory(elContext);
        if (bf.containsBean(beanName)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Successfully resolved variable '" + beanName + "' in Spring BeanFactory");
            }/*w  ww .  j  av a2  s . co  m*/
            elContext.setPropertyResolved(true);
            Object bean = bf.getBean(beanName);
            String className = bean.getClass().getName();
            if (className.startsWith("$Proxy")) {//Spring aop proxy for groovy bean
                try {
                    Object o = com.foreveross.infra.util.mybatis.plugin.ReflectHelper.getValueByFieldName(bean,
                            "h");
                    o = com.foreveross.infra.util.mybatis.plugin.ReflectHelper.getValueByFieldName(o,
                            "advised");
                    o = com.foreveross.infra.util.mybatis.plugin.ReflectHelper.getValueByFieldName(o,
                            "targetSource");
                    org.springframework.aop.TargetSource ts = (org.springframework.aop.TargetSource) o;
                    bean = ts.getTarget();
                } catch (Exception e) {
                    Exceptions.runtime(FormatableCharSequence.get("get [{0}.{1}.{2}.{3}] Error!", className,
                            "h", "advised", "targetSource"), e);
                }
            }
            return bean;
        }
    }
    return null;
}

From source file:org.apache.tiles.evaluator.el.TilesContextELResolver.java

/** {@inheritDoc} */
@Override// www  .  ja  v  a  2 s .com
public Class<?> getType(ELContext context, Object base, Object property) {
    // only resolve at the root of the context
    if (base != null) {
        return null;
    }

    Class<?> retValue = null;
    if (requestProperties.contains(property)) {
        TilesRequestContext request = (TilesRequestContext) context.getContext(TilesRequestContext.class);
        retValue = super.getType(context, request, property);
    } else if (applicationProperties.contains(property)) {
        TilesApplicationContext applicationContext = (TilesApplicationContext) context
                .getContext(TilesApplicationContext.class);
        retValue = super.getType(context, applicationContext, property);
    }

    if (retValue != null) {
        context.setPropertyResolved(true);
    }

    return retValue;
}

From source file:org.apache.tiles.evaluator.el.TilesContextELResolver.java

/** {@inheritDoc} */
@Override/*from  ww w . java2s  .  co  m*/
public Object getValue(ELContext context, Object base, Object property) {
    // only resolve at the root of the context
    if (base != null) {
        return null;
    }

    Object retValue = null;

    if (requestProperties.contains(property)) {
        TilesRequestContext request = (TilesRequestContext) context.getContext(TilesRequestContext.class);
        retValue = super.getValue(context, request, property);
    } else if (applicationProperties.contains(property)) {
        TilesApplicationContext applicationContext = (TilesApplicationContext) context
                .getContext(TilesApplicationContext.class);
        retValue = super.getValue(context, applicationContext, property);
    }

    if (retValue != null) {
        context.setPropertyResolved(true);
    }

    return retValue;
}

From source file:org.betaconceptframework.astroboa.portal.el.AstroboaELResolver.java

@Override
public Object getValue(ELContext context, Object base, Object property) {

    if (base == null || property == null) {
        return super.getValue(context, base, property);
    }//from   w  ww .  j  a  va2  s .c  om

    try {

        if (base instanceof ContentObject) {
            if (keywordIsNotDefinedAsAProperty("systemName", property,
                    ((ContentObject) base).getComplexCmsRootProperty())) {
                context.setPropertyResolved(true);
                return ((ContentObject) base).getSystemName();
            } else if (keywordIsNotDefinedAsAProperty("contentObjectType", property,
                    ((ContentObject) base).getComplexCmsRootProperty())) {
                context.setPropertyResolved(true);
                return ((ContentObject) base).getContentObjectType();
            } else if (keywordIsNotDefinedAsAProperty("owner", property,
                    ((ContentObject) base).getComplexCmsRootProperty())) {
                context.setPropertyResolved(true);
                return ((ContentObject) base).getOwner();
            } else if (keywordIsNotDefinedAsAProperty("complexCmsRootProperty", property,
                    ((ContentObject) base).getComplexCmsRootProperty())) {
                context.setPropertyResolved(true);
                return ((ContentObject) base).getComplexCmsRootProperty();
            } else if (keywordIsNotDefinedAsAProperty("typeDefinition", property,
                    ((ContentObject) base).getComplexCmsRootProperty())) {
                context.setPropertyResolved(true);
                return ((ContentObject) base).getTypeDefinition();
            }

            return resolveInComplexCmsProperty(context, ((ContentObject) base).getComplexCmsRootProperty(),
                    property);
        } else if (base instanceof ComplexCmsProperty) {
            return resolveInComplexCmsProperty(context, (ComplexCmsProperty) base, property);
        } else {
            return super.getValue(context, base, property);
        }
    } catch (Exception e) {
        logger.warn("Unable to evaluate property " + property + " from base " + base, e);
        return super.getValue(context, base, property);
    }
}

From source file:org.betaconceptframework.astroboa.portal.el.AstroboaELResolver.java

private Object resolveInComplexCmsProperty(ELContext context, ComplexCmsProperty complexCmsProperty,
        Object property) {//from   www  .  j a v a2s  .co m

    String propertyPath = (String) property;

    //Keywords
    if (keywordIsNotDefinedAsAProperty("id", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getId();
    } else if (keywordIsNotDefinedAsAProperty("fullPath", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getFullPath();
    } else if (keywordIsNotDefinedAsAProperty("name", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getName();
    } else if (keywordIsNotDefinedAsAProperty("path", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getPath();
    } else if (keywordIsNotDefinedAsAProperty("parentProperty", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getParentProperty();
    } else if (keywordIsNotDefinedAsAProperty("propertyDefinition", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getPropertyDefinition();
    } else if (keywordIsNotDefinedAsAProperty("valueType", property, complexCmsProperty)) {
        context.setPropertyResolved(true);
        return complexCmsProperty.getValueType();
    }

    Object cmsProperty = null;
    try {
        //First assume property is a simple property or a single value complex one
        cmsProperty = complexCmsProperty.getChildProperty(propertyPath);
    } catch (Exception e) {
        //Ignore exception
    }

    if (cmsProperty == null) {
        try {
            //Now assume property is a multivalue complex one
            cmsProperty = complexCmsProperty.getChildPropertyList(propertyPath);
        } catch (Exception e) {
            //Ignore exception
        }
    }

    if (cmsProperty != null) {
        //Property exists. 
        if (cmsProperty instanceof CmsProperty) {

            //Retrieve property definition to decide what it should be returned
            CmsPropertyDefinition childDefinition = ((CmsProperty) cmsProperty).getPropertyDefinition();

            if (ValueType.Complex != childDefinition.getValueType()) {

                //Property is a simple property and therefore its values will be returned
                if (childDefinition.isMultiple()) {
                    context.setPropertyResolved(true);
                    return ((SimpleCmsProperty) cmsProperty).getSimpleTypeValues();
                } else {
                    context.setPropertyResolved(true);
                    return ((SimpleCmsProperty) cmsProperty).getSimpleTypeValue();
                }
            } else {

                //Very special case. Property refers to a multi value child property
                if (childDefinition.isMultiple()) {
                    //User requested a multi value complex property.
                    //We should return the list of values rather than the first value
                    cmsProperty = complexCmsProperty.getChildPropertyList(propertyPath);
                }

                //Property is a complex one, therefore the property will be returned
                context.setPropertyResolved(true);
                return cmsProperty;
            }
        } else {
            //Return property as is (Probably is a list of properties)
            context.setPropertyResolved(true);
            return cmsProperty;
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Could not resolve expression. Could not find definition for property {} in complex property {}. Resolution is continued by Seam EL resolver",
                    new Object[] { propertyPath, complexCmsProperty.getFullPath() });
        }

        //Child property is not defined. Continue with Seam EL resolver
        return super.getValue(context, complexCmsProperty, property);
    }
}