-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathWinNTMozillaSubBuilder.java
More file actions
80 lines (71 loc) · 3.09 KB
/
WinNTMozillaSubBuilder.java
File metadata and controls
80 lines (71 loc) · 3.09 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
/**
* Copyright 2011 OpenDDR LLC
* This software is distributed under the terms of the GNU Lesser General Public License.
*
*
* This file is part of OpenDDR Simple APIs.
* OpenDDR Simple APIs is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* OpenDDR Simple APIs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.openddr.simpleapi.oddr.builder.os.mozilla;
import org.openddr.simpleapi.oddr.builder.Builder;
import org.openddr.simpleapi.oddr.model.UserAgent;
import org.openddr.simpleapi.oddr.model.os.OperatingSystem;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WinNTMozillaSubBuilder implements Builder {
private static final String VERSION_REGEXP = ".*Windows NT ((\\d+)\\.(\\d+)).*";
private static final String TRIDENT_REGEXP = ".*Trident/[0-9.].*";
private static final String NET_CLR_REGEXP = ".*\\.NET CLR[ /][0-9.]+.*";
private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
private Pattern tridentPattern = Pattern.compile(TRIDENT_REGEXP);
private Pattern clrPattern = Pattern.compile(NET_CLR_REGEXP);
public boolean canBuild(UserAgent userAgent) {
return userAgent.containsWindowsPhone();
}
public OperatingSystem build(UserAgent userAgent, int confidenceTreshold) {
final OperatingSystem os = new OperatingSystem();
os.setVendor("Microsoft");
os.setModel("Windows");
os.setConfidence(40);
final String[] splittedTokens = userAgent.getPatternElementsInside().split(";");
for (String tokenElement : splittedTokens) {
final Matcher versionMatcher = versionPattern.matcher(tokenElement);
if (versionMatcher.find()) {
os.setConfidence(85);
if (versionMatcher.group(1) != null) {
os.setVersion(versionMatcher.group(1));
}
if (versionMatcher.group(2) != null) {
os.setMajorRevision(versionMatcher.group(2));
}
if (versionMatcher.group(3) != null) {
os.setMinorRevision(versionMatcher.group(3));
}
} else if (tridentPattern.matcher(tokenElement).find() || clrPattern.matcher(tokenElement).find()) {
if (os.getConfidence() > 80) {
os.setConfidence(100);
} else {
os.setConfidence(85);
}
}
}
if (os.getVersion() != null) {
os.setDescription("Windows " + os.getVersion());
} else {
os.setDescription("Windows");
}
return os;
}
}