Package ucar.unidata.util
Class ResourceCollection
java.lang.Object
ucar.unidata.util.ResourceCollection
- Direct Known Subclasses:
XmlResourceCollection
- Version:
- $Revision: 1.47 $ $Date: 2006/10/30 18:10:31 $
- Author:
- Metapps development team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class Resource holds a string path which may be a file, url or java resource path. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The descriptionprotected String
The id of this collectionprotected Hashtable
A mapping from id (String) to the resource pathprotected Hashtable
A mapping from resource path to idprotected int
Index of the writable indexprotected ResourceCollection.Resource
Path to the writable resource -
Constructor Summary
ConstructorsConstructorDescriptionCreate a ResourceCollection with the given id.ResourceCollection
(String id, String description) Create a ResourceCollection with the given id ad descriptionResourceCollection
(String id, String writable, List resources) CtorResourceCollection
(String id, List resources) CtorResourceCollection
(String id, ResourceCollection that) copy ctor -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add in the given maps of path to label.void
addResource
(String resource) Add the resource.void
addResource
(ResourceCollection.Resource resource) Add the resource.void
addResourceAtStart
(String resourcePath) Add the resource.void
addResourceAtStart
(String resourcePath, String label) Add the given resource to the beginning of the listvoid
Add the given resource to the beginning of the listvoid
addResources
(List rs) Add the list of resourcesvoid
Clear the cacheboolean
Do we contain the given pathvoid
Delete, if possible, all resource files.get
(int i) Return the name of the i'th resourceboolean
Should we keep loading resources from this collection.Get the Description property.getId()
The id of the resource collectiongetLabel
(int resourceIdx) Return the label (or null if none defined) for the given resource.getPathFromId
(String id) Find the path for the given idgetProperty
(String name, int resourceIdx) Get the named property from the given resourcegetResourceId
(int idx) Find the id for the given resource indexGet the list of resourcesgetShortName
(int resourceIdx) Return an abbreviated name of the given resource for display purposes.Get the string path of the writable file resource.boolean
Do we have a writable resourceboolean
isHttp
(int i) Is the given index an http based pathboolean
Is the given path an http based pathboolean
isValid
(int i) Is the given resource index valid.boolean
isWritable
(int i) Is the i'th resource writableboolean
isWritableResource
(int i) Is the ith resource a writable resourceread
(int i) Read the ith resourceread
(int i, boolean lookAtCache) Read the ith resourceprotected String
read
(ResourceCollection.Resource resource, boolean lookAtCache) Read and return the contents of the resource.Read in the writable resource filevoid
Reset all structuresvoid
removeResource
(int index) Remove the index'th resourcevoid
Delete, if possible, the writable resource filevoid
setCanLoadMore
(boolean lm) Set if we can keep loading resourcesvoid
setDescription
(String value) Set the Description property.void
Set the id of the resource collectionvoid
setIdForPath
(String id, String path) Associate the resource id with the pathint
size()
How many resourcestoString()
The toString methodvoid
writeWritableResource
(String contents) Write the given contents into the writable resource file
-
Field Details
-
id
The id of this collection -
description
The description -
idToPath
A mapping from id (String) to the resource path -
pathToId
A mapping from resource path to id -
writableResource
Path to the writable resource -
writableIndex
protected int writableIndexIndex of the writable index
-
-
Constructor Details
-
ResourceCollection
Create a ResourceCollection with the given id. The description of this collection is the id.- Parameters:
id
- The id of this ResourceCollection
-
ResourceCollection
Create a ResourceCollection with the given id ad description- Parameters:
id
- The id of this ResourceCollectiondescription
- The description of this ResourceCollection
-
ResourceCollection
Ctor- Parameters:
id
- Resource idresources
- List of resources
-
ResourceCollection
Ctor- Parameters:
id
- Resource idwritable
- The writable resource deprecated not good anymoreresources
- List of resources
-
ResourceCollection
copy ctor- Parameters:
id
- new idthat
- resourcecollection to copy from
-
-
Method Details
-
contains
Do we contain the given path- Parameters:
path
- the resource path- Returns:
- do we contain the resource path
-
setIdForPath
Associate the resource id with the path- Parameters:
id
- The idpath
- The path
-
getPathFromId
Find the path for the given id- Parameters:
id
- The id- Returns:
- The path
-
getResourceId
Find the id for the given resource index- Parameters:
idx
- The resource index- Returns:
- The id. May be null.
-
getCanLoadMore
public boolean getCanLoadMore()Should we keep loading resources from this collection. Have we seen the loadmore=false yet.- Returns:
- Keep loading resources
-
setCanLoadMore
public void setCanLoadMore(boolean lm) Set if we can keep loading resources- Parameters:
lm
- value
-
getId
The id of the resource collection- Returns:
- resource id
-
setId
Set the id of the resource collection- Parameters:
id
- The id
-
isValid
public boolean isValid(int i) Is the given resource index valid. We try to read that resource.- Parameters:
i
- Resource index- Returns:
- Do we have it
-
getLabel
Return the label (or null if none defined) for the given resource.- Parameters:
resourceIdx
-- Returns:
- A short name for the given resource.
-
getProperty
Get the named property from the given resource- Parameters:
name
- property nameresourceIdx
- which resource- Returns:
- property value or null
-
getShortName
Return an abbreviated name of the given resource for display purposes.- Parameters:
resourceIdx
-- Returns:
- A short name for the given resource.
-
addLabels
Add in the given maps of path to label.- Parameters:
labelMap
- Pat to label map deprecated not used anymore
-
addResources
Add the list of resources- Parameters:
rs
- List of Resource-s
-
removeResource
public void removeResource(int index) Remove the index'th resource- Parameters:
index
- the index to remove
-
addResource
Add the resource. We create a new Resource- Parameters:
resource
- The resource path
-
addResource
Add the resource.- Parameters:
resource
- The resource
-
addResourceAtStart
Add the resource.- Parameters:
resourcePath
- the path to the resource
-
addResourceAtStart
Add the given resource to the beginning of the list- Parameters:
resourcePath
- resource pathlabel
- label
-
addResourceAtStart
Add the given resource to the beginning of the list- Parameters:
resource
- The resource
-
size
public int size()How many resources- Returns:
- How many resources
-
isWritable
public boolean isWritable(int i) Is the i'th resource writable- Parameters:
i
- Resource index- Returns:
- Is it a writable file
-
isHttp
Is the given path an http based path- Parameters:
resource
- Resource path- Returns:
- Is it http
-
isHttp
public boolean isHttp(int i) Is the given index an http based path- Parameters:
i
- Resource index- Returns:
- Is it http
-
get
Return the name of the i'th resource- Parameters:
i
- The resource index- Returns:
- The name of the i'th resource
-
isWritableResource
public boolean isWritableResource(int i) Is the ith resource a writable resource- Parameters:
i
- Resource index- Returns:
- is writable
-
readWritableResource
Read in the writable resource file- Returns:
- The writable resource contents or null
-
writeWritableResource
Write the given contents into the writable resource file- Parameters:
contents
-- Throws:
FileNotFoundException
IOException
-
read
Read and return the contents of the resource. Return null if cannot be read.- Parameters:
resource
- The resourcelookAtCache
- Should we look in the cache or reread- Returns:
- Contents or null
-
read
Read the ith resource- Parameters:
i
- The resource indexlookAtCache
- Should we look in the cache or reread- Returns:
- Contents or null
-
read
Read the ith resource- Parameters:
i
- The resource index- Returns:
- Contents or null
-
getResources
Get the list of resources- Returns:
- List of resources
-
removeWritable
public void removeWritable()Delete, if possible, the writable resource file -
clearCache
public void clearCache()Clear the cache -
deleteAllFiles
public void deleteAllFiles()Delete, if possible, all resource files. -
removeAll
public void removeAll()Reset all structures -
getWritable
Get the string path of the writable file resource.- Returns:
- File path
-
hasWritableResource
public boolean hasWritableResource()Do we have a writable resource- Returns:
- Do we have a writable resource
-
toString
The toString method -
setDescription
Set the Description property.- Parameters:
value
- The new value for Description
-
getDescription
Get the Description property.- Returns:
- The Description
-