01: /*
02: * HelpCommandExecutor.java
03: *
04: * Copyright (C) 2007 Ferran Busquets
05: *
06: * This program is free software: you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation, either version 3 of the License, or
09: * any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program. If not, see <http://www.gnu.org/licenses/>.
18: *
19: */
20: package org.naturalcli.commands;
21:
22: import java.io.*;
23:
24: import org.naturalcli.ParseResult;
25: import org.naturalcli.ICommandExecutor;
26: import org.naturalcli.NaturalCLI;
27:
28: /**
29: * Executor for <code>ExecuteFileCommand</code>
30: *
31: * @see ExecuteFileCommand
32: * @author Ferran Busquets
33: */
34: public class ExecuteFileCommandExecutor implements ICommandExecutor {
35:
36: static final String COMMENT = "#";
37:
38: private NaturalCLI naturalCLI;
39:
40: public ExecuteFileCommandExecutor(NaturalCLI naturalCLI) {
41: this .naturalCLI = naturalCLI;
42: }
43:
44: /* (non-Javadoc)
45: * @see org.naturalcli.ICommandExecutor#execute(java.lang.Object[])
46: */
47: @Override
48: public void execute(ParseResult parseResult) {
49: try {
50: String file_name = parseResult.getParameterValue(0)
51: .toString();
52: BufferedReader in = new BufferedReader(new FileReader(
53: file_name));
54: String command;
55: while ((command = in.readLine()) != null) {
56: if (command.startsWith(COMMENT))
57: continue;
58: this .naturalCLI.execute(command, 0);
59: }
60: in.close();
61: } catch (Exception e) {
62: throw new RuntimeException("Execution aborted", e);
63: }
64: }
65:
66: }
|