public Object getValue(ELContext context, Object base, Object property) {
    // this resolver only resolves top level variable names to execution variable names.
    // only handle if this is a top level variable
    if (base == null) {
      // we assume a NPE-check for property is not needed
      // i don't think the next cast can go wrong.  can it?
      String name = (String) property;

      if (execution != null && NAME_EXECUTION.equals(name)) {
        context.setPropertyResolved(true);
        return execution;
      }

      if (processInstance != null && NAME_PROCESSINSTANCE.equals(name)) {
        context.setPropertyResolved(true);
        return processInstance;
      }

      if (task != null && NAME_TASK.equals(name)) {
        context.setPropertyResolved(true);
        return task;
      }
    }

    return null;
  }
  /**
   * Return an existing scoped object for the specified name (if any); otherwise, return <code>null
   * </code>.
   *
   * @param context <code>ELContext</code> for evaluating this value
   * @param base Base object against which this evaluation occurs (must be null because we are
   *     evaluating a top level variable)
   * @param property Property name to be accessed
   */
  public Object getValue(ELContext context, Object base, Object property) {

    if (base != null) {
      return null;
    }
    if (property == null) {
      throw new PropertyNotFoundException("No property specified");
    }

    FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
    ExternalContext econtext = fcontext.getExternalContext();
    Object value = null;
    value = econtext.getRequestMap().get(property);
    if (value != null) {
      context.setPropertyResolved(true);
      return value;
    }
    value = econtext.getSessionMap().get(property);
    if (value != null) {
      context.setPropertyResolved(true);
      return value;
    }
    value = econtext.getApplicationMap().get(property);
    if (value != null) {
      context.setPropertyResolved(true);
      return value;
    }

    return null;
  }
