package isip.java.bullyse.bullydb; import java.io.*; import java.util.*; import java.text.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class nonMember extends HttpServlet { // Initialize BullyDB Object static BullyDB sessionbase = new BullyDB(); // System parameters are stored in the database, retrieve the values // through the BullyDB object. static String SystemURL = sessionbase.getURL(); static String ServletURL = sessionbase.getServletURL(); static String SystemEmail = sessionbase.getEmail(); static String SystemPath = sessionbase.getPath(); static String SystemName = sessionbase.getName(); static String SystemShortName = sessionbase.getShortName(); public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Initialize variables String task = request.getParameter("task"); String query = (String)null; ResultSet result = null; String SessionId = "nonMember"; sessionbase.putUser(); // Initialize the output stream. response.setContentType("text/html"); PrintWriter out = response.getWriter(); if(task == null) { printTop(out, 1); out.println(""); out.println(""); out.println(""); printBot(out); out.close(); } else if (task.equals("logout")) { String AccountId = (String)null; HttpSession session = request.getSession(); SessionId = session.getId(); // Retrieve AccountId, make sure the user is logged in before we try to log // him out. AccountId = sessionbase.getAccountId(SessionId); if (AccountId == null) { // User login must have timed in already, so // nothing needs to be done. Simply redirect // to Login page. response.sendRedirect(SystemURL + "/index.html"); } else { // Close the HttpSession sessionbase.doLogout(SessionId); session.invalidate(); // User is logged out, simply send them back to the // Login page response.sendRedirect(SystemURL + "/index.html"); } } else if (task.equals("passChange")) { printTop(out, 2); out.println("
"); out.println("\"Home\"
"); out.println("
Welcome to the Bulldog Stock Exchange!
"); sessionbase.displayGraph(out, "1", "SYS", 0); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } else if (task.equals("news")) { displayNews(request, response, "nonMember"); } else if (task.equals("showHeadlines")) { displayHeadlines(request, response, "nonMember"); } else if (task.equals("showArchives")) { displayArchives(request, response, "nonMember"); } else if (task.equals("showArticle")) { displayArticle(request, response, "nonMember"); } else if (task.equals("LI")) { String Type = request.getParameter("Type"); if (Type.equals("1")) { printTop(out, 2); out.println("
"); out.println("\"Home\"
"); out.println("Success:

"); out.println("A new password has been emailed to your account."); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } else if (Type.equals("2")) { printTop(out, 3); out.println("
"); out.println("\"Home\"
"); out.println("Not Logged In

"); out.println("You must be logged in to the system to use this page. You don't appear to be logged in to the system, or you have cookies turned off. To use the " + SystemName + ", Cookies must be enabled in your browser properties."); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } else if (Type.equals("3")) { printTop(out, 4); out.println("
"); out.println("\"Home\"
"); out.println("Not Logged In

"); out.println("You must be logged in to the system to use this page. You don't appear to be logged in to the system, or you have cookies turned off. To use the " + SystemName + ", Cookies must be enabled in your browser properties."); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } } else if (task.equals("Quotes")) { displayAll(request, response); } else if (task.equals("viewQuote")) { String Symbol = request.getParameter("Symbol"); displayQuote(Symbol, request, response); } else if (task.equals("password")) { printTop(out, 3); out.println("
"); out.println("\"Home\"
"); out.println("Not Logged In

"); out.println("You must be logged in to the system to use this page. You don't appear to be logged in to the system, or you have cookies turned off. To use the " + SystemName + ", Cookies must be enabled in your browser properties."); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } else if (task.equals("notloggedin")) { printTop(out, 1); out.println("
"); out.println("\"BSE
"); out.println("If you have forgotten your Username or Password(or both) just enter your Email address here. Your Username and a new Password will then be Emailed to you. You must enter the Email address that is registered to your account.

"); out.println("Note: This is not to create a new account, this is only if you have forgotten the Username or Password of an existing account.
"); out.println("
"); out.println(""); out.println("Email: "); out.println("
"); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } else if (task.equals("createAccount")) { printTop(out, 3); out.println("
"); out.println("\"BSE
"); out.println("Not Logged In:
"); out.println("You must be logged in to the system to use this page. You don't appear to be logged in to the system, or you have cookies turned off. To use the Bulldog Stock Exchange, Cookies must be enabled in your browser properties."); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Extract variable that tells what task we are to perform String task = request.getParameter("task"); String query = (String)null; ResultSet result = null; sessionbase.putUser(); // Initialize the output stream. response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Initialize variables boolean Login = false; String username = request.getParameter("username"); String password = request.getParameter("password"); String Message = ""; int error = 0; if (task.equals("login")) { // Make sure they actually put in a login/password. No need to query the // database if one of these is missing. if (username.length()<1 || password.length()<1) { // Open error file Message += "The username or password you entered is invalid.
"; error++; } else { HttpSession session = request.getSession(true); // Check to see if the user is logged in already. If so, close // the old session. if (!session.isNew()) { session.invalidate(); session = request.getSession(true); } String SessionId = session.getId(); // Check for a user lock query = "select Locked from Account where Username = '" + username + "'"; result = sessionbase.doQuery(query); String LockStatus = (String)null; try { while (result.next()) { LockStatus = result.getString("Locked"); } } catch (Exception e) { e.printStackTrace(); } if (LockStatus.equals("Y")) { // User is locked Message += "Your account has been locked by a " + SystemName + " administrator.
"; error++; } // Check for a System lock. if (sessionbase.checkLock() && !sessionbase.checkRoot(username)) { Message += "Logins are not permitted at this time.
"; error++; } if (error == 0) { // Attempt to log in the user. Login = sessionbase.doLogon(username, password, SessionId); if (Login != true) { // Don't want to leave a session open if the user didn't // successfully log in session.invalidate(); Message += "The username or password you entered is invalid.
"; error++; } } if (error > 0) { printTop(out, 1); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"BSE
"); out.println("Account Creation
"); out.println("Automatic Account creation is not permitted. Email " + SystemEmail + " to get an account."); out.println("
"); out.println(""); out.println(""); printBot(out); out.close(); } else { // Create a new session for the user and set the maximum they // can be inactive session.setAttribute("Exchange.user." + sessionbase.getAccountId(SessionId), sessionbase); session.setMaxInactiveInterval(3600); // Update LastLogin on the Account table query = "update Account set LastLogin = NOW() where AccountId = " + sessionbase.getAccountId(SessionId); sessionbase.doUpdate(query, SessionId); // Check to see what user is logging in. If this is the // Administrative user, send them to a different page if (sessionbase.checkRoot(username)) { // Must be admin, redirect to Admin page response.sendRedirect(ServletURL + ".Admin"); } else { response.sendRedirect(ServletURL + ".Portfolio?task=Members"); } } } } } public void printTop(PrintWriter out, int On) throws IOException { // This method prints out the Link bar and Admin tools portion. // The On variable is to show which link is the active one. // // 1 - Home // 2 - Portfolio // 3 - Account // 4 - Buy & Sell // 5 - Quotes // 6 - News out.println(""); out.println("" + SystemName + ""); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"Home\"

"); out.println("Login Error:"); out.println(Message); out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(" "); out.println(""); out.println(" "); out.println("
"); out.println("
"); out.println(""); out.println("Help"); out.println("
"); out.println(""); out.println(""); out.println("
 
"); if (On == 1) { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } else if (On == 2) { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } else if (On == 3) { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } else if (On == 4) { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } else if (On == 5) { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } else if (On == 6) { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } else { out.println("\"Home\"\"My\"My\"Buy\"Quotes\"News"); } out.println("
"); out.println(" "); out.println(""); } public void printBot(PrintWriter out) throws IOException { String SessionId = "nonMember"; Locale locale = new Locale("en","US"); DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); String weekTitle = (String)null; String weekId = (String)null; java.util.Date weekDate = new java.util.Date(); java.util.Date weekDateO = new java.util.Date(); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println(""); out.println(" "); out.println(" "); out.println(""); out.println("
"); out.println("Login
"); out.println("
to your account"); out.println("
"); out.println("
"); out.println(""); out.println("
"); out.println(""); out.println(""); out.println("
"); out.println(" 
"); out.println(" "); out.println(""); out.println("
"); out.println("° Forgot password?
"); out.println("

"); out.println("MoreCreate account


"); // Output the Quote Flash data try { QuoteFlash(out); } catch (Exception e) { e.printStackTrace(); } // Fill in the blanks from the template out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
  "); out.println(""); out.println(""); out.println(""); out.println("
"); out.println(""); out.println(""); out.println(" "); out.println(""); out.println("
"); out.println(" Market News
"); // We only want to get Headlines within 2 weeks of the current // date, set up the Date qualifier. String query = "select Title, Id, Date from News order by Date desc"; ResultSet result = sessionbase.doQuery(query, SessionId); out.println(""); int reps = 0; try { while (result.next() && reps < 6) { weekDateO = weekDate; reps++; weekTitle = result.getString("Title"); weekId = result.getString("Id"); weekDate = result.getDate("Date"); if (!weekDate.equals(weekDateO)) { // Just a formatting thing, don't want to push down the links // if it is printing the top one. if (reps > 1) { out.println("
"); } out.println(""); out.println(""); } else { out.println(""); } } } catch (Exception e) { e.printStackTrace(); } out.println(""); out.println("
" + shortFormat.format(weekDate) + "
°" + weekTitle + "
°" + weekTitle + "

MoreAll Headlines
"); out.println("
"); out.println(""); out.println(""); out.println("
"); out.println("
"); out.println(""); out.println(" "); out.println(" "); out.println(""); out.println(""); out.println(""); out.println(""); out.println(" "); out.println("
"); out.println(" "); out.println("

"); out.println("Help |"); out.println("Home | "); out.println("Quotes & Research |"); out.println(" News Headlines"); out.println("

Page-Top
"); out.println(""); out.println(""); } public void displayAll(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String query = (String)null; String Name = (String)null; int Tshares = 0; double Ipo = 0.00; double Open = 0.00; double Last = 0.00; int Volume = 0; double Change = 0.00; double WkHi = 0.00; double WkLo = 0.00; double DayHi = 0.00; double DayLo = 0.00; double Previous = 0.00; String fLast = (String)null; String fChange = (String)null; String fLow = (String)null; String fHigh = (String)null; String Symbol = (String)null; ResultSet result = null; double Capitalization = 0.00; boolean member = true; Vector dumpPlace = new Vector(); int i = 0; String SessionId = "nonMember"; // Set up decimal formatting for digits. This will force at least 0.00. DecimalFormat curFormat = new DecimalFormat("$##,###,###,###,###,##0.00"); DecimalFormat numFormat = new DecimalFormat("################0.00"); DecimalFormat intFormat = new DecimalFormat("################0"); // Initialize output stream response.setContentType("text/html"); PrintWriter out=response.getWriter(); // Extract Company info from the database. A null ResultSet means the company // must not be in the database. query = "select * from Companies order by Symbol"; result = sessionbase.doQuery(query); try { while (result.next()) { Symbol = result.getString("Symbol"); Last = result.getDouble("Last"); DayHi = result.getDouble("DayHi"); DayLo = result.getDouble("DayLo"); Volume = result.getInt("Volume"); dumpPlace.addElement(new Companies(Symbol, DayHi, DayLo, Last, Volume)); } } catch (Exception e) { e.printStackTrace(); } printTop(out, 5); out.println("
"); out.println(""); out.println(""); out.println("
"); out.println("\"BSE
"); out.println(""); out.println(""); out.println("
"); out.println(""); out.println(""); out.println(""); Companies Company = new Companies(); int vSize = dumpPlace.size(); for (i = 0 ; i < vSize ; i++) { Company = (Companies)dumpPlace.elementAt(i); Symbol = Company.getSymbol(); DayHi = Company.getHigh(); DayLo = Company.getLow(); Last = Company.getCurrent(); Volume = Company.getVolume(); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); } out.println("
SymbolHighLowCurrentVolume
" + Symbol + "" + numFormat.format(DayHi) + "" + numFormat.format(DayLo) + "" + numFormat.format(Last) + "" + Volume + "
"); out.println("
"); out.println("
"); printBot(out); out.close(); } public void displayQuote(String Symbol, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String query = (String)null; String Name = (String)null; int Tshares = 0; double Ipo = 0.00; double Open = 0.00; double Last = 0.00; int Volume = 0; double Change = 0.00; double WkHi = 0.00; double WkLo = 0.00; double DayHi = 0.00; double DayLo = 0.00; double Previous = 0.00; String fLast = (String)null; String fChange = (String)null; String fLow = (String)null; String fHigh = (String)null; ResultSet result = null; double Capitalization = 0.00; boolean member = true; String Locked = (String)null; String SessionId = "nonMember"; // Set up decimal formatting for digits. This will force at least 0.00. DecimalFormat curFormat = new DecimalFormat("$##,###,###,###,###,##0.00"); DecimalFormat numFormat = new DecimalFormat("################0.00"); DecimalFormat intFormat = new DecimalFormat("################0"); // Initialize output stream response.setContentType("text/html"); PrintWriter out=response.getWriter(); // Extract Company info from the database. A null ResultSet means the company // must not be in the database. query = "select * from Companies where Symbol = '" + Symbol + "'"; result = sessionbase.doQuery(query); try { while(result.next()) { Name = result.getString("Name"); Tshares = result.getInt("Tshares"); Open = result.getDouble("Open"); Last = result.getDouble("Last"); Volume = result.getInt("Volume"); WkHi = result.getDouble("52WkHi"); WkLo = result.getDouble("52WkLo"); DayHi = result.getDouble("DayHi"); DayLo = result.getDouble("DayLo"); Previous = result.getDouble("Previous"); Locked = result.getString("Locked"); } } catch(Exception e) { e.printStackTrace(); } Change = Last - Previous; Capitalization = Tshares * Last; if (Name == null) { response.sendRedirect(sessionbase.getURL() + "/html/errors/invalid_symbol.html"); out.close(); } else { printTop(out, 5); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"BSE
"); out.println(""); out.println(""); out.println("
"); out.println(""); out.println(""); out.println(""); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(""); if (Locked.equals("Y")) { out.println(" "); } out.println("
Today with " + Name + " (" + Symbol + ")
Today's Open:" + numFormat.format(Open) + " Yesterday's Close:" + numFormat.format(Previous) + "
Current Price:" + numFormat.format(Last) + "Change:" + numFormat.format(Change) + "
Today's Low:" + numFormat.format(DayLo) + "Today's High:" + numFormat.format(DayHi) + "
52wk High:" + numFormat.format(WkHi) + "52wk Low:" + numFormat.format(WkLo) + "
Volume:" + Volume + "
Market Capitalization" + curFormat.format(Capitalization) + "
"); out.println("This company is currently in Locked status. "); out.println("Buying and Selling cannot take place for this company until "); out.println("it is unlocked.
"); // Rude and crude to push the graph down - but it works. out.println("











"); // Display the Company graph sessionbase.displayGraph(out, "1", Symbol, 0); out.println("
"); printBot(out); out.close(); } } public void displayNews(HttpServletRequest request, HttpServletResponse response, String SessionId) throws IOException, ServletException { String query = (String)null; ResultSet result = null; // Initialize the output stream response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Let's get the news printTop(out, 6); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"BSE
"); // Get the Front Article String frontTitle = (String)null; String frontAuthor = (String)null; int frontId = 0; java.util.Date frontDate = new java.util.Date(); java.util.Date frontTime = new java.util.Date(); Locale locale = new Locale("en","US"); // Set the format for time and date DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, locale); DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale); String frontStory = (String)null; query = "select Title, Author, Date, Story, Id from News where Type = 3"; result = sessionbase.doQuery(query, SessionId); try { while (result.next()) { frontTitle = result.getString("Title"); frontAuthor = result.getString("Author"); frontDate = result.getDate("Date"); frontTime = result.getTime("Date"); frontStory = result.getString("Story"); frontId = result.getInt("Id"); } } catch (Exception e) { e.printStackTrace(); } // Get Author's Full Name query = "select Fname, Lname from Account where Username = '" + frontAuthor + "'"; result = sessionbase.doQuery(query, SessionId); String frontFullAuthor = ""; try { while (result.next()) { frontFullAuthor += result.getString("Fname"); frontFullAuthor += " "; frontFullAuthor += result.getString("Lname"); } } catch (Exception e) { e.printStackTrace(); } out.println(""); out.println("Article Submitted: " + dateFormat.format(frontDate) + " at " + timeFormat.format(frontTime) + "
"); out.println("" + frontTitle + "
"); out.println(frontStory + "
"); out.println("

"); out.println("Article submitted by: " + frontFullAuthor + "

"); // Get Breaking News Links query = "select Title, Date, Id from News where Type = 2"; result = sessionbase.doQuery(query, SessionId); String breakingTitle = (String)null; java.util.Date breakingDate = new java.util.Date(); java.util.Date breakingTime = new java.util.Date(); String breakingId = (String)null; // Make sure there are any Breaking News articles int bId = 0; query = "select Id from News where Type = 2"; result = sessionbase.doQuery(query, SessionId); try { while (result.next()) { bId = result.getInt("Id"); } } catch (Exception e) { e.printStackTrace(); } if (bId > 0) { out.println("
"); out.println("Breaking News
"); try { while (result.next()) { breakingTitle = result.getString("Title"); breakingDate = result.getDate("Date"); breakingId = result.getString("Id"); out.println("" + dateFormat.format(breakingDate) + " " + breakingTitle + "
"); } } catch (Exception e) { e.printStackTrace(); } } out.println("
MoreView all headlines...

"); out.println("
"); printBot(out); out.close(); } public void displayHeadlines(HttpServletRequest request, HttpServletResponse response, String SessionId) throws IOException, ServletException { String query = (String)null; ResultSet result = null; // Initialize the output stream response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Let's get the news printTop(out, 6); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"Admin\"

"); java.util.Date frontDate = new java.util.Date(); java.util.Date frontTime = new java.util.Date(); Locale locale = new Locale("en","US"); // Set the format for time and date DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, locale); DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale); java.util.Date curDate = new java.util.Date(); int Day = curDate.getDate(); int Month = (curDate.getMonth()) + 1; int Year = (curDate.getYear()) + 1900; Day = Day - 14; if (Day < 1) { Month = Month - 1; if (Month == 1) { Day = 31 + Day; } else if (Month == 2) { Day = 28 + Day; } else if (Month == 3) { Day = 31 + Day; } else if (Month == 4) { Day = 30 + Day; } else if (Month == 5) { Day = 31 + Day; } else if (Month == 6) { Day = 30 + Day; } else if (Month == 7) { Day = 31 + Day; } else if (Month == 8) { Day = 31 + Day; } else if (Month == 9) { Day = 30 + Day; } else if (Month == 10) { Day = 31 + Day; } else if (Month == 11) { Day = 30 + Day; } else if (Month == 12) { Day = 31 + Day; } if (Month < 1) { Month = 12; Year = Year - 1; } } // Get all Headlines String headTitle = (String)null; String headId = (String)null; java.util.Date headDate = new java.util.Date(); java.util.Date headDateO = new java.util.Date(); query = "select Title, Date, Id from News where Date >= " + Year + "-" + Month + "-" + Day + " order by Date desc"; result = sessionbase.doQuery(query, SessionId); int i = 0; out.println("These articles have been submitted within the last two weeks.
"); out.println("To view older articles, visit the archives."); out.println("

News Articles

"); try { while (result.next()) { i++; headDateO = headDate; headTitle = result.getString("Title"); headDate = result.getDate("Date"); headId = result.getString("Id"); if (!headDate.equals(headDateO)) { if (i > 1) { out.println("
"); } out.println("" + shortFormat.format(headDate) + "
"); out.println("° " + headTitle + "
"); } else { out.println("° " + headTitle + "
"); } } } catch (Exception e) { e.printStackTrace(); } if (i == 0) { out.println("No New Articles
"); } out.println("
MoreView old news...

"); out.println("
"); printBot(out); out.close(); } public void displayArchives(HttpServletRequest request, HttpServletResponse response, String SessionId) throws IOException, ServletException { String query = (String)null; ResultSet result = null; // Initialize the output stream response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Let's get the news printTop(out, 6); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"Admin\"

"); java.util.Date frontDate = new java.util.Date(); java.util.Date frontTime = new java.util.Date(); Locale locale = new Locale("en","US"); // Set the format for time and date DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, locale); DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale); java.util.Date curDate = new java.util.Date(); int Day = curDate.getDate(); int Month = (curDate.getMonth()) + 1; int Year = (curDate.getYear()) + 1900; Day = Day - 14; if (Day < 1) { Month = Month - 1; if (Month == 1) { Day = 31 + Day; } else if (Month == 2) { Day = 28 + Day; } else if (Month == 3) { Day = 31 + Day; } else if (Month == 4) { Day = 30 + Day; } else if (Month == 5) { Day = 31 + Day; } else if (Month == 6) { Day = 30 + Day; } else if (Month == 7) { Day = 31 + Day; } else if (Month == 8) { Day = 31 + Day; } else if (Month == 9) { Day = 30 + Day; } else if (Month == 10) { Day = 31 + Day; } else if (Month == 11) { Day = 30 + Day; } else if (Month == 12) { Day = 31 + Day; } if (Month < 1) { Month = 12; Year = Year - 1; } } // Get all Headlines String headTitle = (String)null; String headId = (String)null; java.util.Date headDate = new java.util.Date(); java.util.Date headDateO = new java.util.Date(); query = "select Title, Date, Id from News where Date < " + Year + "-" + Month + "-" + Day + " order by Date desc"; result = sessionbase.doQuery(query, SessionId); int i = 0; out.println("These articles are all over two weeks old. To view newer "); out.println("articles, visit the headlines."); out.println("

News Articles

"); try { while (result.next()) { i++; headDateO = headDate; headTitle = result.getString("Title"); headDate = result.getDate("Date"); headId = result.getString("Id"); if (!headDate.equals(headDateO)) { if (i > 1) { out.println("
"); } out.println("" + shortFormat.format(headDate) + "
"); out.println("° " + headTitle + "
"); } else { out.println("° " + headTitle + "
"); } } } catch (Exception e) { e.printStackTrace(); } if (i == 0) { out.println("No Old Articles
"); } out.println("
MoreView all headlines...

"); out.println("
"); printBot(out); out.close(); } public void displayArticle(HttpServletRequest request, HttpServletResponse response, String SessionId) throws IOException, ServletException { String Id = request.getParameter("Id"); String query = (String)null; ResultSet result = null; // Initialize the output stream response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Get the Article String Title = (String)null; String Author = (String)null; java.util.Date Date = new java.util.Date(); java.util.Date Time = new java.util.Date(); Locale locale = new Locale("en","US"); // Set the format for time and date DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, locale); DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale); String Story = (String)null; query = "select Title, Author, Date, Story from News where Id = " + Id; result = sessionbase.doQuery(query, SessionId); try { while (result.next()) { Title = result.getString("Title"); Author = result.getString("Author"); Date = result.getDate("Date"); Time = result.getTime("Date"); Story = result.getString("Story"); } } catch (Exception e) { e.printStackTrace(); } // Get Author's Full Name query = "select Fname, Lname from Account where Username = '" + Author + "'"; result = sessionbase.doQuery(query, SessionId); String FullAuthor = ""; try { while (result.next()) { FullAuthor += result.getString("Fname"); FullAuthor += " "; FullAuthor += result.getString("Lname"); } } catch (Exception e) { e.printStackTrace(); } printTop(out, 6); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("\"BSE
"); out.println("

"); out.println("Article Submitted: " + dateFormat.format(Date) + " at " + timeFormat.format(Time) + "

"); out.println("" + Title + "
"); out.println(Story + "
"); out.println("

"); out.println("Article submitted by: " + FullAuthor + "
"); out.println("

"); // Get Breaking News Links // Make sure there are Breaking News articles int bId = 0; query = "select COUNT(Id) from News where Type = 2"; result = sessionbase.doQuery(query, SessionId); try { while (result.next()) { bId = result.getInt("COUNT(Id)"); } } catch (Exception e) { e.printStackTrace(); } if (bId > 0) { query = "select Title, Date, Id from News where Type = 2"; result = sessionbase.doQuery(query, SessionId); String breakingTitle = (String)null; java.util.Date breakingDate = new java.util.Date(); java.util.Date breakingTime = new java.util.Date(); String breakingId = (String)null; out.println("

"); out.println("Breaking News
"); try { while (result.next()) { breakingTitle = result.getString("Title"); breakingDate = result.getDate("Date"); breakingId = result.getString("Id"); out.println("" + dateFormat.format(breakingDate) + " " + breakingTitle + "
"); } } catch (Exception e) { e.printStackTrace(); } } out.println("
MoreView all headlines...

"); out.println("
"); printBot(out); out.close(); } public void QuoteFlash(PrintWriter out) throws IOException, ServletException { String query = (String)null; ResultSet result = null; // Storage variables to hold the 5 values for display String Sym = (String)null; String Sym1 = (String)null; String Sym2 = (String)null; String Sym3 = (String)null; String Sym4 = (String)null; String Sym5 = (String)null; double Val = 0.00; double Val1 = 0.00; double Val2 = 0.00; double Val3 = 0.00; double Val4 = 0.00; double Val5 = 0.00; // Number format to force at least 0.00 DecimalFormat numFormat = new DecimalFormat("################0.00"); // Read in the Symbols and Last values query = "select Symbol, Last from Companies"; result = sessionbase.doQuery(query); try { while (result.next()) { Sym = result.getString("Symbol"); Val = result.getDouble("Last"); // Compare values and swap out the greater ones to // get the top 5. If a greater value is found, all // lesser values have to be moved down one. if (Val > Val1) { Val5 = Val4; Sym5 = Sym4; Val4 = Val3; Sym4 = Sym3; Val3 = Val2; Sym3 = Sym2; Val2 = Val1; Sym2 = Sym1; Val1 = Val; Sym1 = Sym; } else if (Val > Val2) { Val5 = Val4; Sym5 = Sym4; Val4 = Val3; Sym4 = Sym3; Val3 = Val2; Sym3 = Sym2; Val2 = Val; Sym2 = Sym; } else if (Val > Val3) { Val5 = Val4; Sym5 = Sym4; Val4 = Val3; Sym4 = Sym3; Val3 = Val; Sym3 = Sym; } else if (Val > Val4) { Val5 = Val4; Sym5 = Sym4; Val4 = Val; Sym4 = Sym; } else if (Val > Val5) { Val5 = Val; Sym5 = Sym; } } } catch (Exception e) { e.printStackTrace(); } if (Sym1 != null) { // Output Quote Flash table out.println(""); out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); } out.println("
"); out.println("Quote Flash
top stocks

"); if (Sym1 != null) { out.println("° " + Sym1.toUpperCase() + "
"); } if (Sym2 != null) { out.println("° " + Sym2.toUpperCase() + "
"); } if (Sym3 != null) { out.println("° " + Sym3.toUpperCase() + "
"); } if (Sym4 != null) { out.println("° " + Sym4.toUpperCase() + "
"); } if (Sym5 != null) { out.println("° " + Sym5.toUpperCase() + "

"); } out.println("

"); if (Sym1 != null) { out.println(numFormat.format(Val1) + "
"); } if (Sym2 != null) { out.println(numFormat.format(Val2) + "
"); } if (Sym3 != null) { out.println(numFormat.format(Val3) + "
"); } if (Sym4 != null) { out.println(numFormat.format(Val4) + "
"); } if (Sym5 != null) { out.println(numFormat.format(Val5) + "

"); out.println(""); out.println("MoreAll Quotes"); out.println("
"); } } static public void reload() { SystemURL = sessionbase.getURL(); ServletURL = sessionbase.getServletURL(); SystemEmail = sessionbase.getEmail(); SystemPath = sessionbase.getPath(); SystemName = sessionbase.getName(); SystemShortName = sessionbase.getShortName(); } }