View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *******************************************************************************/
16  package it.jnrpe.server.console;
17  
18  import java.io.IOException;
19  
20  import jline.console.ConsoleReader;
21  import it.jnrpe.JNRPE;
22  
23  public abstract class ConsoleCommand implements IConsoleCommand {
24      private final JNRPE jnrpeInstance;
25      private final ConsoleReader console;
26      
27      public ConsoleCommand(ConsoleReader consoleReader, JNRPE jnrpe) {
28          jnrpeInstance = jnrpe;
29          console = consoleReader;
30      }
31      
32      protected JNRPE getJNRPE() {
33          return jnrpeInstance;
34      }
35      
36      protected ConsoleReader getConsole() {
37          return console;
38      }
39      
40      protected void println(String msg) throws IOException {
41      	getConsole().println(msg);
42      }
43      
44      protected String highlight(final String msg) {
45          if (msg == null){
46              throw new IllegalArgumentException("Message can't be null");
47          }
48          
49          return new StringBuffer("\u001B[1m")
50              .append(msg)
51              .append("\u001B[0m").toString();
52      }
53  }