Web Shell: Requirements
Version 1.1
A web shell is a program that combines
the functionality of a WWW browser, like Netscape or Internet Explorer,
with the features of a shell (e.g., a typical Unix shell or a Telnet terminal).
It acts as a client to web servers, requesting files from them.
It deals with all different kinds of files that can be transferred
from a web server and the local file system. It however handles
the contents of web documents only in a limited way.
For example, it cannot parse arbitrary HTML tags or display an HTML document
in a way familiar to you from a browser. Instead, it treats an HTML document
as a directory (aka folder) that may contain documents. Every document
that is linked from an HTML page is said to be "contained in the HTML page's
folder".
Documents, Directories, Folders
A remote document is any file you can request from
a web server with a HTTP request.
A local document is any file in the local file system,
that is any file you can refer to via the java.io.File class.
A directory is a document of type HTML. Its contents are
defined as all documents that the directory references. A document is referenced
by a directory, if the directory has a link to this document. A link is
any HTML tag that has a URL as value (examples are: anchor
(syntax: <a href="some.url">), a form's
action
parameter (syntax:
<form action="some.url">)
or images (syntax: <img
src="some.url">)). You may disregard non-HTML tags such
as JavaScript links, and HTML links that are embedded in JavaScript.
Additionally, a local document can be a directory if it is a directory
in the sense of the local file system. It is called a local directory,
and you can easily test local files for this property with the method java.io.File.isDirectory().
Any other document is called
plain.
The shell always has a current directory. On startup,
this is the local directory in which the WebShell application was started.
It can be changed using the commands described below.
Parents, Tree Structure and Traversal
The shell allows for two ways to enter a directory.
-
A relative cd (change directory) is when you change into
one of the directories that are linked from the current directory
(example: cd AnyDocument.html). If the new current directory was entered
for the first time, the directory you came from is called the parent
directory of the directory you changed to.
-
An absolute cd is the change to a directory that is not
linked from the current directory (example: cd http://www.cs.ucsb.edu/~matz).
In this case, if the new current directory was entered for the first time,
it will not have a parent, but it becomes a root directory.
Later traversals of the tree don't modify the parent of a document !
This relationship defines a tree structure which we will call the "parent-tree",
or simply "tree". There will possibly be multiple parent-trees,
but only one for each root document. Parent-trees can be interlinked, but
only "on the way down": At most one parent exists for each document, but
a document can be linked from multiple directories. That's why we also
define a "Most-Recently-Visited-Queue", or MRV-queue.
It contains a history of the last recently visited directories, that is
every new current directory is inserted at the beginning. The queue may
have a fixed length, such that directories at the end of queue drop out
of it on insertion of another directory. (If you ever need a longer directory
history than the queue contains, you may issue an error message and continue
without this information.) Two commands (back and forward)
allow to change the current directory to an arbitrary entry in the queue
without modifying it. However, if a cd command is executed while
we got to the (old) current directory through a series of back commands,
the front end of the queue is discarded and the new current directory is
inserted right before the old directory (at the new beginning of the queue).
A web shell allows for traversal of the tree defined by this relationship,
simple operations on the documents, and some miscellaneous functions.
The User Interface
Write a Java application that implements the functions described below.
The input from the user has to be read from a text interface ("terminal")
that strongly resembles that of a Unix shell or Telnet terminal. You can
either use the terminal (window) in which the Java interpreter for the
WebShell was started or you can pop up a new window. Your decision won't
effect grading, but a "text-only" application - one that does not use the
AWT at all - is much faster and usually easier to debug. A prompt (e.g.,
">") asks for the next command or sequence of commands. After processing
the command[s], another prompt is displayed. The
output depends
on the display. One display makes use of the terminal that also works as
the input device. Terminal output, displayed before the next prompt, is
the part that is described before the "/"; the other display
is a graphical representation of the document structure. This output
is described after the "/". Hint: The Java
Swing
package makes it easy to implement a visualization of both the tree structure
of interlinked directory documents and the content lists of directories
- you have to display both. For an example, look at the WindowsExplorer
(not: Internet Explorer).
NOTE: The costumer is familiar with Unix shells and the WindowsExplorer.
She wants to use the WebShell as intuitively as possible, so try to resemble
this behaviour and interpretation - but reconfirm it anyway !
GUI input: The customer made up her mind, she wants to be able
to input some commands from both the shell and the GUI. For now, those
commands are: double-click on a directory cds to it, it is highlighted
in the tree structure and its contents are displayed. Double-click on a
plain document opens it.
Web Shell Commands
These are the particular commands that can be used in the web shell:
-
cd [name] (change current directory)
The current directory is set to name (which must be the name
of a directory), and the complete URL of the new current directory is displayed.
If no name is provided, the current directory stays unchanged.
OUTPUT: absolute path of new current directory / highlighting
of new current directory.
-
up
The new current directory is set to the current directory's parent.
If it does not have a parent, the current directory stays unchanged. Note:
This replaces "cd ..".
OUTPUT: absolute path of new current directory / highlighting
of new current directory.
-
back
The new current directory is set to the previous current directory,
as determined by the MRV-queue.
OUTPUT: absolute path of new current directory / highlighting
of new current directory.
-
forward
The new current directory is set to the following document of the MRV-queue.
This can be executed k times iff the k most recent changes to the current
directory were done using back.
OUTPUT: absolute path of new current directory / highlighting
of new current directory.
-
ls [name ...]
If name is a directory, its contents are shown: all documents
that are linked from the it. Special tags or other means identify different
types of documents (directory, plain, or even more detailed). If name
is a plain document, only this document is listed. If no name is
given, the current document's contents are listed.
The output list can be sorted by any argument. This is specified
in the environment variable SORT.
OUTPUT: list of documents as text / graphical representation
of documents
-
info [name ...]
Display information about the document, such as the absolute URL, its
type and other attributes if available (see below).
OUTPUT: information as text / if GUI is set to ALL popup window
with information represented appropriately.
-
open [name ...]
Spawn an external application to properly interpret the contents of
this document. The helper application (aka viewer) could be a web browser
for HTML pages, GhostScript for postscript documents, an MP3 player for
sound documents, etc. Provide the functionality to open HTML pages
and two other document types of your choice. Also, let the user configure
at startup-time of the WebShell which helpers are used for what type of
documents.
OUTPUT: nothing - return to prompt as soon as possible / nothing
-
set [variable [value]]
This command assigns an arbitrary value to an environment variable.
Those variables can be either pre-defined (e.g., SORT, GUI) or user-defined.
A variable must not contain whitespace. The value can be enclosed
in double-quotes ("), they are not part of the actual value. If no arguments
are given, all variables and their values are displayed. If the value
is omitted, the variable is set to the empty string. This can be interpreted
as a default value in applications/commands that use this variable.
OUTPUT: nothing / if GUI is set to ALL (this time or any time
before this set), then popup window with all variable settings;
otherwise nothing
-
alias [name value]
Create an alias for a command, a command sequence, or any other linefeed-delimited
string sequence. The name alias can afterwards be used instead of
the value. It hides other commands or aliases with the same
name.
The value can be enclosed in double-quotes ("), they are not part
of the actual value.When no argument is given, all pairs of name-values
are displayed.
The character sequence "!$" (exclamation-mark dollar) is replaced
at alias-invoke time with everything (every string and character, including
whitespaces) behind the alias name, but before a new line or semicolon.
This functions as an argument to the alias. See example.
OUTPUT: nothing / if GUI is set to ALL (this time or any time
before this set), then popup window with all alias settings; otherwise
nothing
-
unalias [name]
Delete the latest (the currently used) entry for name from the
set of aliases.
OUTPUT: nothing / if GUI is set to ALL (this time or any time
before this set), then popup window with all alias settings; otherwise
nothing
Not every command can be applied to every document. Operations for directories
are
cd and info, remote directories can be opened
also; operations for plain documents are
info and open. Generally,
one command is entered at a time. Processing begins after a linefeed character
(return, enter). Commands also can be
concatenated by the semicolon
(";"). After the linefeed, commands are processed in sequence. [name
...] means that more than one name can be supplied, then the operation
is executed for each of the documents. An asterix (*) can be used
for the name argument of commands for which it is meaningful. It
has the same functionality as in a Unix shell: "*.jpg" is expanded to all
documents in the respective directory that end with ".jpg".
Command History, Attributes and Environment Variables
Attributes include the document's URL, type, size, and date of last
change. There may be additional attributes for specific document types,
but you have to support only the standard attributes.
Pre-defined Environment Variables
SORT determines the sort order of directory listings via the
ls
command. Its values are NONE (equivalent to SORT not defined), URL, NAME,
and TYPE.
GUI determines if a graphical output is displayed or not. Its
values are NONE, DEFAULT (initial setting, equivalent to GUI not defined
or defined as the empty string) displays the tree structure of directories
and the documents in the current directory in one window, and ALL (a lot
of additional popup windows for little messages).
Command History
Just like every other decent shell, the web shell keeps a command history
of the most recently entered commands (either a fixed number of commands,
say 50, or by "set HISTORY number"). Given a prompt, the user can
"scroll" through the history by using the arrow-up and arrow-down keys.
On a new prompt, pressing arrow-up once reprints the last command entered,
pressing it again reprints the second-to-last command, etc. The commands
are shown in the same line; the cursor is placed behind the last character,
and a linefeed keystroke executes the chosen command again (using the current
directory, environment variables, and so on).
Examples
Starting from the current document http://www.cs.ucsb.edu/noframes.html,
we can change the current document to the URL http://www.cs.ucsb.edu/search/iaquery:
> cd search/iaquery
http://www.cs.ucsb.edu/search/iaquery
>
Notice the relative path name we used, and notice also the output of the
absolute URL. This "directory" contains:
> ls
http://www.cs.ucsb.edu/ui/icons/srchlogo.gif
http://www.cs.ucsb.edu/ui/usa/help.html/
http://www.cs.ucsb.edu/search/iaquery?NS-query-pat=/usa/NS-advquery.pat&
http://www.cs.ucsb.edu/search/iatoc/
>
Notice the slash / we used behind the second and fourth document to indicate
that these documents are directories.
The next three examples demonstrate the usage of concatenation
and aliases. Output is not shown.
> set SORT NAME
> ls http://www.cs.ucsb.edu
> set SORT NONE
>
has the same effect as
> set SORT NAME; ls http://www.cs.ucsb.edu; set SORT NONE
>
and
> alias lsname "set SORT NAME; ls !$; set SORT NONE"
> lsname http://www.cs.ucsb.edu
>
Be aware of the difference between the two following commands. The first
is a single "alias" command, the second is composed of three commands.
Note the output of the "ls" command issued in the second line. The name-value
pairs for the aliases are shown also.
> alias lsname1 "set SORT NAME; ls; set SORT NONE"
> alias lsname2 set SORT NAME; ls; set SORT NONE
..
SomeDocument.html
AnotherDocument.html
> alias
lsname1 set SORT NAME; ls; set SORT NONE
lsname2 set SORT NAME
Mathias Kölsch
Last modified: Tue Jan 12 00:28:29 PST 1999