|
TypeCommand |
|
1 // joi/7/juno/TypeCommand.java
2 //
3 //
4 // Copyright 2003, Bill Campbell and Ethan Bolker
5
6 import java.util.*;
7
8 /**
9 * The Juno shell command to display the contents of a
10 * text file.
11 * Usage:
12 * <pre>
13 * type textfile
14 * </pre>
15 *
16 * @version 7
17 */
18
19 public class TypeCommand extends ShellCommand
20 {
21 TypeCommand()
22 {
23 super( "display contents of a TextFile", "textfile" );
24 }
25
26 /**
27 * Display the contents of a TextFile.
28 *
29 * @param args the remainder of the command line.
30 * @param sh the current Shell
31 *
32 * @exception JunoException for reporting errors
33 */
34
35 public void doIt( StringTokenizer args, Shell sh )
36 throws JunoException // EEE
37 {
38 String filename;
39 try { // EEE
40 filename = args.nextToken();
41 } // EEE
42 catch (NoSuchElementException e) {
43 throw new BadShellCommandException( this ); // EEE
44 } // EEE
45 try { // EEE
46 sh.getConsole().println(
47 ( (TextFile) sh.getDot().
48 retrieveJFile( filename ) ).getContents() );
49 } // EEE
50 catch (NullPointerException e) { // EEE
51 throw new JunoException( "JFile does not exist: " // EEE
52 + filename); // EEE
53 } // EEE
54 catch (ClassCastException e) { // EEE
55 throw new JunoException( "JFile not a text file: " // EEE
56 + filename); // EEE
57 } // EEE
58 }
59 }
60
|
TypeCommand |
|