devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wk...@apache.org
Subject svn commit: r1639075 - in /incubator/devicemap/trunk/examples/ddr-filter: ./ src/main/java/org/apache/devicemap/example/ddrfilter/ src/main/java/org/apache/devicemap/example/webfilter/ src/main/resources/ src/main/webapp/ src/main/webapp/WEB-INF/
Date Wed, 12 Nov 2014 21:43:11 GMT
Author: wkeil
Date: Wed Nov 12 21:43:11 2014
New Revision: 1639075

URL: http://svn.apache.org/r1639075
Log:
DMAP-53: This is an epic for tasks or issues related to examples 

Task-Url: https://issues.apache.org/jira/browse/DMAP-53

Added:
    incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/
    incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
    incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/package-info.java
    incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties
Removed:
    incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/ddrfilter/
    incubator/devicemap/trunk/examples/ddr-filter/src/main/resources/oddr.properties
Modified:
    incubator/devicemap/trunk/examples/ddr-filter/pom.xml
    incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/web.xml
    incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/index.jsp

Modified: incubator/devicemap/trunk/examples/ddr-filter/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/ddr-filter/pom.xml?rev=1639075&r1=1639074&r2=1639075&view=diff
==============================================================================
--- incubator/devicemap/trunk/examples/ddr-filter/pom.xml (original)
+++ incubator/devicemap/trunk/examples/ddr-filter/pom.xml Wed Nov 12 21:43:11 2014
@@ -1,17 +1,16 @@
-<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">
+<?xml version="1.0"?>
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 	<modelVersion>4.0.0</modelVersion>
-	<artifactId>dmap-ddr-filter</artifactId>
-	<packaging>war</packaging>
-	<name>DeviceMap DDR Simple Filter Example</name>
 	<parent>
 		<groupId>org.apache.devicemap.examples</groupId>
 		<artifactId>examples-parent</artifactId>
 		<version>1.0.0-SNAPSHOT</version>
 	</parent>
-	<properties>
-		<devicemap.ddr.version>1.0.0</devicemap.ddr.version>
-	</properties>
+	<artifactId>ddr-filter</artifactId>
+	<packaging>war</packaging>
+	<name>Apache DeviceMap DDR Filter</name>
 	<dependencies>
 		<dependency>
 			<groupId>javax.servlet</groupId>
@@ -24,11 +23,11 @@
 			<artifactId>devicemap-simpleddr</artifactId>
 			<version>${devicemap.ddr.version}</version>
 		</dependency>
-		<dependency>
-			<groupId>commons-logging</groupId>
-			<artifactId>commons-logging</artifactId>
-			<version>1.1.1</version>
-		</dependency>
+		<!--  <dependency>
+			<groupId>org.w3c</groupId>
+			<artifactId>ddr-simple</artifactId>
+			<version>${w3cddr.version}</version>
+		</dependency> -->
 		<dependency>
 			<groupId>org.apache.devicemap</groupId>
 			<artifactId>devicemap-data</artifactId>
@@ -47,4 +46,18 @@
 			<scope>test</scope>
 		</dependency>
 	</dependencies>
+	<build>
+		<finalName>ddr-filter</finalName>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>${java.version}</source>
+					<target>${java.version}</target>
+					<debug>true</debug>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 </project>

