1 package net.sf.imca.model;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5 import java.util.Locale;
6 import java.util.Properties;
7 import java.util.ResourceBundle;
8
9 import javax.mail.MessagingException;
10 import javax.mail.Session;
11 import javax.mail.internet.InternetAddress;
12 import javax.mail.internet.MimeMessage;
13
14 public class ImcaUtils {
15
16 public static final String IMCA_DATE_PATTERN = "yyyy-MM-dd";
17
18 public static final String MAIL_ENCODING = "UTF-8";
19
20 private final static SimpleDateFormat sdf = new SimpleDateFormat(IMCA_DATE_PATTERN);
21
22 public final static String IMCA_MESSAGE_BUNDLE_BASE = "net.sf.imca.i18n.messages";
23
24
25
26 public static String[] getCountryCodes(){
27 return Locale.getISOCountries();
28 }
29
30 public static String[] getCurrencyCodes() {
31 return new String[]{"AUD", "CHF", "EUR", "GBP", "USD"};
32 }
33
34 public static MimeMessage createEmailMessage() throws MessagingException {
35
36
37 Properties props = System.getProperties();
38 InternetAddress from = new InternetAddress("imcaadmin@moth-sailing.org");
39 props.put("mail.smtp.host", "relay1.nameonthe.net");
40
41 Session session = Session.getDefaultInstance(props, null);
42 MimeMessage message = new MimeMessage(session);
43 message.setFrom(from);
44 message.setSentDate(new Date());
45
46 return message;
47 }
48
49 public static String getMessage(String messageKey, Locale locale) {
50 ResourceBundle i18n = ResourceBundle.getBundle(
51 IMCA_MESSAGE_BUNDLE_BASE, locale);
52 try {
53 return i18n.getString(messageKey);
54 } catch (java.util.MissingResourceException mre) {
55 return "???" + messageKey + "???";
56 }
57 }
58
59 public static String formatDate(Date date){
60 return sdf.format(date);
61 }
62
63 }