diff options
Diffstat (limited to 'BKUCommonGUI')
3 files changed, 35 insertions, 25 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; } diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java index b927aecd..dde71390 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java @@ -12,6 +12,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URL; import java.util.ResourceBundle; import org.junit.After; import org.junit.AfterClass; @@ -32,8 +33,9 @@ public class SecureViewerDialogTest { @BeforeClass public static void setUpClass() throws Exception { + URL baseURL = new URL("../help"); messages = ResourceBundle.getBundle("at/gv/egiz/bku/gui/Messages"); - secureViewer = new SecureViewerDialog(null, messages,null, null, new DummyFontLoader(), new HelpListener("../help", messages.getLocale()), 1f); + secureViewer = new SecureViewerDialog(null, messages,null, null, new DummyFontLoader(), new HelpListener(baseURL, messages.getLocale()), 1f); } @AfterClass |