diff options
Diffstat (limited to 'BKUApplet')
5 files changed, 174 insertions, 89 deletions
diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 97b5869f..470534da 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -21,6 +21,8 @@ import java.net.URL; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; @@ -36,79 +38,105 @@ import at.gv.egiz.bku.gui.BKUGUIFactory; */ public class BKUApplet extends JApplet { - private static Log log = LogFactory.getLog(BKUApplet.class); - public static final String GUI_STYLE = "GuiStyle"; - public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; - public final static String LOCALE_PARAM_KEY = "Locale"; - public final static String LOGO_URL_KEY = "LogoURL"; - public final static String WSDL_URL = "WSDL_URL"; - public static final String HASHDATA_DISPLAY = "HashDataDisplay"; - public final static String HASHDATA_URL = "HashDataURL"; - public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_PARAM = "Background"; - public static final String REDIRECT_URL = "RedirectURL"; - public static final String REDIRECT_TARGET = "RedirectTarget"; - - public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; - - protected ResourceBundle resourceBundle; - protected BKUWorker worker; - protected Thread workerThread; + private static Log log = LogFactory.getLog(BKUApplet.class); + public static final String GUI_STYLE = "GuiStyle"; + public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public final static String LOCALE_PARAM_KEY = "Locale"; + public final static String LOGO_URL_KEY = "LogoURL"; + public final static String WSDL_URL = "WSDL_URL"; + public static final String HASHDATA_DISPLAY = "HashDataDisplay"; + public final static String HASHDATA_URL = "HashDataURL"; + public final static String HELP_URL = "HelpURL"; + public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_PARAM = "Background"; + public static final String REDIRECT_URL = "RedirectURL"; + public static final String REDIRECT_TARGET = "RedirectTarget"; + public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; + protected ResourceBundle resourceBundle; + protected BKUWorker worker; + protected Thread workerThread; - public BKUApplet() { - } + public BKUApplet() { + } - public void init() { - log.info("Welcome to MOCCA\n"); - log.debug("Called init()"); - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); - if (localeString != null) { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, + @Override + public void init() { + log.info("Welcome to MOCCA\n"); + log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); + String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + if (localeString != null) { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, new Locale(localeString)); - } else { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); - } - String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); - URL background = null; - if (backgroundString != null) { - try { - background = new URL(backgroundString); - } catch (MalformedURLException ex) { - log.warn(ex.getMessage() + ", using default background"); - } - } - String guiStyle = getMyAppletParameter(GUI_STYLE); - BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - gui.init(getContentPane(), localeString, background); - worker = new BKUWorker(gui, this, resourceBundle); + } else { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); } - - public void start() { - log.debug("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); + String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); + URL background = null; + if (backgroundString != null) { + try { + background = new URL(backgroundString); + } catch (MalformedURLException ex) { + log.warn(ex.getMessage() + ", using default background"); + } } - - public void stop() { - log.debug("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } + String guiStyle = getMyAppletParameter(GUI_STYLE); + BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); + ExternalHelpListener helpListener = null; + try { + URL helpURL = getMyAppletParameterURL(HELP_URL); + helpListener = new ExternalHelpListener(getAppletContext(), helpURL, localeString); + } catch (MalformedURLException ex) { + log.error("invalid help URL: " + ex.getMessage()); } + gui.init(getContentPane(), localeString, background, helpListener); + worker = new BKUWorker(gui, this, resourceBundle); + } - public void destroy() { - log.debug("Called destroy()"); + @Override + public void start() { + log.debug("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } + + @Override + public void stop() { + log.debug("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); } + } + + @Override + public void destroy() { + log.debug("Called destroy()"); + } + + /** + * Applet configuration parameters + * + * @param paramKey + * @return + */ + String getMyAppletParameter(String paramKey) { + log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); + return getParameter(paramKey); + } - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - public String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); - return getParameter(paramKey); + URL getMyAppletParameterURL(String param) throws MalformedURLException { + String hashDataParam = getMyAppletParameter(param); //BKUApplet.HASHDATA_URL); + if (hashDataParam != null) { + URL codebase = getCodeBase(); + try { + return new URL(codebase, hashDataParam); + } catch (MalformedURLException ex) { + log.error("Paremeter " + param + " is not a valid URL.", ex); + throw new MalformedURLException(ex.getMessage()); + } + } else { + log.error("Paremeter " + param + " not set"); + throw new MalformedURLException(param + " not set"); } + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index f708826d..78f3dc12 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.xml.namespace.QName; import org.apache.commons.logging.Log; @@ -46,6 +48,7 @@ import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; +import javax.naming.ConfigurationException; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, ActionListener, SMCCSTALRequestHandler { @@ -68,7 +71,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, public BKUWorker(BKUGUIFacade gui, BKUApplet parent, ResourceBundle errorMessageBundle) { if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { - throw new NullPointerException("Parameter must not be set to null"); + throw new NullPointerException("Parameter must not be set to null"); } this.gui = gui; this.parent = parent; @@ -117,23 +120,6 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, return stal.getSTALPort(); } - private URL getHashDataURL() throws MalformedURLException { - String hashDataParam = parent.getMyAppletParameter(BKUApplet.HASHDATA_URL); - URL codebase = parent.getCodeBase(); - if (hashDataParam != null) { - try { - return new URL(codebase, hashDataParam); -// log.debug("Found HashDataInputServlet URL: " + hashDataURL); - } catch (MalformedURLException ex) { - log.fatal("Paremeter " + BKUApplet.HASHDATA_URL + " is not a vailid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } - } else { - log.fatal("Paremeter " + BKUApplet.HASHDATA_URL + " not set"); - throw new MalformedURLException(BKUApplet.HASHDATA_URL + " not set"); - } - } - @Override public void run() { gui.showWelcomeDialog(); @@ -165,7 +151,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); } else { //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { - URL hashDataURL = getHashDataURL(); + URL hashDataURL = parent.getMyAppletParameterURL(BKUApplet.HASHDATA_URL); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(parent.getAppletContext(), hashDataURL)); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java new file mode 100644 index 00000000..4d6d5851 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java @@ -0,0 +1,70 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.online.applet; + +import java.applet.AppletContext; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author clemens + */ +public class ExternalHelpListener implements ActionListener { + + protected final static Log log = LogFactory.getLog(ExternalHelpListener.class); + protected AppletContext ctx; + protected String helpURLBase; + protected String locale; + + public ExternalHelpListener(AppletContext ctx, URL helpURL, String locale) { + if (ctx == null) { + throw new RuntimeException("no applet context provided"); + } + if (helpURL == null || "".equals(helpURL)) { + throw new RuntimeException("no help URL provided"); + } + this.ctx = ctx; + this.helpURLBase = helpURL.toString(); + this.locale = locale; + } + + @Override + public void actionPerformed(ActionEvent e) { + log.debug("received help action: " + e.getActionCommand()); + URL helpURL; + try { + String urlString = helpURLBase; + if (locale != null) { + urlString = appendParameter(urlString, "locale", locale); + } + if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { + urlString = appendParameter(urlString, "topic", e.getActionCommand()); + } + helpURL = new URL(urlString); + } catch (MalformedURLException ex) { + try { + log.error("failed to create help URL: " + ex.getMessage()); + helpURL = new URL(helpURLBase); + } catch (MalformedURLException ex1) { + log.error("failed to create default help URL, requested help will not be displayed"); + return; + } + } + ctx.showDocument(helpURL, "_blank"); + } + + private String appendParameter(String url, String paramName, String paramValue) { + if (url.indexOf('?') < 0) { + return url + "?" + paramName + "=" + paramValue; + } else { + return url + "&" + paramName + "=" + paramValue; + } + } +} diff --git a/BKUApplet/src/main/resources/simplelog.properties b/BKUApplet/src/main/resources/simplelog.properties index 51be76a8..d62508cf 100644 --- a/BKUApplet/src/main/resources/simplelog.properties +++ b/BKUApplet/src/main/resources/simplelog.properties @@ -15,7 +15,7 @@ # Logging detail level, # Must be one of ("trace", "debug", "info", "warn", "error", or "fatal"). -org.apache.commons.logging.simplelog.defaultlog=trace +org.apache.commons.logging.simplelog.defaultlog=debug # Logs the Log instance used org.apache.commons.logging.simplelog.showlogname=true #Logs the class name with package(or Path) diff --git a/BKUApplet/src/test/resources/appletTest.html b/BKUApplet/src/test/resources/appletTest.html index 472000de..daf8445b 100644 --- a/BKUApplet/src/test/resources/appletTest.html +++ b/BKUApplet/src/test/resources/appletTest.html @@ -19,14 +19,15 @@ <center> <applet code="at.gv.egiz.bku.online.applet.BKUApplet.class" archive="../BKUApplet-1.0-SNAPSHOT.jar, ../test-libs/commons-logging-1.1.1.jar , ../test-libs/iaik_jce_me4se-3.04.jar" - width=190 height=130> - <param name="GuiStyle" value="simple"/> + width=300 height=200> + <param name="GuiStyle" value="advanced"/> <param name="Background" value="http://localhost:3495/DemoIntegration/mocca_background.png"/> - <param name="WSDL_URL" value="http://localhost:3495/BKUOnline-1.0-SNAPSHOT/stal?wsdl"/> + <param name="WSDL_URL" value="http://localhost:3495/stal?wsdl"/> + <param name="HelpURL" value="http://localhost:3495/help"/> <param name="HashDataDisplay" value="internal"/> <!--param name="HashDataURL" value="http://localhost:3495/BKUOnline-1.0-SNAPSHOT/hashDataInput"/--> <param name="SessionId" value="TestSession"/> - <param name="RedirectURL" value="http://localhost:3495/BKUOnline-1.0-SNAPSHOT/bkuResult"/> + <param name="RedirectURL" value="http://localhost:3495/bkuResult"/> </applet> </center> </body> |