You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2013/06/23 03:52:20 UTC

svn commit: r1495787 [5/5] - in /incubator/devicemap/trunk/devicemapjava: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/devicemap/ src/main/java/org/apache/devicemap/classification/

Added: incubator/devicemap/trunk/devicemapjava/DeviceDataSourcePatch.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/DeviceDataSourcePatch.xml?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/DeviceDataSourcePatch.xml (added)
+++ incubator/devicemap/trunk/devicemapjava/DeviceDataSourcePatch.xml Sun Jun 23 01:52:19 2013
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<ODDR>
+  <version>
+    <ver>dClass 2.0</ver>
+    <last_updated>2012-02-08 13:10:11</last_updated>
+    <official_url></official_url>
+    <maintainers>
+    </maintainers>
+    <authors>
+    </authors>
+    <statement>
+      <![CDATA[
+        Copyright 2011 OpenDDR LLC
+        This file is made available under the terms of the Open Database License: http://opendatacommons.org/licenses/odbl/1.0/.
+        Any rights in individual contents of the database are licensed under the Database Contents License: http://opendatacommons.org/licenses/dbcl/1.0/
+      ]]>
+    </statement>
+  </version>
+  <Devices>
+    <device id="desktopCrawler" parentId="desktopDevice">
+      <property name="is_crawler" value="true"/>
+      <property name="is_desktop" value="false"/>
+    </device>
+    <device id="root" parentId="">
+      <property name="is_crawler" value="false"/>
+      <property name="is_desktop" value="false"/>
+    </device>
+    <device id="desktopDevice" parentId="generic-">
+      <property name="vendor" value="desktop"/>
+      <property name="model" value="browser"/>
+      <property name="displayHeight" value="900"/>
+      <property name="displayWidth" value="1600"/>
+      <property name="is_wireless_device" value="false"/>
+      <property name="is_desktop" value="true"/>
+      <property name="ajax_support_javascript" value="true"/>
+      <property name="ajax_support_getelementbyid" value="true"/>
+      <property name="ajax_support_inner_html" value="true"/>
+      <property name="ajax_manipulate_dom" value="true"/>
+      <property name="ajax_manipulate_css" value="true"/>
+      <property name="ajax_support_events" value="true"/>
+      <property name="ajax_support_event_listener" value="true"/>
+    </device>
+    <device id="genericPhone" parentId="generic-">
+      <property name="vendor" value="generic"/>
+      <property name="model" value="phone"/>
+      <property name="displayHeight" value="200"/>
+      <property name="displayWidth" value="100"/>
+      <property name="is_wireless_device" value="true"/>
+      <property name="ajax_support_javascript" value="false"/>
+    </device>
+    <device id="genericTouchPhone" parentId="generic-">
+      <property name="vendor" value="generic"/>
+      <property name="model" value="touch phone"/>
+      <property name="displayHeight" value="480"/>
+      <property name="displayWidth" value="320"/>
+      <property name="is_wireless_device" value="true"/>
+      <property name="ajax_support_javascript" value="true"/>
+      <property name="inputDevices" value="touchscreen"/>
+    </device>
+    <device id="ZuneHD" parentId="generic-">
+      <property name="vendor" value="Microsoft"/>
+      <property name="model" value="Zune HD"/>
+      <property name="displayHeight" value="272"/>
+      <property name="displayWidth" value="480"/>
+      <property name="is_wireless_device" value="true"/>
+      <property name="ajax_support_javascript" value="true"/>
+      <property name="inputDevices" value="touchscreen"/>
+      <property name="device_os" value="Windows CE"/>
+    </device>
+  </Devices>
+</ODDR>

Added: incubator/devicemap/trunk/devicemapjava/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/pom.xml?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/pom.xml (added)
+++ incubator/devicemap/trunk/devicemapjava/pom.xml Sun Jun 23 01:52:19 2013
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache</groupId>
+        <artifactId>apache</artifactId>
+        <version>9</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>org.apache.devicemap</groupId>
+    <artifactId>devicemap-java</artifactId>
+    <packaging>jar</packaging>
+    <version>0.1</version>
+    <name>Apache DeviceMap Java Client</name>
+    <description>DeviceMap Java Client</description>
+    <url>http://incubator.apache.org/devicemap</url>
+
+    <prerequisites>
+        <maven>3.0.2</maven>
+    </prerequisites>
+  
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/devicemap/trunk/openddr/java</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/devicemap/trunk/openddr/java</developerConnection>
+        <url>http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java</url>
+    </scm>
+  
+    <dependencies>
+    </dependencies>
+
+    <build>
+        <finalName>devicemapclient</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.0</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                    <debug>true</debug>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+  
+    <profiles>
+    </profiles>
+</project>
+

Added: incubator/devicemap/trunk/devicemapjava/src/main/java/Main.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/src/main/java/Main.java?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/src/main/java/Main.java (added)
+++ incubator/devicemap/trunk/devicemapjava/src/main/java/Main.java Sun Jun 23 01:52:19 2013
@@ -0,0 +1,34 @@
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.Map;
+import org.apache.devicemap.classification.Loader;
+
+public class Main {
+    public static void main(String args[]) throws Exception {
+        System.out.println("main()");
+        
+        Loader loader=new Loader();
+        
+        InputStreamReader ddin=new InputStreamReader(new FileInputStream("DeviceDataSource.xml"), "UTF-8");
+        InputStreamReader ddpin=new InputStreamReader(new FileInputStream("DeviceDataSourcePatch.xml"), "UTF-8");
+        InputStreamReader din=new InputStreamReader(new FileInputStream("BuilderDataSource.xml"), "UTF-8");
+        InputStreamReader dpin=new InputStreamReader(new FileInputStream("BuilderDataSource.xml"), "UTF-8");
+        
+        loader.loadDeviceData(ddin);
+        loader.loadDeviceData(ddpin);
+        
+        loader.setParentAttributes();
+        
+        loader.loadDevicePatterns(din);
+        loader.loadDevicePatterns(dpin);
+        
+        ddin.close();
+        ddpin.close();
+        din.close();
+        dpin.close();
+        
+        Map<String,Map<String,String>> devices=loader.getDevices();
+        
+        System.out.println(devices.get(devices.keySet().iterator().next()));
+    }
+}
\ No newline at end of file

Added: incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Loader.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Loader.java?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Loader.java (added)
+++ incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Loader.java Sun Jun 23 01:52:19 2013
@@ -0,0 +1,165 @@
+/*
+   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.classification;
+
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author Reza Naghibi
+ */
+public class Loader {
+    
+    private Map<String,Map<String,String>> devices;
+    
+    public Loader() {
+        devices=new HashMap<String,Map<String,String>>();
+    }
+    
+    /*
+     * loads device data from an InputStreamReader
+     */
+    public void loadDeviceData(InputStreamReader in) {
+        XMLParser parser=new XMLParser(in);
+        String tag;
+        
+        try {
+            String id="";
+            String parent="";
+            Map<String,String> attributes=new HashMap<String,String>();
+            
+            while(!(tag=parser.getNextTag()).isEmpty()) {
+                if(tag.startsWith("<device ")) {
+                    id=XMLParser.getAttribute(tag,"id");
+                    parent=XMLParser.getAttribute(tag,"parentId");
+                } else if(tag.equals("</device>")) {
+                    if(!parent.isEmpty()) {
+                        attributes.put("parentId", parent);
+                    }
+                    
+                    if(!id.isEmpty()) {
+                        getDevices().put(id, attributes);
+                    }
+                    
+                    id="";
+                    parent="";
+                    attributes=new HashMap<String,String>();
+                } else if(tag.startsWith("<property ")) {
+                    String key=XMLParser.getAttribute(tag,"name");
+                    String value=XMLParser.getAttribute(tag,"value");
+                    
+                    attributes.put(key,value);
+                }
+            }
+        } catch(Exception ex) {
+            Util.log("ERROR: "+ex.toString(),ex);
+        }
+    }
+    
+    /*
+     * loads patterns from an InputStreamReader
+     */
+    public void loadDevicePatterns(InputStreamReader in) {
+        XMLParser parser=new XMLParser(in);
+        String tag;
+        
+        try {
+            String builder="";
+            String id="";
+            String patterns="";
+            
+            while(!(tag=parser.getNextTag()).isEmpty()) {
+                if(tag.startsWith("<builder ")) {
+                    builder=XMLParser.getAttribute(tag,"class");
+                } else if(tag.startsWith("<device ")) {
+                    id=XMLParser.getAttribute(tag,"id");
+                } else if(tag.equals("</device>")) {
+                    if(!id.isEmpty() && !patterns.isEmpty()) {
+                        Map<String,String> device=devices.get(id);
+                        
+                        if(device!=null) {
+                            device.put("pattern",patterns);
+                            device.put("builder",builder);
+                        } else {
+                            Util.log("ERROR: device not found: '"+id+"'");
+                        }
+                    }
+                    
+                    id="";
+                    patterns="";
+                    
+                } else if(tag.equals("<value>")) {
+                    String pattern=parser.getTagValue();
+                    
+                    if(!patterns.isEmpty()) {
+                        patterns+=",";
+                    }
+                    
+                    patterns+=pattern;
+                }
+            }
+        } catch(Exception ex) {
+            Util.log("ERROR: "+ex.toString(),ex);
+        }
+    }
+    
+    /**
+     * Sets attributes from parents
+     */
+    public void setParentAttributes() {
+        for(String device:devices.keySet()) {
+            Map<String,String> attributes=devices.get(device);
+            
+            mergeParent(attributes);
+        }
+    }
+    
+    private void mergeParent(Map<String,String> attributes) {
+        String parentId=attributes.get("parentId");
+        
+        if(parentId==null || parentId.isEmpty()) {
+            return;
+        }
+        
+        Map<String,String> parent=devices.get(parentId);
+        
+        if(parent==null || parent.isEmpty()) {
+            return;
+        }
+        
+        mergeParent(parent);
+        
+        for(String key:parent.keySet()) {
+            String value=parent.get(key);
+            
+            if(!attributes.containsKey(key)) {
+                attributes.put(key, value);
+            }
+        }
+    }
+
+    /**
+     * @return the devices
+     */
+    public Map<String,Map<String,String>> getDevices() {
+        return devices;
+    }
+}

