Mihai's WebShell Project:
Requirements (v1.0)

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.  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. In other words, the web shell parses documents for only HTML tags that reference documents, such as the anchor (syntax: <a href="some.url">), a form's action parameter (syntax: <form action="some.url">) or images (syntax: <img src="some.url">).  Every document that is linked from an HTML page is said to be "contained in the HTML page's folder".

Documents

A web shell allows for traversal of the tree defined by this relationship (back-links are ignored), simple operations on the documents, and some miscellaneous functions.

A directory is either a real directory (http://www.cs.ucsb.edu/~cappello/) or an HTML page. Its contents are defined as all files that the web server returns on a request for this URL (possibly empty).

Any other document is called plain.

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.  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 that part that is described before the "/";   the other display is a graphical representation of the document structure.  That output is described after the  "/".  Hint: The Java Swing package makes it easy to implement a visualization of both the tree structure of interlinked documents and the lists of documents - you have to display both. For an example, look at the WindowsExplorer.

Web Shell Commands

These are the particular commands that can be used in the web shell:
  • cd [name] (change directory)
    The current document is set to name, and the complete URL of the current document is displayed. If name equals ".." (two dots), the new current document is set to the current document's (known) parent.  If there is more than one parent, choose the logical parent or the first parent in alphabetical order.  The logical parent of a document with the URL
    http://www.cs.ucsb.edu/~cappello/172/ is either
    http://www.cs.ucsb.edu/~cappello/ or
    http://www.cs.ucsb.edu/~cappello/index.htm(l), whichever exists.
    If no name is provided, the current document stays unchanged.
    OUTPUT: absolute path of new current document / highlighting of new current document.
  • ls [name]
    The contents of the named document are shown:  all documents that are linked from the current document. Special tags or other means identify different types of documents (directory, plain, or even more detailed). 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.
    OUTPUT: information as text / 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.
    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. If no arguments are given, all variables and their values are displayed. If the value is omitted, the variable is removed from the set of defined variables.
    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. 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 behind the alias name. 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; 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.

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.

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 (equivalent to GUI not defined), DEFAULT (display documents in current document and the tree structure of directories), and ALL (a lot of additional popup windows for little messages).
History: Just like every other decent shell, the web shell keeps a 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.png
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
>


Mathias Kölsch

Copyright 1998-2005 Mihai Christodorescu. All rights reserved.
Maintained by Mihai Christodorescu (http://mihai.christodorescu.org).
Created: Mon Dec 21 21:12:13 PST 1998
Last modified: Sat Oct 1 23:06:49 CDT 2005