You are on page 1of 17

Pom.

xml

<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>
<groupId>hashInclude</groupId>
<artifactId>hashInclude</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>hashInclude</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>4.0.0.RELEASE</org.springframework-version>
<hibernate-version>3.6.0.Final</hibernate-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>

<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate-version}</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>

<!-- Servlet -->


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Apache Database Connection Pool -->
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.3</version>
</dependency>
<!-- MySQL JDBC Driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<dependency>
<groupId>ghost4j</groupId>
<artifactId>ghost4j-1.0.1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>jna</groupId>
<artifactId>jna-4.1.0</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>jai-imageio</groupId>
<artifactId>jai-imageio-core-1.3.1</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-4.12</artifactId>
<version>4.12</version>
</dependency>
<!-- mvn install:install-file -Dfile=ghost4j-1.0.1.jar -DgroupId=ghost4j
-DartifactId=ghost4j-1.0.1 -Dversion=1.0 -Dpackaging=jar mvn
install:install-file
-Dfile=jai-imageio-core-1.3.1.jar -DgroupId=jai-imageio -
DartifactId=jai-imageio-core-1.3.1
-Dversion=1.3.1 -Dpackaging=jar mvn install:install-file -
Dfile=jna-4.1.0.jar
-DgroupId=jna -DartifactId=jna-4.1.0 -Dversion=4.1.0 -
Dpackaging=jar mvn
install:install-file -Dfile=junit-4.12.jar -DgroupId=junit -
DartifactId=junit-4.12
-Dversion=4.12 -Dpackaging=jar -->
</dependencies>
<build>
<finalName>hashInclude</finalName>
</build>
</project>
Login.jsp

<%@ page isELIgnored="false" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>HashInclude Team</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="resources/css/default-page-design.css" />
<script src='resources/js/gen_validatorv5.js' type='text/javascript'></script>
<script type="text/javascript">
function setFocus() {
document.getElementById('userid').focus();
}
</script>
</head>
<body onload="return setFocus();">
<center>
<div class="curveborder" style="width: 650px; height: 300px;">
<font color="maroon" face="'Comic Sans MS'" size="9px">Please
Login !</font><br /> <br />
<hr />
<br />

<style type="text/css">
.error_strings {
font-family: Comic Sans MS;
font-size: 15px;
color: #660000;
}

.sfm_float_error_box {
position: absolute;
z-index: 999;
cursor: default;
font-family: Comic Sans MS;
font-size: 15px;
color: #660000;
background-color: #ffffff;
border-style: solid;
border-width: 0px;
border-color: #ffffff;
}

.sfm_float_box_td {
padding: 3px;
cursor: default;
font-family: Comic Sans MS;
font-size: 15px;
color: #660000;
background-color: #ffffff;
}

.sfm_close_box {
font-family: Comic Sans MS;
font-size: 15px;
color: #660000;
background-color: #ffffff;
border-width: 0px;
text-align: center;
}
</style>
<div id='login_errorloc' class='error_strings' style=''></div>
<form name="login" action="login.do" method="post">
<table>
<tr>
<td colspan="2"><font size="4px" color="red"
face="verdana">${login_failed_info}</font></td>
</tr>
<tr>
<td><font color="maroon" face="Algerian"
size="5px">User
Id:</font></td>
<td><input type="text" name="userid"
id="userid"
class="inputNormal" /></td>
</tr>
<tr>
<td><font color="maroon" face="Algerian"
size="5px">Password:</font></td>
<td><input type="password" name="password"
class="inputNormal" /></td>
</tr>
<tr>
<td colspan="2"><br /></td>
</tr>
<tr>
<td colspan="2"><input type="image"
value="Login"
src="resources/images/images_055.jpg"
class="buttonstyle" /><br/></td>
</tr>
</table>
</form>
<script type='text/javascript'>
// <![CDATA[
var loginValidator = new Validator("login");

loginValidator.EnableOnPageErrorDisplaySingleBox();
loginValidator.EnableMsgsTogether();

loginValidator.validate_on_killfocus = true;
loginValidator.addValidation("userid","req","Userid is Required");
loginValidator.addValidation("password","req","Password is Required");
// ]]>
</script>
</div>
</center>
</body>
</html>
videoList.jsp

<%@ page isELIgnored="false"%>


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<title>HashInclude Team</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="resources/css/jqueryui/jquery-ui.css" />

<script src='resources/js/jquery/jquery.js' type='text/javascript'></script>

<script src='resources/js/jquery/jquery-ui.js' type='text/javascript'></script>

<style type="text/css">
.videoTable td, th {
border: 1px blue solid;
}
.videoTable th {
background-color: blue;
color: white;
}
</style>
<script>
$( function() {
$( "#videoTabs" ).tabs({
collapsible: true
});
} );
</script>
</head>
<body>

<div id="videoTabs">
<ul>
<li><a href="#videoTabs-1">Video Upload</a></li>
<li><a href="#videoTabs-2">Search</a></li>
</ul>
<div id="videoTabs-1">
<div style="background-color: #F3FAB6;width: 700px;">
<form method="POST" action="uploadVideoFile"
enctype="multipart/form-data">
File to upload: <input type="file" name="videoFile">
<input type="submit" value="Upload">
</form>

