-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMacOSXMozillaSubBuilder.java
More file actions
67 lines (58 loc) · 2.48 KB
/
MacOSXMozillaSubBuilder.java
File metadata and controls
67 lines (58 loc) · 2.48 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
/**
* 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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openddr.simpleapi.oddr.builder.Builder;
import org.openddr.simpleapi.oddr.model.BuiltObject;
import org.openddr.simpleapi.oddr.model.UserAgent;
import org.openddr.simpleapi.oddr.model.os.OperatingSystem;
public class MacOSXMozillaSubBuilder implements Builder {
private static final String VERSION_REGEXP = ".*(?:(?:Intel)|(?:PPC)).?Mac OS X.?((\\d+)[_\\.](\\d+)(?:[_\\.](\\d+))?).*";
private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
public boolean canBuild(UserAgent userAgent) {
return userAgent.getCompleteUserAgent().contains("Macintosh");
}
public BuiltObject build(UserAgent userAgent, int confidenceTreshold) {
OperatingSystem model = new OperatingSystem();
model.setMajorRevision("-");
model.setVendor("Apple");
model.setModel("Mac OS X");
model.setConfidence(60);
Matcher versionMatcher = versionPattern.matcher(userAgent.getPatternElementsInside());
if (versionMatcher.find()) {
model.setConfidence(80);
if (versionMatcher.group(1) != null) {
model.setVersion(versionMatcher.group(1));
}
if (versionMatcher.group(2) != null) {
model.setMajorRevision(versionMatcher.group(2));
}
if (versionMatcher.group(3) != null) {
model.setMinorRevision(versionMatcher.group(3));
}
if (versionMatcher.group(4) != null) {
model.setMicroRevision(versionMatcher.group(4));
}
}
return model;
}
}