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/05/05 16:23:41 UTC

svn commit: r1479328 - in /incubator/devicemap/trunk/web: ./ src/ src/main/ src/main/config/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/devicemapweb/ src/main/java/org/apache/devicemapweb/controller/ src/main/j...

Author: rezan
Date: Sun May  5 14:23:40 2013
New Revision: 1479328

URL: http://svn.apache.org/r1479328
Log:
website for device map

Added:
    incubator/devicemap/trunk/web/
    incubator/devicemap/trunk/web/pom.xml
    incubator/devicemap/trunk/web/src/
    incubator/devicemap/trunk/web/src/main/
    incubator/devicemap/trunk/web/src/main/config/
    incubator/devicemap/trunk/web/src/main/config/createDB.sql
    incubator/devicemap/trunk/web/src/main/config/dev.properties
    incubator/devicemap/trunk/web/src/main/config/prod.properties
    incubator/devicemap/trunk/web/src/main/java/
    incubator/devicemap/trunk/web/src/main/java/org/
    incubator/devicemap/trunk/web/src/main/java/org/apache/
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/Test.java
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/controller/
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/controller/Review.java
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/dao/
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/dao/UserAgentReviewDAO.java
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/model/
    incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/model/UserAgentReview.java
    incubator/devicemap/trunk/web/src/main/resources/
    incubator/devicemap/trunk/web/src/main/resources/log4j.properties
    incubator/devicemap/trunk/web/src/main/webapp/
    incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/
    incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/applicationContext.xml
    incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml
    incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/web.xml
    incubator/devicemap/trunk/web/src/main/webapp/index.jsp
    incubator/devicemap/trunk/web/src/main/webapp/views/
    incubator/devicemap/trunk/web/src/main/webapp/views/show.jsp

Added: incubator/devicemap/trunk/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/pom.xml?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/pom.xml (added)
+++ incubator/devicemap/trunk/web/pom.xml Sun May  5 14:23:40 2013
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+
+    <artifactId>devicemapweb</artifactId>
+    <groupId>org.apache.devicemap.web</groupId>
+    <name>devicemapweb</name>
+    <version>1.1-SNAPSHOT</version>
+    <packaging>war</packaging>
+
+    <properties>
+        <java.version>1.6</java.version>
+        <build.date>${maven.build.timestamp}</build.date>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.build.timestamp.format>yyyyMMdd_HHmm</maven.build.timestamp.format>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>c3p0</groupId>
+            <artifactId>c3p0</artifactId>
+            <version>0.9.1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.24</version>
+        </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-entitymanager</artifactId>
+            <version>4.1.10.Final</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>3.2.2.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-webmvc</artifactId>
+            <version>3.2.2.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-orm</artifactId>
+            <version>3.2.2.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>jstl</groupId>
+            <artifactId>jstl</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.17</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <finalName>devicemapweb</finalName>
+        <filters>
+            <filter>src/main/config/${env}.properties</filter>
+        </filters>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <version>2.3</version>
+                <configuration>
+                    <webResources>
+                        <resource>
+                            <directory>${basedir}/src/main/webapp</directory>
+                            <filtering>true</filtering>
+                            <includes>
+                                <include>**/*.xml</include>
+                                <include>**/*.jsp</include>
+                            </includes>
+                        </resource>
+                    </webResources>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.0</version>
+                <configuration>
+                    <source>${java.version}</source>
+                    <target>${java.version}</target>
+                    <debug>true</debug>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>dev</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <properties>
+                <env>dev</env>
+            </properties>
+        </profile>
+        <profile>
+            <id>prod</id>
+            <properties>
+                <env>prod</env>
+            </properties>
+        </profile>
+    </profiles>
+</project>

Added: incubator/devicemap/trunk/web/src/main/config/createDB.sql
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/config/createDB.sql?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/config/createDB.sql (added)
+++ incubator/devicemap/trunk/web/src/main/config/createDB.sql Sun May  5 14:23:40 2013
@@ -0,0 +1,4 @@
+CREATE USER 'test'@'localhost' IDENTIFIED BY 'password';
+CREATE DATABASE dmap;
+GRANT ALL PRIVILEGES ON `dmap`.* TO 'test'@'localhost' IDENTIFIED BY 'password';
+FLUSH PRIVILEGES;

Added: incubator/devicemap/trunk/web/src/main/config/dev.properties
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/config/dev.properties?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/config/dev.properties (added)
+++ incubator/devicemap/trunk/web/src/main/config/dev.properties Sun May  5 14:23:40 2013
@@ -0,0 +1,6 @@
+db.url=jdbc:mysql://localhost:3306/dmap
+db.user=test
+db.password=password
+
+log.level.all=INFO
+log.level.src=DEBUG