Exemple #3
0
 public boolean isReadOnly(ELContext context, Object base, Object property) throws ELException {
   if (base != null) {
     return false;
   }
   if (property == null) {
     String message =
         MessageUtils.getExceptionMessageString(
             MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "property");
     throw new PropertyNotFoundException(message);
   }
   // return value will be ignored unless context.propertyResolved is
   // set to true.
   Integer index = IMPLICIT_OBJECTS.get(property.toString());
   if (index == null) {
     return false;
   }
   switch (index) {
     case FACES_CONTEXT:
       context.setPropertyResolved(true);
       return true;
     case VIEW:
       context.setPropertyResolved(true);
       return true;
     default:
       return false;
   }
 }
  @Override
  @SuppressWarnings("deprecation")
  public Object getValue(ELContext context, Object base, Object property) throws ELException {

    // Don't call into the chain unless it's been decorated.
    if (legacyVR instanceof ChainAwareVariableResolver) {
      return null;
    }

    if (base != null) {
      return null;
    }
    if (base == null && property == null) {
      String message =
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "base and property"); // ?????
      throw new PropertyNotFoundException(message);
    }
    context.setPropertyResolved(true);
    Object result = null;

    FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
    String propString = property.toString();
    Map<String, Object> stateMap = RequestStateManager.getStateMap(facesContext);
    try {
      // If we are already in the midst of an expression evaluation
      // that touched this resolver...
      //noinspection unchecked
      List<String> varNames = (List<String>) stateMap.get(RequestStateManager.REENTRANT_GUARD);
      if (varNames != null && !varNames.isEmpty() && varNames.contains(propString)) {
        // take no action and return.
        context.setPropertyResolved(false);
        return null;
      }
      // Make sure subsequent calls don't take action.
      if (varNames == null) {
        varNames = new ArrayList<>();
        stateMap.put(RequestStateManager.REENTRANT_GUARD, varNames);
      }
      varNames.add(propString);

      result = legacyVR.resolveVariable(facesContext, propString);
    } catch (EvaluationException ex) {
      context.setPropertyResolved(false);
      throw new ELException(ex);
    } finally {
      // Make sure to remove the guard after the call returns
      //noinspection unchecked
      List<String> varNames = (List<String>) stateMap.get(RequestStateManager.REENTRANT_GUARD);
      if (varNames != null && !varNames.isEmpty()) {
        varNames.remove(propString);
      }
      // Make sure that the ELContext "resolved" indicator is set
      // in accordance wth the result of the resolution.
      context.setPropertyResolved(result != null);
    }
    return result;
  }
 @Override
 public Class<?> getType(ELContext context, Object base, Object property) {
   Class<?> type = null;
   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;
 }
  /** @see javax.el.ELResolver#getValue(ELContext, Object, Object) */
  @Override
  public Object getValue(ELContext context, Object base, Object property) {
    if (property != null) {
      String propertyString = property.toString();
      Namespace namespace = null;
      if (base == null) {
        if (manager.getRootNamespace().contains(propertyString)) {
          context.setPropertyResolved(true);
          return manager.getRootNamespace().get(propertyString);
        }
      } else if (base instanceof Namespace) {
        namespace = (Namespace) base;
        // We're definitely the responsible party
        context.setPropertyResolved(true);
        if (namespace.contains(propertyString)) {
          // There is a child namespace
          return namespace.get(propertyString);
        }
      } else {
        // let the standard EL resolver chain handle the property
        return null;
      }
      final String name;
      if (namespace != null) {
        // Try looking in the manager for a bean
        name = namespace.qualifyName(propertyString);
      } else {
        name = propertyString;
      }
      Object value = null;
      try {

        Bean<?> bean = manager.resolve(manager.getBeans(name));
        CreationalContext<?> creationalContext = manager.createCreationalContext(bean);
        if (bean != null) {
          value = manager.getReference(bean, creationalContext);
        }
        creationalContext.release();
      } catch (Exception e) {
        throw new RuntimeException(
            "Error resolving property " + propertyString + " against base " + base, e);
      }
      if (value != null) {
        context.setPropertyResolved(true);
        return value;
      }
    }
    return null;
  }
  @Override
  public Object getValue(ELContext context, Object base, Object property)
      throws NullPointerException, PropertyNotFoundException, ELException {
    context.setPropertyResolved(false);

    int start;
    Object result = null;

    if (base == null) {
      // call implicit and app resolvers
      int index = 1 /* implicit */ + appResolversSize;
      for (int i = 0; i < index; i++) {
        result = resolvers[i].getValue(context, base, property);
        if (context.isPropertyResolved()) {
          return result;
        }
      }
      // skip collection-based resolvers (map, resource, list, array, and
      // bean)
      start = index + 5;
    } else {
      // skip implicit resolver only
      start = 1;
    }

    for (int i = start; i < size; i++) {
      result = resolvers[i].getValue(context, base, property);
      if (context.isPropertyResolved()) {
        return result;
      }
    }

    return null;
  }
  @Override
  public Object invoke(
      ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) {
    String targetMethod = coerceToString(method);
    if (targetMethod.length() == 0) {
      throw new ELException(new NoSuchMethodException());
    }

    context.setPropertyResolved(false);

    Object result = null;

    // skip implicit and call app resolvers
    int index = 1 /* implicit */ + appResolversSize;
    for (int i = 1; i < index; i++) {
      result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params);
      if (context.isPropertyResolved()) {
        return result;
      }
    }

    // skip map, resource, list, and array resolvers
    index += 4;
    // call bean and the rest of resolvers
    for (int i = index; i < size; i++) {
      result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params);
      if (context.isPropertyResolved()) {
        return result;
      }
    }

    return null;
  }
