protected void doListFileNames( StoreLocation location, java.io.File dir, FileStoreFilter filter, boolean recurse, boolean exitBranchOnFirstMatch, java.util.Collection<String> names) { java.util.ArrayList<java.io.File> subDirs = new java.util.ArrayList<java.io.File>(); // Search the children of the specified directory. If the child is a directory, append it to the // list of sub // directories to search later. Otherwise, try to list the file as a match. If the file is a // match and // exitBranchOnFirstMatch is true, then exit this branch without considering any other files. // This has the // effect of choosing files closest to the search root. for (java.io.File childFile : dir.listFiles()) { if (childFile == null) continue; if (childFile.isDirectory()) { subDirs.add(childFile); } else { if (this.listFile(location, childFile, filter, names) && exitBranchOnFirstMatch) return; } } if (!recurse) return; // Recursively search each sub-directory. If exitBranchOnFirstMatch is true, then we did not // find a match under // this directory. for (java.io.File childDir : subDirs) { this.doListFileNames(location, childDir, filter, recurse, exitBranchOnFirstMatch, names); } }
@SuppressWarnings({"ResultOfMethodCallIgnored"}) protected void buildWritePaths(org.w3c.dom.Node dataFileCacheNode) { 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/writeLocations/location", dataFileCacheNode.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 create = pathFinder.evaluate("@create", 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; } Logging.logger().log(Level.FINER, "FileStore.AttemptingWriteDir", path); java.io.File pathFile = new java.io.File(path); if (!pathFile.exists() && create != null && (create.contains("t") || create.contains("T"))) { Logging.logger().log(Level.FINER, "FileStore.MakingDirsFor", path); pathFile.mkdirs(); } if (pathFile.isDirectory() && pathFile.canWrite() && pathFile.canRead()) { Logging.logger().log(Level.FINER, "FileStore.WriteLocationSuccessful", path); this.writeLocation = new StoreLocation(pathFile); // Remove the writable location from search path if it already exists. StoreLocation oldLocation = this.storeLocationFor(path); if (oldLocation != null) this.readLocations.remove(oldLocation); // Writable location is always first in search path. this.readLocations.add(0, this.writeLocation); break; // only need one } } } catch (javax.xml.xpath.XPathExpressionException e) { String message = Logging.getMessage("FileStore.ExceptionReadingConfigurationFile"); Logging.logger().severe(message); throw new IllegalStateException(message, e); } }
@SuppressWarnings({"ResultOfMethodCallIgnored"}) protected static void markFileUsed(java.io.File file) { if (file == null) return; long currentTime = System.currentTimeMillis(); if (file.canWrite()) file.setLastModified(currentTime); if (file.isDirectory()) return; java.io.File parent = file.getParentFile(); if (parent != null && parent.canWrite()) parent.setLastModified(currentTime); }
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); } }