@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);
      }
    }
  }
  /**
   * 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);
    }
  }
  /**
   * 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;
  }
  @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 Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext elContext, Object base) {

    List<FeatureDescriptor> featureDescriptors = new ArrayList<>();

    PageContext pageContext = (PageContext) elContext.getContext(JspContext.class);

    Enumeration<?> enumeration = pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE);

    while (enumeration.hasMoreElements()) {
      String name = (String) enumeration.nextElement();

      Object value = pageContext.getAttribute(name, PageContext.PAGE_SCOPE);

      FeatureDescriptor featureDescriptor = getFeatureDescriptor(name, value, "page");

      featureDescriptors.add(featureDescriptor);
    }

    enumeration = pageContext.getAttributeNamesInScope(PageContext.REQUEST_SCOPE);

    while (enumeration.hasMoreElements()) {
      String name = (String) enumeration.nextElement();

      Object value = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE);

      FeatureDescriptor featureDescriptor = getFeatureDescriptor(name, value, "request");

      featureDescriptors.add(featureDescriptor);
    }

    enumeration = pageContext.getAttributeNamesInScope(PageContext.SESSION_SCOPE);

    while (enumeration.hasMoreElements()) {
      String name = (String) enumeration.nextElement();

      Object value = pageContext.getAttribute(name, PageContext.SESSION_SCOPE);

      FeatureDescriptor featureDescriptor = getFeatureDescriptor(name, value, "session");

      featureDescriptors.add(featureDescriptor);
    }

    enumeration = pageContext.getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);

    while (enumeration.hasMoreElements()) {
      String name = (String) enumeration.nextElement();

      Object value = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE);

      FeatureDescriptor featureDescriptor = getFeatureDescriptor(name, value, "application");

      featureDescriptors.add(featureDescriptor);
    }

    return featureDescriptors.iterator();
  }
示例#6
0
文件: XmlNode.java 项目: hongun/ELite
 /** 返回上下文中唯一的文档对象. */
 public static Document getContextDocument(ELContext elctx) {
   Document doc = (Document) elctx.getContext(Document.class);
   if (doc == null) {
     try {
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       DocumentBuilder db = dbf.newDocumentBuilder();
       doc = db.newDocument();
       elctx.putContext(Document.class, doc);
     } catch (ParserConfigurationException ex) {
       throw new ELException(ex);
     }
   }
   return doc;
 }
  @Override
  public Object getValue(ELContext elContext, Object base, Object property) {
    if (elContext == null) {
      throw new NullPointerException();
    }

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

      if (property instanceof String) {
        String attribute = (String) property;

        PageContext pageContext = (PageContext) elContext.getContext(JspContext.class);

        return pageContext.findAttribute(attribute);
      }
    }

    return null;
  }
示例#8
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 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 (!BridgeUtil.isPortletRequest() || base != null) {
      return null;
    }
    if (property == null) {
      throw new PropertyNotFoundException("Null property");
    }

    FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
    ExternalContext extCtx = facesContext.getExternalContext();

    // only process if running in a portlet request
    // Bridge.PortletPhase phase =
    // (Bridge.PortletPhase)
    // FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
    // if (phase == null) {
    // return null;
    // }

    if (PORTLET_CONFIG.equals(property)) {
      context.setPropertyResolved(true);
      return context.getContext(PortletConfig.class);
    } else if (ACTION_REQUEST.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getRequest();
    } else if (ACTION_RESPONSE.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getResponse();
    } else if (RENDER_REQUEST.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getRequest();
    } else if (RENDER_RESPONSE.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getResponse();
    } else if (EVENT_REQUEST.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.EVENT_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getRequest();
    } else if (EVENT_RESPONSE.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.EVENT_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getResponse();
    } else if (RESOURCE_REQUEST.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RESOURCE_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getRequest();
    } else if (RESOURCE_RESPONSE.equals(property)
        && (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RESOURCE_PHASE)) {
      context.setPropertyResolved(true);
      return extCtx.getResponse();
    } else if (SESSION_APPLICATION_SCOPE.equals(property) || HTTP_SESSION_SCOPE.equals(property)) {
      context.setPropertyResolved(true);
      if (mAppScopeSessionMap == null) {
        Object request = extCtx.getRequest();
        // Object portletLifecycleAttr = extCtx.getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
        if (BridgeUtil.isPortletRequest()) {
          mAppScopeSessionMap = new PortletApplicationScopeSessionMap((PortletRequest) request);
        }
      }
      return mAppScopeSessionMap;
    } else if (SESSION_PORTLET_SCOPE.equals(property) || PORTLET_SESSION_SCOPE.equals(property)) {
      context.setPropertyResolved(true);
      return extCtx.getSessionMap();
    } else if (PORTLET_SESSION.equals(property)) {
      context.setPropertyResolved(true);
      return extCtx.getSession(false);
    } else if (PORTLET_PREFERENCE_VALUE.equals(property)) {
      context.setPropertyResolved(true);
      return getPreferencesValueMap(facesContext);
    } else if (PORTLET_PREFERENCES.equals(property)) {
      context.setPropertyResolved(true);
      return ((PortletRequest) extCtx.getRequest()).getPreferences();
    } else if (MUTABLE_PORTLET_PREFERENCES_VALUES.equals(property)) {
      context.setPropertyResolved(true);
      return getPreferenceMap(((PortletRequest) extCtx.getRequest()).getPreferences());
    } else {
      return null;
    }
    // }
  }
  /**
   * Return an <code>Iterator</code> over the attributes that this resolver knows how to deal with.
   *
   * @param context <code>ELContext</code> for evaluating this value
   * @param base Base object against which this evaluation occurs
   */
  public Iterator getFeatureDescriptors(ELContext context, Object base) {

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

    // Create the variables we will need
    FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
    ExternalContext econtext = fcontext.getExternalContext();
    List descriptors = new ArrayList();
    Map map = null;
    Set set = null;
    Iterator items = null;
    String key = null;
    Object value = null;

    // Add feature descriptors for request scoped attributes
    set = econtext.getRequestMap().entrySet();
    items = set.iterator();
    while (items.hasNext()) {
      Entry item = (Entry) items.next();
      key = (String) item.getKey();
      value = item.getValue();
      descriptors.add(
          descriptor(
              key,
              key,
              "Request Scope Attribute " + key,
              false,
              false,
              true,
              value.getClass(),
              true));
    }

    // Add feature descriptors for session scoped attributes
    set = econtext.getSessionMap().entrySet();
    items = set.iterator();
    while (items.hasNext()) {
      Entry item = (Entry) items.next();
      key = (String) item.getKey();
      value = item.getValue();
      descriptors.add(
          descriptor(
              key,
              key,
              "Session Scope Attribute " + key,
              false,
              false,
              true,
              value.getClass(),
              true));
    }

    // Add feature descriptors for application scoped attributes
    set = econtext.getApplicationMap().entrySet();
    items = set.iterator();
    while (items.hasNext()) {
      Entry item = (Entry) items.next();
      key = (String) item.getKey();
      value = item.getValue();
      descriptors.add(
          descriptor(
              key,
              key,
              "Application Scope Attribute " + key,
              false,
              false,
              true,
              value.getClass(),
              true));
    }

    // Return the accumulated descriptors
    return descriptors.iterator();
  }
示例#11
0
 public static ClassResolver getInstance(ELContext context) {
   ClassResolver cr = (ClassResolver) context.getContext(ClassResolver.class);
   if (cr == null) context.putContext(ClassResolver.class, cr = new ClassResolver());
   return cr;
 }