Exemple #9
0
 /*
  * (non-Javadoc)
  *
  * @see javax.el.ValueExpression#setValue(javax.el.ELContext,
  *      java.lang.Object)
  */
 public void setValue(ELContext context, Object value) {
   Object base = this.orig.getValue(context);
   if (base != null) {
     context.setPropertyResolved(false);
     context.getELResolver().setValue(context, base, key, value);
   }
 }
  /**
   * Set the value of a scoped object for the specified name.
   *
   * @param context <code>ELContext</code> for evaluating this value
   * @param base Base object against which this evaluation occurs (must be null because we are
   *     evaluating a top level variable)
   * @param property Property name to be accessed
   * @param value New value to be set
   */
  public void setValue(ELContext context, Object base, Object property, Object value) {

    if (base != null) {
      return;
    }
    if (property == null) {
      throw new PropertyNotFoundException("No property specified");
    }

    context.setPropertyResolved(true);
    String key = property.toString();
    Object result = null;
    FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
    ExternalContext econtext = fcontext.getExternalContext();

    if (econtext.getRequestMap().containsKey(property)) {
      econtext.getRequestMap().put(key, value);
    } else if (econtext.getSessionMap().containsKey(property)) {
      econtext.getSessionMap().put(key, value);
    } else if (econtext.getApplicationMap().containsKey(property)) {
      econtext.getApplicationMap().put(key, value);
    } else {
      econtext.getRequestMap().put(key, value);
    }
  }
 @Override
 public boolean isReadOnly(ELContext context, Object base, Object property) {
   boolean readOnly = false;
   try {
     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;
 }
  @Override
  public void setValue(ELContext elContext, Object base, Object property, Object value) {

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

    if (base != null) {
      return;
    }

    elContext.setPropertyResolved(true);

    if (property instanceof String) {
      PageContext pageContext = (PageContext) elContext.getContext(JspContext.class);

      String attribute = (String) property;

      if (pageContext.getAttribute(attribute, PageContext.REQUEST_SCOPE) != null) {

        pageContext.setAttribute(attribute, value, PageContext.REQUEST_SCOPE);
      } else if (pageContext.getAttribute(attribute, PageContext.SESSION_SCOPE) != null) {

        pageContext.setAttribute(attribute, value, PageContext.SESSION_SCOPE);
      } else if (pageContext.getAttribute(attribute, PageContext.APPLICATION_SCOPE) != null) {

        pageContext.setAttribute(attribute, value, PageContext.APPLICATION_SCOPE);
      } else {
        pageContext.setAttribute(attribute, value, PageContext.PAGE_SCOPE);
      }
    }
  }
Exemple #13
0
  public Class<?> getType(ELContext context, Object base, Object property) throws ELException {
    if (base != null) {
      return null;
    }
    if (property == null) {
      String message =
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "property");
      throw new PropertyNotFoundException(message);
    }

    Integer index = IMPLICIT_OBJECTS.get(property.toString());

    if (index == null) {
      return null;
    }
    switch (index) {
      case FACES_CONTEXT:
      case VIEW:
        context.setPropertyResolved(true);
        return null;
      default:
        return null;
    }
  }
 // Capture the base and property rather than write the value
 @Override
 public void setValue(ELContext context, Object base, Object property, Object value) {
   if (base != null && property != null) {
     context.setPropertyResolved(true);
     valueReference = new ValueReference(base, property.toString());
   }
 }
  /**
   * Return <code>true</code> if the specified property is read only.
   *
   * @param context <code>ELContext</code> for evaluating this value
   * @param base Base object against which this evaluation occurs (must be null because we are
   *     evaluating a top level variable)
   * @param property Property name to be accessed
   */
  public boolean isReadOnly(ELContext context, Object base, Object property) {

    if (base == null) {
      context.setPropertyResolved(true);
      return false;
    }
    return false;
  }
Exemple #16
0
 /*
  * (non-Javadoc)
  *
  * @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
  */
 public boolean isReadOnly(ELContext context) {
   Object base = this.orig.getValue(context);
   if (base != null) {
     context.setPropertyResolved(false);
     return context.getELResolver().isReadOnly(context, base, key);
   }
   return true;
 }
Exemple #17
0
 /*
  * (non-Javadoc)
  *
  * @see javax.el.ValueExpression#getType(javax.el.ELContext)
  */
 public Class getType(ELContext context) {
   Object base = this.orig.getValue(context);
   if (base != null) {
     context.setPropertyResolved(false);
     return context.getELResolver().getType(context, base, key);
   }
   return null;
 }
