aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/HelpService.java26
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java11
2 files changed, 17 insertions, 20 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/HelpService.java b/juick-spring-www/src/main/java/com/juick/www/HelpService.java
index f6e9d352..8ece4cfb 100644
--- a/juick-spring-www/src/main/java/com/juick/www/HelpService.java
+++ b/juick-spring-www/src/main/java/com/juick/www/HelpService.java
@@ -1,13 +1,12 @@
package com.juick.www;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.Cacheable;
-import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.regex.Pattern;
/**
@@ -27,26 +26,23 @@ public class HelpService {
@Cacheable("help")
public String getHelp(final String page, final String lang) {
- if (canPage(page) && canLang(lang)) {
- try {
- Path file = Paths.get(helpPath, lang, page);
- String path = file.toString();
- file = Paths.get(new ClassPathResource(path).getURI());
-
- if (Files.isReadable(file))
- return new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
+ if (canBePage(page) && canBeLang(lang)) {
+ String path = StringUtils.joinWith("/", helpPath, lang, page);
+
+ try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
+ if (is != null)
+ return IOUtils.toString(is, StandardCharsets.UTF_8);
} catch (IOException e) {
}
}
-
return null;
}
- public boolean canPage(final String anything) {
+ public boolean canBePage(final String anything) {
return anything != null && PAGE_PATTERN.matcher(anything).matches();
}
- public boolean canLang(final String anything) {
+ public boolean canBeLang(final String anything) {
return anything != null && LANG_PATTERN.matcher(anything).matches();
}
}
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java
index 22ecacf3..7b1ec4d9 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java
@@ -12,6 +12,7 @@ import javax.inject.Inject;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Locale;
+import java.util.Objects;
import java.util.Optional;
/**
@@ -33,24 +34,24 @@ public class HelpController {
String page = pageParam.orElse("index");
String lang = langParam.orElse(locale.getLanguage());
- String content = null;
String navigation = null;
if (langOrPageParam.isPresent()) {
String langOrPage = langOrPageParam.get();
- if (helpService.canLang(langOrPage)) {
+ if (helpService.canBeLang(langOrPage)) {
navigation = helpService.getHelp("navigation", langOrPage);
if (navigation != null)
lang = langOrPage;
}
- if (navigation == null && helpService.canPage(langOrPage))
+ if (navigation == null && helpService.canBePage(langOrPage))
page = langOrPage;
}
- if (content == null)
- content = helpService.getHelp(page, lang);
+ String content = helpService.getHelp(page, lang);
+ if (content == null && !Objects.equals("index", page))
+ content = helpService.getHelp("index", lang);
if (navigation == null)
navigation = helpService.getHelp("navigation", lang);