]> WPIA git - gigi.git/blob - src/club/wpia/gigi/util/ServerConstants.java
d3901e8d898563cd45afa6a87c1f5dd7238859d1
[gigi.git] / src / club / wpia / gigi / util / ServerConstants.java
1 package club.wpia.gigi.util;
2
3 import java.util.Properties;
4
5 public class ServerConstants {
6
7     private static String wwwHostName = "www.wpia.local";
8
9     private static String secureHostName = "secure.wpia.local";
10
11     private static String staticHostName = "static.wpia.local";
12
13     private static String apiHostName = "api.wpia.local";
14
15     private static String securePort, port, secureBindPort, bindPort;
16
17     private static String suffix = "wpia.local";
18
19     public static void init(Properties conf) {
20         securePort = port = "";
21         if ( !conf.getProperty("https.port").equals("443")) {
22             securePort = ":" + conf.getProperty("https.port");
23         }
24         if ( !conf.getProperty("http.port").equals("80")) {
25             port = ":" + conf.getProperty("http.port");
26         }
27         secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
28         bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
29         wwwHostName = conf.getProperty("name.www");
30         secureHostName = conf.getProperty("name.secure");
31         staticHostName = conf.getProperty("name.static");
32         apiHostName = conf.getProperty("name.api");
33         suffix = conf.getProperty("name.suffix", conf.getProperty("name.www").substring(4));
34
35     }
36
37     public static String getSecureHostName() {
38         return secureHostName;
39     }
40
41     public static String getStaticHostName() {
42         return staticHostName;
43     }
44
45     public static String getWwwHostName() {
46         return wwwHostName;
47     }
48
49     public static String getApiHostName() {
50         return apiHostName;
51     }
52
53     public static String getSecureHostNamePortSecure() {
54         return secureHostName + securePort;
55     }
56
57     public static String getStaticHostNamePortSecure() {
58         return staticHostName + securePort;
59     }
60
61     public static String getWwwHostNamePortSecure() {
62         return wwwHostName + securePort;
63     }
64
65     public static String getStaticHostNamePort() {
66         return staticHostName + port;
67     }
68
69     public static String getWwwHostNamePort() {
70         return wwwHostName + port;
71     }
72
73     public static String getApiHostNamePort() {
74         return apiHostName + securePort;
75     }
76
77     public static int getSecurePort() {
78         if (secureBindPort != null && !secureBindPort.isEmpty()) {
79             if (secureBindPort.equals("stdin")) {
80                 return -1;
81             } else {
82                 return Integer.parseInt(secureBindPort);
83             }
84         }
85         if (securePort.isEmpty()) {
86             return 443;
87         }
88         return Integer.parseInt(securePort.substring(1, securePort.length()));
89     }
90
91     public static int getPort() {
92         if (bindPort != null && !bindPort.isEmpty()) {
93             if (bindPort.equals("stdin")) {
94                 return -1;
95             } else {
96                 return Integer.parseInt(bindPort);
97             }
98         }
99         if (port.isEmpty()) {
100             return 80;
101         }
102         return Integer.parseInt(port.substring(1, port.length()));
103     }
104
105     public static String getSuffix() {
106         return suffix;
107     }
108
109     public static String getSupportMailAddress() {
110         return "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
111     }
112
113     public static String getBoardMailAddress() {
114         return "board@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
115     }
116
117     public static String getQuizMailAddress() {
118         return "quiz@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
119     }
120
121     public static String getQuizAdminMailAddress() {
122         return "quiz-admin@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
123     }
124
125 }