Example usage for javax.el ValueExpression getValue

List of usage examples for javax.el ValueExpression getValue

Introduction

In this page you can find the example usage for javax.el ValueExpression getValue.

Prototype

public abstract Object getValue(ELContext context);

Source Link

Usage

From source file:org.nuxeo.ecm.platform.ui.web.component.document.RestDocumentLink.java

public Boolean getAddTabInfo() {
    if (addTabInfo != null) {
        return addTabInfo;
    }/*from  ww  w  .j a  va  2  s  .  c om*/
    ValueExpression ve = getValueExpression("addTabInfo");
    if (ve != null) {
        try {
            return Boolean.valueOf(!Boolean.FALSE.equals(ve.getValue(getFacesContext().getELContext())));
        } catch (ELException e) {
            throw new FacesException(e);
        }
    } else {
        // default value
        return Boolean.TRUE;
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.component.document.RestDocumentLink.java

public Boolean getResolveOnly() {
    if (resolveOnly != null) {
        return resolveOnly;
    }// ww w. j a  v  a  2 s  . c o m
    ValueExpression ve = getValueExpression("resolveOnly");
    if (ve != null) {
        try {
            return Boolean.valueOf(!Boolean.FALSE.equals(ve.getValue(getFacesContext().getELContext())));
        } catch (ELException e) {
            throw new FacesException(e);
        }
    } else {
        // default value
        return Boolean.FALSE;
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.component.document.RestDocumentLink.java

/**
 * Returns true if URL must link to a page in a new conversation.
 * <p>/*w  ww.  j  a v  a2  s .  c o  m*/
 * Defaults to false.
 */
public Boolean getNewConversation() {
    if (newConversation != null) {
        return newConversation;
    }
    ValueExpression ve = getValueExpression("newConversation");
    if (ve != null) {
        try {
            return Boolean.valueOf(!Boolean.FALSE.equals(ve.getValue(getFacesContext().getELContext())));
        } catch (ELException e) {
            throw new FacesException(e);
        }
    } else {
        // default value
        return Boolean.FALSE;
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.component.file.UIInputFile.java

public String getFilename() {
    if (filename != null) {
        return filename;
    }//from  w  w  w .  j  av  a  2  s .  c  om
    ValueExpression ve = getValueExpression("filename");
    if (ve != null) {
        try {
            return (String) ve.getValue(getFacesContext().getELContext());
        } catch (ELException e) {
            throw new FacesException(e);
        }
    } else {
        return null;
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.tag.handler.SetTagHandler.java

public FaceletHandler getAliasVariableMapper(FaceletContext ctx, AliasVariableMapper target) {
    String varStr = var.getValue(ctx);
    // avoid overriding variable already in the mapper
    if (target.hasVariables(varStr)) {
        return nextHandler;
    }//from   www.  jav a2s  . com

    // handle variable expression
    boolean cacheValue = false;
    if (cache != null) {
        cacheValue = cache.getBoolean(ctx);
    }
    boolean resolveTwiceBool = false;
    if (resolveTwice != null) {
        resolveTwiceBool = resolveTwice.getBoolean(ctx);
    }

    ValueExpression ve;
    if (cacheValue) {
        // resolve value and put it as is in variable mapper
        Object res = value.getObject(ctx);
        if (resolveTwiceBool && res instanceof String && ComponentTagUtils.isValueReference((String) res)) {
            ve = ctx.getExpressionFactory().createValueExpression(ctx, (String) res, Object.class);
            res = ve.getValue(ctx);
        }
        ve = ctx.getExpressionFactory().createValueExpression(res, Object.class);
    } else {
        ve = value.getValueExpression(ctx, Object.class);
        if (resolveTwiceBool) {
            boolean localBool = false;
            if (local != null) {
                localBool = local.getBoolean(ctx);
            }
            if (localBool) {
                ve = new MetaValueExpression(ve);
            } else {
                ve = new MetaValueExpression(ve, ctx.getFunctionMapper(), ctx.getVariableMapper());
            }
        }
    }

    target.setVariable(varStr, ve);

    if (blockPatterns != null) {
        String blockedValue = blockPatterns.getValue(ctx);
        if (!StringUtils.isEmpty(blockedValue)) {
            // split on "," character
            target.setBlockedPatterns(resolveBlockPatterns(blockedValue));
        }
    }

    FaceletHandler nextHandler = this.nextHandler;
    if (nextHandler instanceof SetTagHandler) {
        // try merging with next handler
        SetTagHandler next = (SetTagHandler) nextHandler;
        if (next.isAcceptingMerge(ctx)) {
            // make sure referenced vars will be resolved in this context
            ctx.getVariableMapper().setVariable(varStr, ve);
            try {
                AliasVariableMapper.exposeAliasesToRequest(ctx.getFacesContext(), target);
                nextHandler = next.getAliasVariableMapper(ctx, target);
            } finally {
                AliasVariableMapper.removeAliasesExposedToRequest(ctx.getFacesContext(), target.getId());
            }
        }
    }

    return nextHandler;
}

From source file:org.nuxeo.ecm.platform.ui.web.component.file.UIInputFile.java

public Boolean getEditFilename() {
    if (editFilename != null) {
        return editFilename;
    }//  ww  w.ja v a2  s  .co  m
    ValueExpression ve = getValueExpression("editFilename");
    if (ve != null) {
        try {
            return !Boolean.FALSE.equals(ve.getValue(getFacesContext().getELContext()));
        } catch (ELException e) {
            throw new FacesException(e);
        }
    } else {
        // default value
        return false;
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.rest.services.URLPolicyServiceImpl.java

public void appendParametersToRequest(FacesContext facesContext, String pattern) {
    // try to get doc view from custom mapping
    DocumentView docView = null;//w  ww.  j  a  v  a 2 s .co m
    ExpressionFactory ef = facesContext.getApplication().getExpressionFactory();
    ELContext context = facesContext.getELContext();
    HttpServletRequest httpRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();

    // get existing document view from given pattern, else create it
    URLPatternDescriptor patternDesc = null;
    if (pattern != null && !"".equals(pattern)) {
        patternDesc = getURLPatternDescriptor(pattern);
    } else {
        // iterate over pattern descriptors, and take the first one that
        // applies, or use the default one
        List<URLPatternDescriptor> descs = getURLPatternDescriptors();
        boolean applies = false;
        for (URLPatternDescriptor desc : descs) {
            String documentViewAppliesExpr = desc.getDocumentViewBindingApplies();
            if (!StringUtils.isBlank(documentViewAppliesExpr)) {
                // TODO: maybe put view id to the request to help writing
                // the EL expression
                ValueExpression ve = ef.createValueExpression(context, documentViewAppliesExpr, Object.class);
                try {
                    Object res = ve.getValue(context);
                    if (Boolean.TRUE.equals(res)) {
                        applies = true;
                    }
                } catch (ELException e) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Error executing expression '%s' for " + "url pattern '%s': %s",
                                documentViewAppliesExpr, desc.getName(), e.getMessage()));
                    }
                }
            }
            if (applies) {
                patternDesc = desc;
                break;
            }
        }
        if (patternDesc == null) {
            // default on the default pattern desc
            patternDesc = getDefaultPatternDescriptor();
        }
    }
    if (patternDesc != null) {
        // resolved doc view values thanks to bindings
        Object docViewValue = null;
        String documentViewBinding = patternDesc.getDocumentViewBinding();
        if (!StringUtils.isBlank(documentViewBinding)) {
            ValueExpression ve = ef.createValueExpression(context, documentViewBinding, Object.class);
            docViewValue = ve.getValue(context);
        }
        if (docViewValue == null) {
            documentViewBinding = patternDesc.getNewDocumentViewBinding();
            if (!StringUtils.isBlank(documentViewBinding)) {
                ValueExpression ve = ef.createValueExpression(context, documentViewBinding, Object.class);
                docViewValue = ve.getValue(context);
            }
        }
        if (docViewValue instanceof DocumentView) {
            docView = (DocumentView) docViewValue;
            // set pattern name in case it was just created
            docView.setPatternName(patternDesc.getName());
            ValueBindingDescriptor[] bindings = patternDesc.getValueBindings();
            if (bindings != null) {
                for (ValueBindingDescriptor binding : bindings) {
                    if (!binding.getCallGetter()) {
                        continue;
                    }
                    String paramName = binding.getName();
                    String expr = binding.getExpression();
                    try {
                        Object value;
                        if (ComponentTagUtils.isValueReference(expr)) {
                            ValueExpression ve = ef.createValueExpression(context, expr, Object.class);
                            value = ve.getValue(context);
                        } else {
                            value = expr;
                        }
                        if (docView != null) {
                            // do not set attributes on the request as
                            // document view will be put in the request
                            // anyway
                            docView.addParameter(paramName, (String) value);
                        } else {
                            httpRequest.setAttribute(paramName, value);
                        }
                    } catch (ELException e) {
                        log.error(
                                String.format("Could not get parameter %s from expression %s", paramName, expr),
                                e);
                    }
                }
            }
        }
    }

    // save document view to the request
    setDocumentViewInRequest(httpRequest, docView);
}

From source file:org.nuxeo.ecm.platform.ui.web.directory.ChainSelect.java

public String getDefaultRootKey() {
    ValueExpression ve = getValueExpression("defaultRootKey");
    if (ve != null) {
        return (String) ve.getValue(FacesContext.getCurrentInstance().getELContext());
    } else {/*  ww w.  ja va 2 s .  com*/
        return defaultRootKey;
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.directory.ChainSelect.java

public Object getProperty(String name) {
    ValueExpression ve = getValueExpression(name);
    if (ve != null) {
        try {/*from  w  w w .j av  a2s  . c o m*/
            return ve.getValue(getFacesContext().getELContext());
        } catch (ELException e) {
            throw new FacesException(e);
        }
    } else {
        Map<String, Object> attrMap = getAttributes();
        return attrMap.get(name);
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.directory.ChainSelect.java

public String getOnchange() {
    if (onchange != null) {
        return onchange;
    }// ww  w. j  av a  2  s  .c o  m
    ValueExpression ve = getValueExpression("onchange");
    if (ve != null) {
        try {
            return (String) ve.getValue(getFacesContext().getELContext());
        } catch (ELException e) {
            throw new FacesException(e);
        }
    }
    return null;
}