Initial commit for site for forms

This commit is contained in:
2024-01-13 16:24:54 +01:00
commit 2b908b4e94
39 changed files with 1649 additions and 0 deletions
@@ -0,0 +1,48 @@
package com.alttd.forms.properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Optional;
import java.util.Properties;
public class PropertiesLoader {
private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
public static Optional<Properties> loadProperties(String fileName) {
Properties prop = new Properties();
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
if (currentJarPath.isEmpty()) {
logger.error("Unable to find jar path to load properties (" + fileName + ")");
return Optional.empty();
}
File file = new File(currentJarPath.get(), fileName);
if (!file.exists()) {
logger.warn("Tried to load properties file that doesnt exists (" + fileName + ")");
return Optional.empty();
}
if (!file.canRead()) {
logger.error("Unable to read properties file (" + fileName + ")");
return Optional.empty();
}
if (!file.isFile()) {
logger.error("Invalid properties file (" + fileName + ")");
return Optional.empty();
}
try (FileInputStream input = new FileInputStream(file)) {
prop.load(input);
return Optional.of(prop);
} catch (IOException ex) {
logger.error("Failed to load properties due to an unexpected error", ex);
}
return Optional.empty();
}
}