Class Resource
java.lang.Object
org.nuiton.util.Resource
Cette class permet de rechercher un fichier en indiquant son nom avec son
chemin. Cette librairie ira ensuite chercher ce fichier sur le système de
fichier, et s'il n'est pas trouvé dans le classpath. Le fichier peut donc
être dans un fichier .jar ou .zip. Exemple :
URL image = Resource.getURL("/images/bidulle.png");
Created: 5 août 2003- Author:
- Benjamin Poussin - poussin@codelutin.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsDirectDirectory(URL url, String directory) Test if an url contains the given directory with no recurse seeking.doFindMatchingFileSystemResources(URL rootDirResource, String subPattern) Find all resources in the file system that match the given location pattern via the Java style matcher.doFindPathMatchingJarResources(URL rootDirResource, String subPattern) Find all resources in jar files that match the given location pattern via the Java Regex style Matcher.protected static voiddoRetrieveMatchingFiles(String fullPattern, File dir, List<URL> result) Recursively retrieve files that match the given pattern, adding them to the given result list.static URL[]getClassPathURLsFromJarManifest(URL jarURL) static ImageIconRetourne l'icone demandee.getPatternRessources(String pattern, ClassLoader classLoader) Obtain some resources from a pattern using a specific class loader to seel resources.getResources(String pattern) Find pattern resouces inClassLoader.getSystemClassLoader().getResources(String pattern, ClassLoader classLoader) Find pattern resouces in classloader.static URLRecherche la ressource nom.static URLgetURLOrNull(String name) Recherche la ressource nom.Retourner la liste des fichiers du classLoader.Retourner la liste des fichiers du classLoader.getURLs(String pattern, URLClassLoader urlClassLoader) Retourner la liste des fichiers du classLoader.getURLsFromDirectory(File repository, String pattern) Retourne la liste des fichiers correspondant au pattern donne, aucun ordre ne doit être supposé sur les fichiers.getURLsFromJar(File jarfile, String pattern) getURLsFromZip(File zipFile, String pattern) static booleanVerifie si le fichier est un fichier jar.static booleanTest if an url detnoe a jar file.protected static booleanReturn true ifstris a pattern (contains * or ?).static booleanVerifie si le fichier est un fichier zipretrieveMatchingFiles(File rootDir, String pattern) Retrieve files that match the given path pattern, checking the given directory and its subdirectories.walkThroughClassLoaderAndGetURLs(String pattern)
-
Constructor Details
-
Resource
protected Resource()
-
-
Method Details
-
getURL
Recherche la ressource nom.- Parameters:
name- nom de la ressource- Returns:
- l'url de la ressource
- Throws:
ResourceNotFoundException- si la resource n'a pas ete trouvee
-
getURLOrNull
-
getIcon
-
getURLs
Retourner la liste des fichiers du classLoader. Ces fichiers doivent correspondre au pattern donne. Utile par defautClassLoader.getSystemClassLoader().- Parameters:
pattern- le nom du fichier a extraire du fichier compressé ou du repertoire doit correspondre au pattern (repertoire + nom compris).- Returns:
- la liste des urls correspondant au pattern
-
getURLs
Retourner la liste des fichiers du classLoader. Ces fichiers doivent correspondre au pattern donne.- Parameters:
pattern- le nom du fichier a extraire du fichier compressé ou du repertoire doit correspondre au pattern (repertoire + nom compris).urlClassLoader- classloader to use (if null, useClassLoader.getSystemClassLoader()- Returns:
- la liste des urls correspondant au pattern
-
walkThroughClassLoaderAndGetURLs
-
getURLs
Retourner la liste des fichiers du classLoader. Ces fichiers doivent correspondre au pattern donne.- Parameters:
pattern- le nom du fichier a extraire du fichier compressé ou dur epertoire doit correspondre au pattern (repertoire + nom compris).arrayURL- les urls ou chercher- Returns:
- la liste des urls correspondant au pattern
-
getClassPathURLsFromJarManifest
- Throws:
IOException
-
getURLsFromZip
-
getURLsFromJar
-
getURLsFromDirectory
Retourne la liste des fichiers correspondant au pattern donne, aucun ordre ne doit être supposé sur les fichiers.- Parameters:
repository- repertoire dans lequel on recherche les fichierspattern- le nom du fichier a extraire du fichier du repertoire doit correspondre au pattern (repertoire + nom compris). si le pattern est null, tous les fichiers trouvé sont retourné.- Returns:
- la liste des urls correspondant au pattern
-
isJar
Verifie si le fichier est un fichier jar.- Parameters:
name- nom du fichier a tester- Returns:
- vrai si le fichier se termine par .jar faux sinon
-
isZip
Verifie si le fichier est un fichier zip- Parameters:
name- nom du fichier a tester- Returns:
- vrai si le fichier se termine par .zip faux sinon
-
containsDirectDirectory
Test if an url contains the given directory with no recurse seeking.- Parameters:
url- the url to seekdirectory- the directory to find- Returns:
trueif directory was found,falseotherwise.- Throws:
IOException- if any io pb
-
isPattern
Return true ifstris a pattern (contains * or ?).- Parameters:
str- str to test- Returns:
trueifstris a pattern,falseotherwise- Since:
- 2.2
-
getResources
Find pattern resouces inClassLoader.getSystemClassLoader(). Usage :List<URL> urls = Resources.getResources("META-INF/.*\\.MF"); List<URL> urls = Resources.getResources("org/nuiton/util/.?esource\\.class");- Parameters:
pattern- java regex style pattern to find- Returns:
- url list found
- Throws:
IOException- if any IO problem while seeking resources- Since:
- 2.2
-
getResources
Find pattern resouces in classloader. Usage :List<URL> urls = Resources.getResources("META-INF/.*\\.MF"); List<URL> urls = Resources.getResources("org/nuiton/util/.?esource\\.class");- Parameters:
pattern- java regex style pattern to findclassLoader- classLoader- Returns:
- url list found
- Throws:
IOException- if any IO problem while seeking resources- Since:
- 2.2
-
getPatternRessources
protected static List<URL> getPatternRessources(String pattern, ClassLoader classLoader) throws IOException Obtain some resources from a pattern using a specific class loader to seel resources.- Parameters:
pattern- pattern of searched resourcesclassLoader- class loader which responsible to seek resources- Returns:
- list of resources found
- Throws:
IOException- if any IO problem while scanning resources- Since:
- 2.2
-
isJarUrl
Test if an url detnoe a jar file. Code taken from spring source code : org.springframework.core.io.support.PathMatchingResourcePatternResolver- Parameters:
url- url to test- Returns:
- true if url denote a jar file
- Since:
- 2.2
-
doFindPathMatchingJarResources
protected static List<URL> doFindPathMatchingJarResources(URL rootDirResource, String subPattern) throws IOException Find all resources in jar files that match the given location pattern via the Java Regex style Matcher. Code taken from spring source code : org.springframework.core.io.support.PathMatchingResourcePatternResolver- Parameters:
rootDirResource- the root directory as ResourcesubPattern- the sub pattern to match (below the root directory)- Returns:
- the Set of matching Resource instances
- Throws:
IOException- in case of I/O errors- Since:
- 2.2
- See Also:
-
doFindMatchingFileSystemResources
protected static List<URL> doFindMatchingFileSystemResources(URL rootDirResource, String subPattern) throws IOException Find all resources in the file system that match the given location pattern via the Java style matcher. Code taken from spring source code : org.springframework.core.io.support.PathMatchingResourcePatternResolver- Parameters:
rootDirResource- the root directory as ResourcesubPattern- the sub pattern to match (below the root directory)- Returns:
- the Set of matching Resource instances
- Throws:
IOException- in case of I/O errors- Since:
- 2.2
- See Also:
-
retrieveMatchingFiles
Retrieve files that match the given path pattern, checking the given directory and its subdirectories. Code taken from spring source code : org.springframework.core.io.support.PathMatchingResourcePatternResolver- Parameters:
rootDir- the directory to start frompattern- the pattern to match against, relative to the root directory- Returns:
- the Set of matching File instances
- Throws:
IOException- if directory contents could not be retrieved- Since:
- 2.2
-
doRetrieveMatchingFiles
protected static void doRetrieveMatchingFiles(String fullPattern, File dir, List<URL> result) throws IOException Recursively retrieve files that match the given pattern, adding them to the given result list. Code taken from spring source code : org.springframework.core.io.support.PathMatchingResourcePatternResolver- Parameters:
fullPattern- the pattern to match against, with preprended root directory pathdir- the current directoryresult- the Set of matching File instances to add to- Throws:
IOException- if directory contents could not be retrieved- Since:
- 2.2
-