Programmer's Guide for implementing AniTa for JAVA as a "Bean"

Version 2.9.0.0

Updated 6 April 2017


Add AniTa for JAVA to your project

To add AniTa for JAVA to your project, place janita.jar into a "library" catalog and then add janita.jar as a library. Libraries are normally added in the projects properties.

 


Add a constructor for AniTa for JAVA to your program

The AniTa for JAVA constructor takes no parameters.

private janita my_janita = new janita();

 


Initialize AniTa for JAVA

 
public void bean(boolean is_application, String config_filename)

To initialize AniTa, call the bean() routine. 

is_application should be true if your program is running as an application.

config_filename should be the name of the .ini file where AniTa will find its configuration. A string with no contents ("") will cause AniTa to use the default name.

 
public void setAutoLogon(String host[], String user[])

To enable auto-login set other values for the host and user parameters use the following. This causes the parameters in the configuration file to be ignored.

Connect AniTa as a bean over SSH

Since version 2.9.0.0 it is possible to connect AniTa as a bean over SSH
Examples:

User/password authorization:
janitaInstance.bean(true, "janita.ini");
String[] prompts = new String[] {"", "", "#"};   //the first two strings irrelevant when running SSH
String[] replies = new String[] {"root", "129834756","ls"};
janitaInstance.setAutoLogon(prompts, replies);
janitaInstance.connectBean(host);


Public key authorization:
janitaInstance.bean(true, "janita.ini");
String[] prompts = new String[] {"", "", "$"};   //the first two strings irrelevant when running SSH
String[] replies = new String[] {"admin", "theAdminPhrase", "ls"};  //empty string when no passphrase
janitaInstance.setAutoLogon(prompts, replies);
janitaInstance.connectBean(host, byte[] key);    //keep the newline characters

 


Methods in AniTa for JAVA

public boolean isConnected( )

Returns true if AniTa has a session connected to the host.

 
public String peekScreen(int column, int row, int len)

Returns the contents of the AniTa screen, starting at the specified column (where 1 is the first column) and row (where 1 is the first line). The string will contain the number of characters specified in len, or until then end of the line, whichever is less.

 
public void requestTheFocus( )

Gives the foucus to AniTa.

 
public void sendString(String s)

Causes AniTa to send the specified string to the host. Note that if the string contains macros, these will be executed. 

 


AniTa for JAVA Events

AniTa events will be sent to all registered JanitaEventListeners. These are added and removed using addJanitaEventListener and removeJanitaEventListener. The type of events being notified must be set using the setNotifyXxxxx routines.

 

public void setNotifyConnect(boolean b)

The connect event is fired when AniTa has connected to the host. It will have reason set to 0 and description set to connect.

 

public void setNotifyDisconnect(boolean b)

The disconnect event is fired when AniTa has disconnected from the host. It will have reason set to 0 and description set to disconnect.

 

public void setNotifyHost(boolean b)

The Host event is fired when AniTa has received a special escape sequence from the host. This has the formats:

<esc> [ 4 0 y DescriptionString <esc> backslash

<esc> [ 4 0 ; ReasonNumber y DescriptionString <esc> backslash

The description will be set to the string specified, the reason will be set to the number specified, or to 1 if not.

 

public void setNotifyReceive(boolean b)

The receive event is fired when AniTa has received any data from the host. It will have reason set to 0 and description set to receive.

 

public void setNotifyMacro(boolean b)

The macro event is fired when AniTa has executed the notify macro. This has the format:

%notify%DescriptionString 

The description will be set to the string specified, the reason will be set to 0.

 

public void addJanitaEventListener(JanitaEventListener l)

Used to enable the receiving of events to the specified JanitaEventListener.

 

public void removeJanitaEventListener(JanitaEventListener l)

Used to disable the receiving of events to the specified JanitaEventListener.

 

JanitaEvent

The JanitaEvent contains two items, a reason and a description.

public JanitaEvent(Object src, int reason, String description)
    
public int getReason()

public String getDescription()

public String toString()

JanitaEventListener 

Every JanitaEventListener must implement an onJanitaEvent routine, to which each of the events will be sent.

public interface JanitaEventListener extends EventListener

public void onJanitaEvent(JanitaEvent evt);

 

AniTa for JAVA Key Events

AniTa keyboard events will be sent to all registered JanitaKeyEventListeners. These are added and removed using addJanitaKeyEventListener and removeJanitaKeyEventListener. The type of keyboard events being notified must be set using the addJanitaKeyEventKeys and remove JanitaKeyEventKeys routines.

 
public void addJanitaKeyEventListener(JanitaKeyEventListener l)

Used to enable the receiving of events to the specified JanitaKeyEventListener.

 

public void removeJanitaKeyEventListener(JanitaKeyEventListener l)

Used to disable the receiving of events to the specified JanitaKeyEventListener.

 

public void addJanitaKeyEventKeys(String keycode)

Used to enable sending JanitaKeyEvents for the specified keycode. Keycodes proceeded by a minus sign will be notified, and AniTa will do no further processing on that key.

 

public void removeJanitaKeyEventKeys(String keycode)

Used to disable sending JanitaKeyEvents for the specified keycode. Note that this must be the same keycode object as used in the add, and not just a string that contains the same value.

 

JanitaKeyEvent

The JanitaKeyEvent contains three items, a character, a keycode and a modifier. For details see the standard KeyEvent.

public JanitaKeyEvent(Object src, char key_char, int key_code, int key_modifiers)
 
public int getKeyCode()
 
public int getModifiers()
 
public char getKeyChar()
 
public String toString()
 

JanitaKeyEventListener

Every JanitaKeyEventListener must implement an onJanitaKeyEvent routine, to which each of the events will be sent.

public interface JanitaKeyEventListener extends EventListener

public void onJanitaKeyEvent(JanitaKeyEvent evt);