public java.util.List<? extends java.io.File> getLocations() {
   java.util.ArrayList<java.io.File> locations = new java.util.ArrayList<java.io.File>();
   for (StoreLocation location : this.readLocations) {
     locations.add(location.getFile());
   }
   return locations;
 }
  protected String[] doListFileNames(
      String pathName, FileStoreFilter filter, boolean recurse, boolean exitBranchOnFirstMatch) {
    java.util.ArrayList<String> nameList = null;

    for (StoreLocation location : this.readLocations) {
      // If the path name is null, then just search from the root of each location. Otherwise search
      // from the
      // named cache path.
      java.io.File dir = location.getFile();
      if (pathName != null) dir = new java.io.File(makeAbsolutePath(dir, pathName));

      // Either the location does not exists, or the speciifed path does not exist under that
      // location. In either
      // case we skip searching this location.
      if (!dir.exists()) continue;

      // Lazily initialize the list of file names. If no location contains the specified path, then
      // the list is
      // not created, and this method will return null.
      if (nameList == null) nameList = new java.util.ArrayList<String>();

      this.doListFileNames(location, dir, filter, recurse, exitBranchOnFirstMatch, nameList);
    }

    if (nameList == null) return null;

    String[] names = new String[nameList.size()];
    nameList.toArray(names);
    return names;
  }
  protected StoreLocation storeLocationFor(String path) {
    java.io.File file = new java.io.File(path);

    for (StoreLocation location : this.readLocations) {
      if (file.equals(location.getFile())) return location;
    }

    return null;
  }
  public boolean isInstallLocation(String path) {
    if (path == null || path.length() == 0) {
      String message = Logging.getMessage("nullValue.FileStorePathIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    StoreLocation location = this.storeLocationFor(path);
    return location != null && location.isInstall();
  }
  public boolean containsFile(String fileName) {
    if (fileName == null) return false;

    for (StoreLocation location : this.readLocations) {
      java.io.File dir = location.getFile();
      java.io.File file;

      if (fileName.startsWith(dir.getAbsolutePath())) file = new java.io.File(fileName);
      else file = makeAbsoluteFile(dir, fileName);

      if (file.exists()) return true;
    }

    return false;
  }
  /**
   * @param fileName the name of the file to find
   * @param checkClassPath if <code>true</code>, the class path is first searched for the file,
   *     otherwise the class path is not searched unless it's one of the explicit paths in the cache
   *     search directories
   * @return a handle to the requested file if it exists in the cache, otherwise null
   * @throws IllegalArgumentException if <code>fileName</code> is null
   */
  public java.net.URL findFile(String fileName, boolean checkClassPath) {
    if (fileName == null) {
      String message = Logging.getMessage("nullValue.FilePathIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (checkClassPath) {
      java.net.URL url = this.getClass().getClassLoader().getResource(fileName);
      if (url != null) return url;

      // Check for a thread context class loader. This allows the file store to find resources in a
      // case
      // in which different parts of the application are handled by different class loaders.
      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      if (tccl != null) {
        url = tccl.getResource(fileName);
        if (url != null) return url;
      }
    }

    for (StoreLocation location : this.readLocations) {
      java.io.File dir = location.getFile();
      if (!dir.exists()) continue;

      java.io.File file = new java.io.File(makeAbsolutePath(dir, fileName));
      if (file.exists()) {
        try {
          if (location.isMarkWhenUsed()) markFileUsed(file);
          else markFileUsed(file.getParentFile());

          return file.toURI().toURL();
        } catch (java.net.MalformedURLException e) {
          Logging.logger()
              .log(
                  Level.SEVERE,
                  Logging.getMessage("FileStore.ExceptionCreatingURLForFile", file.getPath()),
                  e);
        }
      }
    }

    return null;
  }
  protected static String storePathForFile(StoreLocation location, java.io.File file) {
    String path = file.getPath();

    if (location != null) {
      String locationPath = location.getFile().getPath();
      if (path.startsWith(locationPath))
        path = path.substring(locationPath.length(), path.length());
    }

    return path;
  }
  public void removeLocation(String path) {
    if (path == null || path.length() == 0) {
      String message = Logging.getMessage("nullValue.FileStorePathIsNull");
      Logging.logger().severe(message);
      // Just warn and return.
      return;
    }

    StoreLocation location = this.storeLocationFor(path);
    if (location == null) // Path is not part of this FileStore.
    return;

    if (location.equals(this.writeLocation)) {
      String message = Logging.getMessage("FileStore.CannotRemoveWriteLocation", path);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.readLocations.remove(location);
  }
  protected void buildReadPaths(org.w3c.dom.Node dataFileStoreNode) {
    javax.xml.xpath.XPathFactory pathFactory = javax.xml.xpath.XPathFactory.newInstance();
    javax.xml.xpath.XPath pathFinder = pathFactory.newXPath();

    try {
      org.w3c.dom.NodeList locationNodes =
          (org.w3c.dom.NodeList)
              pathFinder.evaluate(
                  "/dataFileStore/readLocations/location",
                  dataFileStoreNode.getFirstChild(),
                  javax.xml.xpath.XPathConstants.NODESET);
      for (int i = 0; i < locationNodes.getLength(); i++) {
        org.w3c.dom.Node location = locationNodes.item(i);
        String prop = pathFinder.evaluate("@property", location);
        String wwDir = pathFinder.evaluate("@wwDir", location);
        String append = pathFinder.evaluate("@append", location);
        String isInstall = pathFinder.evaluate("@isInstall", location);
        String isMarkWhenUsed = pathFinder.evaluate("@isMarkWhenUsed", location);

        String path = buildLocationPath(prop, append, wwDir);
        if (path == null) {
          Logging.logger()
              .log(
                  Level.WARNING,
                  "FileStore.LocationInvalid",
                  prop != null ? prop : Logging.getMessage("generic.Unknown"));
          continue;
        }

        StoreLocation oldStore = this.storeLocationFor(path);
        if (oldStore != null) // filter out duplicates
        continue;

        // Even paths that don't exist or are otherwise problematic are added to the list because
        // they may
        // become readable during the session. E.g., removable media. So add them to the search
        // list.

        java.io.File pathFile = new java.io.File(path);
        if (pathFile.exists() && !pathFile.isDirectory()) {
          Logging.logger().log(Level.WARNING, "FileStore.LocationIsFile", pathFile.getPath());
        }

        boolean pathIsInstall =
            isInstall != null && (isInstall.contains("t") || isInstall.contains("T"));
        StoreLocation newStore = new StoreLocation(pathFile, pathIsInstall);

        // If the input parameter "markWhenUsed" is null or empty, then the StoreLocation should
        // keep its
        // default value. Otherwise the store location value is set to true when the input parameter
        // contains
        // "t", and is set to false otherwise.
        if (isMarkWhenUsed != null && isMarkWhenUsed.length() > 0)
          newStore.setMarkWhenUsed(isMarkWhenUsed.toLowerCase().contains("t"));

        this.readLocations.add(newStore);
      }
    } catch (javax.xml.xpath.XPathExpressionException e) {
      String message = Logging.getMessage("FileStore.ExceptionReadingConfigurationFile");
      Logging.logger().severe(message);
      throw new IllegalStateException(message, e);
    }
  }