commit fdc9ee7eb813fd2a1717a34b4eabf32fdb0f72c7 from: leo date: Thu Jul 12 04:53:55 2007 UTC Minor bug fixes fixed bug in Applet not show menu bar commit - bd10750f26f440f44230f7aa116c8443223bf2df commit + fdc9ee7eb813fd2a1717a34b4eabf32fdb0f72c7 blob - bdc3bd619d36f05292b580b245c83868354af2d7 blob + 8012504a7493919667cd88244d2d9015304dcacf --- de/mud/jta/Applet.java +++ de/mud/jta/Applet.java @@ -31,17 +31,8 @@ import de.mud.jta.event.ReturnFocusRequest; import de.mud.jta.event.SocketRequest; import de.mud.jta.event.SoundListener; -import javax.swing.JApplet; -import javax.swing.JFrame; -import javax.swing.RootPaneContainer; -import java.awt.BorderLayout; -import java.awt.Button; -import java.awt.Component; -import java.awt.Menu; -import java.awt.MenuBar; -import java.awt.MenuItem; -import java.awt.MenuShortcut; -import java.awt.PrintJob; +import javax.swing.*; +import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -68,11 +59,11 @@ import java.util.Vector; * This is the Applet implementation for the software. It initializes * the system and adds all needed components, such as the telnet backend and * the terminal front end. - *

+ *

