示例#1
0
 /**
  * Returns whether JAR entry with the specified name is allowed by the extensions list or not.
  *
  * @param entryName JAR entry name
  * @param allowedExtensions list of allowed extensions
  * @return true if JAR entry with the specified name is allowed by the extensions list, false
  *     otherwise
  */
 private static boolean isAllowedExtension(
     final String entryName, final List<String> allowedExtensions) {
   if (allowedExtensions == null || allowedExtensions.size() == 0) {
     return true;
   } else {
     final String entryExt = FileUtils.getFileExtPart(entryName, true).toLowerCase();
     return allowedExtensions.contains(entryExt);
   }
 }
示例#2
0
 /**
  * Returns JAR entry type.
  *
  * @param file file to process
  * @return JAR entry type
  */
 private static JarEntryType getJarEntryType(final String file) {
   final String ext = FileUtils.getFileExtPart(file, false);
   if (ext.equals("java")) {
     return JarEntryType.javaEntry;
   } else if (ext.equals("class")) {
     return JarEntryType.classEntry;
   } else if (!ext.isEmpty()) {
     return JarEntryType.fileEntry;
   } else {
     return JarEntryType.packageEntry;
   }
 }
示例#3
0
  /**
   * Returns JAR archive structure.
   *
   * @param jarClass any class within the JAR
   * @param allowedExtensions list of extension filters
   * @param allowedPackgages list of allowed packages
   * @param listener jar download listener
   * @return JAR archive structure
   */
  public static JarStructure getJarStructure(
      final Class jarClass,
      final List<String> allowedExtensions,
      final List<String> allowedPackgages,
      final FileDownloadListener listener) {
    try {
      final CodeSource src = jarClass.getProtectionDomain().getCodeSource();
      if (src != null) {
        // Creating structure

        // Source url
        final URL jarUrl = src.getLocation();
        final URI uri = jarUrl.toURI();

        // Source file
        final File jarFile;
        final String scheme = uri.getScheme();
        if (scheme != null && scheme.equalsIgnoreCase("file")) {
          // Local jar-file
          jarFile = new File(uri);
        } else {
          // Remote jar-file
          jarFile =
              FileUtils.downloadFile(
                  jarUrl.toString(), File.createTempFile("jar_file", ".tmp"), listener);
        }

        // Creating
        final JarEntry jarEntry = new JarEntry(JarEntryType.jarEntry, jarFile.getName());
        final JarStructure jarStructure = new JarStructure(jarEntry);
        jarStructure.setJarLocation(jarFile.getAbsolutePath());

        // Reading all entries and parsing them into structure
        final ZipInputStream zip = new ZipInputStream(jarUrl.openStream());
        ZipEntry zipEntry;
        while ((zipEntry = zip.getNextEntry()) != null) {
          final String entryName = zipEntry.getName();
          if (isAllowedPackage(entryName, allowedPackgages)
              && (zipEntry.isDirectory() || isAllowedExtension(entryName, allowedExtensions))) {
            parseElement(jarEntry, entryName, zipEntry);
          }
        }
        zip.close();

        return jarStructure;
      }
    } catch (final IOException e) {
      FlatLafLogger.error(ReflectUtils.class, e);
    } catch (final URISyntaxException e) {
      FlatLafLogger.error(ReflectUtils.class, e);
    }
    return null;
  }
 /** {@inheritDoc} */
 @Override
 public boolean isLeaf(final FileTreeNode node) {
   return node.getFile() != null && !FileUtils.isDirectory(node.getFile());
 }