Added: incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java?rev=1639075&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
(added)
+++ incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
Wed Nov 12 21:43:11 2014
@@ -0,0 +1,120 @@
+package org.apache.devicemap.example.webfilter;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.w3c.ddr.simple.Evidence;
+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.ServiceFactory;
+import org.w3c.ddr.simple.exception.NameException;
+//import org.apache.devicemap.client.DeviceMapClient;
+import org.apache.devicemap.simpleddr.ODDRService;
+import org.apache.devicemap.simpleddr.model.ODDRHTTPEvidence;
+
+/**
+ * Servlet Filter implementation class ClassificationFilter
+ */
+public class IdentificationFilter implements Filter {
+	private Service identificationService = null;
+	
+    /**
+     * Default constructor. 
+     */
+    public IdentificationFilter() {
+    }
+    
+	/**
+	 * @see Filter#init(FilterConfig)
+	 */
+	public void init(FilterConfig filterConfig) throws ServletException {
+	     System.out.println("Initialize filter");
+	        Properties initializationProperties = new Properties();
+	        ServletContext context = filterConfig.getServletContext();                
+
+	        try {
+	            initializationProperties.load(context.getResourceAsStream("/WEB-INF/oddr.properties"));
+	            identificationService = ServiceFactory.newService("org.apache.devicemap.simpleddr.ODDRService",
initializationProperties.getProperty(ODDRService.ODDR_VOCABULARY_IRI), initializationProperties);
+	            
+	        } catch (Exception ex) {
+	            throw new RuntimeException(ex);
+	        }
+	}
+	/**
+	 * @see Filter#destroy()
+	 */
+	public void destroy() {
+		System.out.println("Destroy Filter");
+	}
+
+	/**
+	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
+	 */
+	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
+		System.out.println("Do filter");
+		PropertyRef vendorRef;
+        PropertyRef modelRef;
+        PropertyRef displayWidthRef;
+        PropertyRef displayHeightRef;
+
+        try {
+            vendorRef = identificationService.newPropertyRef("vendor");
+            modelRef = identificationService.newPropertyRef("model");
+            displayWidthRef = identificationService.newPropertyRef("displayWidth");
+            displayHeightRef = identificationService.newPropertyRef("displayHeight");
+
+        } catch (NameException ex) {
+        	System.err.println(ex.getLocalizedMessage());
+            throw new RuntimeException(ex);
+        }
+
+        PropertyRef[] propertyRefs = new PropertyRef[] {vendorRef, modelRef, displayWidthRef,
displayHeightRef};
+        Evidence e = new ODDRHTTPEvidence(); //FIXME
+        e.put("User-Agent", ((HttpServletRequest)request).getHeader("User-Agent"));
+
+        try {
+            PropertyValues propertyValues = identificationService.getPropertyValues(e, propertyRefs);
+            PropertyValue vendor = propertyValues.getValue(vendorRef);
+            PropertyValue model = propertyValues.getValue(modelRef);
+            PropertyValue displayWidth = propertyValues.getValue(displayWidthRef);
+            PropertyValue displayHeight = propertyValues.getValue(displayHeightRef);
+
+            System.out.print("Vendor: " + vendor + "(" + vendor.exists() + ")");
+            System.out.print(" ;");
+            System.out.println("Model: " + model + "(" + model.exists() + ")");
+
+            if (vendor.exists())
+                ((HttpServletRequest)request).setAttribute("vendor", vendor.getString());
+            if (model.exists())
+                ((HttpServletRequest)request).setAttribute("model", model.getString());
+            if (displayWidth.exists()) {
+            	System.out.println("W: " + displayWidth + "(" + displayWidth.exists() + ")");
+                request.setAttribute("displayWidth", displayWidth.getInteger());
+            }
+            if (displayHeight.exists()) {
+            	System.out.println("H: " + displayHeight + "(" + displayHeight.exists() + ")");
+            	request.setAttribute("displayHeight", displayHeight.getInteger());
+            }
+            
+            request.setAttribute("vendor",
+					"dummy vendor");
+        } catch (Exception ex) {
+            System.err.println(ex.getLocalizedMessage());
+            throw new RuntimeException(ex);
+        }
+
+        chain.doFilter(request, response);
+	}
+
+}

Added: incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/package-info.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/package-info.java?rev=1639075&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/package-info.java
(added)
+++ incubator/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/package-info.java
Wed Nov 12 21:43:11 2014
@@ -0,0 +1,8 @@
+/**
+ * 
+ */
+/**
+ * @author Werner
+ *
+ */
+package org.apache.devicemap.example.webfilter;
\ No newline at end of file

Added: incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties?rev=1639075&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties
(added)
+++ incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties
Wed Nov 12 21:43:11 2014
@@ -0,0 +1,11 @@
+oddr.ua.device.builder.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/BuilderDataSource.xml
+oddr.ua.device.datasource.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/DeviceDataSource.xml
+oddr.ua.device.builder.patch.paths=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/BuilderDataSourcePatch.xml
+oddr.ua.device.datasource.patch.paths=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/DeviceDataSourcePatch.xml
+oddr.ua.browser.datasource.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/BrowserDataSource.xml
+oddr.ua.operatingSystem.datasource.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/OperatingSystemDataSource.xml
+ddr.vocabulary.core.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/coreVocabulary.xml
+oddr.vocabulary.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/oddrVocabulary.xml
+oddr.limited.vocabulary.path=C:/Users/Werner/workspace/jds7/mobile/devicemap/device-data/src/main/resources/devicedata/oddrLimitedVocabulary.xml
+oddr.vocabulary.device=http://www.openddr.org/oddr-vocabulary
+oddr.threshold=70

Modified: incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/web.xml?rev=1639075&r1=1639074&r2=1639075&view=diff
==============================================================================
--- incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/web.xml Wed Nov
12 21:43:11 2014
@@ -1,11 +1,15 @@
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
-  <display-name>DeviceMap DDR Sample WebApp</display-name>
-  <filter>
-    <filter-name>DDRFilter</filter-name>
-    <filter-class> org.apache.devicemap.example.ddrfilter.DDRFilter</filter-class>
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+  <display-name>DeviceMap DDR Web Application</display-name>
+   <filter>
+    <filter-name>IdentificationFilter</filter-name>
+    <filter-class>org.apache.devicemap.example.webfilter.IdentificationFilter</filter-class>
   </filter>
   <filter-mapping>
-    <filter-name>DDRFilter</filter-name>
+    <filter-name>IdentificationFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
   <session-config>

Modified: incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/index.jsp?rev=1639075&r1=1639074&r2=1639075&view=diff
==============================================================================
--- incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/index.jsp (original)
+++ incubator/devicemap/trunk/examples/ddr-filter/src/main/webapp/index.jsp Wed Nov 12 21:43:11
2014
@@ -8,6 +8,6 @@
         <title>DeviceMap Simple DDR Sample</title>
     </head>
     <body>
-        <h1>${vendor} ${model} resolution: ${displayWidth} x ${displayHeight}</h1>
+        <h1>${vendor} ${model} resolution: <%= request.getAttribute("displayWidth")
%> x <%= request.getAttribute("displayHeight") %></h1>
     </body>
 </html>
\ No newline at end of file



Mime
View raw message