Class ResourceManager

All Implemented Interfaces:
ActionListener, EventListener, HyperlinkListener, IdvConstants

public class ResourceManager extends IdvResourceManager
McIDAS-V's resource manager. The chief differences from Unidata's IdvResourceManager are supporting "default" McIDAS-V bundles, and some initial attempts at safer resource handling.
  • Field Details

  • Constructor Details

  • Method Details

    • init

      protected void init(List rbiFiles)
      Overridden so that McIDAS-V can attempt to verify "critical" resources without causing crashes.

      Currently doesn't do a whole lot.

      Overrides:
      init in class IdvResourceManager
      See Also:
    • verifyResources

      protected void verifyResources()
      Loops through all of the ResourceCollections that the IDV knows about.

      I realize that this could balloon into a really tedious thing... there could potentially be verification steps for each type of resource collection! the better approach is probably to identify a few key collections (like the (default?) maps).

    • isPathValid

      private boolean isPathValid(String path)
      Pretty much relies upon IOUtil.getInputStream(String, Class) to determine if path exists.
      Parameters:
      path - Path to an arbitrary file. It can be a remote URL, normal file on disk, or a file included in a JAR. Just so long as it's not null!
      Returns:
      true iff there were no problems. false otherwise.
    • getResourcePath

      public String getResourcePath(String path)
      Adds support for McIDAS-V macros. Specifically:
      Overrides:
      getResourcePath in class IdvResourceManager
      Parameters:
      path - Path that contains a macro to be translated.
      Returns:
      Resource with our macros applied.
      See Also:
    • checkMoveOutdatedDefaultBundle

      Look for existing "default.mcv" and "default.xidv" bundles in root userpath If they exist, move them to the "bundles" directory, preferring "default.mcv"
    • getInvalidMapsInResource

      Checks an individual map resource (typically from RSC_MAPS) to verify that all of the specified maps exist?

      Currently a no-op. The intention is to return a List so that the set of missing resources can eventually be sent off in a support request...

      We could also decide to allow the user to search the list of plugins or ignore any missing resources (simply remove the bad stuff from the list of available xml).

      Parameters:
      path - Path to a map resource. URLs are allowed, but null is not.
      Returns:
      List of map paths that could not be read. If there were no errors the list is merely empty.
      See Also:
    • getCollection

      Returns either a "normal" ResourceCollection or a XmlResourceCollection, based upon rsrc.
      Parameters:
      rsrc - XML representation of a resource collection. Should not be null.
      name - "name" to associate with the returned ResourceCollection. Should not be null.
      Returns:
      ResourceCollection represented by rsrc.
    • getNodeProperties

      private Map<String,String> getNodeProperties(Element resourceNode)
      "Resource" elements within a RBI file are allowed to have an arbitrary number of "property" child elements (or none at all). The property elements must have "name" and "value" attributes.

      This method iterates through any property elements and creates a Map of name:value pairs.

      Parameters:
      resourceNode - The "resource" element to examine. Should not be null. Resources without propertys are permitted.
      Returns:
      Either a Map of name:value pairs or an empty Map.
    • getNodeAttributes

      private Map<String,String> getNodeAttributes(Element resourceNode)
      Builds an attribute:value Map based upon the contents of resourceNode.

      Be aware that "location" and "id" attributes are ignored, as the IDV apparently considers them to be special.

      Parameters:
      resourceNode - The XML element to examine. Should not be null.
      Returns:
      Either a Map of attribute:value pairs or an empty Map.
    • getPaths

      private List<String> getPaths(String origPath, Map<String,String> props)
      Expands origPath (if needed) and builds a List of paths. Paths beginning with "index:" or "http:" may be in need of expansion.

      "Index" files contain a list of paths. These paths should be used instead of origPath.

      Files that reside on a webserver (these begin with "http:") may be inaccessible for a variety of reasons. McIDAS-V allows a RBI file to specify a "property" named "default" whose "value" is a path to use as a backup.

      For example:

       <resources name="idv.resource.pluginindex">
         <resource label="Plugin Index" location="https://www.ssec.wisc.edu/mcidas/software/v/resources/plugins/plugins.xml">
           <property name="default" value="%APPPATH%/plugins.xml"/>
         </resource>
       </resources>
       
      The origPath parameter will be the value of the "location" attribute. If origPath is inaccessible, then the path given by the "default" property will be used.
      Parameters:
      origPath - Typically the value of the "location" attribute associated with a given resource. Cannot be null.
      props - Contains the property name:value pairs associated with the resource whose path is being examined. Cannot be null.
      Returns:
      List of paths associated with a given resource.
      See Also:
    • fixId

      private static String fixId(Element resource)
      Utility method that calls StateManager.fixIds(String).
      Parameters:
      resource - Resource whose ID should be fixed.
      Returns:
      "Fixed" ID for resource.
      See Also:
    • processRbi

      protected void processRbi(Element root, boolean observeLoadMore)
      Processes the top-level "root" of a RBI XML file. Overridden in McIDAS-V so that remote resources can have a backup location.
      Overrides:
      processRbi in class IdvResourceManager
      Parameters:
      root - The "root" element. Should not be null.
      observeLoadMore - Whether or not processing should continue if a "loadmore" tag is encountered.
      See Also: