commit - ebb2693161ba7d184d5ebb5e9ea90fd59b2cfbd4
commit + 77dcd624b30cb635d49857559171db6a4a952c32
blob - 9470f4b289340cacb4f8017a39c4bd9fa95560d3
blob + 14f0fd8f12319af35e37a9f861bf1fa3df9ed77d
--- de/mud/jta/Common.java
+++ de/mud/jta/Common.java
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
- * "The Java Telnet Application" is distributed in the hope that it will be
+ * "The Java Telnet Application" is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
*/
package de.mud.jta;
-import de.mud.jta.PluginLoader;
-import de.mud.jta.VisualPlugin;
-import de.mud.jta.Plugin;
import de.mud.jta.event.ConfigurationRequest;
-import de.mud.jta.event.SocketRequest;
-import java.util.Properties;
+import java.awt.*;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Properties;
import java.util.Vector;
-import java.util.Enumeration;
-import java.awt.Component;
-import java.awt.Menu;
-
/**
* The common part of the <B>The Java<SUP>tm</SUP> Telnet Application</B>
* is handled here. Mainly this includes the loading of the plugins and
System.out.println("** The Java(tm) Telnet Application");
System.out.println("** Version 2.0 for Java 1.1.x and Java 2");
System.out.println("** Copyright (c) 1996-2000 Matthias L. Jugel, "
- +"Marcus Meissner");
+ + "Marcus Meissner");
try {
- Version build =
- (Version)Class.forName("de.mud.jta.Build").newInstance();
- System.out.println("** Build: "+build.getDate());
- } catch(Exception e) {
+ Version build =
+ (Version) Class.forName("de.mud.jta.Build").newInstance();
+ System.out.println("** Build: " + build.getDate());
+ } catch (Exception e) {
System.out.println("** Build: patched or selfmade, no date");
System.err.println(e);
}
menus = new Hashtable();
Vector names = split(config.getProperty("plugins"), ',');
- if(names == null) {
+ if (names == null) {
System.err.println("jta: no plugins found! aborting ...");
return;
}
Enumeration e = names.elements();
- while(e.hasMoreElements()) {
- String name = (String)e.nextElement();
- String id = null; int idx;
- if((idx = name.indexOf("(")) > 1) {
- if(name.indexOf(")", idx) > idx)
+ while (e.hasMoreElements()) {
+ String name = (String) e.nextElement();
+ String id = null;
+ int idx;
+ if ((idx = name.indexOf("(")) > 1) {
+ if (name.indexOf(")", idx) > idx)
id = name.substring(idx + 1, name.indexOf(")", idx));
- else
- System.err.println("jta: missing ')' for plugin '"+name+"'");
+ else
+ System.err.println("jta: missing ')' for plugin '" + name + "'");
name = name.substring(0, idx);
}
- System.out.println("jta: loading plugin '"+name+"'"
- +(id != null && id.length() > 0 ?
- ", ID: '"+id+"'" : ""));
+ System.out.println("jta: loading plugin '" + name + "'"
+ + (id != null && id.length() > 0 ?
+ ", ID: '" + id + "'" : ""));
Plugin plugin = addPlugin(name, id);
- if(plugin == null) {
- System.err.println("jta: ignoring plugin '"+name+"'"
- +(id != null && id.length() > 0 ?
- ", ID: '"+id+"'" : ""));
- continue;
+ if (plugin == null) {
+ System.err.println("jta: ignoring plugin '" + name + "'"
+ + (id != null && id.length() > 0 ?
+ ", ID: '" + id + "'" : ""));
+ continue;
}
plugins.put(name, plugin);
- if(plugin instanceof VisualPlugin) {
- Component c = ((VisualPlugin)plugin).getPluginVisual();
- if(c != null) components.put(name+(id != null ? "("+id+")" : ""), c);
- Menu menu = ((VisualPlugin)plugin).getPluginMenu();
- if(menu != null) menus.put(name+(id != null ? "("+id+")" : ""), menu);
+ if (plugin instanceof VisualPlugin) {
+ Component c = ((VisualPlugin) plugin).getPluginVisual();
+ if (c != null) components.put(name + (id != null ? "(" + id + ")" : ""), c);
+ Menu menu = ((VisualPlugin) plugin).getPluginMenu();
+ if (menu != null) menus.put(name + (id != null ? "(" + id + ")" : ""), menu);
}
}
* @return a vector containing the path
*/
private static Vector getPluginPath(String path) {
- if(path == null)
+ if (path == null)
path = DEFAULT_PATH;
- // I am not sure that this is desirable, as the applet administrator
- // might use UNIX and thus ':' but the applet user might have a Windows
- // system and thus uses ';' and thus the whole thing will collapse.
- // String separator = System.getProperty("path.separator");
- // if(separator == null)
- // separator = ":";
+// I am not sure that this is desirable, as the applet administrator
+// might use UNIX and thus ':' but the applet user might have a Windows
+// system and thus uses ';' and thus the whole thing will collapse.
+// String separator = System.getProperty("path.separator");
+// if(separator == null)
+// separator = ":";
return split(path, ':');
}
* @return an array of strings
*/
public static Vector split(String s, char separator) {
- if(s == null) return null;
+ if (s == null) return null;
Vector v = new Vector();
int old = -1, idx = s.indexOf(separator);
- while(idx >= 0) {
+ while (idx >= 0) {
v.addElement(s.substring(old + 1, idx));
old = idx;
idx = s.indexOf(separator, old + 1);
- }
+ }
v.addElement(s.substring(old + 1));
return v;
}
blob - /dev/null
blob + a9e481f495e150e0c10c9d834bcfad5846ef98c1 (mode 644)
--- /dev/null
+++ de/mud/jta/plugin/Capture.java
+/*
+ * This file is part of "The Java Telnet Application".
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * "The Java Telnet Application" is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+package 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 java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.DataOutputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+
+/**
+ * A capture plugin that captures data and stores it in a
+ * defined location. The location is specified as a plugin
+ * configuration option Capture.url and can be used in
+ * conjunction with the UploadServlet from the tools directory.
+ * <P>
+ * <B>Maintainer:</B> Matthias L. Jugel
+ *
+ * @version $Id$
+ * @author Matthias L. Jugel, Marcus Meißner
+ */
+public class Capture extends Plugin
+ implements FilterPlugin, VisualPlugin {
+
+ // this enables or disables the compilation of menu entries
+ private final static boolean personalJava = false;
+
+ // for debugging output
+ private final static int debug = 1;
+
+ /** The remote storage URL */
+ protected URL remoteURL = null;
+
+ /** The plugin menu */
+ protected Menu menu;
+
+ /** Whether the capture is currently enabled or not */
+ protected boolean captureEnabled = false;
+
+ // menu entries and the viewing frame/textarea
+ private MenuItem start, stop, clear, save;
+ private Frame frame;
+ private TextArea textArea;
+
+ /**
+ * Initialize the Capture plugin. This sets up the menu entries
+ * and registers the plugin on the bus.
+ */
+ public Capture(final PluginBus bus, final String id) {
+ super(bus, id);
+
+ if (!personalJava) {
+
+ // set up viewing frame
+ frame = new Frame("Java Telnet Applet: Captured Text");
+ frame.setLayout(new BorderLayout());
+ frame.add(textArea = new TextArea(24, 80), BorderLayout.CENTER);
+ textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ frame.setVisible(false);
+ }
+ });
+ frame.pack();
+
+ // an error dialogue, in case the upload fails
+ final Dialog dialog = new Dialog(frame);
+ dialog.setLayout(new BorderLayout());
+ dialog.add(new TextField("Cannot store data on remote server!"));
+ Button close = new Button("Close Dialog");
+ dialog.add(close);
+ close.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.setVisible(false);
+ }
+ });
+
+ // set up menu entries
+ menu = new Menu("Capture");
+ start = new MenuItem("Start");
+ start.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (debug > 0) System.out.println("Capture: start capturing");
+ captureEnabled = true;
+ start.setEnabled(false);
+ stop.setEnabled(true);
+ }
+ });
+ menu.add(start);
+
+ stop = new MenuItem("Stop");
+ stop.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (debug > 0) System.out.println("Capture: stop capturing");
+ captureEnabled = false;
+ start.setEnabled(true);
+ stop.setEnabled(false);
+
+ }
+ });
+ stop.setEnabled(false);
+ menu.add(stop);
+
+ clear = new MenuItem("Clear");
+ clear.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (debug > 0) System.out.println("Capture: cleared captured text");
+ textArea.setText("");
+ }
+ });
+ menu.add(clear);
+ menu.addSeparator();
+
+ MenuItem view = new MenuItem("View/Hide Text");
+ view.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (debug > 0) System.out.println("view/hide text: " + frame.isVisible());
+ if (frame.isVisible()) {
+ frame.setVisible(false);
+ } else {
+ frame.setVisible(true);
+ }
+ }
+ });
+ menu.add(view);
+
+ save = new MenuItem("Save Protocol");
+ save.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (debug > 0) System.err.println("Capture: storing text: " + remoteURL);
+ try {
+ URLConnection urlConnection = remoteURL.openConnection();
+ DataOutputStream out;
+ DataInputStream in;
+
+ // Let the RTS know that we want to do output.
+ urlConnection.setDoInput(true);
+ // Let the RTS know that we want to do output.
+ urlConnection.setDoOutput(true);
+ // No caching, we want the real thing.
+ urlConnection.setUseCaches(false);
+ // Specify the content type.
+ urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+ // Send POST output.
+
+ // send the data to the url receiver ...
+ out = new DataOutputStream(urlConnection.getOutputStream());
+ String content = "content=" + URLEncoder.encode(textArea.getText());
+ if(debug > 0) System.err.println("Capture: " + content);
+ out.writeBytes(content);
+ out.flush();
+ out.close();
+
+ // retrieve response from the remote host and display it.
+ if(debug > 0) System.err.println("Capture: reading response");
+ in = new DataInputStream(urlConnection.getInputStream());
+ String str;
+ while (null != ((str = in.readLine()))) {
+ System.out.println("Capture: "+str);
+ }
+ in.close();
+
+ } catch (IOException ioe) {
+ dialog.setVisible(true);
+ System.err.println("Capture: cannot store text on remote server: " + remoteURL);
+ ioe.printStackTrace();
+ }
+ if (debug > 0) System.err.println("Capture: storage complete: " + remoteURL);
+ }
+ });
+ save.setEnabled(false);
+ menu.add(save);
+ } // !personalJava
+
+ // configure the remote URL
+ bus.registerPluginListener(new ConfigurationListener() {
+ public void setConfiguration(PluginConfig config) {
+ String tmp;
+ if ((tmp = config.getProperty("Capture", id, "url")) != null) {
+ try {
+ remoteURL = new URL(tmp);
+ save.setLabel("Save to: " + tmp);
+ save.setEnabled(true);
+ } catch (MalformedURLException e) {
+ System.err.println("capture url invalid: " + e);
+ }
+ }
+ }
+ });
+ }
+
+ // this is where we get the data from (left side in plugins list)
+ protected FilterPlugin source;
+
+ /**
+ * The filter source is the plugin where Capture is connected to.
+ * In the list of plugins this is the one to the left.
+ * @param source the next plugin
+ */
+ public void setFilterSource(FilterPlugin source) {
+ if (debug > 0) System.err.println("Capture: connected to: " + source);
+ this.source = source;
+ }
+
+ /**
+ * Read data from the left side plugin, capture the content and
+ * pass it on to the next plugin which called this method.
+ * @param b the buffer to store data into
+ */
+ public int read(byte[] b) throws IOException {
+ int size = source.read(b);
+ if (captureEnabled && size > 0) {
+ String tmp = new String(b, 0, size);
+ textArea.append(tmp);
+ }
+ return size;
+ }
+
+ /**
+ * Write data to the backend but also append it to the capture buffer.
+ * @param b the buffer with data to write
+ */
+ public void write(byte[] b) throws IOException {
+ if (captureEnabled) {
+ textArea.append(new String(b));
+ }
+ source.write(b);
+ }
+
+ /**
+ * The Capture plugin has no visual component that is embedded in
+ * the JTA main frame, so this returns null.
+ * @return always null
+ */
+ public Component getPluginVisual() {
+ return null;
+ }
+
+ /**
+ * The Capture menu for the menu bar as configured in the constructor.
+ * @return the drop down menu
+ */
+ public Menu getPluginMenu() {
+ return menu;
+ }
+
+}
blob - /dev/null
blob + 0badc41bff523892dc5abd29ecde0f2080356415 (mode 644)
--- /dev/null
+++ tools/UploadServlet.java
+/*
+ * This file is part of "The Java Telnet Application".
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * "The Java Telnet Application" is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+
+/**
+ * Example UploadServlet for usage with the Capture plugin.
+ *
+ * @author Matthias L. Jugel
+ * @version $Id$
+ */
+public class UploadServlet extends HttpServlet {
+
+
+ /**
+ * Accept POST requests only.
+ * Retrieve the data from text/x-www-urlencoded request.
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+
+
+ res.setContentType("text/html");
+ PrintWriter out = res.getWriter();
+ out.println("<HTML>");
+ out.println("<HEAD><TITLE>JTA Example Upload</TITLE></HEAD>");
+ out.println("<BODY>");
+ out.println("<H1>JTA Example Upload</H1>");
+
+ out.println("<H3>Request Parameters:</H3><PRE>");
+
+ Enumeration enum = req.getParameterNames();
+ while (enum.hasMoreElements()) {
+ String name = (String) enum.nextElement();
+ String values[] = req.getParameterValues(name);
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ out.println(name + " (" + i + "): " + values[i]);
+ }
+ }
+ }
+
+ // place your storage code here to store the data in a file
+ // or data base
+
+ out.println("</PRE>");
+ out.println("</BODY></HTML>");
+ }
+}
\ No newline at end of file