blob: a9404e574a987688e1e17198aa174e32b6a11450 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.openslx.dozmod.util;
import java.awt.Desktop;
import java.net.URI;
import java.net.URLEncoder;
import org.apache.log4j.Logger;
public class OpenLinks {
/**
* Logger instance for this class
*/
private final static Logger LOGGER = Logger.getLogger(OpenLinks.class);
private static final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
enum Link {
FAQ("http://bwlehrpool.hs-offenburg.de"),
VMWARE("https://my.vmware.com/de/web/vmware/free#desktop_end_user_computing/vmware_player/6_0|PLAYER-603|product_downloads"),
INTRO("http://www.hs-offenburg.de/fileadmin/Einrichtungen/hrz/Projekte/bwLehrpool/3_bwLehrpool_-_Image_einbinden_und_starten.pdf");
private final URI uri;
private Link(String uri) {
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 {
desktop.browse(location.uri);
return true;
} catch (Exception e) {
LOGGER.error("Got exception in openWebpage: ", e);
}
}
return false;
}
/**
* 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;
}
}
|