* Maintainer: Matthias L. Jugel * - * @version $Id$ * @author Matthias L. Jugel, Marcus Meissner + * @version $Id$ */ public class Applet extends JApplet { @@ -81,20 +72,32 @@ public class Applet extends JApplet { private String frameTitle = null; private RootPaneContainer appletFrame; - /** holds the defaults */ + /** + * holds the defaults + */ private Properties options = new Properties(); - /** hold the common part of the jta */ + /** + * hold the common part of the jta + */ private Common pluginLoader; - /** hold the host and port for our connection */ + /** + * hold the host and port for our connection + */ private String host, port; - /** disconnect on leave, this is to force applets to break the connection */ + /** + * disconnect on leave, this is to force applets to break the connection + */ private boolean disconnect = true; - /** connect on startup, this is to force applets to connect on detach */ + /** + * connect on startup, this is to force applets to connect on detach + */ private boolean connect = false; - /** close the window (if it exists) after the connection is lost */ + /** + * close the window (if it exists) after the connection is lost + */ private boolean disconnectCloseWindow = true; private Plugin focussedPlugin; @@ -110,7 +113,7 @@ public class Applet extends JApplet { if (pluginLoader == null) { try { options.load(Applet.class - .getResourceAsStream("/de/mud/jta/default.conf")); + .getResourceAsStream("/de/mud/jta/default.conf")); } catch (Exception e) { try { URL url = new URL(getCodeBase() + "default.conf"); @@ -119,7 +122,7 @@ public class Applet extends JApplet { System.err.println("jta: cannot load default.conf"); System.err.println("jta: try extracting it from the jar file"); System.err.println("jta: expected file here: " - + getCodeBase() + "default.conf"); + + getCodeBase() + "default.conf"); } } @@ -191,12 +194,12 @@ public class Applet extends JApplet { if ((new Boolean(options.getProperty("Applet.detach"))).booleanValue()) { if (frameTitle == null) { - appletFrame = (RootPaneContainer)new JFrame("jta: " + host + (port.equals("23")?"":" " + port)); + appletFrame = (RootPaneContainer) new JFrame("jta: " + host + (port.equals("23") ? "" : " " + port)); } else { - appletFrame = (RootPaneContainer)new JFrame(frameTitle); + appletFrame = (RootPaneContainer) new JFrame(frameTitle); } } else { - appletFrame = (RootPaneContainer)this; + appletFrame = (RootPaneContainer) this; } appletFrame.getContentPane().setLayout(new BorderLayout()); @@ -245,11 +248,11 @@ public class Applet extends JApplet { enable.invoke(privilegeManager, new Object[]{privileges.elementAt(i)}); System.out.println("Applet: access for '" + - privileges.elementAt(i) + "' allowed"); + privileges.elementAt(i) + "' allowed"); } catch (Exception e) { System.err.println("Applet: access for '" + - privileges.elementAt(i) + "' denied"); + privileges.elementAt(i) + "' denied"); } // set up the clipboard @@ -258,8 +261,8 @@ public class Applet extends JApplet { System.err.println("Applet: acquired system clipboard: " + clipboard); } catch (Exception e) { System.err.println("Applet: system clipboard access denied: " + - ((e instanceof InvocationTargetException) ? - ((InvocationTargetException) e).getTargetException() : e)); + ((e instanceof InvocationTargetException) ? + ((InvocationTargetException) e).getTargetException() : e)); // e.printStackTrace(); } finally { if (clipboard == null) { @@ -293,7 +296,7 @@ public class Applet extends JApplet { } else { if (frameTitle == null) ((JFrame) appletFrame) - .setTitle("jta: " + host + (port.equals("23")?"":" " + port)); + .setTitle("jta: " + host + (port.equals("23") ? "" : " " + port)); if ((new Boolean(options.getProperty("Applet.detach.fullscreen")) .booleanValue())) ((JFrame) appletFrame) @@ -302,7 +305,7 @@ public class Applet extends JApplet { ((JFrame) appletFrame).pack(); ((JFrame) appletFrame).show(); if (port == null || port.length() <= 0) - port = "23"; + port = "23"; getAppletContext().showStatus("Trying " + host + " " + port + " ..."); pluginLoader.broadcast(new SocketRequest(host, Integer.parseInt(port))); @@ -316,39 +319,39 @@ public class Applet extends JApplet { getContentPane().add("Center", close); // add a menu bar - MenuBar mb = new MenuBar(); - Menu file = new Menu("File"); - file.setShortcut(new MenuShortcut(KeyEvent.VK_F, true)); - MenuItem tmp; - file.add(tmp = new MenuItem("Connect")); + JMenuBar mb = new JMenuBar(); + JMenu file = new JMenu("File"); + file.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, 0)); + JMenuItem tmp; + file.add(tmp = new JMenuItem("Connect")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pluginLoader.broadcast(new SocketRequest(host, Integer.parseInt(port))); } }); - file.add(tmp = new MenuItem("Disconnect")); + file.add(tmp = new JMenuItem("Disconnect")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pluginLoader.broadcast(new SocketRequest()); } }); - file.add(new MenuItem("-")); - file.add(tmp = new MenuItem("Print")); + file.add(new JMenuItem("-")); + file.add(tmp = new JMenuItem("Print")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (pluginLoader.getComponents().get("Terminal") != null) { PrintJob printJob = appletFrame.getContentPane().getToolkit() - .getPrintJob((JFrame) appletFrame, "JTA Terminal", null); + .getPrintJob((JFrame) appletFrame, "JTA Terminal", null); ((Component) pluginLoader.getComponents().get("Terminal")) .print(printJob.getGraphics()); printJob.end(); } } }); - file.add(new MenuItem("-")); - file.add(tmp = new MenuItem("Exit")); + file.add(new JMenuItem("-")); + file.add(tmp = new JMenuItem("Exit")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ((JFrame) appletFrame).setVisible(false); @@ -358,9 +361,9 @@ public class Applet extends JApplet { }); mb.add(file); - Menu edit = new Menu("Edit"); - edit.setShortcut(new MenuShortcut(KeyEvent.VK_E, true)); - edit.add(tmp = new MenuItem("Copy")); + JMenu edit = new JMenu("Edit"); + edit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, 0)); + edit.add(tmp = new JMenuItem("Copy")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (debug > 2) @@ -369,7 +372,7 @@ public class Applet extends JApplet { ((VisualTransferPlugin) focussedPlugin).copy(clipboard); } }); - edit.add(tmp = new MenuItem("Paste")); + edit.add(tmp = new JMenuItem("Paste")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (debug > 2) @@ -384,13 +387,13 @@ public class Applet extends JApplet { names = menuList.keySet().iterator(); while (names.hasNext()) { String name = (String) names.next(); - Object o = menuList.get(name); - if (o instanceof Menu) mb.add((Menu) o); + Object o = menuList.get(name); + if (o instanceof JMenu) mb.add((JMenu) o); } - Menu help = new Menu("Help"); - help.setShortcut(new MenuShortcut(KeyEvent.VK_HELP, true)); - help.add(tmp = new MenuItem("General")); + JMenu help = new JMenu("Help"); + help.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0)); + help.add(tmp = new JMenuItem("General")); tmp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Help.show(appletFrame.getContentPane(), options.getProperty("Help.url")); @@ -401,7 +404,7 @@ public class Applet extends JApplet { // only add the menubar if the property is true if ((new Boolean(options.getProperty("Applet.detach.menuBar")) .booleanValue())) - ((JFrame) appletFrame).setMenuBar(mb); + ((JFrame) appletFrame).setJMenuBar(mb); // add window closing event handler try { @@ -451,7 +454,7 @@ public class Applet extends JApplet { }); } else - // if we have no external frame use this online status listener + // if we have no external frame use this online status listener pluginLoader.registerPluginListener(new OnlineStatusListener() { public void online() { if (debug > 0) System.err.println("Terminal: online"); @@ -493,6 +496,7 @@ public class Applet extends JApplet { /** * Override any properties that are found in the configuration files * with possible values found as applet parameters. + * * @param options the loaded configuration file properties */ private void parameterOverride(Properties options) { blob - 8812950b700b9e32bee964f3ed80e03f8f842e4d blob + 2e4b0fc442b8963819b1c5e8ef20b54f2a0034f6 --- de/mud/jta/plugin/SSH.java +++ de/mud/jta/plugin/SSH.java @@ -25,41 +25,37 @@ package de.mud.jta.plugin; -import de.mud.jta.Plugin; import de.mud.jta.FilterPlugin; +import de.mud.jta.Plugin; import de.mud.jta.PluginBus; import de.mud.jta.PluginConfig; import de.mud.jta.VisualPlugin; - import de.mud.jta.event.ConfigurationListener; -import de.mud.jta.event.SetWindowSizeListener; +import de.mud.jta.event.LocalEchoRequest; import de.mud.jta.event.OnlineStatusListener; +import de.mud.jta.event.SetWindowSizeListener; import de.mud.jta.event.TerminalTypeRequest; import de.mud.jta.event.WindowSizeRequest; -import de.mud.jta.event.LocalEchoRequest; -import de.mud.jta.event.SocketRequest; - import de.mud.ssh.SshIO; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionListener; import java.awt.event.ActionEvent; - +import java.awt.event.ActionListener; import java.io.IOException; /** * Secure Shell plugin for the JTA. This is a plugin * to be used instead of Telnet for secure remote terminal sessions over - * insecure networks. + * insecure networks. * Take a look at the package de.mud.ssh for further information * about ssh or look at the official ssh homepage: * http://www.ssh.fi/. - *

+ *

* Maintainer: Matthias L. Jugel * - * @version $Id$ * @author Matthias L. Jugel, Marcus Mei�ner + * @version $Id$ */ public class SSH extends Plugin implements FilterPlugin, VisualPlugin { @@ -80,19 +76,30 @@ public class SSH extends Plugin implements FilterPlugi // create a new telnet protocol handler handler = new SshIO() { - /** get the current terminal type */ + /** + * get the current terminal type + */ public String getTerminalType() { - return (String)bus.broadcast(new TerminalTypeRequest()); + return (String) bus.broadcast(new TerminalTypeRequest()); } - /** get the current window size */ + + /** + * get the current window size + */ public Dimension getWindowSize() { - return (Dimension)bus.broadcast(new WindowSizeRequest()); + return (Dimension) bus.broadcast(new WindowSizeRequest()); } - /** notify about local echo */ + + /** + * notify about local echo + */ public void setLocalEcho(boolean echo) { bus.broadcast(new LocalEchoRequest(echo)); } - /** write data to our back end */ + + /** + * write data to our back end + */ public void write(byte[] b) throws IOException { source.write(b); } @@ -101,90 +108,92 @@ public class SSH extends Plugin implements FilterPlugi bus.registerPluginListener(new ConfigurationListener() { public void setConfiguration(PluginConfig config) { user = config.getProperty("SSH", id, "user"); - pass = config.getProperty("SSH", id, "password"); + pass = config.getProperty("SSH", id, "password"); } }); bus.registerPluginListener(new SetWindowSizeListener() { public void setWindowSize(int columns, int rows) { try { - handler.setWindowSize(columns,rows); + handler.setWindowSize(columns, rows); } catch (java.io.IOException e) { System.err.println("IO Exception in set window size"); } } }); - // reset the protocol handler just in case :-) bus.registerPluginListener(new OnlineStatusListener() { public void online() { - if(pass == null) { + if (pass == null) { final Frame frame = new Frame("SSH User Authentication"); - Panel panel = new Panel(new GridLayout(3,1)); - panel.add(new Label("SSH Authorization required")); - frame.add("North", panel); - panel = new Panel(new GridLayout(2,2)); - final TextField login = new TextField(user, 10); - final TextField passw = new TextField(10); - login.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - passw.requestFocus(); - } - }); - passw.setEchoChar('*'); - panel.add(new Label("User name")); panel.add(login); - panel.add(new Label("Password")); panel.add(passw); - frame.add("Center", panel); - panel = new Panel(); - Button cancel = new Button("Cancel"); - Button ok = new Button("Login"); - ActionListener enter = new ActionListener() { - public void actionPerformed(ActionEvent evt) { - handler.setLogin(login.getText()); - handler.setPassword(passw.getText()); - frame.dispose(); - auth = true; - } - }; - ok.addActionListener(enter); - passw.addActionListener(enter); - cancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - frame.dispose(); - } - }); - panel.add(cancel); - panel.add(ok); - frame.add("South", panel); - - frame.pack(); - frame.show(); - frame.setLocation(frame.getToolkit().getScreenSize().width/2 - - frame.getSize().width/2, - frame.getToolkit().getScreenSize().height/2 - - frame.getSize().height/2); - if(user != null) { - passw.requestFocus(); - } - } else { - error(user+":"+pass); - handler.setLogin(user); - handler.setPassword(pass); - auth = true; - } + Panel panel = new Panel(new GridLayout(3, 1)); + panel.add(new Label("SSH Authorization required")); + frame.add("North", panel); + panel = new Panel(new GridLayout(2, 2)); + final TextField login = new TextField(user, 10); + final TextField passw = new TextField(10); + login.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + passw.requestFocus(); + } + }); + passw.setEchoChar('*'); + panel.add(new Label("User name")); + panel.add(login); + panel.add(new Label("Password")); + panel.add(passw); + frame.add("Center", panel); + panel = new Panel(); + Button cancel = new Button("Cancel"); + Button ok = new Button("Login"); + ActionListener enter = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + handler.setLogin(login.getText()); + handler.setPassword(passw.getText()); + frame.dispose(); + auth = true; + } + }; + ok.addActionListener(enter); + passw.addActionListener(enter); + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + frame.dispose(); + } + }); + panel.add(cancel); + panel.add(ok); + frame.add("South", panel); + + frame.pack(); + frame.show(); + frame.setLocation(frame.getToolkit().getScreenSize().width / 2 - + frame.getSize().width / 2, + frame.getToolkit().getScreenSize().height / 2 - + frame.getSize().height / 2); + if (user != null) { + passw.requestFocus(); + } + } else { + error(user + ":" + pass); + handler.setLogin(user); + handler.setPassword(pass); + auth = true; + } } + public void offline() { handler.disconnect(); - auth=false; - bus.broadcast(new SocketRequest()); + auth = false; + //bus.broadcast(new SocketRequest()); } }); } - public void setFilterSource(FilterPlugin source) { - if(debug>0) System.err.println("ssh: connected to: "+source); + public void setFilterSource(FilterPlugin source) { + if (debug > 0) System.err.println("ssh: connected to: " + source); this.source = source; } @@ -200,50 +209,51 @@ public class SSH extends Plugin implements FilterPlugi * as the encrypted information is usually smaller than its decrypted * pendant. So it will not read from the backend as long as there is * data in the buffer. + * * @param b the buffer where to read the decrypted data in * @return the amount of bytes actually read. */ public int read(byte[] b) throws IOException { // we don't want to read from the pipeline without authorization - while(!auth) try { + while (!auth) try { Thread.sleep(1000); - } catch(InterruptedException e) { + } catch (InterruptedException e) { e.printStackTrace(); } // Empty the buffer before we do anything else - if(buffer != null) { - int amount = ((buffer.length - pos) <= b.length) ? - buffer.length - pos : b.length; + if (buffer != null) { + int amount = ((buffer.length - pos) <= b.length) ? + buffer.length - pos : b.length; System.arraycopy(buffer, pos, b, 0, amount); - if(pos + amount < buffer.length) { + if (pos + amount < buffer.length) { pos += amount; - } else + } else buffer = null; return amount; } - + // now that the buffer is empty let's read more data and decrypt it int n = source.read(b); - if(n > 0) { + if (n > 0) { byte[] tmp = new byte[n]; System.arraycopy(b, 0, tmp, 0, n); pos = 0; buffer = handler.handleSSH(tmp); - if(debug > 0 && buffer != null && buffer.length > 0) - System.err.println("ssh: "+buffer); + if (debug > 0 && buffer != null && buffer.length > 0) + System.err.println("ssh: " + buffer); - if(buffer != null && buffer.length > 0) { - if(debug > 0) - System.err.println("ssh: incoming="+n+" now="+buffer.length); - int amount = buffer.length <= b.length ? buffer.length : b.length; + if (buffer != null && buffer.length > 0) { + if (debug > 0) + System.err.println("ssh: incoming=" + n + " now=" + buffer.length); + int amount = buffer.length <= b.length ? buffer.length : b.length; System.arraycopy(buffer, 0, b, 0, amount); - pos = n = amount; - if(amount == buffer.length) { - buffer = null; - pos = 0; - } + pos = n = amount; + if (amount == buffer.length) { + buffer = null; + pos = 0; + } } else return 0; } @@ -254,17 +264,18 @@ public class SSH extends Plugin implements FilterPlugi * Write data to the back end. This hands the data over to the ssh * protocol handler who encrypts the information and writes it to * the actual back end pipe. + * * @param b the unencrypted data to be encrypted and sent */ public void write(byte[] b) throws IOException { // no write until authorization is done - if(!auth) return; - for (int i=0;i \r */ - b[i] = 13; - break; - } + if (!auth) return; + for (int i = 0; i < b.length; i++) { + switch (b[i]) { + case 10: /* \n -> \r */ + b[i] = 13; + break; + } } handler.sendData(new String(b)); } blob - 7120d92f49fec7e5890bebe66c606255c60430b7 blob + 97f4043749e44f711108c3c1a4c2dd891a9d4a15 --- de/mud/jta/plugin/Script.java +++ de/mud/jta/plugin/Script.java @@ -25,15 +25,14 @@ package de.mud.jta.plugin; -import de.mud.jta.Plugin; import de.mud.jta.FilterPlugin; +import de.mud.jta.Plugin; import de.mud.jta.PluginBus; import de.mud.jta.PluginConfig; import de.mud.jta.event.ConfigurationListener; import de.mud.jta.event.OnlineStatusListener; import java.io.IOException; - import java.util.Vector; /** @@ -48,18 +47,22 @@ import java.util.Vector; * connect. * The script is very basic but is a very good example how to * write a plugin for JTA - Telnet/SSH for the JAVA(tm) platform. - *

+ *

* Maintainer: Matthias L. Jugel * - * @version $Id$ * @author Matthias L. Jugel, Marcus Mei�ner + * @version $Id$ */ public class Script extends Plugin implements FilterPlugin { - /** debugging level */ + /** + * debugging level + */ private final static int debug = 0; - /** the script after parsing, saved for reinitialization */ + /** + * the script after parsing, saved for reinitialization + */ private Vector savedScript; /** @@ -72,6 +75,7 @@ public class Script extends Plugin implements FilterPl public void online() { setup(savedScript); } + public void offline() { // ignore disconnection } @@ -81,48 +85,51 @@ public class Script extends Plugin implements FilterPl public void setConfiguration(PluginConfig config) { savedScript = new Vector(); String s = config.getProperty("Script", id, "script"); - if(s != null) { - // check if the script is stored in a file - if(s.charAt(0) == '@') { - Script.this.error("@file not implemented yet"); - } - // parse the script and set up - if(debug > 0) Script.this.error(s); - String pair[] = null; + if (s != null) { + // check if the script is stored in a file + if (s.charAt(0) == '@') { + Script.this.error("@file not implemented yet"); + } + // parse the script and set up + if (debug > 0) Script.this.error(s); + String pair[] = null; int old = -1, idx = s.indexOf('|'); - while(idx >= 0) { - if(pair == null) { - pair = new String[2]; + while (idx >= 0) { + if (pair == null) { + pair = new String[2]; pair[0] = s.substring(old + 1, idx); - if(debug > 0) System.out.print("match("+pair[0]+") -> "); - } else { - pair[1] = s.substring(old + 1, idx)+"\n"; - if(debug > 0) System.out.print(pair[1]); - savedScript.addElement(pair); - pair = null; - } + if (debug > 0) System.out.print("match(" + pair[0] + ") -> "); + } else { + pair[1] = s.substring(old + 1, idx) + "\n"; + if (debug > 0) System.out.print(pair[1]); + savedScript.addElement(pair); + pair = null; + } old = idx; idx = s.indexOf('|', old + 1); } - if(pair != null) { - pair[1] = s.substring(old + 1)+"\n"; - savedScript.addElement(pair); - if(debug > 0) System.out.print(pair[1]); - } else - Script.this.error("unmatched pairs of script elements"); - // set up the script - // setup(savedScript); + if (pair != null) { + pair[1] = s.substring(old + 1) + "\n"; + savedScript.addElement(pair); + if (debug > 0) System.out.print(pair[1]); + } else + Script.this.error("unmatched pairs of script elements"); + // set up the script + // setup(savedScript); } } }); } - /** holds the data source for input and output */ + /** + * holds the data source for input and output + */ protected FilterPlugin source; /** * Set the filter source where we can read data from and where to * write the script answer to. + * * @param plugin the filter plugin we use as source */ public void setFilterSource(FilterPlugin plugin) { @@ -135,14 +142,15 @@ public class Script extends Plugin implements FilterPl /** * Read an array of bytes from the back end and put it through the - * script parser to see if it matches. It will send the answer + * script parser to see if it matches. It will send the answer * immediately to the filter source if a match occurs. + * * @param b the array where to read the bytes in * @return the amount of bytes actually read */ public int read(byte[] b) throws IOException { int n = source.read(b); - if(n > 0) match(b, n); + if (n > 0) match(b, n); return n; } @@ -154,31 +162,33 @@ public class Script extends Plugin implements FilterPl // the actual scripting code follows: // ================================================================= - private int matchPos; // current position in the match - private Vector script; // the actual script - private byte[] match; // the current bytes to look for - private boolean done = true; // no script! + private int matchPos; // current position in the match + private Vector script; // the actual script + private byte[] match; // the current bytes to look for + private boolean done = true; // no script! /** * Setup the parser using the passed script. The script contains for * every element a two-element array of String where element zero * contains the match and element one the answer. + * * @param script the script */ private void setup(Vector script) { // clone script to make sure we do not change the original - this.script = (Vector)script.clone(); - if(debug > 0) - System.err.println("Script: script contains "+script.size()+" elements"); + this.script = (Vector) script.clone(); + if (debug > 0) + System.err.println("Script: script contains " + script.size() + " elements"); // If the first element is empty, just send the value string. - match = ((String[])this.script.firstElement())[0].getBytes(); + match = ((String[]) this.script.firstElement())[0].getBytes(); if (match.length == 0) { - try { - write(found()); - } catch (Exception e){ - // Ignore any errors here - }; + try { + write(found()); + } catch (Exception e) { + // Ignore any errors here + } + ; } reset(); @@ -189,18 +199,19 @@ public class Script extends Plugin implements FilterPl * Try to match the byte array s against the most current script match. * It will write the answer immediatly if the script matches and * will return instantly when all the script work is done. - * @param s the array of bytes to match against + * + * @param s the array of bytes to match against * @param length the amount of bytes in the array */ private void match(byte[] s, int length) throws IOException { - for(int i = 0; !done && i < length; i++) { - if(s[i] == match[matchPos]) { + for (int i = 0; !done && i < length; i++) { + if (s[i] == match[matchPos]) { // the whole thing matched so, return the match answer // and reset to use the next match - if(++matchPos >= match.length) + if (++matchPos >= match.length) write(found()); } else // if the current character did not match reset - reset(); + reset(); } } @@ -208,17 +219,18 @@ public class Script extends Plugin implements FilterPl * This method is called when a script match was found and will * setup the next match to be used and return the answer for the * just found one. + * * @return the answer to the found match */ private byte[] found() { - if(debug > 0) System.err.println("Script: found '"+new String(match)+"'"); + if (debug > 0) System.err.println("Script: found '" + new String(match) + "'"); // we have matched the string, so remember the answer ... - byte[] answer = ((String[])script.firstElement())[1].getBytes(); + byte[] answer = ((String[]) script.firstElement())[1].getBytes(); // remove the matched element script.removeElementAt(0); // set the next match if applicable - if(!script.isEmpty()) { - match = ((String[])script.firstElement())[0].getBytes(); + if (!script.isEmpty()) { + match = ((String[]) script.firstElement())[0].getBytes(); reset(); } else done = true;