|
TypeCommand |
|
1 // joi/10/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 10
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
37 {
38 String filename;
39 try {
40 filename = args.nextToken();
41 }
42 catch (NoSuchElementException e) {
43 throw new BadShellCommandException( this );
44 }
45 try {
46 sh.getConsole().println(
47 ( (TextFile) sh.getDot().
48 retrieveJFile( filename ) ).getContents() );
49 }
50 catch (NullPointerException e) {
51 throw new JunoException( "JFile does not exist: "
52 + filename);
53 }
54 catch (ClassCastException e) {
55 throw new JunoException( "JFile not a text file: "
56 + filename);
57 }
58 }
59 }
60
|
TypeCommand |
|