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:org.jahia.services.content.JCRNodePropertiesELResolver.java

public Object getValue(ELContext elContext, Object base, Object property) {
    if (elContext == null) {
        throw new NullPointerException();
    }/*from  w w w .j av a  2 s.c o m*/
    if (base != null && base instanceof JCRNodeWrapper) {
        JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) base;
        try {
            try {
                nodeWrapper.getClass().getMethod("get" + StringUtils.capitalize(property.toString()));
            } catch (NoSuchMethodException e) {
                final JCRPropertyWrapper jcrPropertyWrapper = nodeWrapper
                        .getProperty(property.toString().replace("_", ":"));
                if (jcrPropertyWrapper != null) {
                    elContext.setPropertyResolved(true);
                    return jcrPropertyWrapper;
                }
            }
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.jahia.services.content.JCRNodePropertiesELResolver.java

public Class<?> getType(ELContext elContext, Object base, Object property) {
    if (elContext == null) {
        throw new NullPointerException();
    }//from w ww . java  2s.c  o  m
    if (base != null && base instanceof JCRNodeWrapper) {
        JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) base;
        try {
            try {
                nodeWrapper.getClass().getMethod("get" + StringUtils.capitalize(property.toString()));
            } catch (NoSuchMethodException e) {
                if (nodeWrapper.getProperty(property.toString().replace("_", ":")) != null) {
                    elContext.setPropertyResolved(true);
                    return JCRPropertyWrapper.class;
                }
            }
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.nuxeo.ecm.platform.el.DocumentModelResolver.java

@Override
public Class<?> getType(ELContext context, Object base, Object property) {
    Class<?> type = null;/*  w ww  . j  a v a 2s.c om*/
    if (base instanceof DocumentModel) {
        try {
            type = super.getType(context, base, property);
        } catch (PropertyNotFoundException e) {
            type = DocumentPropertyContext.class;
            context.setPropertyResolved(true);
        }
    } else if (base instanceof DocumentPropertyContext || base instanceof Property) {
        type = Object.class;
        if (base instanceof DocumentPropertyContext) {
            DocumentPropertyContext ctx = (DocumentPropertyContext) base;
            try {
                Property docProperty = getDocumentProperty(ctx, property);
                if (docProperty.isContainer()) {
                    Property subProperty = getDocumentProperty(docProperty, property);
                    if (subProperty.isList()) {
                        type = List.class;
                    }
                } else if (docProperty instanceof ArrayProperty) {
                    type = List.class;
                }
            } catch (PropertyException pe) {
                // avoid errors, return Object
                log.warn(pe.toString());
            }
        } else if (base instanceof Property) {
            try {
                Property docProperty = (Property) base;
                Property subProperty = getDocumentProperty(docProperty, property);
                if (subProperty.isList()) {
                    type = List.class;
                }
            } catch (PropertyException pe) {
                try {
                    // try property getters to resolve
                    // doc.schema.field.type for instance
                    type = super.getType(context, base, property);
                } catch (PropertyNotFoundException e) {
                    // avoid errors, log original error and return Object
                    log.warn(pe.toString());
                }
            }
        }
        context.setPropertyResolved(true);
    }
    return type;
}

From source file:org.nuxeo.ecm.platform.el.DocumentModelResolver.java

@Override
public Object getValue(ELContext context, Object base, Object property) {
    Object value = null;/*from   w  ww . ja va2  s. c o  m*/
    if (base instanceof DocumentModel) {
        try {
            // try document getters first to resolve doc.id for instance
            value = super.getValue(context, base, property);
        } catch (PropertyNotFoundException e) {
            value = new DocumentPropertyContext((DocumentModel) base, (String) property);
            context.setPropertyResolved(true);
        }
    } else if (base instanceof DocumentPropertyContext) {
        try {
            DocumentPropertyContext ctx = (DocumentPropertyContext) base;
            Property docProperty = getDocumentProperty(ctx, property);
            value = getDocumentPropertyValue(docProperty);
        } catch (PropertyException pe) {
            // avoid errors, return null
            log.warn(pe.toString());
        }
        context.setPropertyResolved(true);
    } else if (base instanceof Property) {
        try {
            Property docProperty = (Property) base;
            Property subProperty = getDocumentProperty(docProperty, property);
            value = getDocumentPropertyValue(subProperty);
        } catch (PropertyException pe) {
            try {
                // try property getters to resolve doc.schema.field.type
                // for instance
                value = super.getValue(context, base, property);
            } catch (PropertyNotFoundException e) {
                // avoid errors, log original error and return null
                log.warn(pe.toString());
            }
        }
        context.setPropertyResolved(true);
    }

    return value;
}

From source file:org.nuxeo.ecm.platform.el.DocumentModelResolver.java

@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
    boolean readOnly = false;
    try {// www .j  a v  a  2 s  .  c o m
        readOnly = super.isReadOnly(context, base, property);
    } catch (PropertyNotFoundException e) {
        if (base instanceof DocumentModel || base instanceof DocumentPropertyContext) {
            readOnly = false;
            context.setPropertyResolved(true);
        } else if (base instanceof Property) {
            readOnly = ((Property) base).isReadOnly();
            context.setPropertyResolved(true);
        }
    }
    return readOnly;
}

From source file:org.nuxeo.ecm.platform.el.DocumentModelResolver.java

@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
    if (base instanceof DocumentModel) {
        try {/*  ww w. j a va2 s . com*/
            super.setValue(context, base, property, value);
        } catch (PropertyNotFoundException e) {
            // nothing else to set on doc model
        }
    } else if (base instanceof DocumentPropertyContext) {
        DocumentPropertyContext ctx = (DocumentPropertyContext) base;
        value = FieldAdapterManager.getValueForStorage(value);
        try {
            ctx.doc.setPropertyValue(getDocumentPropertyName(ctx, property), (Serializable) value);
        } catch (PropertyException e) {
            // avoid errors here too
            log.warn(e.toString());
        }
        context.setPropertyResolved(true);
    } else if (base instanceof Property) {
        try {
            Property docProperty = (Property) base;
            Property subProperty = getDocumentProperty(docProperty, property);
            value = FieldAdapterManager.getValueForStorage(value);
            subProperty.setValue(value);
        } catch (PropertyException pe) {
            try {
                // try property setters to resolve doc.schema.field.type
                // for instance
                super.setValue(context, base, property, value);
            } catch (PropertyNotFoundException e) {
                // log original error and avoid errors here too
                log.warn(pe.toString());
            }
        }
        context.setPropertyResolved(true);
    }
}

From source file:org.rhq.enterprise.gui.common.paging.PageControlELResolver.java

@Override
public Class<?> getType(ELContext context, Object base, Object property) {
    Class<?> result = null;

    if (context == null) {
        throw new NullPointerException("ELContext was null for getType method in PageControlELResolver");
    }/*www .j a  v  a2 s  . c o m*/

    if (base == null) {
        // We don't handle setting top-level implicit objects.
    } else if (base.equals(PageControlView.class) || (base instanceof PageControlView)) {
        String propertyName = property.toString().toLowerCase();

        if ("pagesize".equals(propertyName)) {
            result = Integer.class;
        } else if ("pagenumber".equals(propertyName)) {
            result = Integer.class;
        } else if ("unlimited".equals(propertyName)) {
            result = Boolean.class;
        } else {
            throw new PropertyNotWritableException(
                    "Only the pageSize and pageNumber properties of a PageControl object can be resolved");
        }

        context.setPropertyResolved(true);
    }

    return result;
}

From source file:org.rhq.enterprise.gui.common.paging.PageControlELResolver.java

@Override
public Object getValue(ELContext context, Object base, Object property) {
    if (context == null) {
        throw new NullPointerException("ELContext was null for getValue method in PageControlELResolver");
    }//from  ww w  . j a v  a 2 s.  com

    Object result = null;

    if (base == null) {
        // Resolving first two variables (e.g. ${PageControlView.something}).
        String propertyName = (String) property;
        if ("PageControl".equals(propertyName)) {
            result = PageControlView.class;
            context.setPropertyResolved(true);
        }
    } else if (PageControlView.class.equals(base)) {
        // Getting a specific PageControlView instance

        String viewName = property.toString();

        result = PageControlView.valueOf(viewName);
        context.setPropertyResolved(true);
    } else if (base instanceof PageControlView) {
        // cast to required types
        PageControlView view = (PageControlView) base;
        String methodName = (String) property;
        String lowerCaseMethodName = methodName.toLowerCase();
        log.debug("accessing PageControl." + methodName);
        // allows simple misspellings for developer productivity
        if ("pagesize".equals(lowerCaseMethodName)) {
            // find the user for this session-based operation
            WebUser user = EnterpriseFacesContextUtility.getWebUser();
            WebUserPreferences preferences = user.getWebPreferences();
            // get it
            PageControl pc = preferences.getPageControl(view);
            if (log.isDebugEnabled()) {
                log.debug("Getting PageControlView[" + view + "] to " + pc);
            }
            result = pc.getPageSize();
        } else if ("pagenumber".equals(lowerCaseMethodName)) {
            // find the user for this session-based operation
            WebUser user = EnterpriseFacesContextUtility.getWebUser();
            WebUserPreferences preferences = user.getWebPreferences();
            // get it
            PageControl pc = preferences.getPageControl(view);
            if (log.isDebugEnabled()) {
                log.debug("Getting PageControlView[" + view + "] to " + pc);
            }
            result = pc.getPageNumber() + 1; // RF data table is 1-based, our PageControl is 0-based
        } else if ("unlimited".equals(lowerCaseMethodName)) {
            result = view.isUnlimited();
        } else {
            throw new PropertyNotFoundException(
                    "The " + methodName + " property of a PageControl object is not accessible");
        }

        // don't let other resolvers touch this
        context.setPropertyResolved(true);
    }

    return result;
}

From source file:org.rhq.enterprise.gui.common.paging.PageControlELResolver.java

@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
    if (context == null) {
        throw new NullPointerException("ELContext was null for setValue method in PageControlELResolver");
    }//ww w.ja  v a 2  s. c  om

    if (base instanceof PageControlView) {
        // cast to required types
        PageControlView view = (PageControlView) base;
        String methodName = (String) property;
        String lowerCaseMethodName = methodName.toLowerCase();

        // allows simple mispellings for developer productivity
        if ("pagesize".equals(lowerCaseMethodName)) {
            if (value != null) {
                // find the user for this session-based operation
                WebUser user = EnterpriseFacesContextUtility.getWebUser();
                WebUserPreferences preferences = user.getWebPreferences();

                // update it
                PageControl pc = preferences.getPageControl(view);
                int pageSize = (Integer) value;
                if (pc.getPageSize() == pageSize) {
                    // nothing to do
                    if (log.isDebugEnabled()) {
                        log.debug("PageControlView[" + view + "] needs no changes " + pc);
                    }
                } else {
                    pc.setPageSize(pageSize);
                    pc.setPageNumber(0); // reset the page number too

                    if (log.isDebugEnabled()) {
                        log.debug("Setting PageControlView[" + view + "] to " + pc);
                    }
                    preferences.setPageControl(view, pc);
                }
            }

            // don't let other resolvers touch this
            context.setPropertyResolved(true);
        } else if ("pagenumber".equals(lowerCaseMethodName)) {
            if (value != null) {
                // find the user for this session-based operation
                WebUser user = EnterpriseFacesContextUtility.getWebUser();
                WebUserPreferences preferences = user.getWebPreferences();

                // update it
                PageControl pc = preferences.getPageControl(view);
                int pageNumber = (Integer) value;
                pc.setPageNumber(pageNumber - 1); // RF data table is 1-based, our PageControl is 0-based

                if (log.isDebugEnabled()) {
                    log.debug("Setting PageControlView[" + view + "] to " + pc);
                }
                preferences.setPageControl(view, pc);
            }

            // don't let other resolvers touch this
            context.setPropertyResolved(true);
        } else {
            throw new PropertyNotFoundException(
                    "The " + methodName + " property of a PageControl object can not be set, only pageSize");
        }
    }
}

From source file:org.springframework.beans.factory.access.el.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");
            }//from  ww w .  jav  a  2  s.c  o  m
            elContext.setPropertyResolved(true);
            return bf.getBean(beanName);
        }
    }
    return null;
}