4ab5094bf4f4a68fbe8fa239411660219cd3d9b7.svn-base
4.0 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.espeed.ua;
public enum Application {
HOTMAIL(Manufacturer.MICROSOFT, 1, "Windows Live Hotmail",
new String[] { "mail.live.com", "hotmail.msn" }, ApplicationType.WEBMAIL),
GMAIL( Manufacturer.GOOGLE, 5, "Gmail",
new String[] { "mail.google.com" }, ApplicationType.WEBMAIL),
YAHOO_MAIL( Manufacturer.YAHOO, 10, "Yahoo Mail",
new String[] { "mail.yahoo.com" }, ApplicationType.WEBMAIL),
COMPUSERVE( Manufacturer.COMPUSERVE, 20, "Compuserve",
new String[] { "csmail.compuserve.com" }, ApplicationType.WEBMAIL),
AOL_WEBMAIL( Manufacturer.AOL, 30, "AOL webmail",
new String[] { "webmail.aol.com" }, ApplicationType.WEBMAIL),
/**
* MobileMe webmail client by Apple. Previously known as .mac.
*/
MOBILEME( Manufacturer.APPLE, 40, "MobileMe",
new String[] { "www.me.com" }, ApplicationType.WEBMAIL),
/**
* Mail.com
* Mail.com provides consumers with web-based e-mail services
*/
MAIL_COM( Manufacturer.MMC, 50, "Mail.com",
new String[] { ".mail.com" }, ApplicationType.WEBMAIL),
/**
* Popular open source webmail client. Often installed by providers or privately.
*/
HORDE( Manufacturer.OTHER, 50, "horde",
new String[] { "horde" }, ApplicationType.WEBMAIL),
OTHER_WEBMAIL(Manufacturer.OTHER, 60, "Other webmail client",
new String[] { "webmail", "webemail" }, ApplicationType.WEBMAIL),
UNKNOWN(Manufacturer.OTHER, 0, "Unknown",
new String[0], ApplicationType.UNKNOWN);
private final short id;
private final String name;
private final String[] aliases;
private final ApplicationType applicationType;
private final Manufacturer manufacturer;
private Application(Manufacturer manufacturer, int versionId, String name,
String[] aliases, ApplicationType applicationType) {
this.id = (short) ((manufacturer.getId() << 8) + (byte) versionId);
this.name = name;
this.aliases = Utils.toLowerCase(aliases);
this.applicationType = applicationType;
this.manufacturer = manufacturer;
}
public short getId() {
return id;
}
public String getName() {
return name;
}
/**
* @return the applicationType
*/
public ApplicationType getApplicationType() {
return applicationType;
}
/**
* @return the manufacturer
*/
public Manufacturer getManufacturer() {
return manufacturer;
}
/*
* Checks if the given referrer string matches to the application. Only
* checks for one specific application.
*/
public boolean isInReferrerString(String referrerString) {
final String referrerStringLowercase = referrerString.toLowerCase();
return isInReferrerStringLowercase(referrerStringLowercase);
}
private boolean isInReferrerStringLowercase(final String referrerStringLowercase) {
return Utils.contains(referrerStringLowercase, aliases);
}
/*
* Iterates over all Application to compare the signature with the referrer
* string. If no match can be found Application.UNKNOWN will be returned.
*/
public static Application parseReferrerString(String referrerString) {
// skip the empty and "-" referrer
if (referrerString != null && referrerString.length() > 1) {
String referrerStringLowercase = referrerString.toLowerCase();
for (Application applicationInList : Application.values()) {
if (applicationInList.isInReferrerStringLowercase(referrerStringLowercase))
return applicationInList;
}
}
return Application.UNKNOWN;
}
/**
* Returns the enum constant of this type with the specified id. Throws
* IllegalArgumentException if the value does not exist.
*
* @param id Id of the application
* @return Application enum
*/
public static Application valueOf(short id) {
for (Application application : Application.values()) {
if (application.getId() == id)
return application;
}
// same behavior as standard valueOf(string) method
throw new IllegalArgumentException("No enum const for id " + id);
}
}