/**
   * 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);
    }
  }
Exemplo n.º 2
0
  private boolean compressionPathIsValid(ClientResourceInfo resource) throws IOException {

    ExternalContext extContext = getFacesContext().getExternalContext();
    File tempDir = (File) extContext.getApplicationMap().get("javax.servlet.context.tempdir");
    File expected = new File(tempDir, "/jsf-compressed" + File.separatorChar + resource.getPath());
    return expected.getCanonicalPath().equals(resource.getCompressedPath());
  }
  /**
   * 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;
  }
Exemplo n.º 4
0
 public static ApplicationAssociate getInstance(ExternalContext externalContext) {
   if (externalContext == null) {
     return null;
   }
   Map applicationMap = externalContext.getApplicationMap();
   return ((ApplicationAssociate) applicationMap.get(ASSOCIATE_KEY));
 }
Exemplo n.º 5
0
 public GenericResource(Class entityClass) {
   // Get the EMF from the application scope
   ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
   Map<String, Object> attributes = context.getApplicationMap();
   EntityManagerFactory emf = (EntityManagerFactory) attributes.get("entityManagerFactory");
   entityManager = emf.createEntityManager();
   this.entityClass = entityClass;
 }
Exemplo n.º 6
0
 private Workspace getWorkspace() {
   ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
   Workspace ws =
       ((WorkspaceBean) ctx.getApplicationMap().get("workspace"))
           .getActiveWorkspace()
           .getNewWorkspace();
   return ws;
 }
Exemplo n.º 7
0
  public ApplicationAssociate(ApplicationImpl appImpl) {
    app = appImpl;

    propertyEditorHelper = new PropertyEditorHelper(appImpl);

    FacesContext ctx = FacesContext.getCurrentInstance();
    if (ctx == null) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.APPLICATION_ASSOCIATE_CTOR_WRONG_CALLSTACK_ID));
    }
    ExternalContext externalContext = ctx.getExternalContext();
    if (null != externalContext.getApplicationMap().get(ASSOCIATE_KEY)) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(MessageUtils.APPLICATION_ASSOCIATE_EXISTS_ID));
    }
    externalContext.getApplicationMap().put(ASSOCIATE_KEY, this);
    //noinspection CollectionWithoutInitialCapacity
    navigationMap = new ConcurrentHashMap<String, Set<NavigationCase>>();
    injectionProvider = InjectionProviderFactory.createInstance(externalContext);
    WebConfiguration webConfig = WebConfiguration.getInstance(externalContext);
    beanManager =
        new BeanManager(injectionProvider, webConfig.isOptionEnabled(EnableLazyBeanValidation));
    // install the bean manager as a system event listener for custom
    // scopes being destoryed.
    app.subscribeToEvent(PreDestroyCustomScopeEvent.class, ScopeContext.class, beanManager);
    annotationManager = new AnnotationManager();

    groovyHelper = GroovyHelper.getCurrentInstance();

    devModeEnabled = (appImpl.getProjectStage() == ProjectStage.Development);
    // initialize Facelets
    if (!webConfig.isOptionEnabled(DisableFaceletJSFViewHandler)) {
      compiler = createCompiler(webConfig);
      faceletFactory = createFaceletFactory(compiler, webConfig);
    }

    if (!devModeEnabled) {
      resourceCache = new ResourceCache();
    }

    resourceManager = new ResourceManager(resourceCache);
    namedEventManager = new NamedEventManager();
    applicationStateInfo = new ApplicationStateInfo();
  }
Exemplo n.º 8
0
  /**
   * Return the WebConfiguration instance for this application.
   *
   * @param extContext the ExternalContext for this request
   * @return the WebConfiguration for this application
   */
  public static WebConfiguration getInstance(ExternalContext extContext) {

    WebConfiguration config = (WebConfiguration) extContext.getApplicationMap().get(WEB_CONFIG_KEY);
    if (config == null) {
      return getInstance((ServletContext) extContext.getContext());
    } else {
      return config;
    }
  }