Added: incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Util.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Util.java?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Util.java (added)
+++ incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/Util.java Sun Jun 23 01:52:19 2013
@@ -0,0 +1,42 @@
+/*
+   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.classification;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ *
+ * @author Reza Naghibi
+ */
+public class Util {
+    public static void log(String msg) {
+        log(msg, null);
+    }
+    
+    public static void log(String msg, Exception e) {
+        String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS").format(new Date());
+        
+        System.out.println(date+" [dmapjclient] "+msg);
+        
+        if(e!=null) {
+            e.printStackTrace();
+        }
+    }
+}

Added: incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/XMLParser.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/XMLParser.java?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/XMLParser.java (added)
+++ incubator/devicemap/trunk/devicemapjava/src/main/java/org/apache/devicemap/classification/XMLParser.java Sun Jun 23 01:52:19 2013
@@ -0,0 +1,117 @@
+/*
+   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.classification;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ *
+ * @author Reza Naghibi
+ */
+public class XMLParser {
+    
+    private InputStreamReader in;
+    
+    private char pre;
+
+    private XMLParser() {}
+    
+    public XMLParser(InputStreamReader in) {
+        this.in=in;
+        pre=0;
+    }
+    
+    public String getNextTag() throws IOException {
+        StringBuilder ret=new StringBuilder();
+        
+        int i;
+        boolean start=false;
+        
+        if(pre=='<') {
+            ret.append(pre);
+            pre=0;
+            start=true;
+        }
+        
+        while((i=in.read())!=-1) {
+            char c=(char)i;
+            if(c=='<') {
+                start=true;
+                ret.append(c);
+            } else if(c=='>') {
+                ret.append(c);
+                break;
+            } else if(start) {
+                ret.append(c);
+            }
+        }
+        
+        return ret.toString();
+    }
+    
+    public String getTagValue() throws IOException {
+        StringBuilder ret=new StringBuilder();
+        
+        int i;
+        
+        while((i=in.read())!=-1) {
+            char c=(char)i;
+            if(c=='<') {
+                pre='<';
+                break;
+            } else {
+                ret.append(c);
+            }
+        }
+        
+        return ret.toString().trim();
+    }
+    
+    public static String getAttribute(String tag, String name) {
+        int retpos=tag.toLowerCase().indexOf(name.toLowerCase()+"=");
+        
+        if(retpos==-1)
+            return "";
+
+        String ret=tag.substring(retpos+name.length()+1);
+
+        if(ret.startsWith("\"")) {
+            ret=ret.substring(1);
+            int endpos=ret.indexOf("\"");
+            
+            if(endpos==-1) {
+                return "";
+            }
+            
+            ret=ret.substring(0, endpos);
+        } else {
+            int endpos=ret.indexOf(" ");
+            
+            if(endpos==-1) {
+                return "";
+            }
+            
+            ret=ret.substring(0, endpos);
+        }
+        
+        return ret;
+    }
+}

Added: incubator/devicemap/trunk/devicemapjava/test.bat
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/test.bat?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/test.bat (added)
+++ incubator/devicemap/trunk/devicemapjava/test.bat Sun Jun 23 01:52:19 2013
@@ -0,0 +1,4 @@
+@ECHO OFF
+
+java -cp "target\devicemapclient.jar" Main
+

Added: incubator/devicemap/trunk/devicemapjava/test.sh
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemapjava/test.sh?rev=1495787&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemapjava/test.sh (added)
+++ incubator/devicemap/trunk/devicemapjava/test.sh Sun Jun 23 01:52:19 2013
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+java -cp "target/devicemapclient.jar" Main
+

Propchange: incubator/devicemap/trunk/devicemapjava/test.sh
------------------------------------------------------------------------------
    svn:executable = *