1
1
mirror of https://github.com/MarginaliaSearch/MarginaliaSearch.git synced 2025-10-05 21:22:39 +02:00
Files
MarginaliaSearch/code/functions/language-processing/java/nu/marginalia/language/config/LanguageConfigLocation.java
Viktor Lofgren c661ebb619 (refac) Move language-processing into functions
It's long surpassed the single-responsibility library it once was, and is as such out of place in its original location, and fits better among the function-type modules.
2025-09-18 10:30:40 +02:00

44 lines
1.5 KiB
Java

package nu.marginalia.language.config;
import nu.marginalia.WmsaHome;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
sealed public interface LanguageConfigLocation {
InputStream findLanguageConfiguration() throws IOException;
final class Auto implements LanguageConfigLocation {
@Override
public InputStream findLanguageConfiguration() throws IOException {
Path filesystemPath = WmsaHome.getLangugeConfig();
if (Files.exists(filesystemPath)) {
return Files.newInputStream(filesystemPath, StandardOpenOption.READ);
}
if (Boolean.getBoolean("language.experimental")) {
return ClassLoader.getSystemResourceAsStream("languages-experimental.xml");
} else {
return ClassLoader.getSystemResourceAsStream("languages-default.xml");
}
}
}
final class Experimental implements LanguageConfigLocation {
@Override
public InputStream findLanguageConfiguration() throws IOException {
return ClassLoader.getSystemResourceAsStream("languages-experimental.xml");
}
}
final class Default implements LanguageConfigLocation {
@Override
public InputStream findLanguageConfiguration() throws IOException {
return ClassLoader.getSystemResourceAsStream("languages-default.xml");
}
}
}