Beispiel #1
0
  private URL[] getResourceRoots(ExternalContext extContext, ClassLoader curLoader)
      throws IOException {
    URL[] combinedRoots;
    Enumeration<URL> classpathResourceEnumeration = curLoader.getResources("META-INF/resources/");
    List<URL> classpathResourceList = new ArrayList<URL>();
    while (classpathResourceEnumeration.hasMoreElements()) {
      classpathResourceList.add(classpathResourceEnumeration.nextElement());
    }

    // only called during init - safe to cast and save.
    URL u = extContext.getResource(SCRIPT_PATH);
    URL webappRoots[] = getWebappResourceRoots(extContext),
        classpathRoots[] = new URL[classpathResourceList.size()];
    classpathResourceList.toArray(classpathRoots);

    if (null != u || 0 < webappRoots.length || 0 < classpathRoots.length) {
      combinedRoots = new URL[webappRoots.length + classpathRoots.length + (null != u ? 1 : 0)];
      System.arraycopy(webappRoots, 0, combinedRoots, 0, webappRoots.length);
      System.arraycopy(classpathRoots, 0, combinedRoots, webappRoots.length, classpathRoots.length);
      if (null != u) {
        combinedRoots[webappRoots.length + classpathRoots.length] = u;
      }
    } else {
      combinedRoots = new URL[0];
    }

    return combinedRoots;
  }
Beispiel #2
0
 private URL[] getWebappResourceRoots(ExternalContext extContext) {
   URL[] result = null;
   int size = 0, i = 0;
   Set<String> resourceRoots = extContext.getResourcePaths("/resources/");
   if (null != resourceRoots && !resourceRoots.isEmpty()) {
     // Determine the size of script roots that end with "/"
     for (String cur : resourceRoots) {
       if (cur.endsWith("/")) {
         size++;
       }
     }
     result = new URL[size];
     for (String cur : resourceRoots) {
       if (cur.endsWith("/")) {
         try {
           result[i++] = extContext.getResource(cur);
         } catch (MalformedURLException ex) {
           if (LOGGER.isLoggable(Level.SEVERE)) {
             LOGGER.log(Level.SEVERE, null, ex);
           }
         }
       }
     }
   }
   if (null == result) {
     result = new URL[0];
   }
   return result;
 }