Author: rezan
Date: Tue Jan 6 01:09:24 2015
New Revision: 1649704
URL: http://svn.apache.org/r1649704
Log:
w3c simple ddr implementation of classifier
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/
devicemap/trunk/devicemap/java/classifier_w3c_simple/pom.xml
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapEvidence.java
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyName.java
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyRef.java
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValue.java
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValues.java
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
Removed:
devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/DeviceMapW3CSimpleDDR.java
Modified:
devicemap/trunk/devicemap/java/classifier/pom.xml
Modified: devicemap/trunk/devicemap/java/classifier/pom.xml
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier/pom.xml?rev=1649704&r1=1649703&r2=1649704&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/classifier/pom.xml (original)
+++ devicemap/trunk/devicemap/java/classifier/pom.xml Tue Jan 6 01:09:24 2015
@@ -78,5 +78,4 @@
</plugins>
</build>
- <inceptionYear>2014</inceptionYear>
</project>
Added: devicemap/trunk/devicemap/java/classifier_w3c_simple/pom.xml
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/pom.xml?rev=1649704&view=auto
==============================================================================
--- devicemap/trunk/devicemap/java/classifier_w3c_simple/pom.xml (added)
+++ devicemap/trunk/devicemap/java/classifier_w3c_simple/pom.xml Tue Jan 6
01:09:24 2015
@@ -0,0 +1,92 @@
+<?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>16</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.apache.devicemap</groupId>
+ <artifactId>devicemap-client-w3c-simple</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Apache DeviceMap Java W3C Simple API</name>
+ <description>Apache DeviceMap Java W3C Simple API</description>
+
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.devicemap</groupId>
+ <artifactId>devicemap-client</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+
+ <!-- WARNING, this jar is unpublished and unlicensed -->
+ <dependency>
+ <groupId>org.w3c.ddr</groupId>
+ <artifactId>simple</artifactId>
+ <version>20081205</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.devicemap</groupId>
+ <artifactId>devicemap-data</artifactId>
+ <version>1.0.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <debug>true</debug>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.devicemap.DeviceMapClient;
+import org.apache.devicemap.DeviceMapFactory;
+import org.apache.devicemap.loader.LoaderOption;
+import org.apache.devicemap.w3csimple.model.DeviceMapEvidence;
+import org.apache.devicemap.w3csimple.model.DeviceMapPropertyName;
+import org.apache.devicemap.w3csimple.model.DeviceMapPropertyRef;
+import org.apache.devicemap.w3csimple.model.DeviceMapPropertyValues;
+
+import org.w3c.ddr.simple.Evidence;
+import org.w3c.ddr.simple.PropertyName;
+import org.w3c.ddr.simple.PropertyRef;
+import org.w3c.ddr.simple.PropertyValue;
+import org.w3c.ddr.simple.PropertyValues;
+import org.w3c.ddr.simple.Service;
+import org.w3c.ddr.simple.exception.InitializationException;
+import org.w3c.ddr.simple.exception.NameException;
+
+public class DeviceMapW3CSimple implements Service {
+
+ public final static String VERSION = "1.0.0";
+ public final static String NAMESPACE = "org.apache.devicemap";
+ public final static String EVIDENCE = "User-Agent";
+
+ private DeviceMapClient client;
+
+ @Override
+ public void initialize(String defaultVocabularyIRI, Properties props) throws
NameException, InitializationException {
+ client = DeviceMapFactory.getClient(LoaderOption.JAR);
+ }
+
+ @Override
+ public String getImplementationVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public String getDataVersion() {
+ return Service.NOT_SUPPORTED;
+ }
+
+ @Override
+ public PropertyRef[] listPropertyRefs() {
+ PropertyRef[] refs = new PropertyRef[5];
+
+ refs[0] = new DeviceMapPropertyRef("id");
+ refs[1] = new DeviceMapPropertyRef("vendor");
+ refs[2] = new DeviceMapPropertyRef("model");
+ refs[3] = new DeviceMapPropertyRef("displayWidth");
+ refs[4] = new DeviceMapPropertyRef("displayHeight");
+
+ return refs;
+ }
+
+ @Override
+ public PropertyValue getPropertyValue(Evidence evidence, PropertyRef
propertyRef) throws NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE))).getValue(propertyRef);
+ }
+
+ @Override
+ public PropertyValue getPropertyValue(Evidence evidence, PropertyName
propertyName) throws NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE))).getValue(propertyName);
+ }
+
+ @Override
+ public PropertyValue getPropertyValue(Evidence evidence, String
localPropertyName) throws NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE))).getValue(localPropertyName);
+ }
+
+ @Override
+ public PropertyValue getPropertyValue(Evidence evidence, String
localPropertyName, String localAspectName, String vocabularyIRI) throws
NameException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change
body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public PropertyValues getPropertyValues(Evidence evidence) throws
NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE)));
+ }
+
+ @Override
+ public PropertyValues getPropertyValues(Evidence evidence, PropertyRef[]
propertyRefs) throws NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE)));
+ }
+
+ @Override
+ public PropertyValues getPropertyValues(Evidence evidence, String
localAspectName) throws NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE)));
+ }
+
+ @Override
+ public PropertyValues getPropertyValues(Evidence evidence, String
localAspectName, String vocabularyIRI) throws NameException {
+ return new
DeviceMapPropertyValues(client.classifyDevice(evidence.get(EVIDENCE)));
+ }
+
+ @Override
+ public PropertyName newPropertyName(String localPropertyName) throws
NameException {
+ return new DeviceMapPropertyName(localPropertyName);
+ }
+
+ @Override
+ public PropertyName newPropertyName(String localPropertyName, String
vocabularyIRI) throws NameException {
+ return new DeviceMapPropertyName(localPropertyName);
+ }
+
+ @Override
+ public PropertyRef newPropertyRef(String localPropertyName) throws
NameException {
+ return new DeviceMapPropertyRef(localPropertyName);
+ }
+
+ @Override
+ public PropertyRef newPropertyRef(PropertyName propertyName) throws
NameException {
+ return new DeviceMapPropertyRef(propertyName.getLocalPropertyName());
+ }
+
+ @Override
+ public PropertyRef newPropertyRef(PropertyName propertyName, String
localAspectName) throws NameException {
+ return new DeviceMapPropertyRef(propertyName.getLocalPropertyName());
+ }
+
+ @Override
+ public Evidence newHTTPEvidence() {
+ return new DeviceMapEvidence();
+ }
+
+ @Override
+ public Evidence newHTTPEvidence(Map<String, String> map) {
+ return new DeviceMapEvidence(map);
+ }
+
+}
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapEvidence.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapEvidence.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapEvidence.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapEvidence.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.devicemap.data.Device;
+
+import org.w3c.ddr.simple.Evidence;
+
+public class DeviceMapEvidence implements Evidence {
+
+ Map<String, String> headers;
+
+ private Device device;
+
+ public DeviceMapEvidence() {
+ headers = new HashMap<String, String>();
+ }
+
+ public DeviceMapEvidence(Map<String, String> map) {
+ headers = new HashMap<String, String>();
+ headers.putAll(map);
+ }
+
+ @Override
+ public boolean exists(String string) {
+ if (string == null) {
+ return false;
+ }
+ return headers.containsKey(string.toLowerCase());
+ }
+
+ @Override
+ public String get(String key) {
+ return headers.get(key.toLowerCase());
+ }
+
+ /**
+ *
+ * @param key case insensitive
+ * @param value case sensitive
+ */
+ @Override
+ public void put(String key, String value) {
+ headers.put(key.toLowerCase(), value);
+ }
+
+ public Device getDevice() {
+ return device;
+ }
+
+ public void setDevice(Device device) {
+ this.device = device;
+ }
+
+}
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyName.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyName.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyName.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyName.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple.model;
+
+import org.w3c.ddr.simple.PropertyName;
+import org.apache.devicemap.w3csimple.DeviceMapW3CSimple;
+
+public class DeviceMapPropertyName implements PropertyName {
+
+ private String name;
+
+ public DeviceMapPropertyName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getLocalPropertyName() {
+ return name;
+ }
+
+ @Override
+ public String getNamespace() {
+ return DeviceMapW3CSimple.NAMESPACE;
+ }
+
+}
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyRef.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyRef.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyRef.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyRef.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple.model;
+
+import org.w3c.ddr.simple.PropertyRef;
+import org.apache.devicemap.w3csimple.DeviceMapW3CSimple;
+
+public class DeviceMapPropertyRef implements PropertyRef {
+
+ private String name;
+
+ public DeviceMapPropertyRef(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getLocalPropertyName() {
+ return name;
+ }
+
+ @Override
+ public String getAspectName() {
+ return PropertyRef.NULL_ASPECT;
+ }
+
+ @Override
+ public String getNamespace() {
+ return DeviceMapW3CSimple.NAMESPACE;
+ }
+
+}
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValue.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValue.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValue.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValue.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple.model;
+
+import org.w3c.ddr.simple.PropertyRef;
+import org.w3c.ddr.simple.PropertyValue;
+import org.w3c.ddr.simple.exception.ValueException;
+
+public class DeviceMapPropertyValue implements PropertyValue {
+
+ private final String name;
+ private final String value;
+
+ public DeviceMapPropertyValue(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public double getDouble() throws ValueException {
+ throw new ValueException(ValueException.INCOMPATIBLE_TYPES, "Double");
+ }
+
+ @Override
+ public long getLong() throws ValueException {
+ throw new ValueException(ValueException.INCOMPATIBLE_TYPES, "Long");
+ }
+
+ @Override
+ public boolean getBoolean() throws ValueException {
+ throw new ValueException(ValueException.INCOMPATIBLE_TYPES, "Boolean");
+ }
+
+ @Override
+ public int getInteger() throws ValueException {
+ throw new ValueException(ValueException.INCOMPATIBLE_TYPES, "Integer");
+ }
+
+ @Override
+ public String[] getEnumeration() throws ValueException {
+ throw new ValueException(ValueException.INCOMPATIBLE_TYPES, "Enumeration");
+ }
+
+ @Override
+ public float getFloat() throws ValueException {
+ throw new ValueException(ValueException.INCOMPATIBLE_TYPES, "Float");
+ }
+
+ @Override
+ public PropertyRef getPropertyRef() {
+ return new DeviceMapPropertyRef(name);
+ }
+
+ @Override
+ public String getString() throws ValueException {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+}
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValues.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValues.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValues.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/model/DeviceMapPropertyValues.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.devicemap.data.Device;
+import org.w3c.ddr.simple.PropertyName;
+import org.w3c.ddr.simple.PropertyRef;
+import org.w3c.ddr.simple.PropertyValue;
+import org.w3c.ddr.simple.PropertyValues;
+import org.w3c.ddr.simple.exception.NameException;
+
+public class DeviceMapPropertyValues implements PropertyValues {
+
+ List<PropertyValue> values;
+
+ public DeviceMapPropertyValues(Device device) {
+ values = new ArrayList<PropertyValue>();
+
+ values.add(new DeviceMapPropertyValue("id", device.getId()));
+
+ for(String attribute : device.getAttributes().keySet()) {
+ String value = device.getAttribute(attribute);
+ values.add(new DeviceMapPropertyValue(attribute, value));
+ }
+ }
+
+ @Override
+ public PropertyValue[] getAll() {
+ return values.toArray(new PropertyValue[values.size()]);
+ }
+
+ @Override
+ public PropertyValue getValue(PropertyRef prop) throws NameException {
+ for (PropertyValue propertyValue : values) {
+ if
(propertyValue.getPropertyRef().getLocalPropertyName().equals(prop.getLocalPropertyName()))
{
+ return propertyValue;
+ }
+ }
+ throw new NameException(NameException.PROPERTY_NOT_RECOGNIZED,
prop.getLocalPropertyName());
+ }
+
+ public PropertyValue getValue(PropertyName prop) throws NameException {
+ for (PropertyValue propertyValue : values) {
+ if
(propertyValue.getPropertyRef().getLocalPropertyName().equals(prop.getLocalPropertyName()))
{
+ return propertyValue;
+ }
+ }
+ throw new NameException(NameException.PROPERTY_NOT_RECOGNIZED,
prop.getLocalPropertyName());
+ }
+
+ public PropertyValue getValue(String prop) throws NameException {
+ for (PropertyValue propertyValue : values) {
+ if (propertyValue.getPropertyRef().getLocalPropertyName().equals(prop)) {
+ return propertyValue;
+ }
+ }
+ throw new NameException(NameException.PROPERTY_NOT_RECOGNIZED, prop);
+ }
+
+}
Added:
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java?rev=1649704&view=auto
==============================================================================
---
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
(added)
+++
devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
Tue Jan 6 01:09:24 2015
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.w3csimple;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.w3c.ddr.simple.Evidence;
+
+public class DeviceMapW3CSimpleTest {
+
+ @Test
+ public void testDeviceMapW3CSimple() throws Exception {
+ //System.out.println("DeviceMapW3CSimple test");
+
+ DeviceMapW3CSimple simple = new DeviceMapW3CSimple();
+ simple.initialize(DeviceMapW3CSimple.NAMESPACE, null);
+
+ String userAgent = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380
Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile
Safari/524.15.0";
+
+ //System.out.println("Testing: " + userAgent);
+
+ Evidence e = simple.newHTTPEvidence();
+ e.put(DeviceMapW3CSimple.EVIDENCE, userAgent);
+
+ /*
+ PropertyValues values = simple.getPropertyValues(e);
+
+ for(PropertyValue value : values.getAll()) {
+ System.out.println(value.getPropertyRef().getLocalPropertyName() + ": "
+ value.getString());
+ }
+ */
+
+ Assert.assertEquals("test ua not htc aria", "HTC Aria",
simple.getPropertyValue(e, "id").getString());
+ }
+}