Module Specifications

The Classes and Their Methods
FSmain
  • public void doGet/doPost(HttpServletRequest req, HttpServletResponse resp)
  • private void outputHtml(FSrequest reqInput, FSconnection con)
  • private void outputPageHeader(String pagetitle, boolean searchBox, boolean formValidationScript)
  • private void outputDataHtml(FSconnection con, String queryType, FSrequest reqinput)
  • private void outputText(String bigtext, String smalltext)
  • private String outputDataHtml_getStarString(double rating)
  • private String phoneFormat(String input)
  • private void outputPageFooter(boolean admin)
FSrequest


 

  • FSrequest(HttpServletRequest req, HttpServletResponse resp)
  • private void removeLoginCookie(HttpServletResponse resp)
  • private void addLoginCookie(HttpServletResponse resp)
  • private boolean processCookies(HttpServletRequest req)
  • private void parseInputString(HttpServletRequest req)
  • public HashMap getInputParams()
  • public String getUserName()
  • public boolean admin()
  • public String getPassword()
  • public String getQueryType()
FSconnection


 

  • FSconnection()
  • public void open(String username, String password)
  • public void close()
  • public ResultSet doQuery( FSrequest FSreq, String queryType )
FSqueryString


 

  • FSqueryString(HashMap input, String type)
  • public boolean is_update()
  • public String value()
  • private String selectQueryString(HashMap table, String queryType)
  • private String buildWhereString( String key, String keyvalue )
  • private String phoneStrip(String input)
  • private String replaceCharWithString(String input, char chSearch, String strReplace)
  • private String mySqlCheck(String input)
  • private String mySqlSearchCheck(String input) 
Back to top
FSmain public void doGet/doPost(HttpServletRequest req, HttpServletResponse resp)

Description: This is the main "process handler" for the whole program. It is the function that is originally passed the request from the forms, and the one that intiates all the actions. It makes the calls to open and close the database, process the input, and outputs the page.
Input: The servlet request (from the form input) and the servlet response (for the form output).
Output: This function outputs nothing.
Precondition: None
Postcondition: Form input processed and web page outputted based on the action it asks for. If there are any errors at any point in the process, this function outputs a meaningful error message. 


private void outputHtml(FSrequest reqInput, FSconnection con)

Description: This function handles the html output for a specific action. It makes output header, dataHtml, and footer calls depending on the type of query. This function is only used by doGet().
Input: FSrequest holding the parameters passed by the forms, and an FSconnection to make the query calls
Output: A complete page outputted to the response output stream
Precondition: FSconnection has been opened, FSrequest contains valid parameters and a valid action. Response output stream has been initialized.
Postcondition: None.


private void outputPageHeader(String pagetitle, boolean searchBox, boolean formValidationScript)

Description: Outputs an HTML header to the response output stream. This includes the Five Star logo, a specific pagetitle that has been passed, and possibly a searchBox or comment adding javascript validation. This function is used by both outputHtml() and outputTextPage().
Input: The page title (to be appended to a basic page title) describing what the page is about, a boolean variable to say whether there should be a searchBox (general keyword search) in the header, and a boolean to say whether the form needs javascript to validate adding a new comment.
Output: An HTML header and the "header" to the page (such as common links at the top) with the passed page title and options.
Precondition: Response output stream has been initialized.
Postcondition: None.


private void outputDataHtml(FSconnection con, String queryType, FSrequest reqinput)

Description: This function is only called from within outputHtml(). It dynamically creates the "data" determined part of the Html Output. The output it picks is determined by the action passed to it in queryType. Each different action can make doQuery() calls to the FSconnection to return a ResultSet to get the data from and output the webpage.
Input: An open FSconnection to the database, the action that it is going to perform, and the parameters passed to that action.
Output: A formatted HTML page containing the data (ie everything but the header and the footer) portion of the output. 
Precondition: FSconnection has been opened, FSrequest contains valid parameters and a valid action. Response output stream has been initialized.
Postcondition: None.


private String outputDataHtml_getStarString(double rating)

Description: This function only called within outputDataHtml. From the passed rating, it returns the HTML string for the "stars" determined by that number. If there is a zero rating (ie zero comments), then it returns "(no comment)" in italics.
Input: The rating that the user input.
Output: If ( rating == 0 ) then an HTML string containing "(no comments)", otherwise an HTML string containing the code to link to the images of the appropriate stars for the rating. The rating is from 1-5, including half ratings, and is rounded up to the nearest half rating (ie 4.6 --> 5.0 and 4.4 --> 4.5).
Precondition: None.
Postcondition: None.


private void outputText(String bigtext, String smalltext)