Added: incubator/devicemap/trunk/web/src/main/config/prod.properties
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/config/prod.properties?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/config/prod.properties (added)
+++ incubator/devicemap/trunk/web/src/main/config/prod.properties Sun May  5 14:23:40 2013
@@ -0,0 +1,6 @@
+db.url=jdbc:mysql://localhost:3306/dmap
+db.user=test
+db.password=password
+
+log.level.all=ERROR
+log.level.src=WARN

Added: incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/Test.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/Test.java?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/Test.java (added)
+++ incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/Test.java Sun May  5 14:23:40 2013
@@ -0,0 +1,4 @@
+package org.apache.devicemapweb;
+
+class Test {
+}

Added: incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/controller/Review.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/controller/Review.java?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/controller/Review.java (added)
+++ incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/controller/Review.java Sun May  5 14:23:40 2013
@@ -0,0 +1,50 @@
+package org.apache.devicemapweb.controller;
+ 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.apache.devicemapweb.model.UserAgentReview;
+import org.apache.devicemapweb.dao.UserAgentReviewDAO;
+ 
+@Controller
+@RequestMapping("/review")
+public class Review
+{
+    private static final Logger log = Logger.getLogger(Review.class);
+
+    @Autowired
+    private UserAgentReviewDAO userAgentReviewDAO;
+
+    @RequestMapping(method=RequestMethod.GET)
+    public String root(ModelMap model)
+    {
+        log.debug("root() called, redirecting to /");
+
+        return "redirect:/review/";
+    }
+
+    @RequestMapping(value="/",method=RequestMethod.GET)
+    public String showReviews(ModelMap model)
+    {
+        log.debug("showReviews() called");
+
+        model.addAttribute("agents",userAgentReviewDAO.getAll());
+
+        return "show";
+    }
+
+    @RequestMapping(value="/add",method=RequestMethod.POST)
+    public String addReviews(@ModelAttribute UserAgentReview userAgentReview,ModelMap model)
+    {
+        log.debug("addReview() called: "+userAgentReview.getUserAgent());
+
+        userAgentReviewDAO.add(userAgentReview);
+
+        return showReviews(model);
+    }
+}

Added: incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/dao/UserAgentReviewDAO.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/dao/UserAgentReviewDAO.java?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/dao/UserAgentReviewDAO.java (added)
+++ incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/dao/UserAgentReviewDAO.java Sun May  5 14:23:40 2013
@@ -0,0 +1,59 @@
+package org.apache.devicemapweb.dao;
+
+import java.util.List;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.springframework.transaction.annotation.Transactional;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.apache.devicemapweb.model.UserAgentReview;
+
+public class UserAgentReviewDAO
+{
+    @PersistenceContext
+    private EntityManager manager;
+
+
+    @Transactional
+    public void add(UserAgentReview uar)
+    {
+        getManager().persist(uar);
+    }
+
+    @Transactional
+    public UserAgentReview get(Long id)
+    {
+        return getManager().find(UserAgentReview.class,id);
+    }
+
+    @Transactional
+    public List<UserAgentReview> getAll()
+    {
+        Criteria criteria = getSession().createCriteria(UserAgentReview.class);
+        return criteria.list();
+    }
+
+    @Transactional
+    public void update(UserAgentReview uar)
+    {
+        getManager().merge(uar);
+    }
+
+    @Transactional
+    public void delete(UserAgentReview uar)
+    {
+        getManager().remove(uar);
+    }
+
+
+    public Session getSession()
+    {
+        return ((Session)getManager().getDelegate());
+    }
+
+    public EntityManager getManager()
+    {
+        return manager;
+    }
+}

Added: incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/model/UserAgentReview.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/model/UserAgentReview.java?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/model/UserAgentReview.java (added)
+++ incubator/devicemap/trunk/web/src/main/java/org/apache/devicemapweb/model/UserAgentReview.java Sun May  5 14:23:40 2013
@@ -0,0 +1,72 @@
+package org.apache.devicemapweb.model;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Entity
+public class UserAgentReview
+{
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+
+    @Basic
+    @Column(length=1024)
+    private String userAgent;
+
+    @Basic
+    private String reason;
+
+    @Basic
+    private String status;
+
+
+    public UserAgentReview()
+    {
+    }
+
+
+    public Long getId()
+    {
+        return id;
+    }
+
+    public void setId(Long id)
+    {
+        this.id=id;
+    }
+
+    public String getUserAgent()
+    {
+        return userAgent;
+    }
+
+    public void setUserAgent(String userAgent)
+    {
+        this.userAgent=userAgent;
+    }
+
+    public String getReason()
+    {
+        return reason;
+    }
+
+    public void setReason(String reason)
+    {
+        this.reason=reason;
+    }
+
+    public String getStatus()
+    {
+        return status;
+    }
+
+    public void setStatus(String status)
+    {
+        this.status=status;
+    }
+}