Exemplo n.º 9
0
 public static void clearInstance(ExternalContext externalContext) {
   Map applicationMap = externalContext.getApplicationMap();
   ApplicationAssociate me = (ApplicationAssociate) applicationMap.get(ASSOCIATE_KEY);
   if (null != me) {
     if (null != me.resourceBundles) {
       me.resourceBundles.clear();
     }
   }
   applicationMap.remove(ASSOCIATE_KEY);
 }
Exemplo n.º 10
0
  public ApplicationAssociate(ApplicationImpl appImpl) {
    app = appImpl;

    propertyEditorHelper = new PropertyEditorHelper(appImpl);

    FacesContext ctx = FacesContext.getCurrentInstance();
    if (ctx == null) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.APPLICATION_ASSOCIATE_CTOR_WRONG_CALLSTACK_ID));
    }
    ExternalContext externalContext = ctx.getExternalContext();
    if (null != externalContext.getApplicationMap().get(ASSOCIATE_KEY)) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(MessageUtils.APPLICATION_ASSOCIATE_EXISTS_ID));
    }
    externalContext.getApplicationMap().put(ASSOCIATE_KEY, this);
    //noinspection CollectionWithoutInitialCapacity
    caseListMap = new HashMap<String, List<ConfigNavigationCase>>();
    wildcardMatchList = new TreeSet<String>(new SortIt());
    injectionProvider = InjectionProviderFactory.createInstance(externalContext);
    WebConfiguration webConfig = WebConfiguration.getInstance(externalContext);
    beanManager =
        new BeanManager(
            injectionProvider,
            webConfig.isOptionEnabled(BooleanWebContextInitParameter.EnableLazyBeanValidation));
    annotationManager = new AnnotationManager();

    groovyHelper = GroovyHelper.getCurrentInstance();

    // initialize Facelets
    if (!webConfig.isOptionEnabled(BooleanWebContextInitParameter.DisableFaceletJSFViewHandler)) {
      compiler = createCompiler(webConfig);
      faceletFactory = createFaceletFactory(compiler, webConfig);
      devModeEnabled = (appImpl.getProjectStage() == ProjectStage.Development);
    }

    if (devModeEnabled) {
      resourceCache = new ResourceCache();
    }
    resourceManager = new ResourceManager(resourceCache);
  }
Exemplo n.º 11
0
  /**
   * Loads the contents of the sunjsf.js file into memory removing any comments/empty lines it
   * encoutners, and, if enabled, compressing the result. This method should only be called when the
   * application is being initialized.
   *
   * @param extContext the ExternalContext for this application
   */
  public static synchronized void loadSunJsfJs(ExternalContext extContext) {
    Map<String, Object> appMap = extContext.getApplicationMap();
    char[] sunJsfJs;

    BufferedReader reader = null;
    try {
      // Don't use Util.getCurrentLoader().  This JS resource should
      // be available from the same classloader that loaded RenderKitUtils.
      // Doing so allows us to be more OSGi friendly.
      URL url = RenderKitUtils.class.getClassLoader().getResource("com/sun/faces/sunjsf.js");
      if (url == null) {
        LOGGER.severe("jsf.renderkit.util.cannot_load_js");
        return;
      }
      URLConnection conn = url.openConnection();
      conn.setUseCaches(false);
      InputStream input = conn.getInputStream();
      reader = new BufferedReader(new InputStreamReader(input));
      StringBuilder builder = new StringBuilder(128);
      for (String line = reader.readLine(); line != null; line = reader.readLine()) {

        String temp = line.trim();
        if (temp.length() == 0
            || temp.startsWith("/*")
            || temp.startsWith("*")
            || temp.startsWith("*/")
            || temp.startsWith("//")) {
          continue;
        }
        builder.append(line).append('\n');
      }
      builder.deleteCharAt(builder.length() - 1);
      if (WebConfiguration.getInstance(extContext)
          .isOptionEnabled(BooleanWebContextInitParameter.CompressJavaScript)) {
        sunJsfJs = compressJS(builder.toString());
      } else {
        sunJsfJs = builder.toString().toCharArray();
      }
      appMap.put(SUN_JSF_JS, sunJsfJs);
    } catch (IOException ioe) {
      LOGGER.log(Level.SEVERE, "jsf.renderkit.util.cannot_load_js", ioe);
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException ioe) {
          // ignore
        }
      }
    }
  }