Description: This function simply outputs two text strings. The first string is added as a heading in a large font, and the second is used to explain the heading in a small font. This function is used by outputTextPage() and outputDataHtml().
Input: A heading string and a more detailed explanation string. Either of these strings can be Html, but behavior by the Html can be quirky if anything past simple font formatting is used because the strings are embedded into a page.
Output: Formatted Html for a heading in a large font and a smaller explanation.
Precondition: Response output stream has been initialized.
Postcondition: None.


private String phoneFormat(String input)

Description: This function takes a string as input, and returns a formatted phone number in the form of: "(931)-281-3291" or if there are only 7 digits, "281-3291". This function is used by outputDataHtml().
Input: The string from the database containing the phone number.
Output: A formatted phone number suitable for screen output in the form of: "(931)-281-3291" or if there are only 7 digits, "281-3291".
Precondition: Input string contains 7-10 numbers.
Postcondition: None.


private void outputPageFooter(boolean admin)

Description: This function outputs a standard footer onto every page that the database returns. This is used by outputTextPage and outputHtml().
Input: A boolean variable to determine whether the admin logout link should be included at the bottom with the links.
Output: Formatted HTML for the footer of each returned page.
Precondition: Response output stream has been initialized.
Postcondition: None.

Back to top
FSrequest FSrequest(HttpServletRequest req, HttpServletResponse resp)

Description: This is the (only) constructor for FSrequest. It makes calls to parseInputString() and to process the cookies. It sets the member variables of FSrequest from the request.
Input: A request from the web page, and an output response. The output response is only used to add cookies, not to actually output anything.
Output: None.
Precondition: None.
Postcondition: Member variables of FSrequest set. InputParams is set with the parameters from the request and the cookies. If the user is trying to login, cookies are added to contain the username and password. If the user is logging out, then the cookies are cleared to values of " ".


private void removeLoginCookie(HttpServletResponse resp)

Description: Removes the login cookies (such as when an administrator logs out) by setting the username and password variables to " ".
Input: The response to add the cookies to.
Output: None.
Precondition: None.
Postcondition: Cookies added to the response with (name, values): (username, " " ) and ( password, " " ).


private void addLoginCookie(HttpServletResponse resp) 

Description:If a user is logging in (has an action of "login" passed in the queryType variable in the request), then this function is called to add the login cookies with the username and password passed in the servlet request and stored in inputParams. 
Input:The response to which to add the cookies. 
Output:None. 
Precondition:None. 
Postcondition:Username and password cookies added to the response stream with values given by the username and password stored in inputParams. 


private boolean processCookies(HttpServletRequest req) 

Description:processCookies checks to see if there are any cookies 
Input:The request from which to check for cookies. 
Output:Cookies found? 
Precondition:None. 
Postcondition:If there are cookies that are found, they are added as name, value pairs to inputParams (so they are treated as if they were passed as parameters). 


private void parseInputString(HttpServletRequest req) 

Description:Parses the input string and puts the values into the HashMap inputParams.
Input:The request from the web forms. 
Output:None. 
Precondition:None. 
Postcondition:The name, value pairs that are passed in the servlet request are stored in the member variable inputParams. 


public HashMap getInputParams() 

Description:A simple member accessing function for inputParams. 
Input:None. 
Output:inputParams. 
Precondition:None. 
Postcondition:None. 


public String getUserName() 

Description:A simple member accessing function for UserName. Username is a value stored in inputParams. 
Input:None. 
Output:A string containing the username. If there is a username contained in inputParams, it returns that one, otherwise it returns " ". 
Precondition:None. 
Postcondition:None. 


public boolean admin() 

Description:Returns if the user is trying to use a different username and password than " ". 
Input:None. 
Output:Returns true if the user has tried to or is logged in, i.e the password and username are both nonequal to " ". 
Precondition:None. 
Postcondition:None. 


public String getPassword() 

Description:A simple member accessing function for password. Password is a value stored in inputParams. 
Input:None. 
Output:A string containing the password. If there is a password contained in inputParams, it returns that one, otherwise it returns " ". 
Precondition:None. 
Postcondition:None. 


public String getQueryType() 

Description:A simple member accessing function for queryType. queryType is a value stored in inputParams. 
Input:None. 
Output:A string containing the queryType that was contained in inputParams. 
Precondition:There is a queryType stored in inputParams. Every call to query must contain an action stored in the variable queryType. 
Postcondition:None. 

Back to top
FSconnection FSconnection() 

Description:Loads twz driver for JDBC connection to a mySQL database. 
Input:None. 
Output:None. 
Precondition:Driver exists in the classpath that was used when starting the Java server. 
Postcondition:Driver loaded. 


public void open(String username, String password) 

