summaryrefslogtreecommitdiff
path: root/BKUCommonGUI/src/main/java/at/gv/egiz/bku
diff options
context:
space:
mode:
Diffstat (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku')
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpListener.java48
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerHelpListener.java8
2 files changed, 32 insertions, 24 deletions
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpListener.java
index 2f6f1738..a0ab2d77 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpListener.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpListener.java
@@ -20,6 +20,8 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
import org.slf4j.Logger;
@@ -30,14 +32,16 @@ public class HelpListener implements MouseListener, KeyListener, HelpURLProvider
public static final String MESSAGE_BUNDLE = "at/gv/egiz/bku/gui/Messages";
private final Logger log = LoggerFactory.getLogger(HelpListener.class);
- private String helpURL;
+
+ private URL baseURL;
+
protected String helpTopic;
protected ResourceBundle messageBundle;
- public HelpListener(String baseHelpURL, Locale locale) {
-
- helpURL = baseHelpURL;
+ public HelpListener(URL baseURL, Locale locale) {
+ this.baseURL = baseURL;
+
if (locale != null) {
log.trace("Check for support of requested help locale {}.", locale);
messageBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale);
@@ -45,14 +49,18 @@ public class HelpListener implements MouseListener, KeyListener, HelpURLProvider
messageBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE);
}
- if ("".equals(messageBundle.getLocale().getLanguage())) {
- log.trace("Using help locale 'default'.");
- } else {
- log.trace("Using help locale '{}'.", messageBundle.getLocale());
- helpURL += messageBundle.getLocale().getLanguage() + '/';
- }
-
- log.debug("Setting help context to {}.", helpURL);
+ String language = messageBundle.getLocale().getLanguage();
+ log.trace("Using help language '{}'.", language);
+ if (!language.isEmpty()) {
+ try {
+ baseURL = new URL(baseURL, language + "/");
+ } catch (MalformedURLException e) {
+ log.info("Failed to build baseURL using language {}. " +
+ "Using default language.", language, e);
+ }
+ }
+ log.debug("Setting help context to {}.", baseURL);
+
}
@Override
@@ -63,15 +71,15 @@ public class HelpListener implements MouseListener, KeyListener, HelpURLProvider
@Override
public synchronized String getHelpURL() {
- if (helpTopic == null) {
- log.debug("No help topic set, return index.");
- return helpURL + "index.html";
+ try {
+ URL helpURL = new URL(baseURL, (helpTopic != null) ? "index.html" : helpTopic + ".html");
+ log.debug("Return help url: {}.", helpURL);
+ return helpURL.toString();
+ } catch (MalformedURLException e) {
+ log.info("Failed to build helpURL. Returning base URL: {}.", baseURL, e);
+ return baseURL.toString();
}
- StringBuilder url = new StringBuilder(helpURL);
- url.append(helpTopic);
- url.append(".html");
- log.debug("Return help url: {}.", url.toString());
- return url.toString();
+
}
/**
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerHelpListener.java
index 3d01c404..3c35e7b6 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerHelpListener.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerHelpListener.java
@@ -33,12 +33,12 @@ public class ViewerHelpListener extends HelpListener {
protected AppletContext appletCtx;
- public ViewerHelpListener(String helpURL, Locale locale) {
- super(helpURL, locale);
+ public ViewerHelpListener(URL baseURL, Locale locale) {
+ super(baseURL, locale);
}
- public ViewerHelpListener(AppletContext ctx, String helpURL, Locale locale) {
- super(helpURL, locale);
+ public ViewerHelpListener(AppletContext ctx, URL baseURL, Locale locale) {
+ super(baseURL, locale);
this.appletCtx = ctx;
}