diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/crypto/BlowFishCrypt.java b/framework/base/src/main/java/org/apache/ofbiz/base/crypto/BlowFishCrypt.java
index 111141612d..a9a408acac 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/crypto/BlowFishCrypt.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/crypto/BlowFishCrypt.java
@@ -66,10 +66,8 @@ public class BlowFishCrypt {
* @param keyFile A file object containing the secret key as a String object.
*/
public BlowFishCrypt(File keyFile) {
- try (
- FileInputStream is = new FileInputStream(keyFile);
- ObjectInputStream os = new ObjectInputStream(is);
- ) {
+ try (FileInputStream is = new FileInputStream(keyFile);
+ ObjectInputStream os = new ObjectInputStream(is);) {
String keyString = (String) os.readObject();
byte[] keyBytes = keyString.getBytes(StandardCharsets.UTF_8);
secretKeySpec = new SecretKeySpec(keyBytes, "Blowfish");
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/crypto/HashCrypt.java b/framework/base/src/main/java/org/apache/ofbiz/base/crypto/HashCrypt.java
index 40db7b1ccf..2b12e07e2a 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/crypto/HashCrypt.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/crypto/HashCrypt.java
@@ -47,10 +47,10 @@ public class HashCrypt {
private static final String MODULE = HashCrypt.class.getName();
public static final String CRYPT_CHAR_SET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
- private static final String PBKDF2_SHA1 ="PBKDF2-SHA1";
- private static final String PBKDF2_SHA256 ="PBKDF2-SHA256";
- private static final String PBKDF2_SHA384 ="PBKDF2-SHA384";
- private static final String PBKDF2_SHA512 ="PBKDF2-SHA512";
+ private static final String PBKDF2_SHA1 = "PBKDF2-SHA1";
+ private static final String PBKDF2_SHA256 = "PBKDF2-SHA256";
+ private static final String PBKDF2_SHA384 = "PBKDF2-SHA384";
+ private static final String PBKDF2_SHA512 = "PBKDF2-SHA512";
private static final int PBKDF2_ITERATIONS = UtilProperties.getPropertyAsInteger("security.properties", "password.encrypt.pbkdf2.iterations", 10000);
public static MessageDigest getMessageDigest(String type) {
@@ -173,20 +173,20 @@ public class HashCrypt {
byte[] hash = Base64.encodeBase64(skf.generateSecret(spec).getEncoded());
String pbkdf2Type = null;
switch (hashType) {
- case "PBKDF2WithHmacSHA1":
- pbkdf2Type = PBKDF2_SHA1;
- break;
- case "PBKDF2WithHmacSHA256":
- pbkdf2Type = PBKDF2_SHA256;
- break;
- case "PBKDF2WithHmacSHA384":
- pbkdf2Type = PBKDF2_SHA384;
- break;
- case "PBKDF2WithHmacSHA512":
- pbkdf2Type = PBKDF2_SHA512;
- break;
- default:
- pbkdf2Type = PBKDF2_SHA1;
+ case "PBKDF2WithHmacSHA1":
+ pbkdf2Type = PBKDF2_SHA1;
+ break;
+ case "PBKDF2WithHmacSHA256":
+ pbkdf2Type = PBKDF2_SHA256;
+ break;
+ case "PBKDF2WithHmacSHA384":
+ pbkdf2Type = PBKDF2_SHA384;
+ break;
+ case "PBKDF2WithHmacSHA512":
+ pbkdf2Type = PBKDF2_SHA512;
+ break;
+ default:
+ pbkdf2Type = PBKDF2_SHA1;
}
StringBuilder sb = new StringBuilder();
sb.append("{").append(pbkdf2Type).append("}");
@@ -206,23 +206,23 @@ public class HashCrypt {
int typeEnd = crypted.indexOf("}");
String hashType = crypted.substring(1, typeEnd);
String[] parts = crypted.split("\\$");
- int iterations = Integer.parseInt(parts[0].substring(typeEnd+1));
+ int iterations = Integer.parseInt(parts[0].substring(typeEnd + 1));
byte[] salt = Arrays.toString(java.util.Base64.getMimeDecoder().decode(parts[1].getBytes(StandardCharsets.UTF_8))).getBytes(StandardCharsets.UTF_8);
byte[] hash = Base64.decodeBase64(parts[2].getBytes(StandardCharsets.UTF_8));
PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, hash.length * 8);
- switch (hashType.substring(hashType.indexOf("-")+1)) {
- case "SHA256":
- hashType = "PBKDF2WithHmacSHA256";
- break;
- case "SHA384":
- hashType = "PBKDF2WithHmacSHA384";
- break;
- case "SHA512":
- hashType = "PBKDF2WithHmacSHA512";
- break;
- default:
- hashType = "PBKDF2WithHmacSHA1";
+ switch (hashType.substring(hashType.indexOf("-") + 1)) {
+ case "SHA256":
+ hashType = "PBKDF2WithHmacSHA256";
+ break;
+ case "SHA384":
+ hashType = "PBKDF2WithHmacSHA384";
+ break;
+ case "SHA512":
+ hashType = "PBKDF2WithHmacSHA512";
+ break;
+ default:
+ hashType = "PBKDF2WithHmacSHA1";
}
SecretKeyFactory skf = SecretKeyFactory.getInstance(hashType);
byte[] testHash = skf.generateSecret(spec).getEncoded();
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/lang/ThreadSafe.java b/framework/base/src/main/java/org/apache/ofbiz/base/lang/ThreadSafe.java
index 06530394b6..1f8b52c20d 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/lang/ThreadSafe.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/lang/ThreadSafe.java
@@ -28,4 +28,4 @@ import java.lang.annotation.Target;
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
-public @interface ThreadSafe {}
+public @interface ThreadSafe { }
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/metrics/Metrics.java b/framework/base/src/main/java/org/apache/ofbiz/base/metrics/Metrics.java
index cc93d0a1a9..5a1ac50ed8 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/metrics/Metrics.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/metrics/Metrics.java
@@ -61,7 +61,7 @@ public interface Metrics {
/** Returns the total number of processed events. */
long getTotalEvents();
- /**
+ /**
* Records the service time for numEvents taking
* time milliseconds to be processed.
*/
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java
index d08f4fde06..9bca29d239 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java
@@ -76,9 +76,9 @@ public final class Debug {
}
}
- public static Logger getLogger(String MODULE) {
- if (UtilValidate.isNotEmpty(MODULE)) {
- return LogManager.getLogger(MODULE);
+ public static Logger getLogger(String module) {
+ if (UtilValidate.isNotEmpty(module)) {
+ return LogManager.getLogger(module);
}
return root;
}
@@ -91,19 +91,19 @@ public final class Debug {
return levelStringMap.get(levelName.toLowerCase(Locale.getDefault()));
}
- public static void log(int level, Throwable t, String msg, String MODULE) {
- log(level, t, msg, MODULE, "org.apache.ofbiz.base.util.Debug", emptyParams);
+ public static void log(int level, Throwable t, String msg, String module) {
+ log(level, t, msg, module, "org.apache.ofbiz.base.util.Debug", emptyParams);
}
- public static void log(int level, Throwable t, String msg, String MODULE, Object... params) {
- log(level, t, msg, MODULE, "org.apache.ofbiz.base.util.Debug", params);
+ public static void log(int level, Throwable t, String msg, String module, Object... params) {
+ log(level, t, msg, module, "org.apache.ofbiz.base.util.Debug", params);
}
- public static void log(int level, Throwable t, String msg, String MODULE, String callingClass) {
- log(level, t, msg, MODULE, callingClass, new Object[0]);
+ public static void log(int level, Throwable t, String msg, String module, String callingClass) {
+ log(level, t, msg, module, callingClass, new Object[0]);
}
- public static void log(int level, Throwable t, String msg, String MODULE, String callingClass, Object... params) {
+ public static void log(int level, Throwable t, String msg, String module, String callingClass, Object... params) {
if (isOn(level)) {
if (msg != null && params.length > 0) {
StringBuilder sb = new StringBuilder();
@@ -114,7 +114,7 @@ public final class Debug {
}
// log
- Logger logger = getLogger(MODULE);
+ Logger logger = getLogger(module);
logger.log(levelObjs[level], msg, t);
}
}
@@ -136,192 +136,192 @@ public final class Debug {
log(Debug.ALWAYS, t, null, noModuleModule, emptyParams);
}
- public static void log(String msg, String MODULE) {
- log(Debug.ALWAYS, null, msg, MODULE, emptyParams);
+ public static void log(String msg, String module) {
+ log(Debug.ALWAYS, null, msg, module, emptyParams);
}
- public static void log(String msg, String MODULE, Object... params) {
- log(Debug.ALWAYS, null, msg, MODULE, params);
+ public static void log(String msg, String module, Object... params) {
+ log(Debug.ALWAYS, null, msg, module, params);
}
- public static void log(Throwable t, String MODULE) {
- log(Debug.ALWAYS, t, null, MODULE, emptyParams);
+ public static void log(Throwable t, String module) {
+ log(Debug.ALWAYS, t, null, module, emptyParams);
}
- public static void log(Throwable t, String msg, String MODULE) {
- log(Debug.ALWAYS, t, msg, MODULE, emptyParams);
+ public static void log(Throwable t, String msg, String module) {
+ log(Debug.ALWAYS, t, msg, module, emptyParams);
}
- public static void log(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.ALWAYS, t, msg, MODULE, params);
+ public static void log(Throwable t, String msg, String module, Object... params) {
+ log(Debug.ALWAYS, t, msg, module, params);
}
public static boolean verboseOn() {
return isOn(Debug.VERBOSE);
}
- public static void logVerbose(String msg, String MODULE) {
- log(Debug.VERBOSE, null, msg, MODULE, emptyParams);
+ public static void logVerbose(String msg, String module) {
+ log(Debug.VERBOSE, null, msg, module, emptyParams);
}
- public static void logVerbose(String msg, String MODULE, Object... params) {
- log(Debug.VERBOSE, null, msg, MODULE, params);
+ public static void logVerbose(String msg, String module, Object... params) {
+ log(Debug.VERBOSE, null, msg, module, params);
}
- public static void logVerbose(Throwable t, String MODULE) {
- log(Debug.VERBOSE, t, null, MODULE, emptyParams);
+ public static void logVerbose(Throwable t, String module) {
+ log(Debug.VERBOSE, t, null, module, emptyParams);
}
- public static void logVerbose(Throwable t, String msg, String MODULE) {
- log(Debug.VERBOSE, t, msg, MODULE, emptyParams);
+ public static void logVerbose(Throwable t, String msg, String module) {
+ log(Debug.VERBOSE, t, msg, module, emptyParams);
}
- public static void logVerbose(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.VERBOSE, t, msg, MODULE, params);
+ public static void logVerbose(Throwable t, String msg, String module, Object... params) {
+ log(Debug.VERBOSE, t, msg, module, params);
}
public static boolean timingOn() {
return isOn(Debug.TIMING);
}
- public static void logTiming(String msg, String MODULE) {
- log(Debug.TIMING, null, msg, MODULE, emptyParams);
+ public static void logTiming(String msg, String module) {
+ log(Debug.TIMING, null, msg, module, emptyParams);
}
- public static void logTiming(String msg, String MODULE, Object... params) {
- log(Debug.TIMING, null, msg, MODULE, params);
+ public static void logTiming(String msg, String module, Object... params) {
+ log(Debug.TIMING, null, msg, module, params);
}
- public static void logTiming(Throwable t, String MODULE) {
- log(Debug.TIMING, t, null, MODULE, emptyParams);
+ public static void logTiming(Throwable t, String module) {
+ log(Debug.TIMING, t, null, module, emptyParams);
}
- public static void logTiming(Throwable t, String msg, String MODULE) {
- log(Debug.TIMING, t, msg, MODULE, emptyParams);
+ public static void logTiming(Throwable t, String msg, String module) {
+ log(Debug.TIMING, t, msg, module, emptyParams);
}
- public static void logTiming(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.TIMING, t, msg, MODULE, params);
+ public static void logTiming(Throwable t, String msg, String module, Object... params) {
+ log(Debug.TIMING, t, msg, module, params);
}
public static boolean infoOn() {
return isOn(Debug.INFO);
}
- public static void logInfo(String msg, String MODULE) {
- log(Debug.INFO, null, msg, MODULE, emptyParams);
+ public static void logInfo(String msg, String module) {
+ log(Debug.INFO, null, msg, module, emptyParams);
}
- public static void logInfo(String msg, String MODULE, Object... params) {
- log(Debug.INFO, null, msg, MODULE, params);
+ public static void logInfo(String msg, String module, Object... params) {
+ log(Debug.INFO, null, msg, module, params);
}
- public static void logInfo(Throwable t, String MODULE) {
- log(Debug.INFO, t, null, MODULE, emptyParams);
+ public static void logInfo(Throwable t, String module) {
+ log(Debug.INFO, t, null, module, emptyParams);
}
- public static void logInfo(Throwable t, String msg, String MODULE) {
- log(Debug.INFO, t, msg, MODULE, emptyParams);
+ public static void logInfo(Throwable t, String msg, String module) {
+ log(Debug.INFO, t, msg, module, emptyParams);
}
- public static void logInfo(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.INFO, t, msg, MODULE, params);
+ public static void logInfo(Throwable t, String msg, String module, Object... params) {
+ log(Debug.INFO, t, msg, module, params);
}
public static boolean importantOn() {
return isOn(Debug.IMPORTANT);
}
- public static void logImportant(String msg, String MODULE) {
- log(Debug.IMPORTANT, null, msg, MODULE, emptyParams);
+ public static void logImportant(String msg, String module) {
+ log(Debug.IMPORTANT, null, msg, module, emptyParams);
}
- public static void logImportant(String msg, String MODULE, Object... params) {
- log(Debug.IMPORTANT, null, msg, MODULE, params);
+ public static void logImportant(String msg, String module, Object... params) {
+ log(Debug.IMPORTANT, null, msg, module, params);
}
- public static void logImportant(Throwable t, String MODULE) {
- log(Debug.IMPORTANT, t, null, MODULE, emptyParams);
+ public static void logImportant(Throwable t, String module) {
+ log(Debug.IMPORTANT, t, null, module, emptyParams);
}
- public static void logImportant(Throwable t, String msg, String MODULE) {
- log(Debug.IMPORTANT, t, msg, MODULE, emptyParams);
+ public static void logImportant(Throwable t, String msg, String module) {
+ log(Debug.IMPORTANT, t, msg, module, emptyParams);
}
- public static void logImportant(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.IMPORTANT, t, msg, MODULE, params);
+ public static void logImportant(Throwable t, String msg, String module, Object... params) {
+ log(Debug.IMPORTANT, t, msg, module, params);
}
public static boolean warningOn() {
return isOn(Debug.WARNING);
}
- public static void logWarning(String msg, String MODULE) {
- log(Debug.WARNING, null, msg, MODULE, emptyParams);
+ public static void logWarning(String msg, String module) {
+ log(Debug.WARNING, null, msg, module, emptyParams);
}
- public static void logWarning(String msg, String MODULE, Object... params) {
- log(Debug.WARNING, null, msg, MODULE, params);
+ public static void logWarning(String msg, String module, Object... params) {
+ log(Debug.WARNING, null, msg, module, params);
}
- public static void logWarning(Throwable t, String MODULE) {
- log(Debug.WARNING, t, null, MODULE, emptyParams);
+ public static void logWarning(Throwable t, String module) {
+ log(Debug.WARNING, t, null, module, emptyParams);
}
- public static void logWarning(Throwable t, String msg, String MODULE) {
- log(Debug.WARNING, t, msg, MODULE, emptyParams);
+ public static void logWarning(Throwable t, String msg, String module) {
+ log(Debug.WARNING, t, msg, module, emptyParams);
}
- public static void logWarning(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.WARNING, t, msg, MODULE, params);
+ public static void logWarning(Throwable t, String msg, String module, Object... params) {
+ log(Debug.WARNING, t, msg, module, params);
}
public static boolean errorOn() {
return isOn(Debug.ERROR);
}
- public static void logError(String msg, String MODULE) {
- log(Debug.ERROR, null, msg, MODULE, emptyParams);
+ public static void logError(String msg, String module) {
+ log(Debug.ERROR, null, msg, module, emptyParams);
}
- public static void logError(String msg, String MODULE, Object... params) {
- log(Debug.ERROR, null, msg, MODULE, params);
+ public static void logError(String msg, String module, Object... params) {
+ log(Debug.ERROR, null, msg, module, params);
}
- public static void logError(Throwable t, String MODULE) {
- log(Debug.ERROR, t, null, MODULE, emptyParams);
+ public static void logError(Throwable t, String module) {
+ log(Debug.ERROR, t, null, module, emptyParams);
}
- public static void logError(Throwable t, String msg, String MODULE) {
- log(Debug.ERROR, t, msg, MODULE, emptyParams);
+ public static void logError(Throwable t, String msg, String module) {
+ log(Debug.ERROR, t, msg, module, emptyParams);
}
- public static void logError(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.ERROR, t, msg, MODULE, params);
+ public static void logError(Throwable t, String msg, String module, Object... params) {
+ log(Debug.ERROR, t, msg, module, params);
}
public static boolean fatalOn() {
return isOn(Debug.FATAL);
}
- public static void logFatal(String msg, String MODULE) {
- log(Debug.FATAL, null, msg, MODULE, emptyParams);
+ public static void logFatal(String msg, String module) {
+ log(Debug.FATAL, null, msg, module, emptyParams);
}
- public static void logFatal(String msg, String MODULE, Object... params) {
- log(Debug.FATAL, null, msg, MODULE, params);
+ public static void logFatal(String msg, String module, Object... params) {
+ log(Debug.FATAL, null, msg, module, params);
}
- public static void logFatal(Throwable t, String MODULE) {
- log(Debug.FATAL, t, null, MODULE, emptyParams);
+ public static void logFatal(Throwable t, String module) {
+ log(Debug.FATAL, t, null, module, emptyParams);
}
- public static void logFatal(Throwable t, String msg, String MODULE) {
- log(Debug.FATAL, t, msg, MODULE, emptyParams);
+ public static void logFatal(Throwable t, String msg, String module) {
+ log(Debug.FATAL, t, msg, module, emptyParams);
}
- public static void logFatal(Throwable t, String msg, String MODULE, Object... params) {
- log(Debug.FATAL, t, msg, MODULE, params);
+ public static void logFatal(Throwable t, String msg, String module, Object... params) {
+ log(Debug.FATAL, t, msg, module, params);
}
public static void set(int level, boolean on) {
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
index 67c6d062cb..6495c17641 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
@@ -51,7 +51,6 @@ import org.apache.ofbiz.base.location.ComponentLocationResolver;
/**
* File Utilities
- *
*/
public final class FileUtil {
@@ -59,68 +58,6 @@ public final class FileUtil {
private FileUtil() { }
- private static class SearchTextFilesFilter implements FilenameFilter {
- String fileExtension;
- Set stringsToFindInFile = new HashSet<>();
- Set stringsToFindInPath = new HashSet<>();
-
- public SearchTextFilesFilter(String fileExtension, Set stringsToFindInPath, Set 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 (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);
}
@@ -154,9 +91,7 @@ public final class FileUtil {
public static void writeString(String path, String name, String s) {
- try (
- Writer out = getBufferedWriter(path, name);
- ) {
+ try (Writer out = getBufferedWriter(path, name);) {
out.write(s + System.getProperty("line.separator"));
} catch (IOException e) {
Debug.logError(e, MODULE);
@@ -243,8 +178,7 @@ public final class FileUtil {
}
StringBuffer buf = new StringBuffer();
- try (
- BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));) {
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));) {
String str;
while ((str = in.readLine()) != null) {
@@ -259,6 +193,7 @@ public final class FileUtil {
return buf;
}
+
public static StringBuffer readTextFile(String fileName, boolean newline) throws FileNotFoundException, IOException {
File file = new File(fileName);
return readTextFile(file, newline);
@@ -303,10 +238,10 @@ public final class FileUtil {
Set stringsToFindInFile = new HashSet<>();
if (partialPath != null) {
- stringsToFindInPath.add(partialPath);
+ stringsToFindInPath.add(partialPath);
}
if (stringToFind != null) {
- stringsToFindInFile.add(stringToFind);
+ stringsToFindInFile.add(stringToFind);
}
List fileList = new LinkedList<>();
@@ -339,75 +274,67 @@ public final class FileUtil {
}
/**
- *
- *
- * Search for the specified searchString in the given
- * {@link Reader}.
- *
- * @param reader A Reader in which the String will be searched.
- * @param searchString The String to search for
- * @return TRUE if the searchString is found;
- * FALSE otherwise.
- * @throws IOException
- */
- public static boolean containsString(Reader reader, final String searchString) throws IOException {
- char[] buffer = new char[1024];
- int numCharsRead;
- int count = 0;
- while((numCharsRead = reader.read(buffer)) > 0) {
- for (int c = 0; c < numCharsRead; ++c) {
- if (buffer[c] == searchString.charAt(count)) {
- count++;
- } else {
- count = 0;
- }
- if (count == searchString.length()) {
- return true;
- }
- }
- }
- return false;
- }
+ * Search for the specified searchString in the given
+ * {@link Reader}.
+ *
+ * @param reader A Reader in which the String will be searched.
+ * @param searchString The String to search for
+ * @return TRUE if the searchString is found;
+ * FALSE otherwise.
+ * @throws IOException
+ */
+ public static boolean containsString(Reader reader, final String searchString) throws IOException {
+ char[] buffer = new char[1024];
+ int numCharsRead;
+ int count = 0;
+ while ((numCharsRead = reader.read(buffer)) > 0) {
+ for (int c = 0; c < numCharsRead; ++c) {
+ if (buffer[c] == searchString.charAt(count)) {
+ count++;
+ } else {
+ count = 0;
+ }
+ if (count == searchString.length()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
- /**
- *
- *
- * Search for the specified searchString in the given
- * filename. If the specified file doesn't exist, FALSE
- * returns.
- *
- * @param fileName A full path to a file in which the String will be searched.
- * @param searchString The String to search for
- * @return TRUE if the searchString is found;
- * FALSE otherwise.
- * @throws IOException
- */
- public static boolean containsString(final String fileName, final String searchString) throws IOException {
- File inFile = new File(fileName);
- if (inFile.exists()) {
- try (
- BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile), StandardCharsets.UTF_8));
- ) {
- return containsString(in, searchString);
- }
- }
- return false;
- }
+ /**
+ * Search for the specified searchString in the given
+ * filename. If the specified file doesn't exist, FALSE
+ * returns.
+ *
+ * @param fileName A full path to a file in which the String will be searched.
+ * @param searchString The String to search for
+ * @return TRUE if the searchString is found;
+ * FALSE otherwise.
+ * @throws IOException
+ */
+ public static boolean containsString(final String fileName, final String searchString) throws IOException {
+ File inFile = new File(fileName);
+ if (inFile.exists()) {
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile), StandardCharsets.UTF_8));) {
+ return containsString(in, searchString);
+ }
+ }
+ return false;
+ }
- /**
- *
- *
- * Check if the specified fileName exists and is a file (not a directory)
- * If the specified file doesn't exist or is a directory FALSE returns.
- *
- * @param fileName A full path to a file in which the String will be searched.
- * @return TRUE if the fileName exists and is a file (not a directory)
- * FALSE otherwise.
- */
- public static boolean isFile(String fileName) {
- File f = new File(fileName);
- return f.isFile();
- }
+ /**
+ * Check if the specified fileName exists and is a file (not a directory)
+ * If the specified file doesn't exist or is a directory FALSE returns.
+ *
+ * @param fileName A full path to a file in which the String will be searched.
+ * @return TRUE if the fileName exists and is a file (not a directory)
+ * FALSE otherwise.
+ */
+ public static boolean isFile(String fileName) {
+ File f = new File(fileName);
+ return f.isFile();
+ }
/**
* For an inputStream and a file name, create a zip stream containing only one entry with the inputStream set to fileName
@@ -488,10 +415,11 @@ public final class FileUtil {
zis.closeEntry();
zis.close();
}
+
/**
* Creates a File with a normalized file path
- * This useful to prevent path traversal security issues
- * cf. OFBIZ-9973 for more details
+ * This useful to prevent path traversal security issues
+ * cf. OFBIZ-9973 for more details
*
* @param filePath The file path to normalize
* @return A File with a normalized file path
@@ -499,9 +427,10 @@ public final class FileUtil {
public static File createFileWithNormalizedPath(String filePath) {
return new File(filePath).toPath().normalize().toFile();
}
+
/**
* Normalizes a file path
- * This useful to prevent path traversal security issues
+ * This useful to prevent path traversal security issues
*
* @param filePath The file path to normalize
* @return A normalized file path
@@ -510,4 +439,66 @@ public final class FileUtil {
return createFileWithNormalizedPath(filePath).toString();
}
+ private static class SearchTextFilesFilter implements FilenameFilter {
+ String fileExtension;
+ Set stringsToFindInFile = new HashSet<>();
+ Set stringsToFindInPath = new HashSet<>();
+
+ public SearchTextFilesFilter(String fileExtension, Set stringsToFindInPath, Set 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 (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;
+ }
+ }
+
}
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
index 8f9542b68b..9007b48400 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
@@ -153,7 +153,8 @@ public final class GroovyUtil {
Debug.logVerbose("Cached Groovy script at: " + location, MODULE);
}
} else {
- // the newly parsed script is discarded and the one found in the cache (that has been created by a concurrent thread in the meantime) is used
+ // the newly parsed script is discarded and the one found in the cache (that has been created by a concurrent thread in the
+ // meantime) is used
scriptClass = scriptClassCached;
}
}
@@ -213,6 +214,6 @@ public final class GroovyUtil {
Script script = InvokerHelper.createScript(getScriptClassFromLocation(location), getBinding(context));
return UtilValidate.isEmpty(methodName)
? script.run()
- : script.invokeMethod(methodName, new Object[] { context });
+ : script.invokeMethod(methodName, new Object[] {context });
}
}
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java
index 8fe4cf8695..36a6950cac 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java
@@ -249,40 +249,40 @@ public final class SSLUtil {
public static HostnameVerifier getHostnameVerifier(int level) {
switch (level) {
- case HOSTCERT_MIN_CHECK:
- return (hostname, session) -> {
- Certificate[] peerCerts;
+ case HOSTCERT_MIN_CHECK:
+ return (hostname, session) -> {
+ Certificate[] peerCerts;
+ try {
+ peerCerts = session.getPeerCertificates();
+ } catch (SSLPeerUnverifiedException e) {
+ // cert not verified
+ Debug.logWarning(e.getMessage(), MODULE);
+ return false;
+ }
+ for (Certificate peerCert : peerCerts) {
try {
- peerCerts = session.getPeerCertificates();
- } catch (SSLPeerUnverifiedException e) {
- // cert not verified
- Debug.logWarning(e.getMessage(), MODULE);
+ Principal x500s = session.getPeerPrincipal();
+ Map subjectMap = KeyStoreUtil.getX500Map(x500s);
+ if (Debug.infoOn()) {
+ byte[] encodedCert = peerCert.getEncoded();
+ Debug.logInfo(new BigInteger(encodedCert).toString(16)
+ + " :: " + subjectMap.get("CN"), MODULE);
+ }
+ peerCert.verify(peerCert.getPublicKey());
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ // certificate not valid
+ Debug.logWarning("Certificate is not valid!", MODULE);
return false;
}
- for (Certificate peerCert : peerCerts) {
- try {
- Principal x500s = session.getPeerPrincipal();
- Map subjectMap = KeyStoreUtil.getX500Map(x500s);
- if (Debug.infoOn()) {
- byte[] encodedCert = peerCert.getEncoded();
- Debug.logInfo(new BigInteger(encodedCert).toString(16)
- + " :: " + subjectMap.get("CN"), MODULE);
- }
- peerCert.verify(peerCert.getPublicKey());
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- // certificate not valid
- Debug.logWarning("Certificate is not valid!", MODULE);
- return false;
- }
- }
- return true;
- };
- case HOSTCERT_NO_CHECK:
- return (hostname, session) -> true;
- default:
- return null;
+ }
+ return true;
+ };
+ case HOSTCERT_NO_CHECK:
+ return (hostname, session) -> true;
+ default:
+ return null;
}
}
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
index fdae05d9b9..854591a774 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
@@ -53,7 +53,7 @@ public final class UtilGenerics {
if (!(object instanceof Map, ?>)) {
throw new ClassCastException("Not a map");
}
- Map, ?> map = (Map,?>) object;
+ Map, ?> map = (Map, ?>) object;
int i = 0;
for (Map.Entry, ?> entry: map.entrySet()) {
if (entry.getKey() != null && !keyType.isInstance(entry.getKey())) {
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
index ad354b8371..d565eb1f5e 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
@@ -756,7 +756,7 @@ public final class UtilHttp {
if (localeObject == null) {
Map, ?> userLogin = (Map, ?>) session.getAttribute("userLogin");
if (userLogin == null) {
- userLogin = (Map,?>) session.getAttribute("autoUserLogin");
+ userLogin = (Map, ?>) session.getAttribute("autoUserLogin");
}
if (userLogin != null) {
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
index 63c1be568a..ccca665ed4 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
@@ -98,7 +98,7 @@ public final class UtilJavaParse {
// search through the component directories, in the src directory for each, using the class path as the path within it
String sourceSubPath = fullyQualifiedClassName.substring(0, fullyQualifiedClassName.lastIndexOf(".")).replace('.', File.separatorChar);
- String classFileName = fullyQualifiedClassName.substring(fullyQualifiedClassName.lastIndexOf(".")+1) + ".java";
+ String classFileName = fullyQualifiedClassName.substring(fullyQualifiedClassName.lastIndexOf(".") + 1) + ".java";
Collection allComponentConfigs = ComponentConfig.getAllComponents();
for (ComponentConfig cc: allComponentConfigs) {
@@ -163,8 +163,8 @@ public final class UtilJavaParse {
public static int findEndOfBlock(int blockStart, String javaFile) {
- int nextOpen = javaFile.indexOf("{", blockStart+1);
- int nextClose = javaFile.indexOf("}", blockStart+1);
+ int nextOpen = javaFile.indexOf("{", blockStart + 1);
+ int nextClose = javaFile.indexOf("}", blockStart + 1);
if (nextOpen > 0 && nextClose > 0 && nextClose > nextOpen) {
javaFile = javaFile.substring(nextOpen, nextClose);
}
@@ -178,8 +178,8 @@ public final class UtilJavaParse {
if (endOfSubBlock < 0) {
return -1;
}
- nextOpen = javaFile.indexOf("{", endOfSubBlock+1);
- nextClose = javaFile.indexOf("}", endOfSubBlock+1);
+ nextOpen = javaFile.indexOf("{", endOfSubBlock + 1);
+ nextClose = javaFile.indexOf("}", endOfSubBlock + 1);
}
// at this point there should be no nextOpen or nextOpen is after the nextClose, meaning we're at the end of the block
@@ -189,7 +189,7 @@ public final class UtilJavaParse {
public static Set findServiceCallsInBlock(int blockStart, int blockEnd, String javaFile) {
Set serviceNameSet = new HashSet<>();
- int dispatcherIndex = javaFile.indexOf("dispatcher.", blockStart+1);
+ int dispatcherIndex = javaFile.indexOf("dispatcher.", blockStart + 1);
while (dispatcherIndex > 0 && dispatcherIndex < blockEnd) {
// verify it is a call we're looking for
int openParenIndex = javaFile.indexOf("(", dispatcherIndex);
@@ -197,10 +197,10 @@ public final class UtilJavaParse {
if (serviceMethodNames.contains(curMethodName)) {
// find the service name
int openQuoteIndex = javaFile.indexOf("\"", openParenIndex);
- int closeQuoteIndex = javaFile.indexOf("\"", openQuoteIndex+1);
+ int closeQuoteIndex = javaFile.indexOf("\"", openQuoteIndex + 1);
if (openQuoteIndex - openParenIndex <= 3 && openQuoteIndex >= 0 && closeQuoteIndex >= 0) {
//more than two spaces/chars between quote and open paren... consider it something other than what we are looking for
- String serviceName = javaFile.substring(openQuoteIndex+1, closeQuoteIndex).trim();
+ String serviceName = javaFile.substring(openQuoteIndex + 1, closeQuoteIndex).trim();
serviceNameSet.add(serviceName);
}
}
@@ -214,7 +214,7 @@ public final class UtilJavaParse {
public static Set findEntityUseInBlock(int blockStart, int blockEnd, String javaFile) {
Set entityNameSet = new HashSet<>();
- int delegatorIndex = javaFile.indexOf("delegator.", blockStart+1);
+ int delegatorIndex = javaFile.indexOf("delegator.", blockStart + 1);
while (delegatorIndex > 0 && delegatorIndex < blockEnd) {
// verify it is a call we're looking for
int openParenIndex = javaFile.indexOf("(", delegatorIndex);
@@ -222,10 +222,10 @@ public final class UtilJavaParse {
if (entityMethodNames.contains(curMethodName)) {
// find the entity name
int openQuoteIndex = javaFile.indexOf("\"", openParenIndex);
- int closeQuoteIndex = javaFile.indexOf("\"", openQuoteIndex+1);
+ int closeQuoteIndex = javaFile.indexOf("\"", openQuoteIndex + 1);
if (openQuoteIndex - openParenIndex <= 3 && openQuoteIndex >= 0 && closeQuoteIndex >= 0) {
//more than two spaces/chars between quote and open paren... consider it something other than what we are looking for
- String entityName = javaFile.substring(openQuoteIndex+1, closeQuoteIndex).trim();
+ String entityName = javaFile.substring(openQuoteIndex + 1, closeQuoteIndex).trim();
entityNameSet.add(entityName);
}
}
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
index 946fece3ca..4bb7ebaa49 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
@@ -98,6 +98,7 @@ public final class UtilMisc {
/**
* Get an iterator from a collection, returning null if collection is null
+ *
* @param col The collection to be turned in to an iterator
* @return The resulting Iterator
*/
@@ -111,7 +112,7 @@ public final class UtilMisc {
/**
* Creates a pseudo-literal map corresponding to key-values.
*
- * @param kvs the key-value pairs
+ * @param kvs the key-value pairs
* @return the corresponding map.
* @throws IllegalArgumentException when the key-value list is not even.
*/
@@ -122,8 +123,8 @@ public final class UtilMisc {
/**
* Creates a pseudo-literal map corresponding to key-values.
*
- * @param constructor the constructor used to instantiate the map
- * @param kvs the key-value pairs
+ * @param constructor the constructor used to instantiate the map
+ * @param kvs the key-value pairs
* @return the corresponding map.
* @throws IllegalArgumentException when the key-value list is not even.
*/
@@ -134,12 +135,12 @@ public final class UtilMisc {
}
if (kvs.length % 2 == 1) {
IllegalArgumentException e = new IllegalArgumentException(
- "You must pass an even sized array to the toMap method (size = " + kvs.length + ")");
+ "You must pass an even sized array to the toMap method (size = " + kvs.length + ")");
Debug.logInfo(e, MODULE);
throw e;
}
Map map = constructor.get();
- for (int i = 0; i < kvs.length;) {
+ for (int i = 0; i < kvs.length; ) {
map.put((K) kvs[i++], (V) kvs[i++]);
}
return map;
@@ -147,7 +148,7 @@ public final class UtilMisc {
public static String printMap(Map extends K, ? extends V> theMap) {
StringBuilder theBuf = new StringBuilder();
- for (Map.Entry extends K, ? extends V> entry: theMap.entrySet()) {
+ for (Map.Entry extends K, ? extends V> entry : theMap.entrySet()) {
theBuf.append(entry.getKey());
theBuf.append(" --> ");
theBuf.append(entry.getValue());
@@ -182,7 +183,7 @@ public final class UtilMisc {
public static void makeMapSerializable(Map map) {
// now filter out all non-serializable values
Set keysToRemove = new LinkedHashSet<>();
- for (Map.Entry mapEntry: map.entrySet()) {
+ for (Map.Entry mapEntry : map.entrySet()) {
Object entryValue = mapEntry.getValue();
if (entryValue != null && !(entryValue instanceof Serializable)) {
keysToRemove.add(mapEntry.getKey());
@@ -192,13 +193,16 @@ public final class UtilMisc {
}
}
- for (String keyToRemove: keysToRemove) { map.remove(keyToRemove); }
+ for (String keyToRemove : keysToRemove) {
+ map.remove(keyToRemove);
+ }
}
/**
* Sort a List of Maps by specified consistent keys.
+ *
* @param listOfMaps List of Map objects to sort.
- * @param sortKeys List of Map keys to sort by.
+ * @param sortKeys List of Map keys to sort by.
* @return a new List of sorted Maps.
*/
public static List