Description:Opens a connection to the mySQL database using the given username and password. If the username and password are " " (defaults), then it uses a valid default entry of fivestar, fivestar. 
Input:A username and password to use in connecting to the database. 
Output:None. 
Precondition:Database exists, is running, and username and password work to connect, otherwise it throws an exception. 
Postcondition:There is an open database connection. 


public void close() 

Description:Closes the open database connection. 
Input:None. 
Output:None. 
Precondition:Database connection is open (otherwise is throws an exception). 
Postcondition:Database connection is closed. 


public ResultSet doQuery( FSrequest FSreq, String queryType ) 

Description:  Performs the query associated with the parameters passed in the FSrequest and the query specified by queryType. 
Input:Parameters passed in the FSrequest and the type of query to be run in the queryType. 
Output:The result set from the query or if it is an update query, simply null. 
Precondition:Open database connection, valid query type. 
Postcondition:Query has been run on database. This could, in some cases, cause changes to the database. 

Back to top
FSqueryString FSqueryString(HashMap input, String type) 

Description:Constructor for queryString. It takes a HashMap as input and a String as the querytype it is supposed to build, and builds a queryString. 
Input:A Hashmap of parameter information (name, value) pairs, and a query type that it is supposed to build. 
Output:None. 
Precondition:The passed query type is a valid query type. 
Postcondition:Member variables queryString and is_update are set to the values of the valid mySQL queryString and whether that query is an update or not, respectively. 


public boolean is_update() 

Description:Is the queryString an updating query or a simple information selecting one 
Input:None. 
Output:Whether the query updates the database or just selects. 
Precondition:None. 
Postcondition:None. 


public String value() 

Description:A member accessor function for the queryString variable. 
Input:None. 
Output:The value of the member variable queryString. 
Precondition:None. 
Postcondition:None. 


private String selectQueryString(HashMap table, String queryType) 

Description:This function builds a valid mySQL query based on a hashmap table and a queryType. 
Input:The HashMap containing the parameters of the query and the query type which pick the query. 
Output:A valid mySQL query in the form of a string. 
Precondition:None. 
Postcondition:None. 


private String buildWhereString( String key, String keyvalue ) 

Description:Helper function to selectQueryString(). Given a key and a keyvaule, this function returns a string in the form of " and ". is the inputted string, literally. is selected by the value of key. If it is "rating" then it will do a numerical (>=) comparison. If it is an id field matching, then it will always be strict equality. Otherwise, it will do a string comparison. In the case of string comparisons, if there are any wild card characters such as * or ?, the function notes it, and does a search based just on the specified wild cards. Otherwise, if there are no wildcards specified, this function returns a where string for a substring search based on keyvalue (ie *keyvalue*). is the modified key value. This function uses the mySqlCheck() function to trim the field of extraneous whitespace, and also to add escape characters to invalid mySQL characters. In the case of phone numbers, it also strips the (,),-'s as well with phoneStrip(). This function is also smart enough to handle when it has been given fields it shouldn't search on (variables that the program handles and are not stored anywhere in mySQL, such as queryType, username, or password) and also it won't search on blank fields. 
Input:A keyvalue and a key value pair to search on. 
Output:A valid (and meaningful) part of a where clause in a mySQL string. 
Precondition:None. 
Postcondition:None. 


private String phoneStrip(String input) 

Description:Strips all the formatting characters in an inputted phone string. (ie (914)-938-3817 becomes 91493873817). 
Input:An input string to strip the formatting from. 
Output:The formatted string. 
Precondition:None. 
Postcondition:None. 


private String replaceCharWithString(String input, char chSearch, String strReplace) 

Description:Replaces all the characters in the input string that match chSearch with strReplace. 
Input:An input string, a character to replace, and a string to replace it with. 
Output:The modified. 
Precondition:None. 
Postcondition:None. 


private String mySqlCheck(String input) 

Description:This function returns a string which is acceptable for mySQL to insert on. It appends an escape character (\) to all characters that "mean" something past their literal character defnition in mySQL. These special characters include \, ', ", and ;. 
Input:An input string to format. 
Output:The formatted string. 
Precondition:None. 
Postcondition:None. 


private String mySqlSearchCheck(String input) 

Description:This function returns a string which is acceptable for mySQL to search on. It appends an escape character (\) to all characters that "mean" something past their literal character defnition in mySQL. This extends functionality to the mySQLCheck routine which doesn't need to check wild card characters such as %, _, *, and ?. These special characters include \, %, _, ', ", *, ?, and ;. This is more restrictive than mySQLCheck. 
Input:Any input string. 
Output:A string formatted so that mySQL can validly search on it. 
Precondition:None. 
Postcondition:None. 

Back to top
< Back * Contents * Next >