1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>FareFinder Validation</title>
</head>
<body bgcolor="CCCCCC">
	<%@ page import="java.util.*" import="java.io.*"%>
	<%
		String origin = request.getParameter("_origin");
		String depmonthyear = request.getParameter("_depmonthyear");
		String depday = request.getParameter("_depday");
		String dephourmin = request.getParameter("_dephourmin");
		String destination = request.getParameter("_destination");
		String retmonthyear = request.getParameter("_retmonthyear");
		String retday = request.getParameter("_retday");
		String rethourmin = request.getParameter("_rethourmin");
		String adults = request.getParameter("_adults");
		String children = request.getParameter("_children");
		String infants = request.getParameter("_infants");
		String searchBy = request.getParameter("_searchBy");
		
		BufferedReader in = new BufferedReader(new FileReader(
				request.getSession().getServletContext().getRealPath("/")
				+"/destinations.csv"));
		
		Hashtable<String,String> destinations = new Hashtable<String,String>();
		String error = "";
		String line = "";
		String[] data;
		
		// Load the destinations
		while((line = in.readLine())!= null)
		{
			try
			{
				data = line.split("\t");
				if( destinations.contains(data[1]))
				{
					out.println(data[1] + " is a duplicate!<br>");
				}
				destinations.put(data[1], data[0]);
			}catch(Exception e)
			{
				out.println(e.toString() + "<br>" 
						+ " Trying to split line " + line + "<br>");
			}
		}
		out.println("Destinations Size = " + destinations.size() + "<br>");
		
		// Validate the destinations
		if( origin == null || (origin.length()<3) )
		{
			error += "The origin is invalid.<BR>";
		}
		
		if( destination == null || (destination.length() < 3) )
		{
			error += "The destination is invalid.<BR>";
		}
		
		if( !destinations.contains(origin) )
		{
			int numFound = 0;
			for(String key: destinations.values())
			{
				if( destinations.get(key).contains(origin) ||
						destinations.get(key)== origin)
				{
					if( numFound < 1)
					{
						origin = key;
					}
					numFound++;
				}
			}
			
			if( numFound > 1 )
			{
				error += "Too many station listings match your departure entry. Please be more specific.<BR>";
			}
			else if( numFound < 1 )
			{
				error += "There were no station listings that match your departure entry.<BR>";
			}
		}
		
		if( !destinations.contains(destination) )
		{
			int numFound = 0;
			
			for(String key: destinations.values())
			{
				if( destinations.get(key).contains(destination) ||
						destinations.get(key)== destination)
				{
					if( numFound < 1)
					{
						destination = key;
					}
					numFound++;
				}
			}
			
			if( numFound > 1 )
			{
				error += "Too many station listings match your destination entry. Please be more specific.<BR>";
			}
			else if( numFound < 1 )
			{
				error += "There were no station listings that match your destination entry.<BR>";
			}
		}
		
		if( /*no errors*/){/*redirect*/}

		out.println("Origin: " + origin + "<br>");
		out.println("Departure Date: " + depmonthyear + "<br>");
		out.println("Departure Day: " + depday + "<br>");
		out.println("Departure Hour: " + dephourmin + "<br>");
		out.println("Destination: " + destination + "<br>");
		out.println("Return Date: " + retmonthyear + "<br>");
		out.println("Return Day: " + retday + "<br>");
		out.println("Return Hour: " + rethourmin + "<br>");
		out.println("Adults: " + adults + "<br>");
		out.println("Children: " + children + "<br>");
		out.println("Infants: " + infants + "<br>");
		out.println("Searcy by: " + searchBy + "<br>");	
	%>
</body>
</html>