diff options
author | Simon Rettberg | 2015-08-03 15:13:13 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-03 15:13:13 +0200 |
commit | 522998178bfd232c208009483dcf65a532b1464b (patch) | |
tree | 69396759437165c592cb0a8d7e07d449b0950473 /dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java | |
parent | [client] Cleaned up "OpenLinks" class (diff) | |
download | tutor-module-522998178bfd232c208009483dcf65a532b1464b.tar.gz tutor-module-522998178bfd232c208009483dcf65a532b1464b.tar.xz tutor-module-522998178bfd232c208009483dcf65a532b1464b.zip |
[client] Add eMail feature to PersonLabel
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java index 3263ee70..0ee446ed 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java @@ -2,7 +2,7 @@ package org.openslx.dozmod.util; import java.awt.Desktop; import java.net.URI; -import java.net.URISyntaxException; +import java.net.URLEncoder; import org.apache.log4j.Logger; @@ -21,30 +21,56 @@ public class OpenLinks { INTRO( "http://www.hs-offenburg.de/fileadmin/Einrichtungen/hrz/Projekte/bwLehrpool/3_bwLehrpool_-_Image_einbinden_und_starten.pdf"); - // TODO use enum not map private final URI uri; private Link(String uri) { - URI tmp; + this.uri = URI.create(uri); + } + } + + /** + * Open the URI corresponding to the given enum constant in the user's + * default web browser. + * + * @param location web site to open, passed as a member from the + * {@link Link} enum. + * @return success on true + */ + public static boolean openWebpage(Link location) { + if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { - tmp = new URI(uri); - } catch (URISyntaxException e) { - LOGGER.error("Hard-Coded URI contains syntax error!", e); - tmp = null; + desktop.browse(location.uri); + return true; + } catch (Exception e) { + LOGGER.error("Got exception in openWebpage: ", e); } - this.uri = tmp; } + return false; } - public static void openWebpage(Link location) { - - if (desktop == null || !desktop.isSupported(Desktop.Action.BROWSE)) - return; - try { - desktop.browse(location.uri); - } catch (Exception e) { - LOGGER.error("Got exception in openWebpage: ", e); + /** + * Send an email to the given email address, with an optional subject. This + * will open the user's default mail application. + * + * @param address receiver's address + * @param subject default subject to use, <code>null</code> for no subject + * @return false on not-success + */ + public static boolean sendMail(String address, String subject) { + if (desktop != null && desktop.isSupported(Desktop.Action.MAIL)) { + try { + if (subject != null) { + desktop.mail(new URI("mailto:" + address + "?subject=" + + URLEncoder.encode(subject, "UTF-8"))); + } else { + desktop.mail(new URI("mailto:" + address)); + } + return true; + } catch (Exception e) { + LOGGER.error("Got exception in sendMail: ", e); + } } + return false; } } |