Download CS216 Program 5 Design

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS216 Program 5 Design
See the program specification for output/message formats.
There are three components:
1. HTML page containing a form
2. CGI program (named CS216program5.cgi)
3. C++ program (named CS216program5)
4. Perl program (named cs216program5.pl)
The interfaces in the following diagram:
1. Name /value pairs sent to CS316echo.cgi via post method
2. N/V pairs echoed back to browser, data from files read by Java program
3. Directory name passed to Java program as parameter when executed
4. Data from files read by Java program
5. File data read is written to output files
6. Input files read, data assed to CGI and written to output files
1
HTML page
displayed by
browser
3
CS316echo.cgi
2
4
5
6
CS216program5
C++ program
CS216program5.p
l
Perl program
Input files:
customer.data
salesrep.data
CS316echo.cgi
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
CS316echo.cgi
echo version of CS216 program 5 for demonstration
to CS316 students
echo name/value pairs back to browser, execute java program
that reads files, returns lines
Author: Paul Piwowarski
Date: August 2007
Precondition:
Browser executes script CS316echo.cgi via the post method
Browser passed 4 name/value pairs to script
Postcondition:
Name/value pairs sent back to browser two ways:
1. the exact string received
2. Special characters (%xx where xx = hexadecimal value)
converted, then name/value pairs displayed in an
unordered list with spaces inserted for "+"
Special character conversions done (+ a special case) then:
Name/value pairs displayed in a table
Name/value pairs displayed in a list
Java program CS316echo executed
passed 1 parm received from browser as name/value pair
(directory location)
What java program prints is returned to the browser
# print "Content-type: text/html\n\n";
#This is a header line required by HTTP. It tells the browser
# what type of data is in the file.
# Start HTML page
# print "Query Results" as a heading 1
# print "You submitted the following name/value pairs:"
# Receive name/value pairs using post method
# Print the received string
# Convert special chars represented by their hexadecimal value, then print:
# “After special character conversion:" (line received from browser)
# Split up original (before conversion) input pairs on & then =
# Put into arrays: pairs, names, values
# Replace "+" with a space
#
#
#
#
#
Convert special characters after split by & and =
cannot convert before split (values may have & or =)
put received name/value pairs in a table
Put name/value pairs into a list
If directory name received
# execute java program passing it directory (value of directory name)
# print what is returned from Java program (returned to browser)
# else
# print message cannot execute Java program
# end HTML page
CS316echo.java
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
CS316echo.java
Java example to illustrate reading and writing files
CS316echo.cgi executes Java program CS316echo which opens files
and return the data in the files. The files are also written to disk.
Author: Paul Piwowarski
Date: August 2007
Preconditions:
customer.data and salesrep.data exist in passed directory
program has permission to create files in passed directory
One parm is passed:
dirLoc: directory for files (used to open files)
Postconditions:
Passed parm is printed
File names read/written are printed
customer.data, salesrep.data opened, contents printed and
written to files
Implementation
There are simpler ways to accomplish this task.
Some techniques are used
(for example, splitting the line read into words,
then writing each word separately to the output file) for
illustrative purposes
//
//
//
//
//
//
//
//
//
//
Receive and print passed parm (directory location)
Print customer input file Location (including directory)
Open Customer.data file
If open fails, print “Cannot open (dir/file name)” stop program
Print customer output file location (including directory)
Open customer output file custOut.txt
If open fails, print “Cannot open (dir/file name)” stop program
Print sales rep input file location (including directory)
Open salesRep.data file
If open fails, print “Cannot open (dir/file name)” stop program
//
//
//
//
//
//
Print sales rep output file location (including directory)
Open sales rep output file repOut.txt file
If open fails, print “Cannot open (dir/file name)” stop program
Read customer file line
Print "Reading customer file"
while there are customer lines in file
// Print line from file using format:
// "line (line number): " (line)
// split line on spaces into words
// Copy line to output file
// Print each word to output file on one line
// close customer input file
// close customer output file
// Print “Reading salesrep file"
// Read sales rep file line
// while sales rep lines in file
// Print line from file using format:
//"line (line number): " (line)
// split line on spaces put into static array
// Copy line to output file
// Print each word to output file on one line
// close sales rep input file
// close sales rep output file