Improved: Updated case indentation to 0 for all switch statements in framework component. Also done formatting changes as per checkstyle best practices.

(OFBIZ-11904)
This commit is contained in:
Suraj Khurana
2020-07-25 13:50:37 +05:30
parent 4739019732
commit f4f2722d36
67 changed files with 977 additions and 945 deletions
@@ -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");
@@ -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();
@@ -28,4 +28,4 @@ import java.lang.annotation.Target;
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface ThreadSafe {}
public @interface ThreadSafe { }
@@ -61,7 +61,7 @@ public interface Metrics {
/** Returns the total number of processed events. */
long getTotalEvents();
/**
/**
* Records the service time for <code>numEvents</code> taking
* <code>time</code> milliseconds to be processed.
*/
@@ -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) {
@@ -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<String> stringsToFindInFile = new HashSet<>();
Set<String> stringsToFindInPath = new HashSet<>();
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 (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<String> stringsToFindInFile = new HashSet<>();
if (partialPath != null) {
stringsToFindInPath.add(partialPath);
stringsToFindInPath.add(partialPath);
}
if (stringToFind != null) {
stringsToFindInFile.add(stringToFind);
stringsToFindInFile.add(stringToFind);
}
List<File> fileList = new LinkedList<>();
@@ -339,75 +274,67 @@ public final class FileUtil {
}
/**
*
*
* Search for the specified <code>searchString</code> in the given
* {@link Reader}.
*
* @param reader A Reader in which the String will be searched.
* @param searchString The String to search for
* @return <code>TRUE</code> if the <code>searchString</code> is found;
* <code>FALSE</code> 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 <code>searchString</code> in the given
* {@link Reader}.
*
* @param reader A Reader in which the String will be searched.
* @param searchString The String to search for
* @return <code>TRUE</code> if the <code>searchString</code> is found;
* <code>FALSE</code> 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 <code>searchString</code> in the given
* filename. If the specified file doesn't exist, <code>FALSE</code>
* returns.
*
* @param fileName A full path to a file in which the String will be searched.
* @param searchString The String to search for
* @return <code>TRUE</code> if the <code>searchString</code> is found;
* <code>FALSE</code> 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 <code>searchString</code> in the given
* filename. If the specified file doesn't exist, <code>FALSE</code>
* returns.
*
* @param fileName A full path to a file in which the String will be searched.
* @param searchString The String to search for
* @return <code>TRUE</code> if the <code>searchString</code> is found;
* <code>FALSE</code> 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 <code>fileName</code> exists and is a file (not a directory)
* If the specified file doesn't exist or is a directory <code>FALSE</code> returns.
*
* @param fileName A full path to a file in which the String will be searched.
* @return <code>TRUE</code> if the <code>fileName</code> exists and is a file (not a directory)
* <code>FALSE</code> otherwise.
*/
public static boolean isFile(String fileName) {
File f = new File(fileName);
return f.isFile();
}
/**
* Check if the specified <code>fileName</code> exists and is a file (not a directory)
* If the specified file doesn't exist or is a directory <code>FALSE</code> returns.
*
* @param fileName A full path to a file in which the String will be searched.
* @return <code>TRUE</code> if the <code>fileName</code> exists and is a file (not a directory)
* <code>FALSE</code> 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<String> stringsToFindInFile = new HashSet<>();
Set<String> stringsToFindInPath = new HashSet<>();
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 (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;
}
}
}
@@ -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 });
}
}
@@ -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<String, String> 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<String, String> 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;
}
}
@@ -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())) {
@@ -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) {
@@ -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<ComponentConfig> 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<String> findServiceCallsInBlock(int blockStart, int blockEnd, String javaFile) {
Set<String> 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<String> findEntityUseInBlock(int blockStart, int blockEnd, String javaFile) {
Set<String> 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);
}
}
@@ -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<K, V> 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 <K, V> 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 <V> void makeMapSerializable(Map<String, V> map) {
// now filter out all non-serializable values
Set<String> keysToRemove = new LinkedHashSet<>();
for (Map.Entry<String, V> mapEntry: map.entrySet()) {
for (Map.Entry<String, V> 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<Map<Object, Object>> sortMaps(List<Map<Object, Object>> listOfMaps, List<? extends String> sortKeys) {
@@ -310,6 +314,7 @@ public final class UtilMisc {
/**
* Create a set from the passed objects.
*
* @param data
* @return theSet
*/
@@ -342,7 +347,7 @@ public final class UtilMisc {
return null;
}
Set<T> set = new LinkedHashSet<>();
for (T value: data) {
for (T value : data) {
set.add(value);
}
return set;
@@ -350,6 +355,7 @@ public final class UtilMisc {
/**
* Creates a list from passed objects.
*
* @param data
* @return list
*/
@@ -373,7 +379,7 @@ public final class UtilMisc {
return null;
}
List<T> list = new LinkedList<>();
for (T value: data) {
for (T value : data) {
list.add(value);
}
return list;
@@ -406,8 +412,10 @@ public final class UtilMisc {
theSet.add(element);
}
/** Converts an <code>Object</code> to a <code>double</code>. Returns
/**
* Converts an <code>Object</code> to a <code>double</code>. Returns
* zero if conversion is not possible.
*
* @param obj Object to convert
* @return double value
*/
@@ -416,8 +424,10 @@ public final class UtilMisc {
return result == null ? 0.0 : result;
}
/** Converts an <code>Object</code> to a <code>Double</code>. Returns
/**
* Converts an <code>Object</code> to a <code>Double</code>. Returns
* <code>null</code> if conversion is not possible.
*
* @param obj Object to convert
* @return Double
*/
@@ -441,8 +451,10 @@ public final class UtilMisc {
return result;
}
/** Converts an <code>Object</code> to an <code>int</code>. Returns
/**
* Converts an <code>Object</code> to an <code>int</code>. Returns
* zero if conversion is not possible.
*
* @param obj Object to convert
* @return int value
*/
@@ -451,8 +463,10 @@ public final class UtilMisc {
return result == null ? 0 : result;
}
/** Converts an <code>Object</code> to an <code>Integer</code>. Returns
/**
* Converts an <code>Object</code> to an <code>Integer</code>. Returns
* <code>null</code> if conversion is not possible.
*
* @param obj Object to convert
* @return Integer
*/
@@ -476,8 +490,10 @@ public final class UtilMisc {
return result;
}
/** Converts an <code>Object</code> to a <code>long</code>. Returns
/**
* Converts an <code>Object</code> to a <code>long</code>. Returns
* zero if conversion is not possible.
*
* @param obj Object to convert
* @return long value
*/
@@ -486,8 +502,10 @@ public final class UtilMisc {
return result == null ? 0 : result;
}
/** Converts an <code>Object</code> to a <code>Long</code>. Returns
/**
* Converts an <code>Object</code> to a <code>Long</code>. Returns
* <code>null</code> if conversion is not possible.
*
* @param obj Object to convert
* @return Long
*/
@@ -513,6 +531,7 @@ public final class UtilMisc {
/**
* Adds value to the key entry in theMap, or creates a new one if not already there
*
* @param theMap
* @param key
* @param value
@@ -528,6 +547,7 @@ public final class UtilMisc {
/**
* Parse a locale string Locale object
*
* @param localeString The locale string (en_US)
* @return Locale The new Locale object or null if no valid locale can be interpreted
*/
@@ -552,19 +572,22 @@ public final class UtilMisc {
String extension = localeString.substring(6);
locale = new Locale(language, country, extension);
} else {
Debug.logWarning("Do not know what to do with the localeString [" + localeString + "], should be length 2, 5, or greater than 6, returning null", MODULE);
Debug.logWarning("Do not know what to do with the localeString [" + localeString + "], should be length 2, 5, or greater than 6, " +
"returning null", MODULE);
}
return locale;
}
/** The input can be a String, Locale, or even null and a valid Locale will always be returned; if nothing else works, returns the default locale.
/**
* The input can be a String, Locale, or even null and a valid Locale will always be returned; if nothing else works, returns the default locale.
*
* @param localeObject An Object representing the locale
*/
public static Locale ensureLocale(Object localeObject) {
if (localeObject instanceof String) {
Locale locale = parseLocale((String) localeObject);
if (locale != null) {
if (locale != null) {
return locale;
}
} else if (localeObject instanceof Locale) {
@@ -573,39 +596,17 @@ public final class UtilMisc {
return Locale.getDefault();
}
// Private lazy-initializer class
private static class LocaleHolder {
private static final List<Locale> availableLocaleList = getAvailableLocaleList();
private static List<Locale> getAvailableLocaleList() {
TreeMap<String, Locale> localeMap = new TreeMap<>();
String localesString = UtilProperties.getPropertyValue("general", "locales.available");
if (UtilValidate.isNotEmpty(localesString)) {
List<String> idList = StringUtil.split(localesString, ",");
for (String id : idList) {
Locale curLocale = parseLocale(id);
localeMap.put(curLocale.getDisplayName(), curLocale);
}
} else {
Locale[] locales = Locale.getAvailableLocales();
for (int i = 0; i < locales.length && locales[i] != null; i++) {
String displayName = locales[i].getDisplayName();
if (!displayName.isEmpty()) {
localeMap.put(displayName, locales[i]);
}
}
}
return Collections.unmodifiableList(new ArrayList<>(localeMap.values()));
}
}
/** Returns a List of available locales sorted by display name */
/**
* Returns a List of available locales sorted by display name
*/
public static List<Locale> availableLocales() {
return LocaleHolder.availableLocaleList;
return LocaleHolder.AVAIL_LOCALE_LIST;
}
/** List of domains or IP addresses to be checked to prevent Host Header Injection,
/**
* List of domains or IP addresses to be checked to prevent Host Header Injection,
* no spaces after commas, no wildcard, can be extended of course...
*
* @return List of domains or IP addresses to be checked to prevent Host Header Injection,
*/
public static List<String> getHostHeadersAllowed() {
@@ -617,7 +618,9 @@ public final class UtilMisc {
return Collections.unmodifiableList(hostHeadersAllowed);
}
/** @deprecated use Thread.sleep() */
/**
* @deprecated use Thread.sleep()
*/
@Deprecated
public static void staticWait(long timeout) throws InterruptedException {
Thread.sleep(timeout);
@@ -627,10 +630,8 @@ public final class UtilMisc {
if (sourceLocation.isDirectory()) {
throw new IOException("File is a directory, not a file, cannot copy");
}
try (
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);
) {
try (InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);) {
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
@@ -674,4 +675,30 @@ public final class UtilMisc {
return result;
}
// Private lazy-initializer class
private static class LocaleHolder {
private static final List<Locale> AVAIL_LOCALE_LIST = getAvailableLocaleList();
private static List<Locale> getAvailableLocaleList() {
TreeMap<String, Locale> localeMap = new TreeMap<>();
String localesString = UtilProperties.getPropertyValue("general", "locales.available");
if (UtilValidate.isNotEmpty(localesString)) {
List<String> idList = StringUtil.split(localesString, ",");
for (String id : idList) {
Locale curLocale = parseLocale(id);
localeMap.put(curLocale.getDisplayName(), curLocale);
}
} else {
Locale[] locales = Locale.getAvailableLocales();
for (int i = 0; i < locales.length && locales[i] != null; i++) {
String displayName = locales[i].getDisplayName();
if (!displayName.isEmpty()) {
localeMap.put(displayName, locales[i]);
}
}
}
return Collections.unmodifiableList(new ArrayList<>(localeMap.values()));
}
}
}
@@ -219,7 +219,7 @@ public final class UtilNumber {
* @deprecated Use {@link #getRoundingMode(String, String)} instead
*/
@Deprecated
public static int getBigDecimalRoundingMode(String file, String property) {
public static int getBigDecimalRoundingMode(String file, String property) {
return getRoundingMode(file, property).ordinal();
}
@@ -89,7 +89,7 @@ public class UtilTimer {
* @param MODULE The debug/log MODULE/thread to use, can be null for root MODULE
* @return A String with the timing information, the timer String
*/
public String timerString(String message, String MODULE) {
public String timerString(String message, String module) {
// time this call to avoid it interfering with the main timer
long tsStart = System.currentTimeMillis();
@@ -108,7 +108,7 @@ public class UtilTimer {
lastMessage = message;
String retString = retBuf.toString();
if (log) {
Debug.log(Debug.TIMING, null, retString, MODULE, "org.apache.ofbiz.base.util.UtilTimer");
Debug.log(Debug.TIMING, null, retString, module, "org.apache.ofbiz.base.util.UtilTimer");
}
// have lastMessageTime come as late as possible to just time what happens between calls
@@ -222,17 +222,17 @@ public class UtilTimer {
return timer;
}
public static void timerLog(String timerName, String message, String MODULE) {
public static void timerLog(String timerName, String message, String module) {
UtilTimer timer = UtilTimer.getTimer(timerName);
if (!timer.isRunning()) {
timer.startTimer();
}
if (timer.getLog()) {
if (MODULE == null) {
MODULE = timer.getClass().getName();
if (module == null) {
module = timer.getClass().getName();
}
timer.timerString(message, MODULE);
timer.timerString(message, module);
}
}
@@ -244,9 +244,9 @@ public class UtilTimer {
UtilTimer.closeTimer(timerName, message, null);
}
public static void closeTimer(String timerName, String message, String MODULE) {
public static void closeTimer(String timerName, String message, String module) {
if (message != null) {
UtilTimer.timerLog(timerName, message, MODULE);
UtilTimer.timerLog(timerName, message, module);
}
staticTimers.remove(timerName);
}
@@ -169,7 +169,7 @@ public final class UtilURL {
String path = fileUrl.getPath();
if (path.startsWith(ofbizHome)) {
// note: the +1 is to remove the leading slash
path = path.substring(ofbizHome.length()+1);
path = path.substring(ofbizHome.length() + 1);
}
return path;
}
@@ -1097,14 +1097,14 @@ public final class UtilValidate {
String first6digs = cc.substring(0, 6);
if (((cc.length() == 16) || (cc.length() == 18) || (cc.length() == 19))
&& ("4903".equals(first4digs)
|| "4905".equals(first4digs)
|| "4911".equals(first4digs)
|| "4936".equals(first4digs)
|| "564182".equals(first6digs)
|| "633110".equals(first6digs)
|| "6333".equals(first4digs)
|| "6759".equals(first4digs))) {
&& ("4903".equals(first4digs)
|| "4905".equals(first4digs)
|| "4911".equals(first4digs)
|| "4936".equals(first4digs)
|| "564182".equals(first6digs)
|| "633110".equals(first6digs)
|| "6333".equals(first4digs)
|| "6759".equals(first4digs))) {
return isCreditCard(cc);
}
return false;
@@ -1117,8 +1117,7 @@ public final class UtilValidate {
private static boolean isSolo(String cc) {
String first4digs = cc.substring(0, 4);
String first2digs = cc.substring(0, 2);
if (((cc.length() == 16) || (cc.length() == 18) || (cc.length() == 19)) &&
("63".equals(first2digs) || "6767".equals(first4digs))) {
if (((cc.length() == 16) || (cc.length() == 18) || (cc.length() == 19)) && ("63".equals(first2digs) || "6767".equals(first4digs))) {
return isCreditCard(cc);
}
return false;
@@ -1241,7 +1240,7 @@ public final class UtilValidate {
if (("CCT_SOLO".equalsIgnoreCase(cardType)) && (isSolo(cardNumber))) {
return true;
}
if (("CCT_SWITCH".equalsIgnoreCase(cardType)) && (isSwitch (cardNumber))) {
if (("CCT_SWITCH".equalsIgnoreCase(cardType)) && (isSwitch(cardNumber))) {
return true;
}
if (("CCT_VISAELECTRON".equalsIgnoreCase(cardType)) && (isVisaElectron(cardNumber))) {
@@ -81,7 +81,7 @@ import com.thoughtworks.xstream.XStream;
public final class UtilXml {
private static final String MODULE = UtilXml.class.getName();
private static final XStream xstream = createXStream();
private static final XStream X_STREAM = createXStream();
private UtilXml() { }
private static XStream createXStream() {
@@ -255,7 +255,7 @@ public final class UtilXml {
* @return The deserialized <code>Object</code>
*/
public static Object fromXml(InputStream input) {
return xstream.fromXML(input);
return X_STREAM.fromXML(input);
}
/** Deserialize an object from a <code>Reader</code>.
@@ -264,7 +264,7 @@ public final class UtilXml {
* @return The deserialized <code>Object</code>
*/
public static Object fromXml(Reader reader) {
return xstream.fromXML(reader);
return X_STREAM.fromXML(reader);
}
/** Deserialize an object from a <code>String</code>.
@@ -273,7 +273,7 @@ public final class UtilXml {
* @return The deserialized <code>Object</code>
*/
public static Object fromXml(String str) {
return xstream.fromXML(str);
return X_STREAM.fromXML(str);
}
/** Serialize an object to an XML <code>String</code>.
@@ -282,7 +282,7 @@ public final class UtilXml {
* @return An XML <code>String</code>
*/
public static String toXml(Object obj) {
return xstream.toXML(obj);
return X_STREAM.toXML(obj);
}
/** Serialize an object to an <code>OutputStream</code>.
@@ -291,7 +291,7 @@ public final class UtilXml {
* @param output The <code>OutputStream</code>
*/
public static void toXml(Object obj, OutputStream output) {
xstream.toXML(obj, output);
X_STREAM.toXML(obj, output);
}
/** Serialize an object to a <code>Writer</code>.
@@ -300,7 +300,7 @@ public final class UtilXml {
* @param writer The <code>Writer</code>
*/
public static void toXml(Object obj, Writer writer) {
xstream.toXML(obj, writer);
X_STREAM.toXML(obj, writer);
}
// ------------------------------------------------- //
@@ -1045,8 +1045,8 @@ public final class UtilXml {
String dtd = UtilProperties.getSplitPropertyValue(UtilURL.fromResource("localdtds.properties"), publicId);
if (UtilValidate.isNotEmpty(dtd)) {
if (Debug.verboseOn()) {
Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] resolving DTD with publicId [" + publicId +
"], systemId [" + systemId + "] and the dtd file is [" + dtd + "]", MODULE);
Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] resolving DTD with publicId [" + publicId
+ "], systemId [" + systemId + "] and the dtd file is [" + dtd + "]", MODULE);
}
try {
URL dtdURL = UtilURL.fromResource(dtd);
@@ -1059,8 +1059,8 @@ public final class UtilXml {
inputSource.setPublicId(publicId);
hasDTD = true;
if (Debug.verboseOn()) {
Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] got LOCAL DTD input source with publicId [" +
publicId + "] and the dtd file is [" + dtd + "]", MODULE);
Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] got LOCAL DTD input source with publicId ["
+ publicId + "] and the dtd file is [" + dtd + "]", MODULE);
}
return inputSource;
} catch (GeneralException | IOException e) {
@@ -1087,13 +1087,13 @@ public final class UtilXml {
}
hasDTD = true;
if (Debug.verboseOn()) {
Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] got LOCAL DTD/Schema input source with publicId [" +
publicId + "] and the file/resource is [" + filename + "]", MODULE);
Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] got LOCAL DTD/Schema input source with publicId ["
+ publicId + "] and the file/resource is [" + filename + "]", MODULE);
}
return inputSource;
}
Debug.logWarning("[UtilXml.LocalResolver.resolveEntity] could not find LOCAL DTD/Schema with publicId [" +
publicId + "] and the file/resource is [" + filename + "]", MODULE);
Debug.logWarning("[UtilXml.LocalResolver.resolveEntity] could not find LOCAL DTD/Schema with publicId ["
+ publicId + "] and the file/resource is [" + filename + "]", MODULE);
return null;
}
return defaultResolver.resolveEntity(publicId, systemId);
@@ -1129,12 +1129,11 @@ public final class UtilXml {
Matcher matcher = valueFlexExpr.matcher(exceptionMessage.toLowerCase());
if (localResolver.hasDTD() && !matcher.find()) {
Debug.logError("XmlFileLoader: File "
+ docDescription
+ " process error. Line: "
+ String.valueOf(exception.getLineNumber())
+ ". Error message: "
+ exceptionMessage, MODULE
);
+ docDescription
+ " process error. Line: "
+ String.valueOf(exception.getLineNumber())
+ ". Error message: "
+ exceptionMessage, MODULE);
}
}
@@ -1142,12 +1141,11 @@ public final class UtilXml {
public void fatalError(SAXParseException exception) {
if (localResolver.hasDTD()) {
Debug.logError("XmlFileLoader: File "
+ docDescription
+ " process fatal error. Line: "
+ String.valueOf(exception.getLineNumber())
+ ". Error message: "
+ exception.getMessage(), MODULE
);
+ docDescription
+ " process fatal error. Line: "
+ String.valueOf(exception.getLineNumber())
+ ". Error message: "
+ exception.getMessage(), MODULE);
}
}
@@ -1155,12 +1153,11 @@ public final class UtilXml {
public void warning(SAXParseException exception) {
if (localResolver.hasDTD()) {
Debug.logError("XmlFileLoader: File "
+ docDescription
+ " process warning. Line: "
+ String.valueOf(exception.getLineNumber())
+ ". Error message: "
+ exception.getMessage(), MODULE
);
+ docDescription
+ " process warning. Line: "
+ String.valueOf(exception.getLineNumber())
+ ". Error message: "
+ exception.getMessage(), MODULE);
}
}
}
@@ -463,7 +463,7 @@ public class UtilCache<K, V> implements Serializable, EvictionListener<Object, C
/** Removes all elements from this cache */
public static void clearAllCaches() {
// We make a copy since clear may take time
for (UtilCache<?,?> cache : utilCacheTable.values()) {
for (UtilCache<?, ?> cache : utilCacheTable.values()) {
cache.clear();
}
}
@@ -74,7 +74,7 @@ public class FlexibleServletAccessor<T> implements Serializable {
int dotIndex = name.indexOf('.');
if (dotIndex != -1) {
attributeName = name.substring(0, dotIndex);
fma = FlexibleMapAccessor.getInstance(name.substring(dotIndex+1));
fma = FlexibleMapAccessor.getInstance(name.substring(dotIndex + 1));
} else {
attributeName = name;
fma = null;
@@ -215,7 +215,7 @@ public class FlexibleServletAccessor<T> implements Serializable {
int dotIndex = name.indexOf('.');
if (dotIndex != -1) {
attributeName = name.substring(0, dotIndex);
fma = FlexibleMapAccessor.getInstance(name.substring(dotIndex+1));
fma = FlexibleMapAccessor.getInstance(name.substring(dotIndex + 1));
} else {
attributeName = name;
fma = null;
@@ -229,7 +229,7 @@ public class FlexibleServletAccessor<T> implements Serializable {
openBrace = attributeName.indexOf('[');
closeBrace = (openBrace == -1 ? -1 : attributeName.indexOf(']', openBrace));
if (openBrace != -1 && closeBrace != -1) {
String liStr = attributeName.substring(openBrace+1, closeBrace);
String liStr = attributeName.substring(openBrace + 1, closeBrace);
//if brackets are empty, append to list
if (liStr.length() == 0) {
isAddAtEnd = true;
@@ -452,8 +452,7 @@ public class UelFunctions {
} else {
Debug.logError("Unable to locate XML document " + str, MODULE);
}
}
catch (IOException e) {
} catch (IOException e) {
Debug.logError(e, "Error while reading XML document " + str, MODULE);
}
return document;
@@ -483,7 +483,7 @@ public final class UelUtil {
int closeBrace = (openBrace == -1 ? -1 : result.indexOf(']', openBrace));
if (closeBrace != -1) {
String base = result.substring(0, openBrace);
String property = result.substring(openBrace+2, closeBrace).trim();
String property = result.substring(openBrace + 2, closeBrace).trim();
String end = result.substring(closeBrace + 1);
result = base + "['insert@" + property + "']" + end;
}
@@ -129,18 +129,18 @@ public final class FreeMarkerWorker {
String templateClassResolver = UtilProperties.getPropertyValue("security", "templateClassResolver",
"SAFER_RESOLVER");
switch (templateClassResolver) {
case "UNRESTRICTED_RESOLVER":
newConfig.setNewBuiltinClassResolver(TemplateClassResolver.UNRESTRICTED_RESOLVER);
break;
case "SAFER_RESOLVER":
newConfig.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
break;
case "ALLOWS_NOTHING_RESOLVER":
newConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
break;
default:
Debug.logError("Not a TemplateClassResolver.", MODULE);
break;
case "UNRESTRICTED_RESOLVER":
newConfig.setNewBuiltinClassResolver(TemplateClassResolver.UNRESTRICTED_RESOLVER);
break;
case "SAFER_RESOLVER":
newConfig.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
break;
case "ALLOWS_NOTHING_RESOLVER":
newConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
break;
default:
Debug.logError("Not a TemplateClassResolver.", MODULE);
break;
}
// Transforms properties file set up as key=transform name, property=transform class name
ClassLoader loader = Thread.currentThread().getContextClassLoader();