|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opensourcephysics.tools.ResourceLoader
public class ResourceLoader
This defines static methods for loading resources.
| Field Summary | |
|---|---|
protected static java.util.ArrayList<java.lang.String> |
appletSearchPaths
|
protected static boolean |
cacheEnabled
|
protected static boolean |
canceled
|
protected static java.util.Set<java.lang.String> |
extractExtensions
|
protected static java.lang.String |
LINUX_DEFAULT_CACHE
|
protected static int |
maxPaths
|
static java.io.FileFilter |
OSP_CACHE_FILTER
|
protected static java.io.File |
ospCache
|
protected static java.lang.String |
OSX_DEFAULT_CACHE
|
protected static java.util.ArrayList<java.lang.String> |
pathsNotFound
|
protected static java.util.Hashtable<java.lang.String,Resource> |
resources
|
protected static java.lang.String |
SEARCH_CACHE_SUBDIRECTORY
|
protected static java.util.ArrayList<java.lang.String> |
searchPaths
|
protected static java.lang.String |
WIN_XP_DEFAULT_CACHE
|
protected static java.lang.String |
WINDOWS_DEFAULT_CACHE
|
protected static java.net.URLClassLoader |
xsetZipLoader
|
protected static java.util.Map<java.lang.String,java.net.URLClassLoader> |
zipLoaders
|
protected static boolean |
zipURLsOK
|
| Method Summary | |
|---|---|
static void |
addAppletSearchPath(java.lang.String base)
Adds a search path at the beginning of the applet's search path list. |
static void |
addExtractExtension(java.lang.String extension)
Adds an extension to the end of the extractExtensions list. |
static void |
addSearchPath(java.lang.String base)
Adds a path at the beginning of the searchPaths list. |
static java.io.File |
chooseOSPCache(java.awt.Component parent)
Uses a JFileChooser to select a cache directory. |
static boolean |
clearOSPCache(java.io.File cache,
boolean clearSearchCache)
Clears an OSP cache. |
static boolean |
clearOSPCacheHost(java.io.File hostDir)
Clears an OSP cache host directory. |
static boolean |
copyAllFiles(java.io.File inFile,
java.io.File outFile)
Copies a source file to a target file. |
static java.io.File |
copyHTMLToOSPCache(java.lang.String htmlPath)
Copies an HTML file with associated images and stylesheet to the OSP cache. |
static boolean |
deleteFile(java.io.File file)
Deletes a file or folder. |
static java.io.File |
download(java.lang.String urlPath,
java.io.File target,
boolean alwaysOverwrite)
Downloads a file from the web to a target File. |
static java.io.File |
downloadToOSPCache(java.lang.String urlPath,
java.lang.String fileName,
boolean alwaysOverwrite)
Downloads a file from the web to the OSP Cache. |
static java.io.File |
extractFileFromZIP(java.lang.String source,
java.io.File target,
boolean alwaysOverwrite)
Extracts a file from a ZIP archive to a target file. |
static java.applet.AudioClip |
getAudioClip(java.lang.String path)
Gets an audio clip. |
static java.awt.image.BufferedImage |
getBufferedImage(java.lang.String path)
Gets a buffered image. |
static java.awt.image.BufferedImage |
getBufferedImage(java.lang.String path,
int bufferedImageType)
Gets a buffered image. |
static java.io.File |
getDefaultOSPCache()
Gets the default directory for cached files. |
static java.util.List<java.io.File> |
getFiles(java.io.File directory,
java.io.FileFilter filter)
Gets the list of files in a directory and its subdirectories that are accepted by a FileFilter. |
static java.lang.String |
getHTMLCode(java.lang.String path)
Returns the HTML code for a local or web HTML page. |
static javax.swing.ImageIcon |
getIcon(java.lang.String path)
Gets an image icon. |
static java.awt.Image |
getImage(java.lang.String path)
Gets an image. |
static java.lang.String |
getNonURIPath(java.lang.String uriPath)
Removes protocol and "%20" from URI paths. |
static java.io.File |
getOSPCache()
Gets the directory for cached files. |
static java.io.File |
getOSPCacheFile(java.lang.String urlPath)
Gets the cache file associated with a URL path. |
static java.io.File |
getOSPCacheFile(java.lang.String urlPath,
java.lang.String name)
Gets the cache file associated with a URL path. |
static Resource |
getResource(java.lang.String name)
Gets a resource specified by name. |
static Resource |
getResource(java.lang.String name,
boolean searchFiles)
Gets a resource specified by name. |
static Resource |
getResource(java.lang.String name,
java.lang.Class<?> type)
Gets a resource specified by name and Class. |
static Resource |
getResource(java.lang.String name,
java.lang.Class<?> type,
boolean searchFiles)
Gets a resource specified by name and Class. |
static Resource |
getResource(java.lang.String basePath,
java.lang.String name)
Gets a resource specified by base path and name. |
static Resource |
getResource(java.lang.String basePath,
java.lang.String name,
boolean searchFiles)
Gets a resource specified by base path and name. |
static Resource |
getResource(java.lang.String basePath,
java.lang.String name,
java.lang.Class<Resource> type)
Gets a resource specified by base path, name and class. |
static Resource |
getResource(java.lang.String basePath,
java.lang.String name,
java.lang.Class<Resource> type,
boolean searchFiles)
Gets a resource specified by base path, name and class. |
static Resource |
getResourceZipURLsOK(java.lang.String name)
Gets a resource specified by name. |
static java.io.File |
getSearchCache()
Gets the search cache directory. |
static java.io.File |
getSearchCacheFile(java.lang.String urlPath)
Gets the search cache (XML) file associated with a URL path. |
static java.lang.String |
getString(java.lang.String path)
Gets a string. |
static java.lang.String |
getStyleSheetFromHTMLCode(java.lang.String code)
Returns the first stylesheet link, if any, in an HTML page. |
static java.lang.String |
getTitleFromHTMLCode(java.lang.String code)
Returns the title, if any, of an HTML page. |
static java.lang.String |
getURIPath(java.lang.String path)
Converts a path to URI form (spaces replaced by "%20", etc). |
static java.util.Set<java.lang.String> |
getZipContents(java.lang.String zipPath)
Gets the contents of a zip file. |
static boolean |
isCacheEnabled()
Gets the cacheEnabled property. |
static boolean |
isCanceled()
Determines if the current operation is canceled. |
static boolean |
isOSPCachePath(java.lang.String path)
Determines if a path defines a file in the OSP cache. |
static boolean |
isURLAvailable(java.lang.String urlPath)
Determines if a url path is available (ie both valid and connected). |
static java.io.InputStream |
openInputStream(java.lang.String path)
Opens and returns an input stream. |
static java.io.Reader |
openReader(java.lang.String path)
Opens and returns a reader. |
static void |
removeAppletSearchPath(java.lang.String base)
Removes a path from the applet search path list. |
static void |
removeSearchPath(java.lang.String base)
Removes a path from the searchPaths list. |
static void |
setCacheEnabled(boolean enabled)
Sets the cacheEnabled property. |
static void |
setCanceled(boolean cancel)
Cancels the current operation when true. |
static void |
setOSPCache(java.io.File newCache)
Sets the directory for cached files. |
static java.util.Set<java.io.File> |
unzip(java.lang.String zipPath,
java.io.File targetDir,
boolean alwaysOverwrite)
Unzips a ZIP file into the given directory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.io.FileFilter OSP_CACHE_FILTER
protected static final java.lang.String WIN_XP_DEFAULT_CACHE
protected static final java.lang.String WINDOWS_DEFAULT_CACHE
protected static final java.lang.String OSX_DEFAULT_CACHE
protected static final java.lang.String LINUX_DEFAULT_CACHE
protected static final java.lang.String SEARCH_CACHE_SUBDIRECTORY
protected static java.util.ArrayList<java.lang.String> searchPaths
protected static java.util.ArrayList<java.lang.String> appletSearchPaths
protected static int maxPaths
protected static java.util.Hashtable<java.lang.String,Resource> resources
protected static boolean cacheEnabled
protected static boolean canceled
protected static java.util.Map<java.lang.String,java.net.URLClassLoader> zipLoaders
protected static java.net.URLClassLoader xsetZipLoader
protected static java.util.Set<java.lang.String> extractExtensions
protected static java.util.ArrayList<java.lang.String> pathsNotFound
protected static java.io.File ospCache
protected static boolean zipURLsOK
| Method Detail |
|---|
public static Resource getResource(java.lang.String name)
name - the file or URL name
public static Resource getResourceZipURLsOK(java.lang.String name)
name - the file or URL name
public static Resource getResource(java.lang.String name,
boolean searchFiles)
name - the file or URL namesearchFiles - true to search files
public static Resource getResource(java.lang.String name,
java.lang.Class<?> type)
name - the file or URL nametype - the Class providing default ClassLoader resource loading
public static Resource getResource(java.lang.String name,
java.lang.Class<?> type,
boolean searchFiles)
name - the file or URL nametype - the Class providing default ClassLoader resource loadingsearchFiles - true to search files
public static Resource getResource(java.lang.String basePath,
java.lang.String name)
basePath - the base pathname - the file or URL name
public static Resource getResource(java.lang.String basePath,
java.lang.String name,
boolean searchFiles)
basePath - the base pathname - the file or URL namesearchFiles - true to search files
public static Resource getResource(java.lang.String basePath,
java.lang.String name,
java.lang.Class<Resource> type)
basePath - the base pathname - the file or URL nametype - the Class providing ClassLoader resource loading
public static Resource getResource(java.lang.String basePath,
java.lang.String name,
java.lang.Class<Resource> type,
boolean searchFiles)
basePath - the base pathname - the file or URL nametype - the Class providing ClassLoader resource loadingsearchFiles - true to search files
public static void addSearchPath(java.lang.String base)
base - the base path to addpublic static void removeSearchPath(java.lang.String base)
base - the base path to removepublic static void addAppletSearchPath(java.lang.String base)
base - the base path to addpublic static void removeAppletSearchPath(java.lang.String base)
base - the base path to removepublic static void setCacheEnabled(boolean enabled)
enabled - true to enable the cachepublic static boolean isCacheEnabled()
public static void addExtractExtension(java.lang.String extension)
extension - the extension to addpublic static void setCanceled(boolean cancel)
cancel - true to cancelpublic static boolean isCanceled()
public static java.io.InputStream openInputStream(java.lang.String path)
path - the path
public static java.io.Reader openReader(java.lang.String path)
path - the path
public static java.lang.String getString(java.lang.String path)
path - the path
public static javax.swing.ImageIcon getIcon(java.lang.String path)
path - the path
public static java.awt.Image getImage(java.lang.String path)
path - the path
public static java.awt.image.BufferedImage getBufferedImage(java.lang.String path)
path - the path
public static java.awt.image.BufferedImage getBufferedImage(java.lang.String path,
int bufferedImageType)
path - the pathbufferedImageType - one of the types defined by the BufferedImage class
public static java.applet.AudioClip getAudioClip(java.lang.String path)
path - the path
public static void setOSPCache(java.io.File newCache)
newCache - the desired cache directorypublic static java.io.File getOSPCache()
public static java.io.File getDefaultOSPCache()
public static java.io.File chooseOSPCache(java.awt.Component parent)
parent - a component to own the file chooser
public static boolean isOSPCachePath(java.lang.String path)
path - the path
public static java.io.File getOSPCacheFile(java.lang.String urlPath)
urlPath - the path to the file
public static java.io.File getOSPCacheFile(java.lang.String urlPath,
java.lang.String name)
urlPath - the path to the filename - name of the file (may be null)
public static java.io.File getSearchCache()
public static java.io.File getSearchCacheFile(java.lang.String urlPath)
urlPath - the path to the file
public static java.io.File downloadToOSPCache(java.lang.String urlPath,
java.lang.String fileName,
boolean alwaysOverwrite)
urlPath - the path to the filefileName - the name to assign the downloaded filealwaysOverwrite - true to overwrite an existing file, if any
public static java.lang.String getHTMLCode(java.lang.String path)
path - the path to the HTML page
public static java.lang.String getTitleFromHTMLCode(java.lang.String code)
code - the HTML code
public static java.lang.String getStyleSheetFromHTMLCode(java.lang.String code)
code - the HTML code
public static java.io.File copyHTMLToOSPCache(java.lang.String htmlPath)
htmlPath - the path to the source HTML file
public static boolean copyAllFiles(java.io.File inFile,
java.io.File outFile)
inFile - the sourceoutFile - the target
public static boolean clearOSPCache(java.io.File cache,
boolean clearSearchCache)
cache - the cache to clearclearSearchCache - true to clear the search cache
public static boolean clearOSPCacheHost(java.io.File hostDir)
hostDir - the cache host directory to clear
public static boolean deleteFile(java.io.File file)
file - the file to delete
public static java.util.List<java.io.File> getFiles(java.io.File directory,
java.io.FileFilter filter)
directory - the directory to searchfilter - the FileFilter
public static java.util.Set<java.lang.String> getZipContents(java.lang.String zipPath)
zipPath - the path to the zip file
public static java.util.Set<java.io.File> unzip(java.lang.String zipPath,
java.io.File targetDir,
boolean alwaysOverwrite)
zipPath - the (url) path to the zip filetargetDir - target directory to save the extracted filesalwaysOverwrite - true to overwrite existing files, if any
public static java.io.File download(java.lang.String urlPath,
java.io.File target,
boolean alwaysOverwrite)
urlPath - the path to the filetarget - the target filealwaysOverwrite - true to overwrite an existing file, if any
public static java.io.File extractFileFromZIP(java.lang.String source,
java.io.File target,
boolean alwaysOverwrite)
source - the path of the file to be extracted (eg "http:/www.server/folder/images.zip!/image1.png")target - target file to savealwaysOverwrite - true to overwrite existing files, if any
public static boolean isURLAvailable(java.lang.String urlPath)
urlPath - the path in URI form
public static java.lang.String getNonURIPath(java.lang.String uriPath)
uriPath - the path in URI form
public static java.lang.String getURIPath(java.lang.String path)
path - the path
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||