</div><br><br>
<div style="color:red;">${message}</div>

<table class="videoTable"
style="border: 1px blue solid; border-collapse: collapse;
width: 500px">
<thead>
<tr>
<th>Id</th>
<th>Video File Name</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<c:forEach items="${requestScope.allVideoList}"
var="video">
<tr>
<td>${video.vid}</td>
<td>${video.videoname}</td>
<td>${video.type}</td>
</tr>
</c:forEach>
</tbody>

</table>

</div>
<div id="videoTabs-2">
<p>Search</p>
<form action="searchOcr" method="get">
Input String:<input type="text" name="inputString"/> <input
type="submit" value="Search">
</form>

<div style="color:red;">${fileNames}</div>
</div>
</div>
</body>
</html>

package com.fis.constant;

public class Constants {


public static final String LOGIN_FAILED = "UserId or Password is Invalid";

public static final String ROOT_VIDEO_PATH = "c:\\";


public static final String VIDEO_DIR = "videoFileRepo";

public static final String USER_ID_FILE = "userid.txt";


public static final String VIDEOLIST_FILE = "videolist.txt";

public static final String DATE_FORMAT = "dd-MM-yyyy";


public static final String FrameImages = "frame_images";

}
package com.fis.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fis.constant.Constants;
import com.fis.dao.LoginDao;
import com.fis.dao.VideoListDao;
import com.fis.domain.UserId;

@Controller
public class LoginController {

@Autowired
LoginDao loginDao;

@Autowired
VideoListDao videoListDao;

@RequestMapping(value = "/login", method = RequestMethod.POST)


public String validateLogin(@RequestParam("userid") String userid,
@RequestParam("password") String password, HttpServletRequest request) {
UserId user = loginDao.findUser(userid, password);
if (user == null) {
request.setAttribute("login_failed_info",Constants.LOGIN_FAILED);
return "login";
} else {
request.setAttribute("allVideoList", videoListDao.getAllVideoList());
return "videoList";
}
}
}
package com.fis.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sourceforge.tess4j.Tesseract;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fis.constant.Constants;
import com.fis.dao.VideoListDao;

@Controller
public class SearchController {

@Autowired
VideoListDao videoListDao;

@RequestMapping(value = "/searchOcr", method = RequestMethod.GET)


public String searchInImage(@RequestParam("inputString") String inputString,
HttpServletRequest request) {
File dir = new File(Constants.ROOT_VIDEO_PATH + File.separator
+ Constants.VIDEO_DIR + File.separator + Constants.FrameImages);
File dataPathDir = new File(Constants.ROOT_VIDEO_PATH + File.separator
+ Constants.VIDEO_DIR);
Tesseract instance = Tesseract.getInstance(); //
String fileNames[] = dir.list();
Map<String, String> keyWordFound = new HashMap<>();
for (String fileName : fileNames) {
try {
File imageFile = new File(dir.getAbsolutePath()
+ File.separator + fileName);
instance.setDatapath(dataPathDir.getAbsolutePath() + File.separator
+ "tessdata");
instance.setLanguage("eng");
String result = instance.doOCR(imageFile);

if (result.indexOf(inputString) > -1) {


keyWordFound.put(fileName, inputString);
}

} catch (Exception e) {
System.err.println(e.getMessage());
}
}
request.setAttribute("fileNames",keyWordFound.keySet().toString());
return "videoList";
}
}
package com.fis.controller;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.fis.constant.Constants;
import com.fis.dao.VideoListDao;

@Controller
public class VideoPanelController {

@Autowired
VideoListDao videoListDao;

@RequestMapping(value = "/uploadVideoFile", method = RequestMethod.POST)


public String uploadFileHandler(
@RequestParam("videoFile") MultipartFile file, HttpServletRequest request) {
String fileName = file.getOriginalFilename();
String fileType = file.getContentType();
String message ="";
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();

// Creating the directory to store file


File dir = new File(Constants.ROOT_VIDEO_PATH + File.separator
+ Constants.VIDEO_DIR);
if (!dir.exists())
dir.mkdirs();

// Create the file on server


File serverFile = new File(dir.getAbsolutePath() + File.separator +
fileName);
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();

//Store file details to DB


videoListDao.addVedioData(fileName, fileType);

message = "You successfully uploaded file=" + fileName;


} catch (Exception e) {
message = "You failed to upload " + fileName + " => "
+ e.getMessage();
}
} else {
message = "You failed to upload " + fileName
+ " because the file was empty.";
}
request.setAttribute("allVideoList", videoListDao.getAllVideoList());
request.setAttribute("uploadMessage", message);
return "videoList";
}
}
package com.fis.dao;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.fis.constant.Constants;
import com.fis.domain.UserId;

@Component
public class LoginDao {
/*@Autowired
HibernateTemplate template;
*/
public UserId findUser(String userid, String password) {
/*List<Object> users = template.find("from UserId where userid=? and password=?" ,
new Object[]{userid,password});
if(users.size()!=0){
return (UserId)users.get(0);
} else {
return null;
}*/
List<UserId> userList = loadUsers();
UserId userExist = null;
for(UserId u : userList) {
if(u.getUserid().equals(userid) && u.getPassword().equals(password)){
userExist = u;
break;
}
}
return userExist;
}
private List<UserId> loadUsers(){
File userDir = new File(Constants.ROOT_VIDEO_PATH + File.separator
+ Constants.VIDEO_DIR);
File userIdFile = new File(userDir.getAbsolutePath() + File.separator +
Constants.USER_ID_FILE);
List<UserId> userList = new ArrayList<UserId>();
try{
if(userIdFile.exists()) {
BufferedReader br = new BufferedReader(new InputStreamReader(new
FileInputStream(userIdFile)));
String string = null;
while((string=br.readLine()) != null) {
String userDatas[] = string.split(",");
UserId u1 = new UserId();
u1.setUid(Integer.parseInt(userDatas[0]));
u1.setUserid(userDatas[1]);
u1.setPassword(userDatas[2]);
userList.add(u1);
}
br.close();
}
}catch(Exception e){
e.printStackTrace();
}
return userList;
}
}
package com.fis.dao;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.fis.constant.Constants;
import com.fis.domain.VideoList;

@Component
public class VideoListDao {

/*@Autowired
HibernateTemplate template;*/

public List<VideoList> getAllVideoList() {


return loadVideoList();
}

public void addVedioData(String name, String type) {


File videoDir = new File(Constants.ROOT_VIDEO_PATH + File.separator
+ Constants.VIDEO_DIR);
File videoFile = new File(videoDir.getAbsolutePath() + File.separator
+ Constants.VIDEOLIST_FILE);
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(videoFile,
true));
bw.write("0," + name + "," + type + "," + dateToString(new Date())
+ "," + "f" + "\n");
bw.flush();
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}

private List<VideoList> loadVideoList() {


File videoDir = new File(Constants.ROOT_VIDEO_PATH + File.separator
+ Constants.VIDEO_DIR);
File videoFile = new File(videoDir.getAbsolutePath() + File.separator
+ Constants.VIDEOLIST_FILE);
List<VideoList> videoList = new ArrayList<VideoList>();
try {
if (videoFile.exists()) {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(videoFile)));
String string = null;
while ((string = br.readLine()) != null) {
String videoDatas[] = string.split(",");
VideoList v = new VideoList();
v.setVid(Integer.parseInt(videoDatas[0]));
v.setVideoname(videoDatas[1]);
v.setType(videoDatas[2]);
v.setCreatedate(stringTodate(videoDatas[3]));
v.setFramingflag(videoDatas[4]);
videoList.add(v);
}
br.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return videoList;
}

private Date stringTodate(String string) {


Date date = null;
if (string != null && !string.trim().equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATE_FORMAT);
try {
date = sdf.parse(string);
} catch (Exception e) {
e.printStackTrace();
}
}
return date;
}

private String dateToString(Date date) {


SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATE_FORMAT);
String returnDate = null;
try {
returnDate = sdf.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return returnDate;
}
}
package com.fis.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="userid")
public class UserId {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int uid;

@Column
private String userid;

@Column
private String password;
@Column
private Date createddt;

public int getUid() {


return uid;
}

public void setUid(int uid) {


this.uid = uid;
}

public String getUserid() {


return userid;
}

public void setUserid(String userid) {


this.userid = userid;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


this.password = password;
}
public Date getCreateddt() {
return createddt;
}

public void setCreateddt(Date createddt) {


this.createddt = createddt;
}
}
package com.fis.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class VideoList {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int vid;
@Column
private String videoname;
@Column
private String type;
@Column
private Date createdate;
@Column
private String framingflag;
public int getVid() {
return vid;
}
public void setVid(int vid) {
this.vid = vid;
}
public String getVideoname() {
return videoname;
}
public void setVideoname(String videoname) {
this.videoname = videoname;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Date getCreatedate() {
return createdate;
}
public void setCreatedate(Date createdate) {
this.createdate = createdate;
}
public String getFramingflag() {
return framingflag;
}
public void setFramingflag(String framingflag) {
this.framingflag = framingflag;
}
}
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<context:component-scan base-package="com.fis" />


<mvc:resources mapping="/resources/**" location="/resources/"
cache-period="31556926" />
<mvc:annotation-driven />

<!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">


<property name="driverClassName"
value="com.mysql.jdbc.Driver"></property>
<property name="url"
value="jdbc:mysql://localhost:3303/hashinclude"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>

<bean id="mysessionFactory"

class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryB
ean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop
key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.fis.domain.UserId</value>
<value>com.fis.domain.VideoList</value>
</list>
</property>
</bean>
<bean id="template"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mysessionFactory"></property>
</bean> -->

<bean id="multipartResolver"

class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<!-- setting maximum upload size -->


<property name="maxUploadSize" value="100000000" />

</bean>
<bean id="viewResolver”
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
<!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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-
class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/login.jsp</welcome-file>
</welcome-file-list>

</web-app>

You might also like