예제 #1
0
 /**
  * Search for a resource in a local path, or the main repository path.
  *
  * @param path the resource name
  * @param loaders optional list of module loaders
  * @param localRoot a repository to look first
  * @return the resource
  * @throws IOException if an I/O error occurred
  */
 public Resource findResource(String path, ModuleLoader[] loaders, Repository localRoot)
     throws IOException {
   // Note: as an extension to the CommonJS modules API
   // we allow absolute module paths for resources
   File file = new File(path);
   if (file.isAbsolute()) {
     Resource res;
     outer:
     if (loaders != null) {
       // loaders must contain at least one loader
       assert loaders.length > 0 && loaders[0] != null;
       for (ModuleLoader loader : loaders) {
         res = new FileResource(path + loader.getExtension());
         if (res.exists()) {
           break outer;
         }
       }
       res = new FileResource(path + loaders[0].getExtension());
     } else {
       res = new FileResource(file);
     }
     res.setAbsolute(true);
     return res;
   } else if (localRoot != null && (path.startsWith("./") || path.startsWith("../"))) {
     String newpath = localRoot.getRelativePath() + path;
     return findResource(newpath, loaders, null);
   } else {
     return config.getResource(normalizePath(path), loaders);
   }
 }