Java Code Examples for javax.el.ELContext#getContext()

The following examples show how to use javax.el.ELContext#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScopedAttributeELResolver.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
    Objects.requireNonNull(context);

    if (base == null) {
        context.setPropertyResolved(base, property);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
 
Example 2
Source File: ScopedAttributeELResolver.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            return page.findAttribute(key);
        }
    }

    return null;
}
 
Example 3
Source File: ScopedAttributeELResolver.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
 
Example 4
Source File: ScopedAttributeELResolver.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            return page.findAttribute(key);
        }
    }

    return null;
}
 
Example 5
Source File: ScopedAttributeELResolver.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
 
Example 6
Source File: VariableContextElResolver.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property) {
  if (base == null) {
    VariableContext variableContext = (VariableContext) context.getContext(VariableContext.class);
    if(variableContext != null) {
      if(VARIABLE_CONTEXT_KEY.equals(property)) {
        context.setPropertyResolved(true);
        return variableContext;
      }
      TypedValue typedValue = variableContext.resolve((String) property);
      if(typedValue != null) {
        context.setPropertyResolved(true);
        return unpack(typedValue);
      }
    }
  }
  return null;
}
 
Example 7
Source File: VariableContextElResolver.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property) {
  if (base == null) {
    VariableContext variableContext = (VariableContext) context.getContext(VariableContext.class);
    if(variableContext != null) {
      if(VARIABLE_CONTEXT_KEY.equals(property)) {
        context.setPropertyResolved(true);
        return variableContext;
      }
      TypedValue typedValue = variableContext.resolve((String) property);
      if(typedValue != null) {
        context.setPropertyResolved(true);
        return unpack(typedValue);
      }
    }
  }
  return null;
}
 
Example 8
Source File: ImplicitObjectELResolver.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);

    if (base == null && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());

        if (idx >= 0) {
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            context.setPropertyResolved(base, property);
            switch (idx) {
            case APPLICATIONSCOPE:
                return ScopeManager.get(page).getApplicationScope();
            case COOKIE:
                return ScopeManager.get(page).getCookie();
            case HEADER:
                return ScopeManager.get(page).getHeader();
            case HEADERVALUES:
                return ScopeManager.get(page).getHeaderValues();
            case INITPARAM:
                return ScopeManager.get(page).getInitParam();
            case PAGECONTEXT:
                return ScopeManager.get(page).getPageContext();
            case PAGESCOPE:
                return ScopeManager.get(page).getPageScope();
            case PARAM:
                return ScopeManager.get(page).getParam();
            case PARAM_VALUES:
                return ScopeManager.get(page).getParamValues();
            case REQUEST_SCOPE:
                return ScopeManager.get(page).getRequestScope();
            case SESSION_SCOPE:
                return ScopeManager.get(page).getSessionScope();
            }
        }
    }
    return null;
}
 
Example 9
Source File: BeyondViewScopeELResolver.java    From JSF-on-Spring-Boot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getValue(final ELContext elContext, final Object base, final Object property) {

	if (property == null) {
		throw new PropertyNotFoundException();
	}
	
	FacesContext facesContext = (FacesContext) elContext.getContext(FacesContext.class);

	if ((null == base) && BeyondViewScope.SCOPE_NAME.equals(property.toString())) {

		// Scope is referenced directly
		BeyondViewScope scope = getScope(facesContext);
		elContext.setPropertyResolved(true);
		return scope;

	} else if ((null != base) && (base instanceof BeyondViewScope)) {

		// An object within the scope is referenced

		return resolve(facesContext, (BeyondViewScope) base, property.toString());

	} else if (null == base) {
		BeyondViewScope customScope = getScope(facesContext);
		return null != customScope ? resolve(facesContext, customScope, property.toString()):null;

	}
	return null;
}
 
