You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by bd...@apache.org on 2012/10/02 15:32:32 UTC

svn commit: r1392911 [4/7] - in /incubator/devicemap/trunk/openddr: ./ java/ java/src/ java/src/org/ java/src/org/openddr/ java/src/org/openddr/simpleapi/ java/src/org/openddr/simpleapi/oddr/ java/src/org/openddr/simpleapi/oddr/builder/ java/src/org/op...

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariBrowserBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariBrowserBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariMobileBrowserBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariMobileBrowserBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariMobileBrowserBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariMobileBrowserBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,104 @@
+/**
+ * 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.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.browser.Browser;
+
+public class SafariMobileBrowserBuilder extends LayoutEngineBrowserBuilder {
+
+    private static final String VERSION_REGEXP = ".*Version/([0-9\\.]+).*?";
+    private static final String SAFARI_REGEXP = ".*Safari/([0-9\\.]+).*?";
+    private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
+    private Pattern safariPattern = Pattern.compile(SAFARI_REGEXP);
+
+    public boolean canBuild(UserAgent userAgent) {
+        return (userAgent.containsIOSDevices());
+    }
+
+    @Override
+    protected Browser buildBrowser(UserAgent userAgent, String layoutEngine, String layoutEngineVersion, int hintedWidth, int hintedHeight) {
+        if (!userAgent.containsIOSDevices()) {
+            return null;
+        }
+
+        int confidence = 70;
+        Browser identified = new Browser();
+
+        identified.setVendor("Apple");
+        identified.setModel("Mobile Safari");
+
+        Matcher versionMatcher = versionPattern.matcher(userAgent.getCompleteUserAgent());
+        if (versionMatcher.matches()) {
+            if (versionMatcher.group(1) != null) {
+                identified.setVersion(versionMatcher.group(1));
+                String version[] = versionMatcher.group(1).split("\\.");
+
+                if (version.length > 0) {
+                    identified.setMajorRevision(version[0]);
+                }
+
+                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.APPLEWEBKIT)) {
+                confidence += 10;
+            }
+        }
+
+        Matcher safariMatcher = safariPattern.matcher(userAgent.getCompleteUserAgent());
+        if (safariMatcher.matches()) {
+            if (safariMatcher.group(1) != null) {
+                identified.setReferenceBrowser("Safari");
+                identified.setReferenceBrowserVersion(safariMatcher.group(1));
+                confidence += 10;
+            }
+        }
+
+        identified.setDisplayWidth(hintedWidth);
+        identified.setDisplayHeight(hintedHeight);
+        identified.setConfidence(confidence);
+
+        return identified;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariMobileBrowserBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SafariMobileBrowserBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SilkBrowserBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SilkBrowserBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SilkBrowserBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SilkBrowserBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,127 @@
+/**
+ * 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.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.browser.Browser;
+
+public class SilkBrowserBuilder extends LayoutEngineBrowserBuilder {
+
+    private static final String VERSION_REGEXP = ".*Version/([0-9\\.]+).*?";
+    private static final String SILK_VERSION_REGEXP = ".*Silk/([0-9a-z\\.\\-]+)";
+    private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
+    private Pattern silkVersionPattern = Pattern.compile(SILK_VERSION_REGEXP);
+
+    public boolean canBuild(UserAgent userAgent) {
+        return (userAgent.getCompleteUserAgent().contains("Silk-Accelerated"));
+    }
+
+    @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("Amazon");
+        identified.setModel("Silk");
+        identified.setVersion("-");
+        identified.setMajorRevision("-");
+
+        Matcher silkMatcher = silkVersionPattern.matcher(userAgent.getPatternElementsInside());
+        if (silkMatcher.matches()) {
+            if (silkMatcher.group(1) != null) {
+                identified.setVersion(silkMatcher.group(1));
+                String version[] = silkMatcher.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[2] != null) {
+                    String subVersion[] = version[2].split("-");
+                    if (subVersion.length > 0) {
+                        identified.setMicroRevision(subVersion[0]);
+                    }
+
+                    if (subVersion.length > 1) {
+                        identified.setNanoRevision(subVersion[1]);
+                    }
+                }
+            }
+
+        } else {
+            //fallback version
+            identified.setVersion("1.0");
+            identified.setMajorRevision("1");
+        }
+
+        if (layoutEngine != null) {
+            identified.setLayoutEngine(layoutEngine);
+            identified.setLayoutEngineVersion(layoutEngineVersion);
+            if (layoutEngine.equals(LayoutEngineBrowserBuilder.APPLEWEBKIT)) {
+                confidence += 10;
+            }
+        }
+
+
+        if (userAgent.containsAndroid()) {
+            identified.setReferenceBrowser("Android Browser");
+            Matcher androidMatcher = versionPattern.matcher(userAgent.getCompleteUserAgent());
+            if (androidMatcher.matches()) {
+                if (androidMatcher.group(1) != null) {
+                    identified.setReferenceBrowserVersion(androidMatcher.group(1));
+                    confidence += 5;
+                }
+            }
+            confidence += 5;
+        } else if (userAgent.getCompleteUserAgent().contains("Safari") && !userAgent.getCompleteUserAgent().contains("Mobile")) {
+            identified.setReferenceBrowser("Safari");
+            Matcher safariMatcher = versionPattern.matcher(userAgent.getCompleteUserAgent());
+            if (safariMatcher.matches()) {
+                if (safariMatcher.group(1) != null) {
+                    identified.setReferenceBrowserVersion(safariMatcher.group(1));
+                    confidence += 5;
+                }
+            }
+            confidence += 5;
+        }
+
+
+        identified.setDisplayWidth(hintedWidth);
+        identified.setDisplayHeight(hintedHeight);
+        identified.setConfidence(confidence);
+
+        return identified;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SilkBrowserBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/SilkBrowserBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/UPBrowserBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/UPBrowserBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/UPBrowserBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/UPBrowserBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,90 @@
+/**
+ * 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.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.browser.Browser;
+
+public class UPBrowserBuilder extends LayoutEngineBrowserBuilder {
+
+    private static final String VERSION_REGEXP = ".*?(?:(?:UP\\.Browser))[/ ]?(?:WAP)?([0-9\\.abcd]+).*?";
+    private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.getCompleteUserAgent().contains("UP.Browser")) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected Browser buildBrowser(UserAgent userAgent, String layoutEngine, String layoutEngineVersion, int hintedWidth, int hintedHeight) {
+        String version = null;
+
+        Matcher versionMatcher = versionPattern.matcher(userAgent.getCompleteUserAgent());
+        if (!versionMatcher.matches()) {
+            return null;
+
+        } else {
+            if (versionMatcher.group(1) != null) {
+                version = versionMatcher.group(1);
+            }
+        }
+
+        int confidence = 60;
+        Browser identified = new Browser();
+
+        identified.setVendor("Openwave");
+        identified.setModel("UP.Browser");
+        identified.setVersion(version);
+        String[] versionEl = version.split("\\.");
+
+        if (versionEl.length > 0) {
+            identified.setMajorRevision(versionEl[0]);
+        }
+
+        if (versionEl.length > 1) {
+            identified.setMinorRevision(versionEl[1]);
+            confidence += 10;
+        }
+
+        if (versionEl.length > 2) {
+            identified.setMicroRevision(versionEl[2]);
+        }
+
+        if (versionEl.length > 3) {
+            identified.setNanoRevision(versionEl[3]);
+        }
+
+        if (layoutEngine != null) {
+            identified.setLayoutEngine(layoutEngine);
+            identified.setLayoutEngineVersion(layoutEngineVersion);
+        }
+
+        identified.setDisplayWidth(hintedWidth);
+        identified.setDisplayHeight(hintedHeight);
+        identified.setConfidence(confidence);
+
+        return identified;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/UPBrowserBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/UPBrowserBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/WebOsBrowserBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/WebOsBrowserBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/WebOsBrowserBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/WebOsBrowserBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,62 @@
+package org.openddr.simpleapi.oddr.builder.browser;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.browser.Browser;
+
+public class WebOsBrowserBuilder extends LayoutEngineBrowserBuilder {
+
+    private static final String VERSION_REGEXP = ".*webOSBrowser/([0-9\\.]+).*?";
+    private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.getCompleteUserAgent().contains("webOSBrowser")) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected Browser buildBrowser(UserAgent userAgent, String layoutEngine, String layoutEngineVersion, int hintedWidth, int hintedHeight) {
+        String version = null;
+
+        Matcher versionMatcher = versionPattern.matcher(userAgent.getCompleteUserAgent());
+        if (!versionMatcher.matches()) {
+            return null;
+
+        } else {
+            if (versionMatcher.group(1) != null) {
+                version = versionMatcher.group(1);
+            }
+        }
+
+        int confidence = 60;
+        Browser identified = new Browser();
+
+        identified.setVendor("HP");
+        identified.setModel("Web OS Browser");
+        identified.setVersion(version);
+        String[] versionEl = version.split("\\.");
+
+        if (versionEl.length > 0) {
+            identified.setMajorRevision(versionEl[0]);
+        }
+
+        if (versionEl.length > 1) {
+            identified.setMinorRevision(versionEl[1]);
+            confidence += 10;
+        }
+
+        if (layoutEngine != null) {
+            identified.setLayoutEngine(layoutEngine);
+            identified.setLayoutEngineVersion(layoutEngineVersion);
+        }
+
+        identified.setDisplayWidth(hintedWidth);
+        identified.setDisplayHeight(hintedHeight);
+        identified.setConfidence(confidence);
+
+        return identified;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/WebOsBrowserBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/browser/WebOsBrowserBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/AndroidDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/AndroidDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/AndroidDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/AndroidDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,221 @@
+/**
+ * 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.device;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.openddr.simpleapi.oddr.model.device.Device;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+
+public class AndroidDeviceBuilder extends OrderedTokenDeviceBuilder {
+
+    private static final String BUILD_HASH_REGEXP = ".*Build/([^ \\)\\(]*).*";
+    private Pattern buildHashPattern = Pattern.compile(BUILD_HASH_REGEXP);
+    private Map<String, Device> devices;
+
+    public AndroidDeviceBuilder() {
+        super();
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.containsAndroid()) {
+            return true;
+
+        } else {
+            return false;
+        }
+    }
+
+    public Device build(UserAgent userAgent, int confidenceTreshold) {
+        ArrayList<Device> foundDevices = new ArrayList<Device>();
+        Iterator it = orderedRules.keySet().iterator();
+        while (it.hasNext()) {
+            String token = (String) it.next();
+            Device d = elaborateAndroidDeviceWithToken(userAgent, token);
+            if (d != null) {
+                if (d.getConfidence() > confidenceTreshold) {
+                    return d;
+
+                } else {
+                    if (d.getConfidence() > 0) {
+                        foundDevices.add(d);
+                    }
+                }
+            }
+        }
+        if (foundDevices.size() > 0) {
+            Collections.sort(foundDevices, Collections.reverseOrder());
+            return foundDevices.get(0);
+        }
+        return null;
+    }
+
+    public void putDevice(String deviceID, List<String> initProperties) {
+        orderedRules.put(initProperties.get(0), deviceID);
+    }
+
+    private Device elaborateAndroidDeviceWithToken(UserAgent userAgent, String token) {
+        if (userAgent.hasMozillaPattern() || userAgent.hasOperaPattern()) {
+            int subtract = 0;
+            String currentToken = token;
+
+            String looseToken = token.replaceAll("[ _/-]", ".?");
+
+            Pattern loosePattern = Pattern.compile("(?i).*" + looseToken + ".*");
+
+            if (!loosePattern.matcher(userAgent.getCompleteUserAgent().replaceAll("Android", "")).matches()) {
+                return null;
+            }
+
+            String patternElementInsideClean = cleanPatternElementInside(userAgent.getPatternElementsInside());
+
+            Pattern currentPattern = null;
+
+            for (int i = 0; i <= 1; i++) {
+                if (i == 1) {
+                    currentToken = looseToken;
+                }
+
+                currentPattern = Pattern.compile("(?i).*" + currentToken + ".?Build/.*");
+                if (patternElementInsideClean != null && currentPattern.matcher(patternElementInsideClean).matches()) {//&& userAgent.getPatternElementsInside().matches(".*" + currentToken + ".?Build/.*")) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(100 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                currentPattern = Pattern.compile("(?i).*" + currentToken);
+                if (userAgent.getPatternElementsPre() != null && currentPattern.matcher(userAgent.getPatternElementsPre()).matches()) {//userAgent.getPatternElementsPre().matches(".*" + currentToken)) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(95 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (patternElementInsideClean != null && currentPattern.matcher(patternElementInsideClean).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken)) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(90 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                currentPattern = Pattern.compile("(?i).*" + currentToken + ".?;.*");
+                if (patternElementInsideClean != null && currentPattern.matcher(patternElementInsideClean).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken + ".?;.*")) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(90 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (i == 1) {
+                    currentPattern = loosePattern;
+
+                } else {
+                    currentPattern = Pattern.compile("(?i).*" + currentToken + ".*");
+                }
+                if (patternElementInsideClean != null && currentPattern.matcher(patternElementInsideClean).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(80 - subtract);
+                        return retDevice;
+                    }
+                }
+                if (userAgent.getPatternElementsPre() != null && currentPattern.matcher(userAgent.getPatternElementsPre()).matches()) {//userAgent.getPatternElementsPre().matches(".*" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(80 - subtract);
+                        return retDevice;
+                    }
+                }
+                if (userAgent.getPatternElementsPost() != null && currentPattern.matcher(userAgent.getPatternElementsPost()).matches()) {//userAgent.getPatternElementsPost().matches(".*" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(60 - subtract);
+                        return retDevice;
+                    }
+                }
+                if (i == 1) {
+                    if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken + ".*")) {
+                        String deviceId = (String) orderedRules.get(token);
+
+			if (devices.containsKey(deviceId)) {
+                            Device retDevice = (Device) devices.get(deviceId).clone();
+                            retDevice.setConfidence(40);
+                            return retDevice;
+                        }
+                    }
+                }
+                subtract += 20;
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    protected void afterOderingCompleteInit(Map<String, Device> devices) {
+        this.devices = devices;
+        for (Object devIdObj : orderedRules.values()) {
+            String devId = (String) devIdObj;
+            if (!devices.containsKey(devId)) {
+                throw new IllegalStateException("unable to find device with id: " + devId + "in devices");
+            }
+        }
+    }
+
+    private String cleanPatternElementInside(String patternElementsInside) {
+        String patternElementInsideClean = patternElementsInside;
+
+        Matcher buildHashMatcher = buildHashPattern.matcher(patternElementInsideClean);
+
+        if (buildHashMatcher.find()) {
+            String build = buildHashMatcher.group(1);
+	    patternElementInsideClean = patternElementInsideClean.replaceAll("Build/" + Pattern.quote(build), "Build/");
+
+        }
+        patternElementInsideClean = patternElementInsideClean.replaceAll("Android", "");
+
+        return patternElementInsideClean;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/AndroidDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/AndroidDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/DeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/DeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/DeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/DeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.device;
+
+import java.util.List;
+import java.util.Map;
+import org.openddr.simpleapi.oddr.builder.Builder;
+import org.openddr.simpleapi.oddr.model.device.Device;
+
+public interface DeviceBuilder extends Builder {
+
+    public void putDevice(String deviceID, List<String> initProperties);
+
+    public void completeInit(Map<String, Device> devices);
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/DeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/DeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/IOSDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/IOSDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/IOSDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/IOSDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,84 @@
+/**
+ * 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.device;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.openddr.simpleapi.oddr.model.device.Device;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+
+public class IOSDeviceBuilder implements DeviceBuilder {
+
+    private LinkedHashMap<String, String> iOSDevices;
+    private Map<String, Device> devices;
+
+    public IOSDeviceBuilder() {
+        iOSDevices = new LinkedHashMap<String, String>();
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.containsIOSDevices() && (!userAgent.containsAndroid()) && (!userAgent.containsWindowsPhone())) {
+            return true;
+
+        } else {
+            return false;
+        }
+    }
+
+    public Device build(UserAgent userAgent, int confidenceTreshold) {
+        Iterator it = iOSDevices.keySet().iterator();
+        while (it.hasNext()) {
+            String token = (String) it.next();
+            if (userAgent.getCompleteUserAgent().matches(".*" + token + ".*")) {
+                String iosDeviceID = iOSDevices.get(token);
+                if (iosDeviceID != null) {
+                    Device retDevice = (Device) devices.get(iosDeviceID).clone();
+                    retDevice.setConfidence(90);
+                    return retDevice;
+                }
+            }
+        }
+        return null;
+    }
+
+    public void putDevice(String device, List<String> initProperties) {
+        iOSDevices.put(initProperties.get(0), device);
+    }
+
+    public void completeInit(Map<String, Device> devices) {
+        String global = "iPhone";
+        if (iOSDevices.containsKey(global)) {
+            String iphone = iOSDevices.get(global);
+            iOSDevices.remove(global);
+            iOSDevices.put(global, iphone);
+        }
+
+        this.devices = devices;
+
+        for (String deviceID : iOSDevices.values()) {
+            if (!devices.containsKey(deviceID)) {
+                throw new IllegalStateException("unable to find device with id: " + deviceID + "in devices");
+            }
+        }
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/IOSDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/IOSDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/OrderedTokenDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/OrderedTokenDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/OrderedTokenDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/OrderedTokenDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,95 @@
+/**
+ * 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.device;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.openddr.simpleapi.oddr.model.device.Device;
+
+public abstract class OrderedTokenDeviceBuilder implements DeviceBuilder {
+
+    protected LinkedHashMap<String, Object> orderedRules;
+
+    public OrderedTokenDeviceBuilder() {
+        orderedRules = new LinkedHashMap<String, Object>();
+    }
+
+    abstract protected void afterOderingCompleteInit(Map<String, Device> devices);
+
+    public final void completeInit(Map<String, Device> devices) {
+        LinkedHashMap<String, Object> tmp = new LinkedHashMap<String, Object>();
+        ArrayList<String> keys = new ArrayList<String>(orderedRules.keySet());
+        Collections.sort(keys, new Comparator<String>() {
+
+            public int compare(String o1, String o2) {
+                return o2.length() - o1.length();
+            }
+        });
+        for (String string : keys) {
+            tmp.put(string, orderedRules.get(string));
+        }
+        ArrayList<String> keysOrdered = new ArrayList<String>();
+
+        orderedRules = new LinkedHashMap();
+
+        while (keys.size() > 0) {
+            boolean found = false;
+            for (String k1 : keys) {
+                for (String k2 : keys) {
+                    if ((!k1.equals(k2)) && k2.matches(".*" + k1 + ".*")) {
+                        found = true;
+                        break;
+                    }
+                }
+                if (!found) {
+                    keysOrdered.add(k1);
+                    keys.remove(k1);
+                    break;
+                }
+            }
+            if (!found) {
+                continue;
+            }
+            int max = 0;
+            int idx = -1;
+            for (int i = 0; i < keys.size(); i++) {
+                String string = keys.get(i);
+                if (string.length() > max) {
+                    max = string.length();
+                    idx = i;
+                }
+            }
+            if (idx >= 0) {
+                keysOrdered.add(keys.get(idx));
+                keys.remove(idx);
+            }
+        }
+        for (String key : keysOrdered) {
+            orderedRules.put(key, tmp.get(key));
+            tmp.remove(key);
+        }
+
+        afterOderingCompleteInit(devices);
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/OrderedTokenDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/OrderedTokenDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SimpleDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SimpleDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SimpleDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SimpleDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,81 @@
+/**
+ * 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.device;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import org.openddr.simpleapi.oddr.model.BuiltObject;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.device.Device;
+
+public class SimpleDeviceBuilder implements DeviceBuilder {
+
+    private LinkedHashMap<String, String> simpleTokenMap;
+    private Map<String, Device> devices;
+
+    public SimpleDeviceBuilder() {
+        simpleTokenMap = new LinkedHashMap<String, String>();
+    }
+
+    public void putDevice(String deviceId, List<String> initProperties) {
+
+        for (String token : initProperties) {
+            simpleTokenMap.put(token, deviceId);
+        }
+    }
+
+    public void completeInit(Map<String, Device> devices) {
+        this.devices = devices;
+
+        for (String deviceID : simpleTokenMap.values()) {
+            if (!devices.containsKey(deviceID)) {
+                throw new IllegalStateException("unable to find device with id: " + deviceID + "in devices");
+            }
+        }
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        for (String token : simpleTokenMap.keySet()) {
+            if (userAgent.getCompleteUserAgent().matches("(?i).*" + Pattern.quote(token) + ".*")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public BuiltObject build(UserAgent userAgent, int confidenceTreshold) {
+        Iterator it = simpleTokenMap.keySet().iterator();
+        while (it.hasNext()) {
+            String token = (String) it.next();
+            if (userAgent.getCompleteUserAgent().matches("(?i).*" + Pattern.quote(token) + ".*")) {
+                String desktopDeviceId = simpleTokenMap.get(token);
+                if (desktopDeviceId != null) {
+                    Device device = devices.get(desktopDeviceId);
+                    return device;
+                }
+            }
+        }
+        return null;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SimpleDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SimpleDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SymbianDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SymbianDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SymbianDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SymbianDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,232 @@
+/**
+ * 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.device;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import org.openddr.simpleapi.oddr.model.device.Device;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+
+public class SymbianDeviceBuilder extends OrderedTokenDeviceBuilder {
+
+    private Map<String, Device> devices;
+
+    public SymbianDeviceBuilder() {
+        super();
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.containsSymbian()) {
+            return true;
+
+        } else {
+            return false;
+        }
+    }
+
+    public Device build(UserAgent userAgent, int confidenceTreshold) {
+        ArrayList<Device> foundDevices = new ArrayList<Device>();
+        Iterator it = orderedRules.keySet().iterator();
+        while (it.hasNext()) {
+            String token = (String) it.next();
+            Device d = elaborateSymbianDeviceWithToken(userAgent, token);
+            if (d != null) {
+                if (d.getConfidence() > confidenceTreshold) {
+                    return d;
+
+                } else {
+                    if (d.getConfidence() > 0) {
+                        foundDevices.add(d);
+                    }
+                }
+            }
+        }
+
+        if (foundDevices.size() > 0) {
+            Collections.sort(foundDevices, Collections.reverseOrder());
+            return foundDevices.get(0);
+        }
+        return null;
+    }
+
+    public void putDevice(String device, List<String> initProperties) {
+        orderedRules.put(initProperties.get(0), device);
+    }
+
+    private Device elaborateSymbianDeviceWithToken(UserAgent userAgent, String token) {
+        String originalToken = token;
+
+        if (userAgent.hasMozillaPattern() || userAgent.hasOperaPattern()) {
+            int subtract = 0;
+            String currentToken = token;
+
+            String looseToken = token.replaceAll("[ _/-]", ".?");
+
+            Pattern loosePattern = Pattern.compile(".*" + looseToken + ".*");
+
+            if (!loosePattern.matcher(userAgent.getCompleteUserAgent()).matches()) {
+                return null;
+            }
+
+            Pattern currentPattern = null;
+
+            if (userAgent.hasOperaPattern()) {
+                subtract += 10;
+            }
+            for (int i = 0; i <= 1; i++) {
+                if (i == 1) {
+                    currentToken = looseToken;
+                }
+
+                currentPattern = Pattern.compile(".*Series60.?(\\d+)\\.(\\d+).?" + currentToken + ".*");
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {// userAgent.getPatternElementsInside().matches(".*Series60.?(\\d+)\\.(\\d+).?" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(100 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                currentPattern = Pattern.compile(".*" + currentToken);
+                if (userAgent.getPatternElementsPre() != null && currentPattern.matcher(userAgent.getPatternElementsPre()).matches()) {//userAgent.getPatternElementsPre().matches(".*" + currentToken)) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(95 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken)) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(90 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                currentPattern = Pattern.compile(".*" + currentToken + ".?;.*");
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken + ".?;.*")) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(90 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (i == 1) {
+                    currentPattern = loosePattern;
+
+                } else {
+                    currentPattern = Pattern.compile(".*" + currentToken + ".*");
+                }
+
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {//userAgent.getPatternElementsInside().matches(".*" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(80 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (userAgent.getPatternElementsPre() != null && currentPattern.matcher(userAgent.getPatternElementsPre()).matches()) {//userAgent.getPatternElementsPre().matches(".*" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(80 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (userAgent.getPatternElementsPost() != null && currentPattern.matcher(userAgent.getPatternElementsPost()).matches()) {//userAgent.getPatternElementsPost().matches(".*" + currentToken + ".*")) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(60 - subtract);
+                        return retDevice;
+                    }
+                }
+                subtract += 20;
+            }
+        } else {
+            String ua = userAgent.getCompleteUserAgent().replaceAll("SN[0-9]*", "");
+
+            int subtract = 0;
+            String currentToken = token;
+
+            String looseToken = token.replaceAll("[ _/-]", ".?");
+            Pattern loosePattern = Pattern.compile(".*" + looseToken + ".*");
+
+            if (!loosePattern.matcher(userAgent.getCompleteUserAgent()).matches()) {
+                return null;
+            }
+
+            Pattern currentPattern = null;
+
+            for (int i = 0; i <= 1; i++) {
+                if (i == 1) {
+                    currentToken = looseToken;
+                }
+
+                currentPattern = Pattern.compile(".*" + currentToken + ".*");
+                if (currentPattern.matcher(ua).matches()) {
+                    String deviceId = (String) orderedRules.get(originalToken);
+
+                    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(100 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                subtract += 20;
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    protected void afterOderingCompleteInit(Map<String, Device> devices) {
+        this.devices = devices;
+        for (Object devIdObj : orderedRules.values()) {
+            String devId = (String) devIdObj;
+            if (!devices.containsKey(devId)) {
+                throw new IllegalStateException("unable to find device with id: " + devId + "in devices");
+            }
+        }
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SymbianDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/SymbianDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/TwoStepDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/TwoStepDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/TwoStepDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/TwoStepDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,244 @@
+/**
+ * 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.device;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.openddr.simpleapi.oddr.model.device.Device;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+
+public class TwoStepDeviceBuilder extends OrderedTokenDeviceBuilder {
+
+    private Map<String, Device> devices;
+
+    public TwoStepDeviceBuilder() {
+        super();
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        for (String step1Token : orderedRules.keySet()) {
+            if (userAgent.getCompleteUserAgent().matches("(?i).*" + step1Token + ".*")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public Device build(UserAgent userAgent, int confidenceTreshold) {
+        ArrayList<Device> foundDevices = new ArrayList<Device>();
+        for (String step1Token : orderedRules.keySet()) {
+            if (userAgent.getCompleteUserAgent().matches("(?i).*" + step1Token + ".*")) {
+                Map<String, String> step1Compliant = (Map<String, String>) orderedRules.get(step1Token);
+                for (String step2token : step1Compliant.keySet()) {
+                    Device d = elaborateTwoStepDeviceWithToken(userAgent, step1Token, step2token);
+                    if (d != null) {
+                        if (d.getConfidence() > confidenceTreshold) {
+                            return d;
+
+                        } else {
+                            if (d.getConfidence() > 0) {
+                                foundDevices.add(d);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        if (foundDevices.size() > 0) {
+            Collections.sort(foundDevices, Collections.reverseOrder());
+            return foundDevices.get(0);
+        }
+
+        return null;
+    }
+
+    public void putDevice(String device, List<String> initProperties) {
+        String step1TokenString = initProperties.get(0);
+        String step2TokenString = initProperties.get(1);
+
+        if (step2TokenString.matches(".*" + step1TokenString + ".*")) {
+            step2TokenString = step2TokenString.replaceAll(step1TokenString + "[^\\p{Alnum}]?", "");
+        }
+
+        Map<String, String> step1Token = (Map<String, String>) orderedRules.get(step1TokenString);
+        if (step1Token == null) {
+            step1Token = new LinkedHashMap<String, String>();
+            orderedRules.put(initProperties.get(0), step1Token);
+        }
+        step1Token.put(step2TokenString, device);
+    }
+
+    private Device elaborateTwoStepDeviceWithToken(UserAgent userAgent, String step1Token, String step2Token) {
+        int maxLittleTokensDistance = 4;
+        int maxBigTokensDistance = 8;
+        int confidence;
+
+        String originalToken = step2Token;
+        String looseToken = step2Token.replaceAll("[ _/-]", ".?");
+
+        if (userAgent.getCompleteUserAgent().matches("(?i).*" + step2Token + ".*")) {
+            confidence = 100;
+
+        } else if (userAgent.getCompleteUserAgent().matches("(?i).*" + looseToken + ".*")) {
+            step2Token = looseToken;
+            confidence = 90;
+
+        } else {
+            return null;
+        }
+
+        Matcher result = Pattern.compile("(?i)(?:(?:.*" + step1Token + "(.*?)" + step2Token + ".*)|(?:.*" + step2Token + "(.*?)" + step1Token + ".*))").matcher(userAgent.getCompleteUserAgent());
+        if (result.matches()) {
+            //test for case sensitive match
+            Matcher bestResult = Pattern.compile("(?:(?:.*" + step1Token + "(.*?)" + step2Token + ".*)|(?:.*" + step2Token + "(.*?)" + step1Token + ".*))").matcher(userAgent.getCompleteUserAgent());
+            if (bestResult.matches()) {
+                result = bestResult;
+
+            } else {
+                confidence -= 20;
+            }
+
+            String betweenTokens = result.group(1);
+            String s2 = result.group(2);
+            if (s2 != null && (betweenTokens == null || betweenTokens.length() > s2.length())) {
+                betweenTokens = s2;
+            }
+            int betweenTokensLength = betweenTokens.length();
+
+            if (step2Token.length() > 3) {
+                if (betweenTokensLength > maxBigTokensDistance) {
+                    confidence -= 10;
+                }
+
+                String deviceId = ((Map<String, String>) orderedRules.get(step1Token)).get(originalToken);
+
+                if (devices.containsKey(deviceId)) {
+                    Device retDevice = (Device) devices.get(deviceId).clone();
+                    retDevice.setConfidence(confidence);
+                    return retDevice;
+                }
+            }
+
+            if ((betweenTokensLength < maxLittleTokensDistance) || (betweenTokensLength < maxBigTokensDistance && (step2Token.length() < 6 || !step2Token.matches(".*[a-zA-Z].*")))) {
+                if (betweenTokensLength <= 1) {
+                    if (!betweenTokens.matches("[ _/-]?")) {
+                        confidence -= 20;
+                    }
+
+                } else {
+                    confidence -= 40;
+                }
+
+                confidence -= (betweenTokensLength * 4);
+
+                String deviceId = ((Map<String, String>) orderedRules.get(step1Token)).get(originalToken);
+
+                if (devices.containsKey(deviceId)) {
+                    Device retDevice = (Device) devices.get(deviceId).clone();
+                    retDevice.setConfidence(confidence);
+                    return retDevice;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    protected void afterOderingCompleteInit(Map<String, Device> devices) {
+        for (String step1Token : orderedRules.keySet()) {
+            sortElement(step1Token);
+        }
+
+        this.devices = devices;
+        for (Object devIdsMapObj : orderedRules.values()) {
+            Map<String, String> devIdsMap = (Map<String, String>) devIdsMapObj;
+            for (Object devIdObj : devIdsMap.values()) {
+                String devId = (String) devIdObj;
+                if (!devices.containsKey(devId)) {
+                    throw new IllegalStateException("unable to find device with id: " + devId + "in devices");
+                }
+            }
+        }
+    }
+
+    private void sortElement(String step1Token) {
+        Map<String, String> currentStep1Map = (Map<String, String>) orderedRules.get(step1Token);
+
+        LinkedHashMap<String, String> tmp = new LinkedHashMap<String, String>();
+        ArrayList<String> keys = new ArrayList<String>(currentStep1Map.keySet());
+        Collections.sort(keys, new Comparator<String>() {
+
+            public int compare(String o1, String o2) {
+                return o2.length() - o1.length();
+            }
+        });
+        for (String string : keys) {
+            tmp.put(string, currentStep1Map.get(string));
+        }
+        ArrayList<String> keysOrdered = new ArrayList<String>();
+        currentStep1Map = new LinkedHashMap();
+        while (keys.size() > 0) {
+            boolean found = false;
+            for (String k1 : keys) {
+                for (String k2 : keys) {
+                    if ((!k1.equals(k2)) && k2.matches(".*" + k1 + ".*")) {
+                        found = true;
+                        break;
+                    }
+                }
+                if (!found) {
+                    keysOrdered.add(k1);
+                    keys.remove(k1);
+                    break;
+                }
+            }
+            if (!found) {
+                continue;
+            }
+            int max = 0;
+            int idx = -1;
+            for (int i = 0; i < keys.size(); i++) {
+                String string = keys.get(i);
+                if (string.length() > max) {
+                    max = string.length();
+                    idx = i;
+                }
+            }
+            if (idx >= 0) {
+                keysOrdered.add(keys.get(idx));
+                keys.remove(idx);
+            }
+        }
+        for (String key : keysOrdered) {
+            currentStep1Map.put(key, tmp.get(key));
+            tmp.remove(key);
+        }
+
+        orderedRules.put(step1Token, currentStep1Map);
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/TwoStepDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/TwoStepDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/WinPhoneDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/WinPhoneDeviceBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/WinPhoneDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/WinPhoneDeviceBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,183 @@
+/**
+ * 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.device;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import org.openddr.simpleapi.oddr.model.device.Device;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+
+public class WinPhoneDeviceBuilder extends OrderedTokenDeviceBuilder {
+
+    private Map<String, Device> devices;
+
+    public WinPhoneDeviceBuilder() {
+        super();
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.containsWindowsPhone()) {
+            return true;
+
+        } else {
+            return false;
+        }
+    }
+
+    public Device build(UserAgent userAgent, int confidenceTreshold) {
+        ArrayList<Device> foundDevices = new ArrayList<Device>();
+        Iterator it = orderedRules.keySet().iterator();
+        while (it.hasNext()) {
+            String token = (String) it.next();
+            Device d = elaborateWinPhoneDeviceWithToken(userAgent, token);
+            if (d != null) {
+                if (d.getConfidence() > confidenceTreshold) {
+                    return d;
+
+                } else {
+                    if (d.getConfidence() > 0) {
+                        foundDevices.add(d);
+                    }
+                }
+            }
+        }
+        if (foundDevices.size() > 0) {
+            Collections.sort(foundDevices, Collections.reverseOrder());
+            return foundDevices.get(0);
+        }
+        return null;
+    }
+
+    public void putDevice(String device, List<String> initProperties) {
+        orderedRules.put(initProperties.get(0), device);
+    }
+
+    private Device elaborateWinPhoneDeviceWithToken(UserAgent userAgent, String token) {
+        if (userAgent.hasMozillaPattern() || userAgent.hasOperaPattern()) {
+            int subtract = 0;
+            String currentToken = token;
+
+            String looseToken = token.replaceAll("[ _/-]", ".?");
+
+            Pattern loosePattern = Pattern.compile("(?i).*" + looseToken + ".*");
+
+            if (!loosePattern.matcher(userAgent.getCompleteUserAgent()).matches()) {
+                return null;
+            }
+
+            Pattern currentPattern = null;
+
+            if (userAgent.hasOperaPattern()) {
+                subtract += 10;
+            }
+
+            for (int i = 0; i <= 1; i++) {
+                if (i == 1) {
+                    currentToken = looseToken;
+                }
+
+                currentPattern = Pattern.compile("(?i).*" + currentToken);
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(100 - subtract);
+                        return retDevice;
+                    }
+                }
+                if (userAgent.getPatternElementsPre() != null && currentPattern.matcher(userAgent.getPatternElementsPre()).matches()) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(95 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                currentPattern = Pattern.compile("(?i).*" + currentToken + ".?;.*");
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(90 - subtract);
+                        return retDevice;
+                    }
+                }
+
+                if (i == 1) {
+                    currentPattern = loosePattern;
+
+                } else {
+                    currentPattern = Pattern.compile("(?i).*" + currentToken + ".*");
+                }
+
+                if (userAgent.getPatternElementsInside() != null && currentPattern.matcher(userAgent.getPatternElementsInside()).matches()) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(80 - subtract);
+                        return retDevice;
+                    }
+                }
+                if (userAgent.getPatternElementsPre() != null && currentPattern.matcher(userAgent.getPatternElementsPre()).matches()) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(80 - subtract);
+                        return retDevice;
+                    }
+                }
+                if (userAgent.getPatternElementsPost() != null && currentPattern.matcher(userAgent.getPatternElementsPost()).matches()) {
+                    String deviceId = (String) orderedRules.get(token);
+
+		    if (devices.containsKey(deviceId)) {
+                        Device retDevice = (Device) devices.get(deviceId).clone();
+                        retDevice.setConfidence(60 - subtract);
+                        return retDevice;
+                    }
+                }
+                subtract += 20;
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    protected void afterOderingCompleteInit(Map<String, Device> devices) {
+        this.devices = devices;
+        for (Object devIdObj : orderedRules.values()) {
+            String devId = (String) devIdObj;
+            if (!devices.containsKey(devId)) {
+                throw new IllegalStateException("unable to find device with id: " + devId + "in devices");
+            }
+        }
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/WinPhoneDeviceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/device/WinPhoneDeviceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/BlackBerryOSBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/BlackBerryOSBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/BlackBerryOSBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/BlackBerryOSBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,78 @@
+/**
+ * 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;
+
+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 BlackBerryOSBuilder implements Builder {
+
+    private static final String VERSION_REGEXP = "(?:.*?[Bb]lack.?[Bb]erry(?:\\d+)/((\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?).*)";
+    private Pattern versionPattern = Pattern.compile(VERSION_REGEXP);
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.containsBlackBerryOrRim()) {
+            return true;
+        }
+        return false;
+    }
+
+    public BuiltObject build(UserAgent userAgent, int confidenceTreshold) {
+        OperatingSystem model = new OperatingSystem();
+
+        model.setVendor("Research In Motion");
+        model.setModel("Black Berry OS");
+        model.setMajorRevision("1");
+
+        Matcher versionMatcher = versionPattern.matcher(userAgent.getCompleteUserAgent());
+        if (versionMatcher.find()) {
+            if (versionMatcher.group(1) != null) {
+                model.setConfidence(50);
+                model.setVersion(versionMatcher.group(1));
+
+                if (versionMatcher.group(2) != null) {
+                    model.setMajorRevision(versionMatcher.group(2));
+                    model.setConfidence(60);
+                }
+
+                if (versionMatcher.group(3) != null) {
+                    model.setMinorRevision(versionMatcher.group(3));
+                    model.setConfidence(70);
+                }
+
+                if (versionMatcher.group(4) != null) {
+                    model.setMicroRevision(versionMatcher.group(4));
+                    model.setConfidence(80);
+                }
+
+                if (versionMatcher.group(5) != null) {
+                    model.setNanoRevision(versionMatcher.group(5));
+                    model.setConfidence(90);
+                }
+            }
+        }
+        return model;
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/BlackBerryOSBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/BlackBerryOSBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/DefaultOSBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/DefaultOSBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/DefaultOSBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/DefaultOSBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,86 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.openddr.simpleapi.oddr.builder.Builder;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.os.OperatingSystem;
+
+public class DefaultOSBuilder implements Builder {
+
+    private static DefaultOSBuilder instance;
+    private Builder[] builders;
+
+    public static synchronized DefaultOSBuilder getInstance() {
+        if (instance == null) {
+            instance = new DefaultOSBuilder();
+        }
+        return instance;
+    }
+
+    private DefaultOSBuilder() {
+        this.builders = new Builder[]{
+                    new MozillaOSModelBuilder(),
+                    new OperaOSModelBuilder(),
+                    new BlackBerryOSBuilder(),};
+    }
+
+    public boolean canBuild(UserAgent userAgent) {
+        for (Builder builder : builders) {
+            if (builder.canBuild(userAgent)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public OperatingSystem build(UserAgent userAgent, int confidenceTreshold) {
+        List<OperatingSystem> founds = new ArrayList<OperatingSystem>();
+        OperatingSystem found = null;
+        for (Builder builder : builders) {
+            if (builder.canBuild(userAgent)) {
+                OperatingSystem builded = (OperatingSystem) builder.build(userAgent, confidenceTreshold);
+                if (builded != null) {
+                    founds.add(builded);
+                    if (builded.getConfidence() >= confidenceTreshold) {
+                        found = builded;
+                        break;
+                    }
+                }
+            }
+        }
+
+        if (found != null) {
+            return found;
+
+        } else {
+            if (founds.isEmpty()) {
+                return null;
+            }
+
+            Collections.sort(founds, Collections.reverseOrder());
+            return founds.get(0);
+        }
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/DefaultOSBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/DefaultOSBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/MozillaOSModelBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/MozillaOSModelBuilder.java?rev=1392911&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/MozillaOSModelBuilder.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/MozillaOSModelBuilder.java Tue Oct  2 13:32:28 2012
@@ -0,0 +1,92 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.openddr.simpleapi.oddr.builder.Builder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.AndroidMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.BadaMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.BlackBerryMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.BrewMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.IOSMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.LinuxMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.MacOSXMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.SymbianMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.WebOSMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.WinCEMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.builder.os.mozilla.WinPhoneMozillaSubBuilder;
+import org.openddr.simpleapi.oddr.model.UserAgent;
+import org.openddr.simpleapi.oddr.model.os.OperatingSystem;
+
+public class MozillaOSModelBuilder implements Builder {
+
+    private Builder[] builders = {
+        new IOSMozillaSubBuilder(),
+        new AndroidMozillaSubBuilder(),
+        new WinPhoneMozillaSubBuilder(),
+        new BlackBerryMozillaSubBuilder(),
+        new SymbianMozillaSubBuilder(),
+        new WinCEMozillaSubBuilder(),
+        new BadaMozillaSubBuilder(),
+        new BrewMozillaSubBuilder(),
+        new WebOSMozillaSubBuilder(),
+        new LinuxMozillaSubBuilder(),
+        new MacOSXMozillaSubBuilder()
+    };
+
+    public boolean canBuild(UserAgent userAgent) {
+        if (userAgent.hasMozillaPattern()) {
+            return true;
+        }
+        return false;
+    }
+
+    public OperatingSystem build(UserAgent userAgent, int confidenceTreshold) {
+        List<OperatingSystem> founds = new ArrayList<OperatingSystem>();
+        OperatingSystem found = null;
+        for (Builder builder : builders) {
+            if (builder.canBuild(userAgent)) {
+                OperatingSystem builded = (OperatingSystem) builder.build(userAgent, confidenceTreshold);
+                if (builded != null) {
+                    founds.add(builded);
+                    if (builded.getConfidence() >= confidenceTreshold) {
+                        found = builded;
+                        break;
+                    }
+                }
+            }
+        }
+
+        if (found != null) {
+            return found;
+
+        } else {
+            if (founds.isEmpty()) {
+                return null;
+            }
+
+            Collections.sort(founds, Collections.reverseOrder());
+            return founds.get(0);
+        }
+    }
+}

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/MozillaOSModelBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/org/openddr/simpleapi/oddr/builder/os/MozillaOSModelBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL