/
ViewLog.java
144 lines (141 loc) · 4.9 KB
/
ViewLog.java
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
133
134
135
136
137
138
139
140
141
142
143
144
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ViewLog extends HttpServlet
{
private ConnectionPool pool;
private static String servletName="ViewLog";
private ServletContext context;
public void init()
{
context = getServletContext();
synchronized(context)
{
pool=(ConnectionPool)context.getAttribute("pool");
if(pool==null)
{
String driverClassName = context.getInitParameter("driverClassName");
String url = context.getInitParameter("url");
String userName = context.getInitParameter("username");
String password = context.getInitParameter("password");
try
{
pool=new ConnectionPool(driverClassName,url,userName,password);
}
catch(Exception error)
{
Routines.writeToLog(servletName,"Unable to create connection pool : " + error,false,context);
}
context.setAttribute("pool",pool);
}
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
{
response.setContentType("text/html");
PrintWriter webPageOutput=null;
try
{
webPageOutput=response.getWriter();
}
catch(IOException error)
{
Routines.writeToLog(servletName,"getWriter error : " + error,false,context);
}
HttpSession session=request.getSession();
session.setAttribute("redirect",request.getRequestURL() + "?" + request.getQueryString());
Connection database=null;
try
{
database=pool.getConnection(servletName);
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to connect to database : " + error,false,context);
}
if(Routines.loginCheck(true,request,response,database,context))
{
return;
}
String server=context.getInitParameter("server");
boolean liveSever=false;
if(server==null)
{
server="";
}
if(server.equals("live"))
{
response.setHeader("Refresh","60");
}
Routines.WriteHTMLHead("View System Log",//title
false,//showMenu
13,//menuHighLight
false,//seasonsMenu
false,//weeksMenu
false,//scores
false,//standings
false,//gameCenter
false,//schedules
false,//previews
false,//teamCenter
false,//draft
database,//database
request,//request
response,//response
webPageOutput,//webPageOutput
context);//context
webPageOutput.println("<CENTER>");
webPageOutput.println("<IMG SRC=\"../Images/Admin.gif\"" +
" WIDTH='125' HEIGHT='115' ALT='Admin'>");
webPageOutput.println("</CENTER>");
pool.returnConnection(database);
webPageOutput.println(Routines.spaceLines(1));
Routines.tableStart(false,webPageOutput);
Routines.tableHeader("System Log",0,webPageOutput);
Routines.tableDataStart(true,false,false,true,true,0,0,"scoresrow",webPageOutput);
boolean firstLine=true;
int numOfLines=0;
try
{
String file=context.getRealPath("/");
FileReader logFile=new FileReader(file + "/Data/log.txt");
BufferedReader logFileBuffer=new BufferedReader(logFile);
boolean endOfFile=false;
while(!endOfFile)
{
String logFileText=logFileBuffer.readLine();
if(logFileText==null)
{
endOfFile=true;
}
else
{
if(firstLine)
{
firstLine=false;
}
else
{
webPageOutput.println(Routines.spaceLines(1));
}
numOfLines++;
webPageOutput.println(logFileText);
}
}
logFileBuffer.close();
}
catch(IOException error)
{
Routines.writeToLog(servletName,"Problem with log file : " + error,false,context);
}
Routines.tableDataEnd(false,true,true,webPageOutput);
Routines.tableEnd(webPageOutput);
if(numOfLines<20)
{
webPageOutput.println(Routines.spaceLines(20-numOfLines));
}
Routines.WriteHTMLTail(request,response,webPageOutput);
}
}