Example 10
Source File: ScopedAttributeELResolver.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);

    Object result = null;

    if (base == null) {
        context.setPropertyResolved(base, property);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            result = page.findAttribute(key);

            if (result == null) {
                boolean resolveClass = true;
                // Performance short-cut available when running on Tomcat
                if (AST_IDENTIFIER_KEY != null) {
                    // Tomcat will set this key to Boolean.TRUE if the
                    // identifier is a stand-alone identifier (i.e.
                    // identifier) rather than part of an AstValue (i.e.
                    // identifier.something). Imports do not need to be
                    // checked if this is a stand-alone identifier
                    Boolean value = (Boolean) context.getContext(AST_IDENTIFIER_KEY);
                    if (value != null && value.booleanValue()) {
                        resolveClass = false;
                    }
                }
                // This might be the name of an imported class
                ImportHandler importHandler = context.getImportHandler();
                if (importHandler != null) {
                    Class<?> clazz = null;
                    if (resolveClass) {
                        clazz = importHandler.resolveClass(key);
                    }
                    if (clazz != null) {
                        result = new ELClass(clazz);
                    }
                    if (result == null) {
                        // This might be the name of an imported static field
                        clazz = importHandler.resolveStatic(key);
                        if (clazz != null) {
                            try {
                                result = clazz.getField(key).get(null);
                            } catch (IllegalArgumentException | IllegalAccessException |
                                    NoSuchFieldException | SecurityException e) {
                                // Most (all?) of these should have been
                                // prevented by the checks when the import
                                // was defined.
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}
 
Example 11
Source File: ImplicitObjectELResolver.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());

        if (idx >= 0) {
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            context.setPropertyResolved(true);
            switch (idx) {
            case APPLICATIONSCOPE:
                return ScopeManager.get(page).getApplicationScope();
            case COOKIE:
                return ScopeManager.get(page).getCookie();
            case HEADER:
                return ScopeManager.get(page).getHeader();
            case HEADERVALUES:
                return ScopeManager.get(page).getHeaderValues();
            case INITPARAM:
                return ScopeManager.get(page).getInitParam();
            case PAGECONTEXT:
                return ScopeManager.get(page).getPageContext();
            case PAGESCOPE:
                return ScopeManager.get(page).getPageScope();
            case PARAM:
                return ScopeManager.get(page).getParam();
            case PARAM_VALUES:
                return ScopeManager.get(page).getParamValues();
            case REQUEST_SCOPE:
                return ScopeManager.get(page).getRequestScope();
            case SESSION_SCOPE:
                return ScopeManager.get(page).getSessionScope();
            }
        }
    }
    return null;
}
 
Example 12
Source File: ScopedAttributeELResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If the base object is <code>null</code>, searches the page, 
 * request, session and application scopes for an attribute with
 * the given name and returns it, or <code>null</code> if no
 * attribute exists with the current name.
 *
 * <p>The <code>propertyResolved</code> property of the 
 * <code>ELContext</code> object must be set to <code>true</code> by 
 * this resolver before returning if base is <code>null</code>. If 
 * this property is not <code>true</code> after this method is called,
 * the caller should ignore the return value.</p>
 *
 * @param context The context of this evaluation.
 * @param base Only <code>null</code> is handled by this resolver.
 *     Other values will result in an immediate return.
 * @param property The name of the scoped attribute to resolve.
 * @return If the <code>propertyResolved</code> property of 
 *     <code>ELContext</code> was set to <code>true</code>, then
 *     the scoped attribute; otherwise undefined.
 * @throws NullPointerException if context is <code>null</code>
 * @throws ELException if an exception was thrown while performing
 *     the property or variable resolution. The thrown exception
 *     must be included as the cause property of this exception, if
 *     available.
 */
public Object getValue(ELContext context,
                       Object base,
                       Object property) {

    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property instanceof String) {
            String attribute = (String) property;
            PageContext ctxt = (PageContext)
                                   context.getContext(JspContext.class);
            return ctxt.findAttribute(attribute);
        }
    }
    return null;
}
 
Example 13
Source File: ImplicitObjectELResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If the base object is <code>null</code>, and the property matches
 * the name of a JSP implicit object, returns the implicit object.
 *
 * <p>The <code>propertyResolved</code> property of the 
 * <code>ELContext</code> object must be set to <code>true</code> by 
 * this resolver before returning if an implicit object is matched. If 
 * this property is not <code>true</code> after this method is called,
 * the caller should ignore the return value.</p>
 *
 * @param context The context of this evaluation.
 * @param base Only <code>null</code> is handled by this resolver.
 *     Other values will result in an immediate return.
 * @param property The name of the implicit object to resolve.
 * @return If the <code>propertyResolved</code> property of 
 *     <code>ELContext</code> was set to <code>true</code>, then
 *     the implicit object; otherwise undefined.
 * @throws NullPointerException if context is <code>null</code>
 * @throws ELException if an exception was thrown while performing
 *     the property or variable resolution. The thrown exception
 *     must be included as the cause property of this exception, if
 *     available.
 */
