Class ResourceCollection

java.lang.Object
ucar.unidata.util.ResourceCollection
Direct Known Subclasses:
XmlResourceCollection

public class ResourceCollection extends Object
Version:
$Revision: 1.47 $ $Date: 2006/10/30 18:10:31 $
Author:
Metapps development team
  • Field Details

    • id

      protected String id
      The id of this collection
    • description

      protected String description
      The description
    • idToPath

      protected Hashtable idToPath
      A mapping from id (String) to the resource path
    • pathToId

      protected Hashtable pathToId
      A mapping from resource path to id
    • writableResource

      protected ResourceCollection.Resource writableResource
      Path to the writable resource
    • writableIndex

      protected int writableIndex
      Index of the writable index
  • Constructor Details

    • ResourceCollection

      public ResourceCollection(String id)
      Create a ResourceCollection with the given id. The description of this collection is the id.
      Parameters:
      id - The id of this ResourceCollection
    • ResourceCollection

      public ResourceCollection(String id, String description)
      Create a ResourceCollection with the given id ad description
      Parameters:
      id - The id of this ResourceCollection
      description - The description of this ResourceCollection
    • ResourceCollection

      public ResourceCollection(String id, List resources)
      Ctor
      Parameters:
      id - Resource id
      resources - List of resources
    • ResourceCollection

      public ResourceCollection(String id, String writable, List resources)
      Ctor
      Parameters:
      id - Resource id
      writable - The writable resource deprecated not good anymore
      resources - List of resources
    • ResourceCollection

      public ResourceCollection(String id, ResourceCollection that)
      copy ctor
      Parameters:
      id - new id
      that - resourcecollection to copy from
  • Method Details

    • contains

      public boolean contains(String path)
      Do we contain the given path
      Parameters:
      path - the resource path
      Returns:
      do we contain the resource path
    • setIdForPath

      public void setIdForPath(String id, String path)
      Associate the resource id with the path
      Parameters:
      id - The id
      path - The path
    • getPathFromId

      public String getPathFromId(String id)
      Find the path for the given id
      Parameters:
      id - The id
      Returns:
      The path
    • getResourceId

      public String getResourceId(int idx)
      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

      public String getId()
      The id of the resource collection
      Returns:
      resource id
    • setId

      public void setId(String id)
      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

      public String getLabel(int resourceIdx)
      Return the label (or null if none defined) for the given resource.
      Parameters:
      resourceIdx -
      Returns:
      A short name for the given resource.
    • getProperty

      public String getProperty(String name, int resourceIdx)
      Get the named property from the given resource
      Parameters:
      name - property name
      resourceIdx - which resource
      Returns:
      property value or null
    • getShortName

      public String getShortName(int resourceIdx)
      Return an abbreviated name of the given resource for display purposes.
      Parameters:
      resourceIdx -
      Returns:
      A short name for the given resource.
    • addLabels

      public void addLabels(Hashtable labelMap)
      Add in the given maps of path to label.
      Parameters:
      labelMap - Pat to label map deprecated not used anymore
    • addResources

      public void addResources(List rs)
      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

      public void addResource(String resource)
      Add the resource. We create a new Resource
      Parameters:
      resource - The resource path
    • addResource

      public void addResource(ResourceCollection.Resource resource)
      Add the resource.
      Parameters:
      resource - The resource
    • addResourceAtStart

      public void addResourceAtStart(String resourcePath)
      Add the resource.
      Parameters:
      resourcePath - the path to the resource
    • addResourceAtStart

      public void addResourceAtStart(String resourcePath, String label)
      Add the given resource to the beginning of the list
      Parameters:
      resourcePath - resource path
      label - label
    • addResourceAtStart

      public void addResourceAtStart(ResourceCollection.Resource resource)
      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

      public boolean isHttp(String resource)
      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

      public Object get(int i)
      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

      public String readWritableResource()
      Read in the writable resource file
      Returns:
      The writable resource contents or null
    • writeWritableResource

      public void writeWritableResource(String contents) throws FileNotFoundException, IOException
      Write the given contents into the writable resource file
      Parameters:
      contents -
      Throws:
      FileNotFoundException
      IOException
    • read

      protected String read(ResourceCollection.Resource resource, boolean lookAtCache)
      Read and return the contents of the resource. Return null if cannot be read.
      Parameters:
      resource - The resource
      lookAtCache - Should we look in the cache or reread
      Returns:
      Contents or null
    • read

      public String read(int i, boolean lookAtCache)
      Read the ith resource
      Parameters:
      i - The resource index
      lookAtCache - Should we look in the cache or reread
      Returns:
      Contents or null
    • read

      public String read(int i)
      Read the ith resource
      Parameters:
      i - The resource index
      Returns:
      Contents or null
    • getResources

      public List 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

      public String 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

      public String toString()
      The toString method
      Overrides:
      toString in class Object
      Returns:
      String representation
    • setDescription

      public void setDescription(String value)
      Set the Description property.
      Parameters:
      value - The new value for Description
    • getDescription

      public String getDescription()
      Get the Description property.
      Returns:
      The Description