Ejemplo n.º 1
0
 private static XmlNode combine(XmlNode appNode, XmlNode compNode) {
   XmlNode result = new XmlNode(appNode.getNodeName());
   result.setAttribute(compNode.getAttributes());
   result.setAttribute(appNode.getAttributes());
   if (!CollectionUtil.isEmpty(compNode.getSubNodes())) {
     result.addAll(compNode.getSubNodes());
   }
   if (!CollectionUtil.isEmpty(appNode.getSubNodes())) {
     result.addAll(appNode.getSubNodes());
   }
   return result;
 }
  private void doRetrieveMatchingFiles(
      String fullPattern, String subPattern, File dir, Set<Resource> result) throws IOException {
    LOGGER.logMessage(
        LogLevel.DEBUG,
        "Searching directory ["
            + dir.getAbsolutePath()
            + "] for files matching pattern ["
            + fullPattern
            + "]");
    File[] dirContents = dir.listFiles();
    if (dirContents == null) {
      LOGGER.logMessage(
          LogLevel.WARN,
          "Could not retrieve contents of directory [" + dir.getAbsolutePath() + "]");
      return;
    }
    for (File content : dirContents) {
      String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
      if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
        if (!content.canRead()) {
          LOGGER.logMessage(
              LogLevel.DEBUG,
              "Skipping subdirectory ["
                  + dir.getAbsolutePath()
                  + "] because the application is not allowed to read the directory");
        } else {
          doRetrieveMatchingFiles(fullPattern, subPattern, content, result);
        }
      }

      // can accurately judge by : new JarFile(content);
      if (content.isFile() && content.getName().endsWith(".jar")) {
        // JarFile jarFile= new JarFile(content);
        URL jarFileUrl = new URL("jar:" + content.toURI() + "!/");
        LOGGER.logMessage(LogLevel.INFO, "find match jar resource [{0}]", jarFileUrl.toString());
        Resource dirRes = new UrlResource(jarFileUrl);
        Set<Resource> resources = doFindPathMatchingJarResources(dirRes, subPattern);
        if (!CollectionUtil.isEmpty(resources)) {
          result.addAll(resources);
        }
      }

      if (getPathMatcher().match(fullPattern, currPath)) {
        result.add(new FileSystemResource(content));
      }
    }
  }
 /**
  * Find all class location resources with the given location via the ClassLoader.
  *
  * @param location the absolute path within the classpath
  * @return the result as Resource array
  * @throws IOException in case of I/O errors
  * @see java.lang.ClassLoader#getResources
  * @see #convertClassLoaderURL
  */
 protected Resource[] findAllClassPathResources(String location) throws IOException {
   Set<Resource> result = new LinkedHashSet<Resource>(16);
   List<String> scanPaths = getScanPaths();
   if (CollectionUtil.isEmpty(scanPaths)) {
     return super.findAllClassPathResources(location);
   }
   for (String path : scanPaths) {
     File file = new File(path);
     if (file.exists()) {
       Resource resource = null;
       if (path.endsWith(".jar")) {
         URL jarFileUrl = new URL("jar:" + file.toURI() + "!/");
         LOGGER.logMessage(LogLevel.INFO, "find match jar resource [{0}]", jarFileUrl.toString());
         resource = new UrlResource(jarFileUrl);
       } else {
         resource = new FileSystemResource(path);
       }
       result.add(resource);
     }
   }
   return result.toArray(new Resource[result.size()]);
 }