Exemplo n.º 12
0
    public FactoryManagerCacheKey(
        FacesContext facesContext,
        ClassLoader cl,
        Map<FactoryManagerCacheKey, FactoryManager> factoryMap) {
      this.cl = cl;
      boolean resolveValueFromFactoryMap = false;

      if (null == facesContext) {
        resolveValueFromFactoryMap = true;
      } else {
        ExternalContext extContext = facesContext.getExternalContext();
        context = extContext.getContext();
        if (null == context) {
          resolveValueFromFactoryMap = true;
        } else {
          Map<String, Object> appMap = extContext.getApplicationMap();

          Long val = (Long) appMap.get(KEY);
          if (null == val) {
            marker = new Long(System.currentTimeMillis());
            appMap.put(KEY, marker);
          } else {
            marker = val;
          }
        }
      }
      if (resolveValueFromFactoryMap) {
        // We don't have a FacesContext.
        // Our only recourse is to inspect the keys of the
        // factoryMap and see if any of them has a classloader
        // equal to our argument cl.
        Set<FactoryManagerCacheKey> keys = factoryMap.keySet();
        FactoryManagerCacheKey match = null;
        for (FactoryManagerCacheKey cur : keys) {
          if (this.cl.equals(cur.cl)) {
            if (null != cur && null != match) {
              LOGGER.log(
                  Level.WARNING,
                  "Multiple JSF Applications found on same ClassLoader.  Unable to safely determine which FactoryManager instance to use. Defaulting to first match.");
              break;
            }
            match = cur;
          }
        }
        if (null != match) {
          this.marker = match.marker;
        }
      }
    }
  /**
   * Returns the value of the PPR optimization parameter. We currently support "on" and "off"
   *
   * @param context
   * @return
   */
  private static String _getPprOptimization(FacesContext context) {
    ExternalContext external = context.getExternalContext();

    Map<String, Object> applicationMap = external.getApplicationMap();

    // first check if this has been overridden at the application level
    String pprOptimization = (String) applicationMap.get(_PPR_OPTIMIZATION_PROP);

    if (pprOptimization == null) {
      // the value hasn't been set, so check the initialization parameter
      pprOptimization = external.getInitParameter(_PPR_OPTIMIZATION_PROP);

      // default to "off"
      if (pprOptimization == null) pprOptimization = "off";

      // cache in the application so that we don't need to fetch this again
      applicationMap.put(_PPR_OPTIMIZATION_PROP, pprOptimization);
    }

    return pprOptimization;
  }
Exemplo n.º 14
0
  GroovyHelperImpl() throws Exception {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext extContext = facesContext.getExternalContext();
    ClassLoader curLoader = Thread.currentThread().getContextClassLoader();

    URL combinedRoots[] = getResourceRoots(extContext, curLoader);

    if (0 < combinedRoots.length) {
      GroovyScriptEngine engine = new GroovyScriptEngine(combinedRoots, curLoader);
      //            Class<?> c = Util.loadClass("groovy.util.GroovyScriptEngine",
      // GroovyHelperFactory.class);
      //            Constructor<?> ctor = c.getConstructor(URL[].class, ClassLoader.class);
      //            GroovyScriptEngine engine = (GroovyScriptEngine)ctor.newInstance(combinedRoots,
      // curLoader);
      loader = new MojarraGroovyClassLoader(engine);
      if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO, "Groovy support enabled.");
      }
      extContext.getApplicationMap().put("com.sun.faces.groovyhelper", this);
      ((ServletContext) (extContext.getContext())).setAttribute("com.sun.faces.groovyhelper", this);
    }
  }
Exemplo n.º 15
0
 @Produces
 @ApplicationMap
 public Map<String, Object> getApplicationMap(ExternalContext externalContext) {
   return externalContext.getApplicationMap();
 }
  /**
   * 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();
  }
Exemplo n.º 17
0
 @SuppressWarnings("unchecked")
 public Handler(RequestContextBean bean, ExternalContext context) {
   _applicationMap = context.getApplicationMap();
   _bean = bean;
 }