|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.andromda.core.common.ResourceUtils
public class ResourceUtils
Provides utilities for loading resources.
| Constructor Summary | |
|---|---|
ResourceUtils()
|
|
| Method Summary | |
|---|---|
static void |
deleteDirectory(java.io.File directory)
Recursively deletes a directory and its contents. |
static java.util.zip.ZipFile |
getArchive(java.net.URL resource)
If this resource is an archive file, it will return the resource as an archive. |
static java.util.List |
getClassPathArchiveContents(java.net.URL resource)
If the resource represents a classpath archive (i.e. |
static java.net.URL |
getClassResource(java.lang.String className)
Takes a className as an argument and returns the URL for the class. |
static java.lang.String |
getContents(java.io.Reader resource)
Loads the resource and returns the contents as a String. |
static java.lang.String |
getContents(java.lang.String resourceName)
Loads the file resource and returns the contents as a String. |
static java.lang.String |
getContents(java.net.URL resource)
Loads the resource and returns the contents as a String. |
static java.util.List |
getDirectoryContents(java.net.URL url,
boolean absolute,
java.lang.String[] patterns)
Gets the contents of this directory and any of its sub directories based on the given patterns. |
static java.util.List |
getDirectoryContents(java.net.URL resource,
int levels)
If this resource happens to be a directory, it will load the contents of that directory into a
List and return the list of names relative to the given resource (otherwise it will return an empty
List). |
static java.util.List |
getDirectoryContents(java.net.URL resource,
int levels,
boolean includeSubdirectories)
If this resource happens to be a directory, it will load the contents of that directory into a
List and return the list of names relative to the given resource (otherwise it will return an empty
List). |
static long |
getLastModifiedTime(java.net.URL resource)
Gets the time as a long when this resource was last modified. |
static java.net.URL |
getResource(java.lang.String resourceName)
Retrieves a resource from the current classpath. |
static java.net.URL |
getResource(java.lang.String resourceName,
java.lang.String directory)
Retrieves a resource from an optionally given directory or from the package on the classpath. |
static java.net.URL |
getResource(java.lang.String resourceName,
java.net.URL directory)
Retrieves a resource from an optionally given directory or from the package on the classpath. |
static boolean |
isArchive(java.net.URL resource)
Returns true/false on whether or not this resource represents an archive or not (i.e. |
static boolean |
isFile(java.net.URL url)
Indicates whether or not the given url is a file. |
static void |
makeDirectories(java.lang.String location)
Makes the directory for the given location if it doesn't exist. |
static boolean |
matchesAtLeastOnePattern(java.lang.String path,
java.lang.String[] patterns)
Indicates whether or not the given path matches on
one or more of the patterns defined within this class
returns true if no patterns are defined. |
static boolean |
modifiedAfter(long time,
java.io.File directory)
Indicates whether or not the contents of the given directory
and any of its sub directories have been modified after the given time. |
static java.lang.String |
normalizePath(java.lang.String path)
Removes any extra path separators and converts all from back slashes to forward slashes. |
static java.lang.String |
renameExtension(java.lang.String path,
java.lang.String oldExtension,
java.lang.String newExtension)
Takes a path and replaces the oldException with the newExtension. |
static java.net.URL |
resolveClasspathResource(java.lang.String path)
Resolves a URL to a classpath resource, this method will treat occurrences of the exclamation mark similar to what URL does with the jar:file protocol. |
static java.net.URL |
toURL(java.lang.String path)
Attempts to construct the given path
to a URL instance. |
static java.lang.String |
unescapeFilePath(java.lang.String filePath)
Replaces any escape characters in the given file path with their counterparts. |
static void |
writeUrlToFile(java.net.URL url,
java.lang.String fileLocation,
java.lang.String encoding)
Writes the URL contents to a file specified by the fileLocation argument. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ResourceUtils()
| Method Detail |
|---|
public static java.net.URL getResource(java.lang.String resourceName)
resourceName - the name of the resource
public static java.lang.String getContents(java.net.URL resource)
resource - the name of the resource.
public static java.lang.String getContents(java.io.Reader resource)
resource - the name of the resource.
public static java.util.List getClassPathArchiveContents(java.net.URL resource)
resource represents a classpath archive (i.e. jar, zip, etc), this method will retrieve all
contents from that resource as a List of relative paths (relative to the archive base). Otherwise an empty List
will be returned.
resource - the resource from which to retrieve the contents
public static java.util.List getDirectoryContents(java.net.URL resource,
int levels)
resource happens to be a directory, it will load the contents of that directory into a
List and return the list of names relative to the given resource (otherwise it will return an empty
List).
resource - the resource from which to retrieve the contentslevels - the number of levels to step down if the resource ends up being a directory (if its an artifact,
levels will be ignored).
public static java.lang.String unescapeFilePath(java.lang.String filePath)
filePath - the path of the file to unescape.
public static java.util.List getDirectoryContents(java.net.URL resource,
int levels,
boolean includeSubdirectories)
resource happens to be a directory, it will load the contents of that directory into a
List and return the list of names relative to the given resource (otherwise it will return an empty
List).
resource - the resource from which to retrieve the contentslevels - the number of levels to step down if the resource ends up being a directory (if its an artifact,
levels will be ignored).includeSubdirectories - whether or not to include subdirectories in the contents.
public static boolean isArchive(java.net.URL resource)
resource represents an archive or not (i.e. jar, or zip,
etc).
public static java.util.zip.ZipFile getArchive(java.net.URL resource)
resource is an archive file, it will return the resource as an archive.
public static java.lang.String getContents(java.lang.String resourceName)
resourceName - the name of the resource.
public static java.net.URL getClassResource(java.lang.String className)
className -
public static java.net.URL getResource(java.lang.String resourceName,
java.lang.String directory)
directory or from the package on the classpath.
If the directory is specified and is a valid directory then an attempt at finding the resource by appending the
resourceName to the given directory will be made, otherwise an attempt to find the
resourceName directly on the classpath will be initiated.
resourceName - the name of a resourcedirectory - the directory location
public static void makeDirectories(java.lang.String location)
location - the location to make the directory.public static long getLastModifiedTime(java.net.URL resource)
long when this resource was last modified.
If it can not be determined 0 is returned.
resource - the resource from which to retrieve
the last modified time.
public static java.net.URL getResource(java.lang.String resourceName,
java.net.URL directory)
Retrieves a resource from an optionally given directory or from the package on the classpath.
resourceName to the given directory will be made, otherwise an attempt to find the
resourceName directly on the classpath will be initiated.
resourceName - the name of a resourcedirectory - the directory location
public static java.net.URL toURL(java.lang.String path)
path
to a URL instance. If the argument cannot be resolved as a resource
on the file system this method will attempt to locate it on the
classpath.
path - the path from which to construct the URL.
public static java.net.URL resolveClasspathResource(java.lang.String path)
URL does with the jar:file protocol.
Example: my/path/to/some.zip!/file.xml represents a resource file.xml
that is located in a ZIP file on the classpath called my/path/to/some.zip
It is possible to have nested ZIP files, example:
my/path/to/first.zip!/subdir/second.zip!/file.xml.
Please note that the extension of the ZIP file can be anything,
but in the case the extension is .jar the JVM will automatically unpack resources
one level deep and put them all on the classpath
path - the name of the resource to resolve to a URL, potentially nested in ZIP archives
null if the argument is null or impossible to resolve
public static void writeUrlToFile(java.net.URL url,
java.lang.String fileLocation,
java.lang.String encoding)
throws java.io.IOException
url - the URL to readfileLocation - the location which to write.encoding - the optional encoding
java.io.IOExceptionpublic static boolean isFile(java.net.URL url)
url is a file.
url - the URL to check.
public static void deleteDirectory(java.io.File directory)
directory - the directory to delete.
public static java.util.List getDirectoryContents(java.net.URL url,
boolean absolute,
java.lang.String[] patterns)
patterns.
And returns absolute or relative paths depending on the value of absolute.
url - the URL of the directory.absolute - whether or not the returned content paths should be absoluate (if
false paths will be relative to URL).
public static boolean matchesAtLeastOnePattern(java.lang.String path,
java.lang.String[] patterns)
path matches on
one or more of the patterns defined within this class
returns true if no patterns are defined.
path - the path to match on.
public static boolean modifiedAfter(long time,
java.io.File directory)
directory
and any of its sub directories have been modified after the given time.
directory - the directory to checktime - the time to check against
public static java.lang.String normalizePath(java.lang.String path)
path - the path to normalize.
public static java.lang.String renameExtension(java.lang.String path,
java.lang.String oldExtension,
java.lang.String newExtension)
path - the path to rename.oldExtension - the extension to rename from.newExtension - the extension to rename to.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||