Complete the provided test program that reads
the location of a Web site as a string and calls a function that splits it into
protocol name, port number, server name, and file name that starts with /. The
program checks if the given Web site location was provided as a command line
argument. If so, it uses it (add code). If not, it asks the user to enter it
(already provided). The program calls a function called UrlSplitter
that returns a variable of type Locator. (Class
Locator) is already provided.) Your main task is to implement
that function.
The complete location has the format of
protocol://server:port/file/name/with.folder, for example
http://gdansk.bradley.edu:80/olekmali/index.html. However, not all
parts of it are always present. If protocol:// is omited please assume "http",
if :port is omited, please assume 80 for "http" and 21 for "ftp". (Ideally you
could get default values for other protocls as well.) Assume the Web server name
is always there. If there is no filename, assume "/". Please note that in case
the filename is not provided they may or may not be "/" present after the server
name.
Here are examples of inputs and outputs that may be used to test your program:
| Input String | protocol | port | server | file |
|---|---|---|---|---|
| http://gdansk.bradley.edu:80/olemali/index.html | http | 80 | gdansk.bradley.edu | /olekmali/index.html |
| gdansk.bradley.edu/olekmali/index.html | http | 80 | gdansk.bradley.edu | /olekmali/index.html |
| gdansk.bradley.edu/olekmali/index.html | http | 80 | gdansk.bradley.edu | /olekmali/index.html |
| http://cegt201.bradley.edu/ | http | 80 | cegt201.bradley.edu | / |
| http://cegt201.bradley.edu | http | 80 | cegt201.bradley.edu | / |
| http://cegt201.bradley.edu:88 | http | 88 | cegt201.bradley.edu | / |
| cegt201.bradley.edu | http | 80 | cegt201.bradley.edu | / |
| ftp://cegt201.bradley.edu | ftp | 21 | cegt201.bradley.edu | / |
| e.t.c. | ||||
Please send the source code only for the complete program as a file attachment with proper name. Source code pasted into the body of an email will not be graded. The program must compile to get any credit
Hint: you may do elaborate but straightforward work with String class or look up and study another class in the extensive Java library, and complete the function almost in one line. (three letter name that starts with letter 'U'.)
Attach all source code in files with proper names and extensions (*.html, *.java, *.pl, *.php, .htaccess e.t.c.). Do not ZIP files together or include compiled files (e.g. *.class). In case of dynamic Web pages (JavaScript or CGI) or Java applets also send the complete URL (including http://) that points to a page on your Web site that demonstrates your homework. Send your homework via e- mail to the instructor at olekmali at bradley dot edu. Please set the message subject to: web-hw4.
Thank you.