You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by wk...@apache.org on 2016/05/08 23:44:01 UTC
svn commit: r1742852 - in /devicemap/trunk:
clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java
clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java
examples/1.0/java/pom.xml
Author: wkeil
Date: Sun May 8 23:44:01 2016
New Revision: 1742852
URL: http://svn.apache.org/viewvc?rev=1742852&view=rev
Log:
DMAP-92: Investigate IE user agent changes
Task-Url: https://issues.apache.org/jira/browse/DMAP-92
Added:
devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java
Modified:
devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java
devicemap/trunk/examples/1.0/java/pom.xml
Added: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java?rev=1742852&view=auto
==============================================================================
--- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java (added)
+++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java Sun May 8 23:44:01 2016
@@ -0,0 +1,62 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.devicemap;
+
+abstract class DeviceHints {
+ static enum WindowsVersion {
+ WIN_81("Windows NT 6.3" ,"Windows 8.1", "8.1"),
+ WIN_8("Windows NT 6.2", "Windows 8", "8.0"),
+ WIN_7("Windows NT 6.1", "Windows 7", "7.0"),
+ VISTA("Windows NT 6.0", "Windows Vista", "6.0"),
+ WIN_2003("Windows NT 5.2", "Windows Server 2003; Windows XP x64 Edition", "2003"),
+ WIN_XP("Windows NT 5.1", "Windows XP", "5.1"),
+ WIN_2000_SP1("Windows NT 5.01", "Windows 2000, Service Pack 1 (SP1)", "5.01"),
+ WIN_2000("Windows NT 5.0", "Windows 2000", "2000"),
+ WIN_NT_4("Windows NT 4.0", "Microsoft Windows NT 4.0", "4.0"),
+ WIN_ME("Windows 98; Win 9x 4.90", "Windows Millennium Edition (Windows Me)", "4.90"),
+ WIN_98("Windows 98", "Windows 98", "98"),
+ WIN_95("Windows 95", "Windows 95", "95"),
+ WIN_CE("Windows CE", "Windows CE", "CE"); // TODO version nr?
+
+ private final String token;
+ private final String description;
+ private final String version;
+
+ private WindowsVersion(String t, String d, String v) {
+ token = t;
+ description = d;
+ version = v;
+ }
+
+ String getDescription() {
+ return description;
+ }
+
+ String getVersion() {
+ return version;
+ }
+
+ static final WindowsVersion ofToken(String token) {
+ for (WindowsVersion version : values()) {
+ if (version.token.equalsIgnoreCase(token)) return version;
+ }
+ return null;
+ }
+ }
+}
Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java?rev=1742852&r1=1742851&r2=1742852&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java Sun May 8 23:44:01 2016
@@ -32,7 +32,7 @@ import org.apache.devicemap.loader.Loade
/**
* @author Werner Keil
- * @version 1.0.9
+ * @version 1.0.10
*/
public class DeviceMapClient {
private static final Logger LOG = Logger.getLogger(DeviceMapClient.class.getName());
@@ -61,7 +61,6 @@ public class DeviceMapClient {
public synchronized void initDeviceData(LoaderOption option, String path) throws IOException {
devices = LoaderFactory.getLoader(option, path).getData();
-
initCount++;
if (initCount % 1000 == 0) {
@@ -72,7 +71,6 @@ public class DeviceMapClient {
patterns = null;
return;
}
-
createIndex();
}
@@ -112,9 +110,7 @@ public class DeviceMapClient {
Set<DeviceType> hitDevices = new HashSet<DeviceType>();
DeviceType winner = null;
Pattern winnerPattern = null;
-
LOG.log(Level.FINE, "classify: ''{0}''", text);
-
List<String> parts = split(text);
//generate ngrams upto size 4
@@ -160,9 +156,12 @@ public class DeviceMapClient {
}
}
+ private static final String DEVICE_OS = "device_os";
private static final String DEVICE_OS_VERSION = "device_os_version";
+ private static final String VENDOR = "vendor";
private static final String ANDROID = "Android";
private static final String LIKE_MAC = "like Mac OS X";
+ private static final String WINDOWS = "Windows";
private DeviceType fixFromUserAgent(final DeviceType device, final UserAgent userAgent) {
String pattern = userAgent.getPatternElementsInside();
@@ -190,7 +189,7 @@ public class DeviceMapClient {
}
}
if (part.trim().endsWith(LIKE_MAC)) {
- String versionCandidate = part.trim().substring(0, part.trim().length() - LIKE_MAC.length()).trim();
+ final String versionCandidate = part.trim().substring(0, part.trim().length() - LIKE_MAC.length()).trim();
if (versionCandidate.contains("OS")) {
final String versionPart = versionCandidate.substring(versionCandidate.indexOf("OS")+2).trim().replaceAll("_", ".");
final String versionExisting = attributes.get(DEVICE_OS_VERSION);
@@ -201,6 +200,31 @@ public class DeviceMapClient {
}
}
}
+ if (part.trim().startsWith(WINDOWS)) {
+ final String versionCandidate = part.trim();
+ DeviceHints.WindowsVersion version = DeviceHints.WindowsVersion.ofToken(versionCandidate);
+ if (version != null) {
+ final String osExisting = attributes.get(DEVICE_OS);
+ LOG.fine("Fixing '" + osExisting +"' to '" + version.getDescription() + "'" );
+ attributes.put(DEVICE_OS, version.getDescription());
+ final String versionExisting = attributes.get(DEVICE_OS_VERSION);
+ if (!version.getVersion().equals(versionExisting)) {
+ LOG.fine("Fixing '" + versionExisting +"' to '" + version.getVersion() + "'" );
+ attributes.put(DEVICE_OS_VERSION, version.getVersion());
+ }
+// final String vendorExisting = attributes.get(VENDOR);
+// if (vendorExisting == null || vendorExisting.length()==0 || "-".equals(vendorExisting) ) {
+// LOG.finer("Desktop" + attributes.get("is_desktop"));
+// if (Boolean.parseBoolean(attributes.get("is_desktop"))) {
+// attributes.put(VENDOR, "Microsoft");
+// }
+// }
+ device.setAttributes(attributes);
+ }
+ } else {
+ String versionCandidate = part.trim();
+ System.out.println(versionCandidate);
+ }
}
}
}
Modified: devicemap/trunk/examples/1.0/java/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/1.0/java/pom.xml?rev=1742852&r1=1742851&r2=1742852&view=diff
==============================================================================
--- devicemap/trunk/examples/1.0/java/pom.xml (original)
+++ devicemap/trunk/examples/1.0/java/pom.xml Sun May 8 23:44:01 2016
@@ -46,7 +46,7 @@
<dependency>
<groupId>org.apache.devicemap</groupId>
<artifactId>devicemap-data</artifactId>
- <version>1.0.2</version>
+ <version>1.0.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>