X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fresources%2FTransBundle_ResourceList.java;h=9983b8bc09915f16e26dbd67cbd391d097b345dd;hb=9e7330d793887fe9ee378ca1413141d7761e76ca;hp=e1c874034c0bd35024e9307e9e756cca4c30a68b;hpb=cd0c27d2e457ea19fcd9def879e1534a528292c2;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java b/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java deleted file mode 100644 index e1c8740..0000000 --- a/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java +++ /dev/null @@ -1,107 +0,0 @@ -package be.nikiroo.utils.resources; - -// code copied from from: -// http://forums.devx.com/showthread.php?t=153784, -// via: -// http://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.regex.Pattern; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -/** - * list resources available from the classpath @ * - */ -class TransBundle_ResourceList { - - /** - * for all elements of java.class.path get a Collection of resources Pattern - * pattern = Pattern.compile(".*"); gets all resources - * - * @param pattern - * the pattern to match - * @return the resources in the order they are found - */ - public static Collection getResources(final Pattern pattern) { - final ArrayList retval = new ArrayList(); - final String classPath = System.getProperty("java.class.path", "."); - final String[] classPathElements = classPath.split(System - .getProperty("path.separator")); - for (final String element : classPathElements) { - retval.addAll(getResources(element, pattern)); - } - - return retval; - } - - private static Collection getResources(final String element, - final Pattern pattern) { - final ArrayList retval = new ArrayList(); - final File file = new File(element); - if (file.isDirectory()) { - retval.addAll(getResourcesFromDirectory(file, pattern)); - } else { - retval.addAll(getResourcesFromJarFile(file, pattern)); - } - - return retval; - } - - private static Collection getResourcesFromJarFile(final File file, - final Pattern pattern) { - final ArrayList retval = new ArrayList(); - ZipFile zf; - try { - zf = new ZipFile(file); - } catch (final ZipException e) { - throw new Error(e); - } catch (final IOException e) { - throw new Error(e); - } - final Enumeration e = zf.entries(); - while (e.hasMoreElements()) { - final ZipEntry ze = e.nextElement(); - final String fileName = ze.getName(); - final boolean accept = pattern.matcher(fileName).matches(); - if (accept) { - retval.add(fileName); - } - } - try { - zf.close(); - } catch (final IOException e1) { - throw new Error(e1); - } - - return retval; - } - - private static Collection getResourcesFromDirectory( - final File directory, final Pattern pattern) { - final ArrayList retval = new ArrayList(); - final File[] fileList = directory.listFiles(); - for (final File file : fileList) { - if (file.isDirectory()) { - retval.addAll(getResourcesFromDirectory(file, pattern)); - } else { - try { - final String fileName = file.getCanonicalPath(); - final boolean accept = pattern.matcher(fileName).matches(); - if (accept) { - retval.add(fileName); - } - } catch (final IOException e) { - throw new Error(e); - } - } - } - - return retval; - } -}