public Object getValue(ELContext context,
                       Object base,
                       Object property) {

    if (context == null) {
        throw new NullPointerException();
    }

    if (base != null) {
        return null;
    }

    PageContext ctxt = (PageContext)context.getContext(JspContext.class);
                           
    if ("pageContext".equals(property)) {
        context.setPropertyResolved(true);
        return ctxt;
    }
    ImplicitObjects implicitObjects =
        ImplicitObjects.getImplicitObjects(ctxt);
    if ("pageScope".equals(property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getPageScopeMap();
    }
    if ("requestScope".equals(property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getRequestScopeMap();
    }
    if ("sessionScope".equals(property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getSessionScopeMap();
    }
    if ("applicationScope".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getApplicationScopeMap ();
    }
    if ("param".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getParamMap();
    }
    if ("paramValues".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getParamsMap();
    }
    if ("header".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getHeaderMap();
    }
    if ("headerValues".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getHeadersMap();
    }
    if ("initParam".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getInitParamMap ();
    }
    if ("cookie".equals (property)) {
        context.setPropertyResolved(true);
        return implicitObjects.getCookieMap ();
    }
    return null;
}
 
Example 14
Source File: ImplicitObjectELResolver.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());

        if (idx >= 0) {
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            context.setPropertyResolved(true);
            switch (idx) {
            case APPLICATIONSCOPE:
                return ScopeManager.get(page).getApplicationScope();
            case COOKIE:
                return ScopeManager.get(page).getCookie();
            case HEADER:
                return ScopeManager.get(page).getHeader();
            case HEADERVALUES:
                return ScopeManager.get(page).getHeaderValues();
            case INITPARAM:
                return ScopeManager.get(page).getInitParam();
            case PAGECONTEXT:
                return ScopeManager.get(page).getPageContext();
            case PAGESCOPE:
                return ScopeManager.get(page).getPageScope();
            case PARAM:
                return ScopeManager.get(page).getParam();
            case PARAM_VALUES:
                return ScopeManager.get(page).getParamValues();
            case REQUEST_SCOPE:
                return ScopeManager.get(page).getRequestScope();
            case SESSION_SCOPE:
                return ScopeManager.get(page).getSessionScope();
            }
        }
    }
    return null;
}
 
Example 15
Source File: ScopedAttributeELResolver.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * If the base object is <code>null</code>, sets an existing scoped
 * attribute to the new value, or creates a new scoped attribute if one
 * does not exist by this name.
 *
 * <p>If the provided attribute name matches the key of an attribute 
 * in page scope, request scope, session scope, or application scope, the 
 * corresponding attribute value will be replaced by the provided value.
 * Otherwise, a new page scope attribute will be created with the
 * given name and value.</p>
 *
 * <p>The <code>propertyResolved</code> property of the 
 * <code>ELContext</code> object must be set to <code>true</code> by 
 * this resolver before returning if base is <code>null</code>. If 
 * this property is not <code>true</code> after this method is called,
 * the caller should ignore the return value.</p>
 *
 * @param context The context of this evaluation.
 * @param base Only <code>null</code> is handled by this resolver.
 *     Other values will result in an immediate return.
 * @param property The name of the scoped attribute to set.
 * @param val The value for the scoped attribute.
 * @throws NullPointerException if context is <code>null</code>.
 * @throws ELException if an exception was thrown while performing
 *     the property or variable resolution. The thrown exception
 *     must be included as the cause property of this exception, if
 *     available.
 */
public void  setValue(ELContext context,
                      Object base,
                      Object property,
                      Object val) {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property instanceof String) {
            PageContext ctxt = (PageContext)
                                   context.getContext(JspContext.class);
            String attr = (String) property;
            if (ctxt.getAttribute(attr, PageContext.REQUEST_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.REQUEST_SCOPE);
            else if (ctxt.getAttribute(attr, PageContext.SESSION_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.SESSION_SCOPE);
            else if (ctxt.getAttribute(attr, PageContext.APPLICATION_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.APPLICATION_SCOPE);
            else {
                ctxt.setAttribute(attr, val, PageContext.PAGE_SCOPE);
            }
        }
    }
}
 
Example 16
Source File: ManualScopeELResolver.java    From JSF-on-Spring-Boot with GNU General Public License v3.0 3 votes vote down vote up
@Override
public Object getValue(final ELContext elContext, final Object base, final Object property) {

	if (property == null) {
		throw new PropertyNotFoundException();
	}
	
	FacesContext facesContext = (FacesContext) elContext.getContext(FacesContext.class);

	if ((null == base) && ManualScope.SCOPE_NAME.equals(property.toString())) {

		// Scope is referenced directly

		ManualScope scope = getScope(facesContext);
		elContext.setPropertyResolved(true);
		return scope;

	} else if ((null != base) && (base instanceof ManualScope)) {

		// An object within the scope is referenced

		return resolve(facesContext, (ManualScope) base, property.toString());

	} else if (null == base) {
		ManualScope customScope = getScope(facesContext);
		return null != customScope ? resolve(facesContext, customScope, property.toString()):null;

	}
	return null;
}