Added: incubator/devicemap/trunk/web/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/resources/log4j.properties?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/resources/log4j.properties (added)
+++ incubator/devicemap/trunk/web/src/main/resources/log4j.properties Sun May  5 14:23:40 2013
@@ -0,0 +1,6 @@
+log4j.rootLogger=${log.level.all},stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p (%c{1}:%L): %m%n
+
+log4j.category.org.apache.devicemapweb=${log.level.src}

Added: incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/applicationContext.xml?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/applicationContext.xml (added)
+++ incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/applicationContext.xml Sun May  5 14:23:40 2013
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
+    xsi:schemaLocation="http://www.springframework.org/schema/beans
+    http://www.springframework.org/schema/beans/spring-beans.xsd
+    http://www.springframework.org/schema/tx
+    http://www.springframework.org/schema/tx/spring-tx.xsd"
+    default-autowire="byName">
+
+    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
+        <property name="driverClass" value="com.mysql.jdbc.Driver" />
+        <property name="jdbcUrl" value="${db.url}" />
+        <property name="user" value="${db.user}" />
+        <property name="password" value="${db.password}" />
+    </bean>
+    
+    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+        <property name="dataSource" ref="dataSource" />
+        <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
+        <property name="jpaProperties">
+            <props>
+                <prop key="hibernate.hbm2ddl.auto">update</prop>
+            </props>
+        </property>
+        <property name="packagesToScan">
+            <list>
+                <value>org.apache.devicemapweb.model</value>
+            </list>
+        </property>
+    </bean>
+
+    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+        <property name="entityManagerFactory" ref="entityManagerFactory" />
+    </bean>
+    
+    <tx:annotation-driven transaction-manager="transactionManager" />
+
+    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
+
+    <bean id="userAgentReviewDAO" class="org.apache.devicemapweb.dao.UserAgentReviewDAO" />
+
+</beans>

Added: incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml (added)
+++ incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml Sun May  5 14:23:40 2013
@@ -0,0 +1,21 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:context="http://www.springframework.org/schema/context"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="
+        http://www.springframework.org/schema/beans     
+        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+        http://www.springframework.org/schema/context 
+        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ 
+    <context:component-scan base-package="org.apache.devicemapweb.controller" />
+ 
+    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+        <property name="prefix">
+            <value>/views/</value>
+        </property>
+        <property name="suffix">
+            <value>.jsp</value>
+        </property>
+    </bean>
+ 
+</beans>

Added: incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/web.xml?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/web.xml (added)
+++ incubator/devicemap/trunk/web/src/main/webapp/WEB-INF/web.xml Sun May  5 14:23:40 2013
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+    <!-- ${hello.world} -->
+
+    <display-name>deviceMap</display-name>
+    <description>Device Map Web Interface</description>
+
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+
+    <servlet>
+        <servlet-name>mvc-dispatcher</servlet-name>
+        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+ 
+    <servlet-mapping>
+        <servlet-name>mvc-dispatcher</servlet-name>
+        <url-pattern>/</url-pattern>
+    </servlet-mapping>
+    
+    <context-param>
+        <param-name>contextConfigLocation</param-name>
+        <param-value>/WEB-INF/applicationContext.xml</param-value>
+    </context-param>
+
+    <listener>
+        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+    </listener>
+
+</web-app>

Added: incubator/devicemap/trunk/web/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/webapp/index.jsp?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/webapp/index.jsp (added)
+++ incubator/devicemap/trunk/web/src/main/webapp/index.jsp Sun May  5 14:23:40 2013
@@ -0,0 +1,11 @@
+<html>
+<head>
+<title>Device Map Web</title>
+</head>
+<body>
+<h1>Device Map Web</h1>
+Project name: ${project.name}<br>
+Project version: ${project.version}<br>
+Build date: ${build.date}<br>
+</body>
+</html>

Added: incubator/devicemap/trunk/web/src/main/webapp/views/show.jsp
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/web/src/main/webapp/views/show.jsp?rev=1479328&view=auto
==============================================================================
--- incubator/devicemap/trunk/web/src/main/webapp/views/show.jsp (added)
+++ incubator/devicemap/trunk/web/src/main/webapp/views/show.jsp Sun May  5 14:23:40 2013
@@ -0,0 +1,18 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
+<html>
+<body>
+<h1>User-Agents</h1>   
+agents: ${fn:length(agents)}<br>
+<c:forEach items="${agents}" var="agent">
+id: ${agent.id} user-agent: '${agent.userAgent}' reason: ${agent.reason} status: ${agent.status}<br>
+</c:forEach>
+<h1>Add</h1>   
+<form action="add" method="POST">
+<input type="hidden" name="reason" value="new">
+<input type="hidden" name="status" value="unassigned">
+User-Agent: <input type="text" name="userAgent"><br>
+<input type="submit" value="Submit">
+</form>
+</body>
+</html>