-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathKonquerorBrowserBuilder.java
More file actions
100 lines (83 loc) · 3.51 KB
/
KonquerorBrowserBuilder.java
File metadata and controls
100 lines (83 loc) · 3.51 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
/**
* 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.browser;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.openddr.simpleapi.oddr.model.UserAgent;
import org.openddr.simpleapi.oddr.model.browser.Browser;
public class KonquerorBrowserBuilder extends LayoutEngineBrowserBuilder {
private static final String KONQUEROR_VERSION_REGEXP = ".*[Kk]onqueror/([0-9a-z\\.\\-]+).*";
private Pattern konquerorVersionPattern = Pattern.compile(KONQUEROR_VERSION_REGEXP);
public boolean canBuild(UserAgent userAgent) {
return (userAgent.getCompleteUserAgent().toLowerCase().contains("konqueror"));
}
@Override
protected Browser buildBrowser(UserAgent userAgent, String layoutEngine, String layoutEngineVersion, int hintedWidth, int hintedHeight) {
if (!(userAgent.hasMozillaPattern())) {
return null;
}
int confidence = 60;
Browser identified = new Browser();
identified.setVendor("KDE");
identified.setModel("Konqueror");
identified.setVersion("-");
identified.setMajorRevision("-");
Matcher chromeMatcher = konquerorVersionPattern.matcher(userAgent.getCompleteUserAgent());
if (chromeMatcher.matches()) {
if (chromeMatcher.group(1) != null) {
identified.setVersion(chromeMatcher.group(1));
String version[] = chromeMatcher.group(1).split("\\.");
if (version.length > 0) {
identified.setMajorRevision(version[0]);
if (identified.getMajorRevision().length() == 0) {
identified.setMajorRevision("1");
}
}
if (version.length > 1) {
identified.setMinorRevision(version[1]);
confidence += 10;
}
if (version.length > 2) {
identified.setMicroRevision(version[2]);
}
if (version.length > 3) {
identified.setNanoRevision(version[3]);
}
}
} else {
//fallback version
identified.setVersion("1.0");
identified.setMajorRevision("1");
}
if (layoutEngine != null) {
identified.setLayoutEngine(layoutEngine);
identified.setLayoutEngineVersion(layoutEngineVersion);
if (layoutEngine.equals(LayoutEngineBrowserBuilder.KHML)) {
confidence += 10;
}
}
identified.setDisplayWidth(hintedWidth);
identified.setDisplayHeight(hintedHeight);
identified.setConfidence(confidence);
return identified;
}
}