Exemple #18
0
 /*
  * (non-Javadoc)
  *
  * @see javax.el.ValueExpression#getValue(javax.el.ELContext)
  */
 public Object getValue(ELContext context) {
   Object base = this.orig.getValue(context);
   if (base != null) {
     context.setPropertyResolved(true);
     return new Entry((Map) base, key);
   }
   return null;
 }
 @SuppressWarnings("unchecked")
 public <T> T getExpressionValue(FacesContext context, String exp, Class<T> returnType) {
   ELContext elContext = context.getELContext();
   boolean propertyResolved = elContext.isPropertyResolved();
   try {
     ValueExpression valueExpression = createElExpression(elContext, exp, returnType);
     return (T) valueExpression.getValue(elContext);
   } finally {
     elContext.setPropertyResolved(propertyResolved);
   }
 }
  /**
   * Return the Java type of the specified property.
   *
   * @param context <code>ELContext</code> for evaluating this value
   * @param base Base object against which this evaluation occurs (must be null because we are
   *     evaluating a top level variable)
   * @param property Property name to be accessed
   */
  public Class getType(ELContext context, Object base, Object property) {

    if (base != null) {
      return null;
    }
    if (property == null) {
      throw new PropertyNotFoundException("No property specified");
    }
    context.setPropertyResolved(true);
    return Object.class;
  }
  @Override
  public Object getValue(ELContext context, Object base, Object property) {
    Object value = null;
    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;
  }
 protected <T> T findBean(FacesContext context, Class<T> type, String beanName) {
   ELContext elContext = context.getELContext();
   boolean propertyResolved = elContext.isPropertyResolved();
   try {
     return context
         .getApplication()
         .evaluateExpressionGet(
             context, "#" + "{" + beanName + "}", type); // Warning EL string is not closed
   } finally {
     elContext.setPropertyResolved(propertyResolved);
   }
 }
  @Override
  public boolean isReadOnly(ELContext elContext, Object base, Object property) {

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

    if (base == null) {
      elContext.setPropertyResolved(true);
    }

    return false;
  }
Exemple #24
0
  public Object getValue(ELContext context, Object base, Object property) throws ELException {
    // variable resolution is a special case of property resolution
    // where the base is null.
    if (base != null) {
      return null;
    }
    if (property == null) {
      String message =
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "property");
      throw new PropertyNotFoundException(message);
    }

    Integer index = IMPLICIT_OBJECTS.get(property.toString());

    if (index == null) {
      return null;
    }

    FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);

    switch (index.intValue()) {
      case FACES_CONTEXT:
        context.setPropertyResolved(true);
        return facesContext;
      case VIEW:
        context.setPropertyResolved(true);
        return facesContext.getViewRoot();
      case VIEW_SCOPE:
        context.setPropertyResolved(true);
        return facesContext.getViewRoot().getViewMap();
      case RESOURCE:
        context.setPropertyResolved(true);
        return facesContext.getApplication().getResourceHandler();
      default:
        return null;
    }
  }
  @Override
  public Class<?> getType(ELContext elContext, Object base, Object property) {
    if (elContext == null) {
      throw new NullPointerException();
    }

    if (base == null) {
      elContext.setPropertyResolved(true);

      return Object.class;
    }

    return null;
  }
    @Override
    public boolean isReadOnly(ELContext context, Object base, Object property) {
      boolean readOnly;

      if (handles(base, property)) {
        readOnly = true;

        context.setPropertyResolved(true);
      } else {
        readOnly = false;
      }

      return readOnly;
    }
    @Override
    public Class<?> getType(ELContext context, Object base, Object property) {
      Class<?> type;

      if (handles(base, property)) {
        type = String.class;

        context.setPropertyResolved(true);
      } else {
        type = null;
      }

      return type;
    }
    @Override
    public Object getValue(ELContext context, Object base, Object property) {
      Object value;

      if (handles(base, property)) {
        value = ((Dictionary) base).translate((String) property);

        context.setPropertyResolved(true);
      } else {
        value = null;
      }

      return value;
    }
 @Override
 public void setValue(ELContext context, Object base, Object property, Object value) {
   if (base instanceof DocumentModel) {
     try {
       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);
   }
 }
  @Override
  public Class<?> getType(ELContext context, Object base, Object property) throws ELException {

    // Don't call into the chain unless it's been decorated.
    if (legacyVR instanceof ChainAwareVariableResolver) {
      return null;
    }

    Object result = getValue(context, base, property);
    context.setPropertyResolved(result != null);
    if (result != null) {
      return result.getClass();
    }
    return null;
  }