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. 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: 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