You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2003/11/20 23:10:19 UTC
cvs commit: jakarta-log4j/src/java/org/apache/log4j/chainsaw FileMenu.java FileLoadAction.java
psmith 2003/11/20 14:10:19
Modified: src/java/org/apache/log4j/chainsaw FileMenu.java
FileLoadAction.java
Log:
added the ability to load remote URLs into Chainsaw
Revision Changes Path
1.2 +114 -31 jakarta-log4j/src/java/org/apache/log4j/chainsaw/FileMenu.java
Index: FileMenu.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/FileMenu.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileMenu.java 25 Jun 2003 04:05:21 -0000 1.1
+++ FileMenu.java 20 Nov 2003 22:10:19 -0000 1.2
@@ -1,4 +1,53 @@
/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
+/*
* @author Paul Smith <ps...@apache.org>
*
*/
@@ -15,58 +64,92 @@
import javax.swing.JSeparator;
import javax.swing.KeyStroke;
- /**
- * The complete File Menu for the main GUI, containing
- * the Load, Save, Close Welcome Tab, and Exit actions
- *
- * @author Paul Smith <ps...@apache.org>
- * @author Scott Deboy <sd...@apache.org>
- */
-class FileMenu extends JMenu {
-
+/**
+ * The complete File Menu for the main GUI, containing
+ * the Load, Save, Close Welcome Tab, and Exit actions
+ *
+ * @author Paul Smith <ps...@apache.org>
+ * @author Scott Deboy <sd...@apache.org>
+ */
+class FileMenu extends JMenu {
private Action exitAction;
private Action loadLog4JAction;
private Action loadUtilLoggingAction;
+ private Action remoteLog4JAction;
+ private Action remoteUtilLoggingAction;
private Action saveAction;
private Action saveSettingsAction;
-
+
public FileMenu(final LogUI logUI) {
super("File");
setMnemonic(KeyEvent.VK_F);
-
- loadLog4JAction = new FileLoadAction(logUI, "org.apache.log4j.xml.XMLDecoder", "Load Log4J File...");
- loadUtilLoggingAction = new FileLoadAction(logUI, "org.apache.log4j.xml.UtilLoggingXMLDecoder", "Load Java Util File...");
+
+ loadLog4JAction =
+ new FileLoadAction(
+ logUI, "org.apache.log4j.xml.XMLDecoder", "Load Log4J File...", false);
+ loadUtilLoggingAction =
+ new FileLoadAction(
+ logUI, "org.apache.log4j.xml.UtilLoggingXMLDecoder",
+ "Load Java Util File...", false);
+
+ remoteLog4JAction =
+ new FileLoadAction(
+ logUI, "org.apache.log4j.xml.XMLDecoder", "Load Remote Log4J File...",
+ true);
+ remoteUtilLoggingAction =
+ new FileLoadAction(
+ logUI, "org.apache.log4j.xml.UtilLoggingXMLDecoder",
+ "Load Remote Java Util File...", true);
+
saveAction = new FileSaveAction(logUI);
-
+
JMenuItem loadLog4JFile = new JMenuItem(loadLog4JAction);
JMenuItem loadUtilLoggingFile = new JMenuItem(loadUtilLoggingAction);
+ JMenuItem remoteLog4JFile = new JMenuItem(remoteLog4JAction);
+ JMenuItem remoteUtilLoggingFile = new JMenuItem(remoteUtilLoggingAction);
JMenuItem saveFile = new JMenuItem(saveAction);
- exitAction = new AbstractAction() {
-
- public void actionPerformed(ActionEvent e) {
- logUI.exit();
- }
- };
-
- exitAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK));
+ exitAction =
+ new AbstractAction() {
+ public void actionPerformed(ActionEvent e) {
+ logUI.exit();
+ }
+ };
+
+ exitAction.putValue(
+ Action.ACCELERATOR_KEY,
+ KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK));
exitAction.putValue(Action.SHORT_DESCRIPTION, "Exits the Application");
exitAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X));
exitAction.putValue(Action.NAME, "Exit");
-
+
JMenuItem menuItemExit = new JMenuItem(exitAction);
-
+
add(loadLog4JFile);
add(loadUtilLoggingFile);
+ addSeparator();
+ add(remoteLog4JFile);
+ add(remoteUtilLoggingFile);
+ addSeparator();
add(saveFile);
- add(new JSeparator());
+ addSeparator();
add(menuItemExit);
}
-
- Action getLog4JFileOpenAction() { return loadLog4JAction;}
- Action getUtilLoggingJFileOpenAction() { return loadUtilLoggingAction;}
- Action getFileSaveAction() { return saveAction;}
- Action getExitAction() { return exitAction;}
-
+
+ Action getLog4JFileOpenAction() {
+ return loadLog4JAction;
+ }
+
+ Action getUtilLoggingJFileOpenAction() {
+ return loadUtilLoggingAction;
+ }
+
+ Action getFileSaveAction() {
+ return saveAction;
+ }
+
+ Action getExitAction() {
+ return exitAction;
+ }
}
1.4 +70 -30 jakarta-log4j/src/java/org/apache/log4j/chainsaw/FileLoadAction.java
Index: FileLoadAction.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/FileLoadAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FileLoadAction.java 2 Nov 2003 19:53:47 -0000 1.3
+++ FileLoadAction.java 20 Nov 2003 22:10:19 -0000 1.4
@@ -50,6 +50,7 @@
package org.apache.log4j.chainsaw;
import org.apache.log4j.Decoder;
+import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.icons.ChainsawIcons;
import java.awt.event.ActionEvent;
@@ -59,6 +60,8 @@
import java.io.File;
import java.io.IOException;
+import java.net.URL;
+
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
@@ -67,6 +70,7 @@
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.filechooser.FileFilter;
@@ -77,9 +81,11 @@
*
* @author Paul Smith <ps...@apache.org>
* @author Scott Deboy <sd...@apache.org>
- *
+ *
*/
class FileLoadAction extends AbstractAction {
+ private static final Logger LOG = Logger.getLogger(FileLoadAction.class);
+
/**
* This action must have a reference to a LogUI
* window so that it can append the events it loads
@@ -88,10 +94,12 @@
Decoder decoder = null;
private LogUI parent;
private JFileChooser chooser = null;
+ private boolean remoteURL = false;
- public FileLoadAction(LogUI parent, String decoder, String title) {
+ public FileLoadAction(
+ LogUI parent, String decoder, String title, boolean isRemoteURL) {
super(title);
-
+ remoteURL = isRemoteURL;
try {
Class c = Class.forName(decoder);
@@ -124,43 +132,75 @@
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
- if( chooser == null ){
- chooser = new JFileChooser();
- }
+ String name = "";
+ URL url = null;
- chooser.setDialogTitle("Load Events from XML file...");
+ if (!remoteURL) {
+ if (chooser == null) {
+ chooser = new JFileChooser();
+ }
- chooser.setAcceptAllFileFilterUsed(true);
+ chooser.setDialogTitle("Load Events from XML file...");
- chooser.setFileFilter(
- new FileFilter() {
- public boolean accept(File f) {
- return (f.getName().toLowerCase().endsWith(".xml")|| f.isDirectory());
- }
+ chooser.setAcceptAllFileFilterUsed(true);
- public String getDescription() {
- return "XML files (*.xml)";
- }
- });
+ chooser.setFileFilter(
+ new FileFilter() {
+ public boolean accept(File f) {
+ return (f.getName().toLowerCase().endsWith(".xml")
+ || f.isDirectory());
+ }
- chooser.showOpenDialog(parent);
+ public String getDescription() {
+ return "XML files (*.xml)";
+ }
+ });
- File selectedFile = chooser.getSelectedFile();
+ chooser.showOpenDialog(parent);
- if (selectedFile != null) {
- Map additionalProperties = new HashMap();
- additionalProperties.put(
- ChainsawConstants.LOG4J_MACHINE_KEY,
- "localhost:" + selectedFile.getName());
- decoder.setAdditionalProperties(additionalProperties);
+ File selectedFile = chooser.getSelectedFile();
try {
- Vector events = decoder.decode(selectedFile);
- parent.handler.appendBatch(events);
- } catch (IOException e1) {
- // TODO Handle the error with a nice msg
- e1.printStackTrace();
+ url = selectedFile.toURL();
+ name = "localhost:" + selectedFile.getName();
+ } catch (Exception ex) {
+ // TODO: handle exception
+ }
+ } else {
+ String urltext =
+ JOptionPane.showInputDialog(
+ parent,
+ "<html>Please type in the <b>complete</b> URL to the remote XML source.</html>",
+ "file://");
+
+ if (urltext != null) {
+ try {
+ url = new URL(urltext);
+ } catch (Exception ex) {
+ JOptionPane.showMessageDialog(
+ parent, "'" + urltext + "' is not a valid URL.");
+ }
}
+ }
+
+ if (url != null) {
+ Map additionalProperties = new HashMap();
+ additionalProperties.put(ChainsawConstants.LOG4J_MACHINE_KEY, name);
+ decoder.setAdditionalProperties(additionalProperties);
+
+ final URL urlToUse = url;
+ new Thread(
+ new Runnable() {
+ public void run() {
+ try {
+ Vector events = decoder.decode(urlToUse);
+ parent.handler.appendBatch(events);
+ } catch (IOException e1) {
+ // TODO Handle the error with a nice msg
+ LOG.error(e1);
+ }
+ }
+ }).start();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org