Author: arunpatidar
Date: Wed Jun 29 15:20:09 2016 New Revision: 1750663 URL: http://svn.apache.org/viewvc?rev=1750663&view=rev Log: Applied patch from jira issue - OFBIZ-7540 - Enforce noninstantiability to FileUtil class. Thanks Rishi Solanki and Rohit Koushal for your contribution. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java?rev=1750663&r1=1750662&r2=1750663&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java Wed Jun 29 15:20:09 2016 @@ -44,10 +44,77 @@ import org.ofbiz.base.location.Component * File Utilities * */ -public class FileUtil { +public final class FileUtil { public static final String module = FileUtil.class.getName(); + private FileUtil () {} + + private static class SearchTextFilesFilter implements FilenameFilter { + String fileExtension; + Set<String> stringsToFindInFile = new HashSet<String>(); + Set<String> stringsToFindInPath = new HashSet<String>(); + + public SearchTextFilesFilter(String fileExtension, Set<String> stringsToFindInPath, Set<String> stringsToFindInFile) { + this.fileExtension = fileExtension; + if (stringsToFindInPath != null) { + this.stringsToFindInPath.addAll(stringsToFindInPath); + } + if (stringsToFindInFile != null) { + this.stringsToFindInFile.addAll(stringsToFindInFile); + } + } + + @Override + public boolean accept(File dir, String name) { + File file = new File(dir, name); + if (file.getName().startsWith(".")) { + return false; + } + if (file.isDirectory()) { + return true; + } + + boolean hasAllPathStrings = true; + String fullPath = dir.getPath().replace('\\', '/'); + for (String pathString: stringsToFindInPath) { + if (fullPath.indexOf(pathString) < 0) { + hasAllPathStrings = false; + break; + } + } + + if (hasAllPathStrings && name.endsWith("." + fileExtension)) { + if (stringsToFindInFile.size() == 0) { + return true; + } + StringBuffer xmlFileBuffer = null; + try { + xmlFileBuffer = FileUtil.readTextFile(file, true); + } catch (FileNotFoundException e) { + Debug.logWarning("Error reading xml file [" + file + "] for file search: " + e.toString(), module); + return false; + } catch (IOException e) { + Debug.logWarning("Error reading xml file [" + file + "] for file search: " + e.toString(), module); + return false; + } + if (UtilValidate.isNotEmpty(xmlFileBuffer)) { + boolean hasAllStrings = true; + for (String stringToFile: stringsToFindInFile) { + if (xmlFileBuffer.indexOf(stringToFile) < 0) { + hasAllStrings = false; + break; + } + } + return hasAllStrings; + } + } else { + return false; + } + return false; + } + } + public static File getFile(String path) { return getFile(null, path); } @@ -277,71 +344,6 @@ public class FileUtil { return fileList; } - public static class SearchTextFilesFilter implements FilenameFilter { - String fileExtension; - Set<String> stringsToFindInFile = new HashSet<String>(); - Set<String> stringsToFindInPath = new HashSet<String>(); - - public SearchTextFilesFilter(String fileExtension, Set<String> stringsToFindInPath, Set<String> stringsToFindInFile) { - this.fileExtension = fileExtension; - if (stringsToFindInPath != null) { - this.stringsToFindInPath.addAll(stringsToFindInPath); - } - if (stringsToFindInFile != null) { - this.stringsToFindInFile.addAll(stringsToFindInFile); - } - } - - @Override - public boolean accept(File dir, String name) { - File file = new File(dir, name); - if (file.getName().startsWith(".")) { - return false; - } - if (file.isDirectory()) { - return true; - } - - boolean hasAllPathStrings = true; - String fullPath = dir.getPath().replace('\\', '/'); - for (String pathString: stringsToFindInPath) { - if (fullPath.indexOf(pathString) < 0) { - hasAllPathStrings = false; - break; - } - } - - if (hasAllPathStrings && name.endsWith("." + fileExtension)) { - if (stringsToFindInFile.size() == 0) { - return true; - } - StringBuffer xmlFileBuffer = null; - try { - xmlFileBuffer = FileUtil.readTextFile(file, true); - } catch (FileNotFoundException e) { - Debug.logWarning("Error reading xml file [" + file + "] for file search: " + e.toString(), module); - return false; - } catch (IOException e) { - Debug.logWarning("Error reading xml file [" + file + "] for file search: " + e.toString(), module); - return false; - } - if (UtilValidate.isNotEmpty(xmlFileBuffer)) { - boolean hasAllStrings = true; - for (String stringToFile: stringsToFindInFile) { - if (xmlFileBuffer.indexOf(stringToFile) < 0) { - hasAllStrings = false; - break; - } - } - return hasAllStrings; - } - } else { - return false; - } - return false; - } - } - /** * * |
Free forum by Nabble | Edit this page |