You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by Apache Wiki <wi...@apache.org> on 2014/12/23 18:54:26 UTC
[Devicemap Wiki] Update of "JavaClient1" by rezan
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Devicemap Wiki" for change notification.
The "JavaClient1" page has been changed by rezan:
https://wiki.apache.org/devicemap/JavaClient1?action=diff&rev1=5&rev2=6
Comment:
update
- = Java Client 1.0 =
+ = Java Client 1.1 =
-
- -Install devicemap-data and devicemap-client-java (mvn install)
-Include the following 2 maven dependencies:
@@ -10, +8 @@
<dependency>
<groupId>org.apache.devicemap</groupId>
<artifactId>devicemap-client</artifactId>
- <version>1.0.0</version>
+ <version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.devicemap</groupId>
<artifactId>devicemap-data</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1</version>
</dependency>
}}}
+
+ NOTE: If using LoaderOption URL or FOLDER, you can drop the above devicemap-data dependency.
-Include the following Java code:
{{{#!highlight java
- //create a client object, store this somewhere permanent
- DeviceMapClient client = new DeviceMapClient();
+ //get client using JAR data source
+ DeviceMapClient client = DeviceMapFactory.getClient(LoaderOption.JAR);
- //load the device data, do this only once!!!
- client.initDeviceData(LoaderOption.JAR);
+ //get client using data from a URL
+ //DeviceMapClient client = DeviceMapFactory.getClient(LoaderOption.URL, "http://devicemap-vm.apache.org/data/latest");
+ //get client using data from a local filesystem
+ //DeviceMapClient client = DeviceMapFactory.getClient(LoaderOption.FOLDER, "/some/path/devicemap/latest/devicedata");
- //classify a User-Agent string
- String test = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0";
- Map<String, String> m = client.classify(test);
+ String userAgent = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0";
+
+ //classify the userAgent
+ Device device = client.classifyDevice(userAgent);
+
+ System.out.println("Device detected: " + device.getId());
+
- //iterate thru the attributes
+ //iterate thru the attributes
- for (String attr : m.keySet()) {
+ for (String attr : device.getAttributes().keySet()) {
- System.out.println(attr + ": " + m.get(attr));
+ System.out.println(attr + ": " + device.getAttribute(attr));
- }
+ }
}}}
- If using LoaderOption.URL, the devicemap-data dependency can be dropped.
-
- = Java Client 1.1 =
-
- Changes: https://issues.apache.org/jira/browse/DMAP-40?jql=project%20%3D%20DMAP%20AND%20fixVersion%20%3D%20%221.1.0%20Java%22
-
- * Type is now part of a pattern, before it was an attribute of the device. So essentially we have proper pattern ranking, so 1 pattern can be ranked above another pattern.
- * DeviceMapClient factory. Easier and less error prone to initialize and pattern index the client.
- * Device object. So you can now classify a string as a Device, this gives you access to Device specific attributes, instead of just a generic map. This is important when we want to split our attributes up into 3 classifications: device, os, and browser.
- * Better logging.
-
- In progress...
-