From af24a20257f4958ef5335d471a7fe2c93f475a35 Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 28 Jul 2010 09:05:04 +0000 Subject: Resolved issue [#MOCCA-745] (Two simultaneous requests within the same session cause failure in both requests). git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@790 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/HelpListener.java | 48 +++++++++++++--------- .../at/gv/egiz/bku/gui/ViewerHelpListener.java | 8 ++-- .../at/gv/egiz/bku/gui/SecureViewerDialogTest.java | 4 +- 3 files changed, 35 insertions(+), 25 deletions(-) (limited to 'BKUCommonGUI/src') 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 -- cgit v1.2.3