From e43da93a79e5fbb729329c0262107566c832c955 Mon Sep 17 00:00:00 2001 From: axelcl Date: Mon, 25 Oct 2004 18:43:03 +0000 Subject: [PATCH] inital plugin from webtools project --- .../.classpath | 7 + .../.project | 28 + .../build.properties | 10 + .../plugin.properties | 12 + .../plugin.xml | 37 ++ .../schema/contentFilters.exsd | 127 ++++ .../schema/protocolAdapters.exsd | 123 ++++ .../schema/requestListeners.exsd | 115 ++++ .../phpdt/monitor/core/IContentFilter.java | 25 + .../phpdt/monitor/core/IContentFilterDelegate.java | 19 + .../sourceforge/phpdt/monitor/core/IMonitor.java | 33 ++ .../phpdt/monitor/core/IMonitorListener.java | 21 + .../phpdt/monitor/core/IMonitorWorkingCopy.java | 27 + .../phpdt/monitor/core/IProtocolAdapter.java | 19 + .../monitor/core/IProtocolAdapterDelegate.java | 20 + .../sourceforge/phpdt/monitor/core/IRequest.java | 109 ++++ .../phpdt/monitor/core/IRequestListener.java | 36 ++ .../phpdt/monitor/core/MonitorCore.java | 186 ++++++ .../phpdt/monitor/core/internal/AcceptThread.java | 123 ++++ .../phpdt/monitor/core/internal/Connection.java | 31 + .../phpdt/monitor/core/internal/ContentFilter.java | 58 ++ .../phpdt/monitor/core/internal/DefaultThread.java | 73 +++ .../phpdt/monitor/core/internal/IMemento.java | 192 +++++++ .../phpdt/monitor/core/internal/Monitor.java | 115 ++++ .../monitor/core/internal/MonitorManager.java | 302 ++++++++++ .../phpdt/monitor/core/internal/MonitorPlugin.java | 156 +++++ .../monitor/core/internal/MonitorWorkingCopy.java | 91 +++ .../monitor/core/internal/ProtocolAdapter.java | 51 ++ .../phpdt/monitor/core/internal/Request.java | 263 +++++++++ .../core/internal/TCPIPProtocolAdapter.java | 30 + .../phpdt/monitor/core/internal/Trace.java | 53 ++ .../phpdt/monitor/core/internal/XMLMemento.java | 448 +++++++++++++++ .../monitor/core/internal/http/HTTPConnection.java | 110 ++++ .../core/internal/http/HTTPProtocolAdapter.java | 32 + .../monitor/core/internal/http/HTTPRequest.java | 84 +++ .../monitor/core/internal/http/HTTPThread.java | 602 ++++++++++++++++++++ .../.classpath | 7 + .../net.sourceforge.phpeclipse.monitor.ui/.project | 28 + .../build.properties | 10 + .../icons/clcl16/clear.gif | Bin 0 -> 553 bytes .../icons/clcl16/httpHeader.gif | Bin 0 -> 556 bytes .../icons/clcl16/sortResponseTime.gif | Bin 0 -> 573 bytes .../icons/cview16/monitorView.gif | Bin 0 -> 590 bytes .../icons/dlcl16/clear.gif | Bin 0 -> 326 bytes .../icons/dlcl16/httpHeader.gif | Bin 0 -> 327 bytes .../icons/dlcl16/sortResponseTime.gif | Bin 0 -> 339 bytes .../icons/elcl16/clear.gif | Bin 0 -> 553 bytes .../icons/elcl16/httpHeader.gif | Bin 0 -> 556 bytes .../icons/elcl16/sortResponseTime.gif | Bin 0 -> 573 bytes .../icons/eview16/monitorView.gif | Bin 0 -> 590 bytes .../icons/obj16/host.gif | Bin 0 -> 568 bytes .../icons/obj16/monitorOff.gif | Bin 0 -> 209 bytes .../icons/obj16/monitorOn.gif | Bin 0 -> 545 bytes .../icons/obj16/tcp.gif | Bin 0 -> 586 bytes .../plugin.properties | 68 +++ .../plugin.xml | 71 +++ .../schema/viewers.exsd | 128 +++++ .../phpdt/monitor/ui/IContentViewer.java | 46 ++ .../phpdt/monitor/ui/internal/ContextIds.java | 25 + .../monitor/ui/internal/MonitorComposite.java | 254 ++++++++ .../ui/internal/MonitorContentProvider.java | 73 +++ .../phpdt/monitor/ui/internal/MonitorDialog.java | 266 +++++++++ .../monitor/ui/internal/MonitorPreferencePage.java | 111 ++++ .../ui/internal/MonitorPrefrencesDialog.java | 82 +++ .../ui/internal/MonitorTableLabelProvider.java | 127 ++++ .../phpdt/monitor/ui/internal/MonitorUIPlugin.java | 225 ++++++++ .../phpdt/monitor/ui/internal/RequestListener.java | 30 + .../phpdt/monitor/ui/internal/SWTUtil.java | 77 +++ .../phpdt/monitor/ui/internal/Trace.java | 51 ++ .../monitor/ui/internal/view/FilterAction.java | 27 + .../monitor/ui/internal/view/IViewerManager.java | 82 +++ .../internal/view/MonitorTreeContentProvider.java | 213 +++++++ .../monitor/ui/internal/view/MonitorView.java | 540 ++++++++++++++++++ .../ui/internal/view/TreeLabelProvider.java | 108 ++++ .../monitor/ui/internal/view/ViewerManager.java | 226 ++++++++ .../monitor/ui/internal/viewers/ByteViewer.java | 79 +++ .../monitor/ui/internal/viewers/HeaderViewer.java | 202 +++++++ .../monitor/ui/internal/viewers/ImageViewer.java | 95 +++ .../monitor/ui/internal/viewers/XMLViewer.java | 227 ++++++++ 79 files changed, 7246 insertions(+), 0 deletions(-) create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/.project create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/plugin.properties create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/schema/contentFilters.exsd create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/schema/protocolAdapters.exsd create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/schema/requestListeners.exsd create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilter.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilterDelegate.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitor.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorListener.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorWorkingCopy.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapter.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapterDelegate.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequest.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequestListener.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/MonitorCore.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/AcceptThread.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Connection.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ContentFilter.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/DefaultThread.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/IMemento.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Monitor.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorManager.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorPlugin.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorWorkingCopy.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ProtocolAdapter.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Request.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/TCPIPProtocolAdapter.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Trace.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/XMLMemento.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPConnection.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPProtocolAdapter.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPRequest.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPThread.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/.project create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/clear.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/httpHeader.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/sortResponseTime.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/cview16/monitorView.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/clear.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/httpHeader.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/sortResponseTime.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/elcl16/clear.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/elcl16/httpHeader.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/elcl16/sortResponseTime.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/eview16/monitorView.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/host.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/monitorOff.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/monitorOn.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/tcp.gif create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/plugin.properties create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/schema/viewers.exsd create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/IContentViewer.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/ContextIds.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorComposite.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorContentProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorDialog.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPreferencePage.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPrefrencesDialog.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorTableLabelProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorUIPlugin.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/RequestListener.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/SWTUtil.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/Trace.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/FilterAction.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/IViewerManager.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorTreeContentProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorView.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/TreeLabelProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/ViewerManager.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ByteViewer.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/HeaderViewer.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ImageViewer.java create mode 100644 archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/XMLViewer.java diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/.classpath b/archive/net.sourceforge.phpeclipse.monitor.core/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/.project b/archive/net.sourceforge.phpeclipse.monitor.core/.project new file mode 100644 index 0000000..fe0dafd --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/.project @@ -0,0 +1,28 @@ + + + net.sourceforge.phpeclipse.monitor.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/build.properties b/archive/net.sourceforge.phpeclipse.monitor.core/build.properties new file mode 100644 index 0000000..32a2141 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/build.properties @@ -0,0 +1,10 @@ +bin.includes = plugin.xml,\ + *.jar,\ + monitorcore.jar,\ + plugin.properties,\ + .options +jars.compile.order = +src.includes = build.properties,\ + schema/ +output.monitorcore.jar = bin/ +source.monitorcore.jar = monitorcore/ diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/plugin.properties b/archive/net.sourceforge.phpeclipse.monitor.core/plugin.properties new file mode 100644 index 0000000..3b31ca7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/plugin.properties @@ -0,0 +1,12 @@ +pluginName=Monitor +providerName=IBM + +# --------------- Errors --------------- +errorPortInUse=The TCP/IP monitor could not start because the port is in use. + +extensionPointProtocolAdapters=Protocol Adapters +extensionPointContentFilters=Content Filters +extensionPointRequestListeners=Request Listeners + +HTTP=HTTP +TCPIP=TCP/IP \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/plugin.xml b/archive/net.sourceforge.phpeclipse.monitor.core/plugin.xml new file mode 100644 index 0000000..f536ed5 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/plugin.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/schema/contentFilters.exsd b/archive/net.sourceforge.phpeclipse.monitor.core/schema/contentFilters.exsd new file mode 100644 index 0000000..49fd747 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/schema/contentFilters.exsd @@ -0,0 +1,127 @@ + + + + + + + + + This extension point is used to filter content received in a monitor. + + + + + + + + + + + + a fully qualified identifier of the target extension point + + + + + + + an optional identifier of the extension instance + + + + + + + an optional name of the extension instance + + + + + + + + + + + + + + + + + + + specifies a unique identifier for this extension point + + + + + + + specifies the fully qualified name of a Java class that implements <samp>net.sourceforge.phpeclipse.monitor.core.IContentFilterDelegate</samp>. +Content filter instances of this type will delegate to instances of this class. + + + + + + + + + + a translatable name used to identify the filter + + + + + + + a integer used to order filters relative to each other + + + + + + + + + + + + The following is an example of a content filter extension point: + +<p> +<pre> + <extension point="net.sourceforge.phpeclipse.monitor.core.contentFilter"> + <filter + id="com.example.ExampleIdentifier" + name="%exampleName" + class="com.example.ExampleContentFilter"/> + </extension> +</pre> + + + + + + + + + Value of the attribute <b>class</b> must be a fully qualified name of a Java class that implements the interface <b>org.eclipse.monitor.core.IContentFilterDelegate</b>. + + + + + + + + + Copyright (c) 2000, 2003 IBM Corporation and others.<br> +All rights reserved. This program and the accompanying materials are made +available under the terms of the Common Public License v1.0 which accompanies +this distribution, and is available at +<a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a> + + + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/schema/protocolAdapters.exsd b/archive/net.sourceforge.phpeclipse.monitor.core/schema/protocolAdapters.exsd new file mode 100644 index 0000000..f6ae97a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/schema/protocolAdapters.exsd @@ -0,0 +1,123 @@ + + + + + + + + + This extension point is used to provide an adapter for a new protocol (e.g. HTTP). This allows different types of protocols to be monitored. + + + + + + + + + + + + a fully qualified identifier of the target extension point + + + + + + + an optional identifier of the extension instance + + + + + + + an optional name of the extension instance + + + + + + + + + + + + + + + + + + + specifies a unique identifier for this extension point + + + + + + + specifies the fully qualified name of the Java class that implements <samp>net.sourceforge.phpeclipse.monitor.core.IProtocolAdapter</samp> +Protocol adapter instances of this type will delegate to instances of this class. + + + + + + + + + + a translatable name used to identify the protocol adapter + + + + + + + + + + + + The following is an example of a protocol adapter extension point: + +<p> +<pre> +<extension point="net.sourceforge.phpeclipse.monitor.core.protocolAdapters"> + <protocolAdapter + id="TCPIP" + class="com.example.TCPIPProtocolAdapter" + name="%TCPIP"/> +</extension> +</pre> +</p> + +In the example above, + + + + + + + + + Value of the attribute <b>class</b> must be a fully qualified name of a Java class that implements the interface <b>net.sourceforge.phpeclipse.monitor.core.IProtocolAdapterDelegate</b>. + + + + + + + + + Copyright (c) 2000, 2003 IBM Corporation and others.<br> +All rights reserved. This program and the accompanying materials are made +available under the terms of the Common Public License v1.0 which accompanies +this distribution, and is available at +<a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a> + + + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/schema/requestListeners.exsd b/archive/net.sourceforge.phpeclipse.monitor.core/schema/requestListeners.exsd new file mode 100644 index 0000000..cf4c0c5 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/schema/requestListeners.exsd @@ -0,0 +1,115 @@ + + + + + + + + + This extension point is used to listen for new monitor traffic (requests), or changes to existing requests. The extension point will be called whenever the monitor adds, changes, or removes a request. + + + + + + + + + + + + a fully qualified identifier of the target extension point + + + + + + + an optional identifier of the extension instance + + + + + + + an optional name of the extension instance + + + + + + + + + + + + + + + + + + + specifies a unique identifier for this extension point + + + + + + + specifies the fully qualified name of the Java class that implements <samp>net.sourceforge.phpdt.monitor.core.IRequestListener</samp> +RequestListener instances of this type will delegate to instances of this class. + + + + + + + + + + + + + + + The following is an example of a request listener extension point: + +<p> +<pre> +<extension point="net.sourceforge.phpdt.monitor.core.requestListeners"> + <requestListener + id="com.example.requestListener" + class="com.example.MyRequestListener"/> +</extension> +</pre> +</p> + +In the example above, + + + + + + + + + Value of the attribute <b>class</b> must be a fully qualified name of a Java class that implements the interface <b>net.sourceforge.phpdt.monitor.core.IRequestListener</b>. + + + + + + + + + Copyright (c) 2000, 2003 IBM Corporation and others.<br> +All rights reserved. This program and the accompanying materials are made +available under the terms of the Common Public License v1.0 which accompanies +this distribution, and is available at +<a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a> + + + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilter.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilter.java new file mode 100644 index 0000000..06e8b35 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilter.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; + +import java.io.IOException; +/** + * + */ +public interface IContentFilter { + public String getId(); + + public String getName(); + + public int getOrder(); + + public byte[] filter(IRequest request, boolean isRequest, byte[] b) throws IOException; +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilterDelegate.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilterDelegate.java new file mode 100644 index 0000000..5e6a6fd --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IContentFilterDelegate.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; + +import java.io.IOException; +/** + * + */ +public interface IContentFilterDelegate { + public byte[] filter(IRequest request, boolean isRequest, byte[] b) throws IOException; +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitor.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitor.java new file mode 100644 index 0000000..6effe53 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitor.java @@ -0,0 +1,33 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; +/** + * + */ +public interface IMonitor { + public String getId(); + + public String getRemoteHost(); + + public int getRemotePort(); + + public int getLocalPort(); + + public IProtocolAdapter getProtocolAdapter(); + + public boolean isRunning(); + + public void delete(); + + public boolean isWorkingCopy(); + + public IMonitorWorkingCopy getWorkingCopy(); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorListener.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorListener.java new file mode 100644 index 0000000..7e12601 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorListener.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; +/** + * + */ +public interface IMonitorListener { + public void monitorAdded(IMonitor monitor); + + public void monitorChanged(IMonitor monitor); + + public void monitorRemoved(IMonitor monitor); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorWorkingCopy.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorWorkingCopy.java new file mode 100644 index 0000000..f7f0c05 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IMonitorWorkingCopy.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; +/** + * + */ +public interface IMonitorWorkingCopy extends IMonitor { + public void setId(String id); + + public void setRemoteHost(String host); + + public void setRemotePort(int port); + + public void setLocalPort(int port); + + public void setProtocolAdapter(IProtocolAdapter type); + + public IMonitor save(); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapter.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapter.java new file mode 100644 index 0000000..04b96b1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapter.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; +/** + * + */ +public interface IProtocolAdapter { + public String getId(); + + public String getName(); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapterDelegate.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapterDelegate.java new file mode 100644 index 0000000..1394d59 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IProtocolAdapterDelegate.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; + +import java.io.IOException; +import java.net.Socket; +/** + * + */ +public interface IProtocolAdapterDelegate { + public void parse(IMonitor monitor, Socket in, Socket out) throws IOException; +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequest.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequest.java new file mode 100644 index 0000000..b60f970 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequest.java @@ -0,0 +1,109 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; + +import java.util.Date; +/** + * + */ +public interface IRequest { + public static final byte TRANSPORT = 1; + public static final byte CONTENT = 2; + public static final byte ALL = 3; + + /** + * Return the type of the request. + * + * @return net.sourceforge.phpdt.monitor.core.IType + */ + public IProtocolAdapter getType(); + + /** + * Return the date/time of this request. + * + * @return java.util.Date + */ + public Date getDate(); + + /** + * Returns the local port. + * + * @return int + */ + public int getLocalPort(); + + /** + * Returns the remote host. + * + * @return java.lang.String + */ + public String getRemoteHost(); + + /** + * Returns the remote port. + * + * @return int + */ + public int getRemotePort(); + + /** + * Returns the request as a byte array. + * + * @return byte[] + */ + public byte[] getRequest(byte type); + + /** + * Returns the response as a byte array. + * + * @return byte[] + */ + public byte[] getResponse(byte type); + + /** + * Returns the response time in milliseconds. + * + * @return long + */ + public long getResponseTime(); + + /** + * Returns a label for this request. + * + * @return java.lang.String + */ + public String getLabel(); + + /** + * + */ + public void addProperty(String key, Object value); + + /** + * + */ + public String getStringProperty(String key); + + /** + * + */ + public Integer getIntegerProperty(String key); + + /** + * + */ + public Object getObjectProperty(String key); + + /** + * + */ + public void fireChangedEvent(); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequestListener.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequestListener.java new file mode 100644 index 0000000..9e3dc96 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/IRequestListener.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; +/** + * A listener for changes to the requests. + */ +public interface IRequestListener { + /** + * The given request has been added to the list. + * + * @param rr + */ + public void requestAdded(IRequest rr); + + /** + * The given request has been changed. + * + * @param rr + */ + public void requestChanged(IRequest rr); + + /** + * The given request is been removed from the list. + * + * @param rr + */ + public void requestRemoved(IRequest rr); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/MonitorCore.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/MonitorCore.java new file mode 100644 index 0000000..13d92ea --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/MonitorCore.java @@ -0,0 +1,186 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; +import java.util.List; + +import net.sourceforge.phpdt.monitor.core.internal.MonitorManager; +import net.sourceforge.phpdt.monitor.core.internal.MonitorPlugin; +import net.sourceforge.phpdt.monitor.core.internal.Trace; +/** + * + */ +public class MonitorCore { + public static String TCPIP_PROTOCOL_ID = "TCPIP"; + public static String HTTP_PROTOCOL_ID = "HTTP"; + + private static MonitorManager manager = MonitorManager.getInstance(); + + private static final String lineSeparator = System.getProperty("line.separator"); + + /** + * Return a list of all the existing monitors. + * + * @return java.util.List + */ + public static List getMonitors() { + return manager.getMonitors(); + } + + /** + * Create a new monitor. + * + * @return working copy + */ + public static IMonitorWorkingCopy createMonitor() { + return manager.createMonitor(); + } + + /** + * Start the given monitor. + * + * @param monitor + * @throws Exception + */ + public static void startMonitor(IMonitor monitor) throws Exception { + manager.startMonitor(monitor); + } + + /** + * Stop the given monitor. + * + * @param monitor + */ + public static void stopMonitor(IMonitor monitor) { + manager.stopMonitor(monitor); + } + + /** + * Return the protocol adapters. + * + * @return array of protocol adapters + */ + public static IProtocolAdapter[] getProtocolAdapters() { + return MonitorPlugin.getInstance().getProtocolAdapters(); + } + + /** + * Return the protocol adapter with the given id. + * + * @return protocol adapter + */ + public static IProtocolAdapter getProtocolAdapter(String id) { + return MonitorPlugin.getInstance().getProtocolAdapter(id); + } + + /** + * Return the content filters. + * + * @return array of content filters + */ + public static IContentFilter[] getContentFilters() { + return MonitorPlugin.getInstance().getContentFilters(); + } + + /** + * Return the content filter with the given id. + * + * @return content filter + */ + public static IContentFilter getContentFilter(String id) { + return MonitorPlugin.getInstance().getContentFilter(id); + } + + /** + * Add monitor listener. + * + * @param listener + */ + public static void addMonitorListener(IMonitorListener listener) { + manager.addMonitorListener(listener); + } + + /** + * Remove monitor listener. + * + * @param listener + */ + public static void removeMonitorListener(IMonitorListener listener) { + manager.removeMonitorListener(listener); + } + + /** + * Return all requests. + * + * @return + */ + public static List getRequests() { + return manager.getRequests(); + } + + /** + * Remove all requests. + */ + public static void removeAllRequests() { + manager.removeAllRequests(); + } + + /** + * Add request listener. + * + * @param listener + */ + public static void addRequestListener(IRequestListener listener) { + manager.addRequestListener(listener); + } + + /** + * Remove request listener. + * + * @param listener + */ + public static void removeRequestListener(IRequestListener listener) { + manager.removeRequestListener(listener); + } + + /** + * Parse the given bytes into String form. + * + * @param b + * @return + */ + public static String parse(byte[] b) { + if (b == null) + return ""; + + ByteArrayInputStream bin = new ByteArrayInputStream(b); + BufferedReader br = new BufferedReader(new InputStreamReader(bin)); + StringBuffer sb = new StringBuffer(); + try { + String s = br.readLine(); + + while (s != null) { + sb.append(s); + s = br.readLine(); + if (s != null) + sb.append(lineSeparator); + } + sb.append(lineSeparator); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error parsing input", e); + } + + return sb.toString(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/AcceptThread.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/AcceptThread.java new file mode 100644 index 0000000..0b2d08d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/AcceptThread.java @@ -0,0 +1,123 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.InterruptedIOException; +import java.net.*; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +/** + * The actual TCP/IP monitoring server. This is a thread that + * listens on a port and relays a call to another server. + */ +public class AcceptThread { + protected IMonitor monitor; + + protected boolean alive = true; + protected ServerSocket serverSocket; + + protected Thread thread; + + class ServerThread extends Thread { + /** + * Actual running of the server proxy. + */ + public void run() { + // create a new server socket + try { + serverSocket = new ServerSocket(monitor.getLocalPort()); + serverSocket.setSoTimeout(2000); + + Trace.trace(Trace.FINEST, "Monitoring localhost:" + monitor.getLocalPort() + " -> " + monitor.getRemoteHost() + ":" + monitor.getRemotePort()); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not start monitoring"); + return; + } + + while (alive) { + try { + // accept the connection from the client + Socket localSocket = serverSocket.accept(); + + // connect to the remote server + Socket remoteSocket = new Socket(monitor.getRemoteHost(), monitor.getRemotePort()); + + // relay the call through + ProtocolAdapter adapter = (ProtocolAdapter) monitor.getProtocolAdapter(); + adapter.parse(monitor, localSocket, remoteSocket); + } catch (InterruptedIOException e) { + // do nothing + } catch (Exception e) { + if (alive) + Trace.trace(Trace.SEVERE, "Error while monitoring", e); + } + } + } + } + + /** + * ServerMonitorThread constructor comment. + */ + public AcceptThread(IMonitor monitor) { + super(); + this.monitor = monitor; + } + + public void startServer() { + if (thread != null) + return; + thread = new ServerThread(); + thread.setDaemon(true); + thread.start(); + } + + public boolean isRunning() { + return (thread != null); + } + + /** + * Correctly close the server socket and shut down the server. + */ + public void stopServer() { + try { + alive = false; + thread = null; + serverSocket.close(); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error stopping server", e); + } + } + + /** + * Returns true if this port is in use. + * + * @return boolean + * @param port int + */ + public static boolean isPortInUse(int port) { + ServerSocket s = null; + try { + s = new ServerSocket(port); + } catch (SocketException e) { + return true; + } catch (Exception e) { + return true; + } finally { + if (s != null) { + try { + s.close(); + } catch (Exception e) { } + } + } + + return false; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Connection.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Connection.java new file mode 100644 index 0000000..ef7eadc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Connection.java @@ -0,0 +1,31 @@ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.net.Socket; +/** + * + */ +public class Connection { + protected Socket in; + protected Socket out; + + public Connection(Socket in, Socket out) { + this.in = in; + this.out = out; + } + + public void close() { + Trace.trace(Trace.FINEST, "Closing connection"); + try { + in.getOutputStream().flush(); + in.shutdownInput(); + in.shutdownOutput(); + + out.getOutputStream().flush(); + out.shutdownInput(); + out.shutdownOutput(); + Trace.trace(Trace.FINEST, "Connection closed"); + } catch (Exception ex) { + Trace.trace(Trace.WARNING, "Error closing connection " + this + " " + ex.getMessage()); + } + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ContentFilter.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ContentFilter.java new file mode 100644 index 0000000..f682619 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ContentFilter.java @@ -0,0 +1,58 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.IOException; + +import net.sourceforge.phpdt.monitor.core.IContentFilter; +import net.sourceforge.phpdt.monitor.core.IContentFilterDelegate; +import net.sourceforge.phpdt.monitor.core.IRequest; + +import org.eclipse.core.runtime.IConfigurationElement; +/** + * + */ +public class ContentFilter implements IContentFilter { + protected IConfigurationElement element; + protected IContentFilterDelegate delegate; + + protected ContentFilter(IConfigurationElement element) { + this.element = element; + } + + public String getId() { + return element.getAttribute("id"); + } + + public int getOrder() { + try { + return Integer.parseInt(element.getAttribute("order")); + } catch (Exception e) { + return 0; + } + } + + public String getName() { + return element.getAttribute("name"); + } + + public byte[] filter(IRequest request, boolean isRequest, byte[] b) throws IOException { + if (delegate == null) { + try { + delegate = (IContentFilterDelegate) element.createExecutableExtension("class"); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not create content filter delegate: " + getId(), e); + return new byte[0]; + } + } + return delegate.filter(request, isRequest, b); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/DefaultThread.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/DefaultThread.java new file mode 100644 index 0000000..bd8c2a3 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/DefaultThread.java @@ -0,0 +1,73 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.*; +/** + * Monitor server I/O thread. + */ +public class DefaultThread extends Thread { + private static final int BUFFER = 2048; + protected InputStream in; + protected OutputStream out; + protected boolean isRequest; + + protected Connection conn; + protected Request request; + + /** + * MonitorThread constructor comment. + */ + public DefaultThread(Connection conn, Request request, InputStream in, OutputStream out, boolean isRequest) { + super(); + this.conn = conn; + this.request = request; + this.in = in; + this.out = out; + this.isRequest = isRequest; + setPriority(Thread.NORM_PRIORITY + 1); + setDaemon(true); + } + + /** + * Listen for input, save it, and pass to the output stream. + */ + public void run() { + try { + byte[] b = new byte[BUFFER]; + int n = in.read(b); + while (n > 0) { + out.write(b, 0, n); + if (b != null && n > 0) { + byte[] x = null; + if (n == BUFFER) + x = b; + else { + x = new byte[n]; + System.arraycopy(b, 0, x, 0, n); + } + if (isRequest) + request.addToRequest(x); + else + request.addToResponse(x); + } + n = in.read(b); + Thread.yield(); + } + out.flush(); + } catch (IOException e) { + } finally { + request.fireChangedEvent(); + if (!isRequest) + conn.close(); + } + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/IMemento.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/IMemento.java new file mode 100644 index 0000000..25f0e77 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/IMemento.java @@ -0,0 +1,192 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.util.List; +/** + * Interface to a memento used for saving the important state of an object + * in a form that can be persisted in the file system. + *

+ * Mementos were designed with the following requirements in mind: + *

    + *
  1. Certain objects need to be saved and restored across platform sessions. + *
  2. + *
  3. When an object is restored, an appropriate class for an object might not + * be available. It must be possible to skip an object in this case.
  4. + *
  5. When an object is restored, the appropriate class for the object may be + * different from the one when the object was originally saved. If so, the + * new class should still be able to read the old form of the data.
  6. + *
+ *

+ *

+ * Mementos meet these requirements by providing support for storing a + * mapping of arbitrary string keys to primitive values, and by allowing + * mementos to have other mementos as children (arranged into a tree). + * A robust external storage format based on XML is used. + *

+ * The key for an attribute may be any alpha numeric value. However, the + * value of TAG_ID is reserved for internal use. + *

+ * This interface is not intended to be implemented by clients. + *

+ * + * @see IPersistableElement + * @see IElementFactory + */ +public interface IMemento { + /** + * Special reserved key used to store the memento id + * (value "org.eclipse.ui.id"). + * + * @see #getId + */ + public static final String TAG_ID = "IMemento.internal.id"; //$NON-NLS-1$ + + /** + * Creates a new child of this memento with the given type. + *

+ * The getChild and getChildren methods + * are used to retrieve children of a given type. + *

+ * + * @param type the type + * @return a new child memento + * @see #getChild + * @see #getChildren + */ + public IMemento createChild(String type); + + /** + * Creates a new child of this memento with the given type and id. + * The id is stored in the child memento (using a special reserved + * key, TAG_ID) and can be retrieved using getId. + *

+ * The getChild and getChildren methods + * are used to retrieve children of a given type. + *

+ * + * @param type the type + * @param id the child id + * @return a new child memento with the given type and id + * @see #getId + */ + public IMemento createChild(String type, String id); + + /** + * Returns the first child with the given type id. + * + * @param type the type id + * @return the first child with the given type + */ + public IMemento getChild(String type); + + /** + * Returns all children with the given type id. + * + * @param type the type id + * @return the list of children with the given type + */ + public IMemento[] getChildren(String type); + + /** + * Returns the floating point value of the given key. + * + * @param key the key + * @return the value, or null if the key was not found or was found + * but was not a floating point number + */ + public Float getFloat(String key); + + /** + * Returns the id for this memento. + * + * @return the memento id, or null if none + * @see #createChild(java.lang.String,java.lang.String) + */ + public String getId(); + + /** + * Returns the name for this memento. + * + * @return the memento name, or null if none + * @see #createChild(java.lang.String,java.lang.String) + */ + public String getName(); + + /** + * Returns the integer value of the given key. + * + * @param key the key + * @return the value, or null if the key was not found or was found + * but was not an integer + */ + public Integer getInteger(String key); + + /** + * Returns the string value of the given key. + * + * @param key the key + * @return the value, or null if the key was not found or was found + * but was not an integer + */ + public String getString(String key); + + /** + * Returns the boolean value of the given key. + * + * @param key the key + * @return the value, or null if the key was not found or was found + * but was not a boolean + */ + public Boolean getBoolean(String key); + + public List getNames(); + + /** + * Sets the value of the given key to the given floating point number. + * + * @param key the key + * @param value the value + */ + public void putFloat(String key, float value); + + /** + * Sets the value of the given key to the given integer. + * + * @param key the key + * @param value the value + */ + public void putInteger(String key, int value); + + /** + * Sets the value of the given key to the given boolean value. + * + * @param key the key + * @param value the value + */ + public void putBoolean(String key, boolean value); + + /** + * Copy the attributes and children from memento + * to the receiver. + * + * @param memento the IMemento to be copied. + */ + public void putMemento(IMemento memento); + + /** + * Sets the value of the given key to the given string. + * + * @param key the key + * @param value the value + */ + public void putString(String key, String value); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Monitor.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Monitor.java new file mode 100644 index 0000000..4271d1c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Monitor.java @@ -0,0 +1,115 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import net.sourceforge.phpdt.monitor.core.*; +/** + * + */ +public class Monitor implements IMonitor { + private static final String MEMENTO_ID = "id"; + private static final String MEMENTO_LOCAL_PORT = "local-port"; + private static final String MEMENTO_REMOTE_HOST = "remote-host"; + private static final String MEMENTO_REMOTE_PORT = "remote-port"; + private static final String MEMENTO_TYPE_ID = "type-id"; + + protected String id; + protected String remoteHost; + protected int remotePort = 80; + protected int localPort = 80; + protected IProtocolAdapter type; + + public Monitor() { + type = MonitorPlugin.getInstance().getDefaultType(); + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitor#getId() + */ + public String getId() { + return id; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitor#getRemoteHost() + */ + public String getRemoteHost() { + return remoteHost; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitor#getRemotePort() + */ + public int getRemotePort() { + return remotePort; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitor#getLocalPort() + */ + public int getLocalPort() { + return localPort; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitor#isHTTPEnabled() + */ + public IProtocolAdapter getProtocolAdapter() { + return type; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitor#isRunning() + */ + public boolean isRunning() { + return MonitorManager.getInstance().isRunning(this); + } + + public void delete() { + MonitorManager.getInstance().removeMonitor(this); + } + + public boolean isWorkingCopy() { + return false; + } + + public IMonitorWorkingCopy getWorkingCopy() { + return new MonitorWorkingCopy(this); + } + + protected void setInternal(IMonitor monitor) { + id = monitor.getId(); + remoteHost = monitor.getRemoteHost(); + remotePort = monitor.getRemotePort(); + localPort = monitor.getLocalPort(); + type = monitor.getProtocolAdapter(); + } + + protected void save(IMemento memento) { + memento.putString(MEMENTO_ID, id); + memento.putString(MEMENTO_TYPE_ID, type.getId()); + memento.putInteger(MEMENTO_LOCAL_PORT, localPort); + memento.putString(MEMENTO_REMOTE_HOST, remoteHost); + memento.putInteger(MEMENTO_REMOTE_PORT, remotePort); + } + + protected void load(IMemento memento) { + id = memento.getString(MEMENTO_ID); + type = MonitorPlugin.getInstance().getProtocolAdapter(memento.getString(MEMENTO_TYPE_ID)); + Integer temp = memento.getInteger(MEMENTO_LOCAL_PORT); + if (temp != null) + localPort = temp.intValue(); + remoteHost = memento.getString(MEMENTO_REMOTE_HOST); + temp = memento.getInteger(MEMENTO_REMOTE_PORT); + if (temp != null) + remotePort = temp.intValue(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorManager.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorManager.java new file mode 100644 index 0000000..f846947 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorManager.java @@ -0,0 +1,302 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import net.sourceforge.phpdt.monitor.core.*; + +import org.eclipse.core.runtime.Preferences; +/** + * + */ +public class MonitorManager { + private static final int ADD = 0; + private static final int CHANGE = 1; + private static final int REMOVE = 2; + + // monitors + protected List monitors; + protected Map threads = new HashMap(); + + protected List monitorListeners = new ArrayList(); + + // requests + protected List requests = new ArrayList(); + + protected List requestListeners = new ArrayList(); + + private Preferences.IPropertyChangeListener pcl; + protected boolean ignorePreferenceChanges = false; + + protected static MonitorManager instance; + + public static MonitorManager getInstance() { + if (instance == null) + instance = new MonitorManager(); + return instance; + } + + private MonitorManager() { + loadMonitors(); + + pcl = new Preferences.IPropertyChangeListener() { + public void propertyChange(Preferences.PropertyChangeEvent event) { + if (ignorePreferenceChanges) + return; + String property = event.getProperty(); + if (property.equals("monitors")) { + loadMonitors(); + } + } + }; + + MonitorPlugin.getInstance().getPluginPreferences().addPropertyChangeListener(pcl); + } + + protected void dispose() { + MonitorPlugin.getInstance().getPluginPreferences().removePropertyChangeListener(pcl); + } + + public IMonitorWorkingCopy createMonitor() { + return new MonitorWorkingCopy(); + } + + public List getMonitors() { + return new ArrayList(monitors); + } + + protected void addMonitor(IMonitor monitor) { + if (!monitors.contains(monitor)) + monitors.add(monitor); + fireMonitorEvent(monitor, ADD); + saveMonitors(); + } + + protected boolean isRunning(IMonitor monitor) { + return (threads.get(monitor) != null); + } + + public void startMonitor(IMonitor monitor) throws Exception { + if (!monitors.contains(monitor)) + return; + + if (AcceptThread.isPortInUse(monitor.getLocalPort())) + throw new Exception(MonitorPlugin.getString("%errorPortInUse")); + + AcceptThread thread = new AcceptThread(monitor); + thread.startServer(); + threads.put(monitor, thread); + } + + public void stopMonitor(IMonitor monitor) { + if (!monitors.contains(monitor)) + return; + + AcceptThread thread = (AcceptThread) threads.get(monitor); + if (thread != null) { + thread.stopServer(); + threads.remove(monitor); + } + } + + protected void removeMonitor(IMonitor monitor) { + if (monitor.isRunning()) + stopMonitor(monitor); + monitors.remove(monitor); + fireMonitorEvent(monitor, REMOVE); + saveMonitors(); + } + + protected void monitorChanged(IMonitor monitor) { + fireMonitorEvent(monitor, CHANGE); + saveMonitors(); + } + + /** + * Add monitor listener. + * + * @param listener + */ + public void addMonitorListener(IMonitorListener listener) { + monitorListeners.add(listener); + } + + /** + * Remove monitor listener. + * + * @param listener + */ + public void removeMonitorListener(IMonitorListener listener) { + monitorListeners.remove(listener); + } + + /** + * Fire a monitor event. + * @param rr + * @param type + */ + protected void fireMonitorEvent(IMonitor monitor, int type) { + Object[] obj = monitorListeners.toArray(); + + int size = obj.length; + for (int i = 0; i < size; i++) { + IMonitorListener listener = (IMonitorListener) obj[i]; + if (type == ADD) + listener.monitorAdded(monitor); + else if (type == CHANGE) + listener.monitorChanged(monitor); + else if (type == REMOVE) + listener.monitorRemoved(monitor); + } + } + + /** + * Returns a list of the current requests. + * + * @return java.util.List + */ + public List getRequests() { + return requests; + } + + /** + * Add a new request response pair. + * + * @param pair org.eclipse.tcpip.monitor.RequestResponse + */ + public void addRequest(IRequest rr) { + if (requests.contains(rr)) + return; + + requests.add(rr); + fireRequestEvent(rr, ADD); + } + + public void requestChanged(IRequest rr) { + fireRequestEvent(rr, CHANGE); + } + + public void removeRequest(IRequest rr) { + if (!requests.contains(rr)) + return; + + requests.remove(rr); + fireRequestEvent(rr, REMOVE); + } + + public void removeAllRequests() { + int size = requests.size(); + IRequest[] rrs = new IRequest[size]; + requests.toArray(rrs); + + for (int i = 0; i < size; i++) { + removeRequest(rrs[i]); + } + } + + /** + * Add request listener. + * + * @param listener + */ + public void addRequestListener(IRequestListener listener) { + requestListeners.add(listener); + } + + /** + * Remove request listener. + * + * @param listener + */ + public void removeRequestListener(IRequestListener listener) { + requestListeners.remove(listener); + } + + /** + * Fire a request event. + * @param rr + * @param type + */ + protected void fireRequestEvent(IRequest rr, int type) { + int size = requestListeners.size(); + IRequestListener[] xrl = MonitorPlugin.getInstance().getRequestListeners(); + int size2 = xrl.length; + + IRequestListener[] rl = new IRequestListener[size + size2]; + System.arraycopy(xrl, 0, rl, 0, size2); + for (int i = 0; i < size; i++) + rl[size2 + i] = (IRequestListener) requestListeners.get(i); + + for (int i = 0; i < size + size2; i++) { + IRequestListener listener = rl[i]; + if (type == ADD) + listener.requestAdded(rr); + else if (type == CHANGE) + listener.requestChanged(rr); + else if (type == REMOVE) + listener.requestRemoved(rr); + } + } + + protected void loadMonitors() { + Trace.trace(Trace.FINEST, "Loading monitors"); + + monitors = new ArrayList(); + Preferences prefs = MonitorPlugin.getInstance().getPluginPreferences(); + String xmlString = prefs.getString("monitors"); + if (xmlString != null && xmlString.length() > 0) { + try { + ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes()); + IMemento memento = XMLMemento.loadMemento(in); + + IMemento[] children = memento.getChildren("monitor"); + if (children != null) { + int size = children.length; + for (int i = 0; i < size; i++) { + Monitor monitor = new Monitor(); + monitor.load(children[i]); + monitors.add(monitor); + } + } + } catch (Exception e) { + Trace.trace(Trace.WARNING, "Could not load monitors: " + e.getMessage()); + } + } + } + + protected void saveMonitors() { + try { + ignorePreferenceChanges = true; + XMLMemento memento = XMLMemento.createWriteRoot("monitors"); + + Iterator iterator = monitors.iterator(); + while (iterator.hasNext()) { + Monitor monitor = (Monitor) iterator.next(); + IMemento child = memento.createChild("monitor"); + monitor.save(child); + } + + String xmlString = memento.saveToString(); + Preferences prefs = MonitorPlugin.getInstance().getPluginPreferences(); + prefs.setValue("monitors", xmlString); + MonitorPlugin.getInstance().savePluginPreferences(); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not save browsers", e); + } + ignorePreferenceChanges = false; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorPlugin.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorPlugin.java new file mode 100644 index 0000000..d62498b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorPlugin.java @@ -0,0 +1,156 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.util.*; + +import net.sourceforge.phpdt.monitor.core.IContentFilter; +import net.sourceforge.phpdt.monitor.core.IProtocolAdapter; +import net.sourceforge.phpdt.monitor.core.IRequestListener; + +import org.eclipse.core.runtime.*; +/** + * The monitor core plugin. + */ +public class MonitorPlugin extends Plugin { + public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.monitor.core"; + + private static MonitorPlugin singleton; + + protected Map protocolAdapters; + protected Map contentFilters; + protected IRequestListener[] requestListeners; + + /** + * MonitorPlugin constructor comment. + */ + public MonitorPlugin() { + super(); + singleton = this; + loadProtocolAdapters(); + loadContentFilters(); + } + + /** + * Returns the singleton instance of this plugin. + * + * @return net.sourceforge.phpdt.monitor.core.MonitorPlugin + */ + public static MonitorPlugin getInstance() { + return singleton; + } + + /** + * Returns the translated String found with the given key. + * + * @return java.lang.String + * @param key java.lang.String + */ + public static String getString(String key) { + try { + return Platform.getResourceString(getInstance().getBundle(), key); + } catch (Exception e) { + return key; + } + } + + public IProtocolAdapter getDefaultType() { + return (ProtocolAdapter) protocolAdapters.get("HTTP"); + } + + public IProtocolAdapter getProtocolAdapter(String id) { + return (ProtocolAdapter) protocolAdapters.get(id); + } + + public IProtocolAdapter[] getProtocolAdapters() { + List list = new ArrayList(); + Iterator iterator = protocolAdapters.values().iterator(); + while (iterator.hasNext()) { + list.add(iterator.next()); + } + IProtocolAdapter[] types = new IProtocolAdapter[list.size()]; + list.toArray(types); + return types; + } + + public IContentFilter[] getContentFilters() { + List list = new ArrayList(); + Iterator iterator = contentFilters.values().iterator(); + while (iterator.hasNext()) { + list.add(iterator.next()); + } + IContentFilter[] cf = new IContentFilter[list.size()]; + list.toArray(cf); + return cf; + } + + public IContentFilter getContentFilter(String id) { + return (IContentFilter) contentFilters.get(id); + } + + public IRequestListener[] getRequestListeners() { + if (requestListeners == null) + loadRequestListeners(); + return requestListeners; + } + + public void loadProtocolAdapters() { + Trace.trace(Trace.CONFIG, "Loading protocol adapters"); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "protocolAdapters"); + + int size = cf.length; + protocolAdapters = new HashMap(size); + for (int i = 0; i < size; i++) { + String id = cf[i].getAttribute("id"); + Trace.trace(Trace.CONFIG, "Loading adapter: " + id); + protocolAdapters.put(id, new ProtocolAdapter(cf[i])); + } + } + + public void loadContentFilters() { + Trace.trace(Trace.CONFIG, "Loading content filters"); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "contentFilters"); + + int size = cf.length; + contentFilters = new HashMap(size); + for (int i = 0; i < size; i++) { + String id = cf[i].getAttribute("id"); + Trace.trace(Trace.CONFIG, "Loading filter: " + id); + contentFilters.put(id, new ContentFilter(cf[i])); + } + } + + public void loadRequestListeners() { + Trace.trace(Trace.CONFIG, "Loading request listeners"); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "requestListeners"); + + int size = cf.length; + List list = new ArrayList(); + for (int i = 0; i < size; i++) { + String id = cf[i].getAttribute("id"); + Trace.trace(Trace.CONFIG, "Loading request listener: " + id); + try { + IRequestListener rl = (IRequestListener) cf[i].createExecutableExtension("class"); + list.add(rl); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not create request listener: " + id, e); + return; + } + } + + size = list.size(); + requestListeners = new IRequestListener[size]; + list.toArray(requestListeners); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorWorkingCopy.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorWorkingCopy.java new file mode 100644 index 0000000..ecca3dc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/MonitorWorkingCopy.java @@ -0,0 +1,91 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import net.sourceforge.phpdt.monitor.core.*; +/** + * + */ +public class MonitorWorkingCopy extends Monitor implements IMonitorWorkingCopy { + protected Monitor monitor; + + // creation + public MonitorWorkingCopy() { } + + // working copy + public MonitorWorkingCopy(Monitor monitor) { + this.monitor = monitor; + setInternal(monitor); + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitorWorkingCopy#setRemoteHost(java.lang.String) + */ + public void setId(String newId) { + id = newId; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitorWorkingCopy#setRemoteHost(java.lang.String) + */ + public void setRemoteHost(String host) { + remoteHost = host; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitorWorkingCopy#setRemotePort(int) + */ + public void setRemotePort(int port) { + remotePort = port; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitorWorkingCopy#setLocalPort(int) + */ + public void setLocalPort(int port) { + localPort = port; + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.IMonitorWorkingCopy#setType(IType) + */ + public void setProtocolAdapter(IProtocolAdapter t) { + type = t; + } + + public boolean isWorkingCopy() { + return true; + } + + public IMonitorWorkingCopy getWorkingCopy() { + return this; + } + + public IMonitor save() { + MonitorManager mm = MonitorManager.getInstance(); + if (monitor != null) { + //boolean restart = false; + if (monitor.isRunning()) { + //restart = true; + mm.stopMonitor(monitor); + } + monitor.setInternal(this); + mm.monitorChanged(monitor); + //if (restart) + // mm.startMonitor(monitor); + } else { + monitor = new Monitor(); + monitor.setInternal(this); + mm.addMonitor(monitor); + } + return monitor; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ProtocolAdapter.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ProtocolAdapter.java new file mode 100644 index 0000000..ee4e6be --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/ProtocolAdapter.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.IOException; +import java.net.Socket; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +import net.sourceforge.phpdt.monitor.core.IProtocolAdapter; +import net.sourceforge.phpdt.monitor.core.IProtocolAdapterDelegate; + +import org.eclipse.core.runtime.IConfigurationElement; +/** + * + */ +public class ProtocolAdapter implements IProtocolAdapter { + protected IConfigurationElement element; + protected IProtocolAdapterDelegate delegate; + + protected ProtocolAdapter(IConfigurationElement element) { + this.element = element; + } + + public String getId() { + return element.getAttribute("id"); + } + + public String getName() { + return element.getAttribute("name"); + } + + public void parse(IMonitor monitor, Socket in, Socket out) throws IOException { + if (delegate == null) { + try { + delegate = (IProtocolAdapterDelegate) element.createExecutableExtension("class"); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not create protocol adapter delegate: " + getId(), e); + return; + } + } + delegate.parse(monitor, in, out); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Request.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Request.java new file mode 100644 index 0000000..208b00b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Request.java @@ -0,0 +1,263 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.util.Date; +import java.util.Properties; + +import net.sourceforge.phpdt.monitor.core.IProtocolAdapter; +import net.sourceforge.phpdt.monitor.core.IRequest; +/** + * A single TCP/IP request/response pair. + */ +public class Request implements IRequest { + protected Date date; + protected long responseTime = -1; + protected int localPort; + protected String remoteHost; + protected int remotePort; + protected byte[] request; + protected byte[] response; + + protected String label; + protected IProtocolAdapter type; + + protected Properties properties; + + /** + * RequestResponse constructor comment. + */ + public Request(IProtocolAdapter type, int localPort, String remoteHost, int remotePort) { + super(); + this.type = type; + this.localPort = localPort; + this.remoteHost = remoteHost; + this.remotePort = remotePort; + date = new Date(); + properties = new Properties(); + MonitorManager.getInstance().addRequest(this); + } + + public IProtocolAdapter getType() { + return type; + } + + /** + * Add to the request. + * + * @param addRequest byte[] + */ + public void addToRequest(byte[] addRequest) { + if (addRequest == null || addRequest.length == 0) + return; + + if (request == null || request.length == 0) { + setRequest(addRequest); + return; + } + + int size = request.length + addRequest.length; + byte[] b = new byte[size]; + System.arraycopy(request, 0, b, 0, request.length); + System.arraycopy(addRequest, 0, b, request.length, addRequest.length); + request = b; + } + + /** + * Add to the response. + * + * @param addResponse byte[] + */ + public void addToResponse(byte[] addResponse) { + if (addResponse == null || addResponse.length == 0) + return; + + if (response == null || response.length == 0) { + setResponse(addResponse); + return; + } + + int size = response.length + addResponse.length; + byte[] b = new byte[size]; + System.arraycopy(response, 0, b, 0, response.length); + System.arraycopy(addResponse, 0, b, response.length, addResponse.length); + response = b; + } + + /** + * Return the date/time of this request. + * + * @return java.util.Date + */ + public Date getDate() { + return date; + } + + /** + * Returns the local port. + * + * @return int + */ + public int getLocalPort() { + return localPort; + } + + /** + * Returns the remote host. + * + * @return java.lang.String + */ + public String getRemoteHost() { + return remoteHost; + } + + /** + * Returns the remote port. + * + * @return int + */ + public int getRemotePort() { + return remotePort; + } + + /** + * Returns the request as a byte array. + * + * @return byte[] + */ + public byte[] getRequest(byte type2) { + return request; + } + + /** + * Returns the response as a byte array. + * + * @return byte[] + */ + public byte[] getResponse(byte type2) { + return response; + } + + /** + * Returns the response time in milliseconds. + * + * @return long + */ + public long getResponseTime() { + return responseTime; + } + + /** + * Returns the title, if one exists. + * + * @return java.lang.String + */ + public String getLabel() { + if (label == null) + return getRemoteHost() + ":" + getRemotePort(); + else + return label; + } + + /** + * Set the request. + * + * @param request byte[] + */ + protected void setRequest(byte[] request) { + if (request == null || request.length == 0) + return; + + this.request = request; + + MonitorManager.getInstance().requestChanged(this); + } + + /** + * Set the response. + * + * @param response byte[] + */ + protected void setResponse(byte[] response) { + if (response == null || response.length == 0) + return; + + this.response = response; + + responseTime = System.currentTimeMillis() - date.getTime(); + + MonitorManager.getInstance().requestChanged(this); + } + + /** + * Sets the title. + * + * @param s java.lang.String + */ + public void setLabel(String s) { + // property can only be set once + if (label != null) + return; + + label = s; + MonitorManager.getInstance().requestChanged(this); + } + + /** + * + */ + public void addProperty(String key, Object value) { + try { + if (properties.containsKey(key)) + properties.remove(key); + properties.put(key, value); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not add property", e); + } + } + + /** + * + */ + public String getStringProperty(String key) { + try { + return (String) properties.get(key); + } catch (Exception e) { + return ""; + } + } + + /** + * + */ + public Integer getIntegerProperty(String key) { + try { + return (Integer) properties.get(key); + } catch (Exception e) { + return null; + } + } + + /** + * + */ + public Object getObjectProperty(String key) { + try { + return properties.get(key); + } catch (Exception e) { + return null; + } + } + + public void fireChangedEvent() { + MonitorManager.getInstance().requestChanged(this); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/TCPIPProtocolAdapter.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/TCPIPProtocolAdapter.java new file mode 100644 index 0000000..7d28d15 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/TCPIPProtocolAdapter.java @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.IOException; +import java.net.Socket; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +import net.sourceforge.phpdt.monitor.core.IProtocolAdapterDelegate; +import net.sourceforge.phpdt.monitor.core.MonitorCore; +/** + * + */ +public class TCPIPProtocolAdapter implements IProtocolAdapterDelegate { + public void parse(IMonitor monitor, Socket in, Socket out) throws IOException { + Request request = new Request(MonitorCore.getProtocolAdapter("TCPIP"), monitor.getLocalPort(), monitor.getRemoteHost(), monitor.getRemotePort()); + Connection conn = new Connection(in, out); + DefaultThread requestThread = new DefaultThread(conn, request, in.getInputStream(), out.getOutputStream(), true); + requestThread.start(); + new DefaultThread(conn, request, out.getInputStream(), in.getOutputStream(), false).start(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Trace.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Trace.java new file mode 100644 index 0000000..a530662 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/Trace.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; +/** + * Helper class to route trace output. + */ +public class Trace { + public static byte CONFIG = 0; + public static byte WARNING = 1; + public static byte SEVERE = 2; + public static byte FINEST = 3; + + public static byte PARSING = 4; + + /** + * Trace constructor comment. + */ + private Trace() { + super(); + } + + /** + * Trace the given text. + * + * @param s java.lang.String + */ + public static void trace(byte level, String s) { + trace(level, s, null); + } + + /** + * Trace the given message and exception. + * + * @param s java.lang.String + * @param t java.lang.Throwable + */ + public static void trace(byte level, String s, Throwable t) { + if (!MonitorPlugin.getInstance().isDebugging()) + return; + + System.out.println(s); + if (t != null) + t.printStackTrace(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/XMLMemento.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/XMLMemento.java new file mode 100644 index 0000000..bd4f98d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/XMLMemento.java @@ -0,0 +1,448 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal; + +import java.io.*; +import java.util.*; +import java.net.URL; +import org.w3c.dom.*; +import org.xml.sax.*; + +import javax.xml.parsers.*; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +/** + * A Memento is a class independent container for persistence + * info. It is a reflection of 3 storage requirements. + * + * 1) We need the ability to persist an object and restore it. + * 2) The class for an object may be absent. If so we would + * like to skip the object and keep reading. + * 3) The class for an object may change. If so the new class + * should be able to read the old persistence info. + * + * We could ask the objects to serialize themselves into an + * ObjectOutputStream, DataOutputStream, or Hashtable. However + * all of these approaches fail to meet the second requirement. + * + * Memento supports binary persistance with a version ID. + */ +public final class XMLMemento implements IMemento { + private Document factory; + private Element element; + + /** + * Answer a memento for the document and element. For simplicity + * you should use createReadRoot and createWriteRoot to create the initial + * mementos on a document. + */ + public XMLMemento(Document doc, Element el) { + factory = doc; + element = el; + } + + /** + * @see IMemento. + */ + public IMemento createChild(String type) { + Element child = factory.createElement(type); + element.appendChild(child); + return new XMLMemento(factory, child); + } + + /** + * @see IMemento. + */ + public IMemento createChild(String type, String id) { + Element child = factory.createElement(type); + child.setAttribute(TAG_ID, id); + element.appendChild(child); + return new XMLMemento(factory, child); + } + + /** + * Create a Document from a Reader and answer a root memento for reading + * a document. + */ + protected static XMLMemento createReadRoot(Reader reader) { + Document document = null; + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder parser = factory.newDocumentBuilder(); + document = parser.parse(new InputSource(reader)); + Node node = document.getFirstChild(); + if (node instanceof Element) + return new XMLMemento(document, (Element) node); + } catch (ParserConfigurationException e) { + } catch (IOException e) { + } catch (SAXException e) { + } finally { + try { + reader.close(); + } catch (Exception e) { } + } + return null; + } + + /** + * Answer a root memento for writing a document. + */ + public static XMLMemento createWriteRoot(String type) { + Document document; + try { + document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + Element element = document.createElement(type); + document.appendChild(element); + return new XMLMemento(document, element); + } catch (ParserConfigurationException e) { + throw new Error(e); + } + } + + /** + * @see IMemento. + */ + public IMemento getChild(String type) { + // Get the nodes. + NodeList nodes = element.getChildNodes(); + int size = nodes.getLength(); + if (size == 0) + return null; + + // Find the first node which is a child of this node. + for (int nX = 0; nX < size; nX ++) { + Node node = nodes.item(nX); + if (node instanceof Element) { + Element element2 = (Element)node; + if (element2.getNodeName().equals(type)) + return new XMLMemento(factory, element2); + } + } + + // A child was not found. + return null; + } + + /** + * @see IMemento. + */ + public IMemento [] getChildren(String type) { + // Get the nodes. + NodeList nodes = element.getChildNodes(); + int size = nodes.getLength(); + if (size == 0) + return new IMemento[0]; + + // Extract each node with given type. + ArrayList list = new ArrayList(size); + for (int nX = 0; nX < size; nX ++) { + Node node = nodes.item(nX); + if (node instanceof Element) { + Element element2 = (Element)node; + if (element2.getNodeName().equals(type)) + list.add(element2); + } + } + + // Create a memento for each node. + size = list.size(); + IMemento [] results = new IMemento[size]; + for (int x = 0; x < size; x ++) { + results[x] = new XMLMemento(factory, (Element)list.get(x)); + } + return results; + } + + /** + * Return the contents of this memento as a byte array. + * + * @return byte[] + */ + public byte[] getContents() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + save(out); + return out.toByteArray(); + } + + /** + * Returns an input stream for writing to the disk with a local locale. + * + * @return java.io.InputStream + */ + public InputStream getInputStream() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + save(out); + return new ByteArrayInputStream(out.toByteArray()); + } + + /** + * @see IMemento. + */ + public Float getFloat(String key) { + Attr attr = element.getAttributeNode(key); + if (attr == null) + return null; + String strValue = attr.getValue(); + try { + return new Float(strValue); + } catch (NumberFormatException e) { + return null; + } + } + + /** + * @see IMemento. + */ + public String getId() { + return element.getAttribute(TAG_ID); + } + + /** + * @see IMemento. + */ + public String getName() { + return element.getNodeName(); + } + + /** + * @see IMemento. + */ + public Integer getInteger(String key) { + Attr attr = element.getAttributeNode(key); + if (attr == null) + return null; + String strValue = attr.getValue(); + try { + return new Integer(strValue); + } catch (NumberFormatException e) { + return null; + } + } + + /** + * @see IMemento. + */ + public String getString(String key) { + Attr attr = element.getAttributeNode(key); + if (attr == null) + return null; + return attr.getValue(); + } + + public List getNames() { + NamedNodeMap map = element.getAttributes(); + int size = map.getLength(); + List list = new ArrayList(); + for (int i = 0; i < size; i++) { + Node node = map.item(i); + String name = node.getNodeName(); + list.add(name); + } + return list; + } + + /** + * Loads a memento from the given filename. + * + * @param in java.io.InputStream + * @return org.eclipse.ui.IMemento + * @exception java.io.IOException + */ + public static IMemento loadMemento(InputStream in) { + return createReadRoot(new InputStreamReader(in)); + } + + /** + * Loads a memento from the given filename. + * + * @param in java.io.InputStream + * @return org.eclipse.ui.IMemento + * @exception java.io.IOException + */ + public static IMemento loadCorruptMemento(InputStream in) { + Document document = null; + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder parser = factory.newDocumentBuilder(); + document = parser.parse(in); + Node node = document.getFirstChild(); + if (node instanceof Element) + return new XMLMemento(document, (Element) node); + } catch (ParserConfigurationException e) { + } catch (IOException e) { + } catch (SAXException e) { + } finally { + try { + in.close(); + } catch (Exception e) { } + } + return null; + } + + /** + * Loads a memento from the given filename. + * + * @param filename java.lang.String + * @return org.eclipse.ui.IMemento + * @exception java.io.IOException + */ + public static IMemento loadMemento(String filename) throws IOException { + return XMLMemento.createReadRoot(new FileReader(filename)); + } + + /** + * Loads a memento from the given filename. + * + * @param url java.net.URL + * @return org.eclipse.ui.IMemento + * @exception java.io.IOException + */ + public static IMemento loadMemento(URL url) throws IOException { + return XMLMemento.createReadRoot(new InputStreamReader(url.openStream())); + } + + /** + * @see IMemento. + */ + private void putElement(Element element2) { + NamedNodeMap nodeMap = element2.getAttributes(); + int size = nodeMap.getLength(); + for (int i = 0; i < size; i++){ + Attr attr = (Attr)nodeMap.item(i); + putString(attr.getName(),attr.getValue()); + } + + NodeList nodes = element2.getChildNodes(); + size = nodes.getLength(); + for (int i = 0; i < size; i ++) { + Node node = nodes.item(i); + if (node instanceof Element) { + XMLMemento child = (XMLMemento)createChild(node.getNodeName()); + child.putElement((Element)node); + } + } + } + + /** + * @see IMemento. + */ + public void putFloat(String key, float f) { + element.setAttribute(key, String.valueOf(f)); + } + + /** + * @see IMemento. + */ + public void putInteger(String key, int n) { + element.setAttribute(key, String.valueOf(n)); + } + + /** + * @see IMemento. + */ + public void putMemento(IMemento memento) { + XMLMemento xmlMemento = (XMLMemento) memento; + putElement(xmlMemento.element); + } + + /** + * @see IMemento. + */ + public void putString(String key, String value) { + if (value == null) + return; + element.setAttribute(key, value); + } + + /** + * Save this Memento to a Writer. + */ + public void save(Writer writer) throws IOException { + Result result = new StreamResult(writer); + Source source = new DOMSource(factory); + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ + transformer.transform(source, result); + } catch (Exception e) { + throw (IOException) (new IOException().initCause(e)); + } + } + + /** + * Save this Memento to a Writer. + */ + public void save(OutputStream os) throws IOException { + Result result = new StreamResult(os); + Source source = new DOMSource(factory); + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ + transformer.transform(source, result); + } catch (Exception e) { + throw (IOException) (new IOException().initCause(e)); + } + } + + /** + * Saves the memento to the given file. + * + * @param filename java.lang.String + * @exception java.io.IOException + */ + public void saveToFile(String filename) throws IOException { + Writer w = null; + try { + w = new FileWriter(filename); + save(w); + } catch (IOException e) { + throw e; + } catch (Exception e) { + throw new IOException(e.getLocalizedMessage()); + } finally { + if (w != null) { + try { + w.close(); + } catch (Exception e) { } + } + } + } + + public String saveToString() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + save(out); + return out.toString("UTF-8"); + } + + /* + * @see IMemento#getBoolean(String) + */ + public Boolean getBoolean(String key) { + Attr attr = element.getAttributeNode(key); + if (attr == null) + return null; + String strValue = attr.getValue(); + if ("true".equalsIgnoreCase(strValue)) + return new Boolean(true); + else + return new Boolean(false); + } + + /* + * @see IMemento#putBoolean(String, boolean) + */ + public void putBoolean(String key, boolean value) { + element.setAttribute(key, value ? "true" : "false"); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPConnection.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPConnection.java new file mode 100644 index 0000000..f6ab4c3 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPConnection.java @@ -0,0 +1,110 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal.http; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.core.internal.Request; +import net.sourceforge.phpdt.monitor.core.internal.Trace; + + +import java.util.List; +import java.util.ArrayList; +/** + * Manages a monitor server connection between two hosts. This + * connection may spawn one or more TCP/IP pairs to be displayed + * in the monitor server view. + */ +public class HTTPConnection { + protected IMonitor monitor; + + protected int req = -1; + protected int resp = -1; + + protected List calls = new ArrayList(); + + /** + * MonitorHTTPConnection constructor comment. + */ + public HTTPConnection(IMonitor monitor) { + super(); + this.monitor = monitor; + Trace.trace(Trace.PARSING, "TCP/IP monitor connection opened " + monitor); + } + + /** + * Add a request. + * @param req byte[] + * @param isNew boolean + */ + public void addRequest(byte[] request, boolean isNew) { + if (isNew) + req ++; + Request pair = (Request) getRequestResponse(req); + pair.addToRequest(request); + } + + /** + * Add a response. + * @param req byte[] + * @param isNew boolean + */ + public void addResponse(byte[] response, boolean isNew) { + if (isNew) + resp ++; + Request pair = (Request) getRequestResponse(resp); + pair.addToResponse(response); + } + + /** + * + */ + public void addProperty(String key, Object value) { + IRequest pair = getRequestResponse(req); + pair.addProperty(key, value); + } + + /** + * + */ + public IRequest getRequestResponse(boolean isRequest) { + if (isRequest) + return getRequestResponse(req); + else + return getRequestResponse(resp); + } + + /** + * + */ + protected IRequest getRequestResponse(int i) { + synchronized (this) { + while (i >= calls.size()) { + Request rr = new HTTPRequest(monitor.getLocalPort(), monitor.getRemoteHost(), monitor.getRemotePort()); + calls.add(rr); + return rr; + } + return (Request) calls.get(i); + } + } + + /** + * Set the title + * @param req byte[] + * @param isNew boolean + */ + public void setLabel(String title, boolean isNew) { + if (isNew) + req ++; + Request pair = (Request) getRequestResponse(req); + pair.setLabel(title); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPProtocolAdapter.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPProtocolAdapter.java new file mode 100644 index 0000000..4e47e84 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPProtocolAdapter.java @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html +  * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal.http; + +import java.io.IOException; +import java.net.Socket; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +import net.sourceforge.phpdt.monitor.core.IProtocolAdapterDelegate; +import net.sourceforge.phpdt.monitor.core.internal.Connection; + +/** + * + */ +public class HTTPProtocolAdapter implements IProtocolAdapterDelegate { + public void parse(IMonitor monitor, Socket in, Socket out) throws IOException { + Connection conn2 = new Connection(in, out); + HTTPConnection conn = new HTTPConnection(monitor); + HTTPThread request = new HTTPThread(conn2, in.getInputStream(), out.getOutputStream(), conn, true, monitor.getRemoteHost(), monitor.getRemotePort()); + HTTPThread response = new HTTPThread(conn2, out.getInputStream(), in.getOutputStream(), conn, false, "localhost", monitor.getLocalPort(), request); + request.start(); + response.start(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPRequest.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPRequest.java new file mode 100644 index 0000000..af0c664 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPRequest.java @@ -0,0 +1,84 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal.http; + +import net.sourceforge.phpdt.monitor.core.MonitorCore; +import net.sourceforge.phpdt.monitor.core.internal.Request; + +/** + * + */ +public class HTTPRequest extends Request { + protected static final String HTTP_REQUEST_HEADER = "request-header"; + protected static final String HTTP_RESPONSE_HEADER = "response-header"; + + protected static final String HTTP_REQUEST_BODY = "request-body"; + protected static final String HTTP_RESPONSE_BODY = "response-body"; + + protected static final byte[] EMPTY = new byte[0]; + + /** + * HTTPRequestResponse constructor comment. + */ + public HTTPRequest(int localPort, String remoteHost, int remotePort) { + super(MonitorCore.getProtocolAdapter(MonitorCore.HTTP_PROTOCOL_ID), localPort, remoteHost, remotePort); + } + + public byte[] getRequest(byte type2) { + if (type2 == ALL) + return request; + else if (type2 == TRANSPORT) + return getRequestHeader(); + else + return getRequestContent(); + } + + public byte[] getResponse(byte type2) { + if (type2 == ALL) + return response; + else if (type2 == TRANSPORT) + return getResponseHeader(); + else + return getResponseContent(); + } + + protected byte[] getRequestHeader() { + Object obj = getObjectProperty(HTTP_REQUEST_HEADER); + if (obj == null || !(obj instanceof byte[])) + return null; + else + return (byte[]) obj; + } + + protected byte[] getRequestContent() { + Object obj = getObjectProperty(HTTP_REQUEST_BODY); + if (obj == null || !(obj instanceof byte[])) + return null; + else + return (byte[]) obj; + } + + protected byte[] getResponseHeader() { + Object obj = getObjectProperty(HTTP_RESPONSE_HEADER); + if (obj == null || !(obj instanceof byte[])) + return null; + else + return (byte[]) obj; + } + + protected byte[] getResponseContent() { + Object obj = getObjectProperty(HTTP_RESPONSE_BODY); + if (obj == null || !(obj instanceof byte[])) + return null; + else + return (byte[]) obj; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPThread.java b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPThread.java new file mode 100644 index 0000000..1530d89 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.core/src/net/sourceforge/phpdt/monitor/core/internal/http/HTTPThread.java @@ -0,0 +1,602 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.core.internal.http; + +import java.io.*; + +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.core.internal.Connection; +import net.sourceforge.phpdt.monitor.core.internal.Trace; + +/** + * Monitor server I/O thread. + */ +public class HTTPThread extends Thread { + private static final int BUFFER = 2048; + private static final byte CR = (byte) '\r'; + private static final byte LF = (byte) '\n'; + protected static int threadCount = 0; + + private byte[] readBuffer = new byte[BUFFER]; + + // buffer and index + protected byte[] buffer = new byte[0]; + protected int bufferIndex = 0; + + protected InputStream in; + protected OutputStream out; + protected HTTPConnection conn; + protected boolean isRequest; + protected Connection conn2; + + protected HTTPThread request; + protected boolean isWaiting; + + // user to translate the Host: header + protected String host; + protected int port; + + protected int contentLength = -1; + protected byte transferEncoding = -1; + protected String responseType = null; + protected boolean keepAlive = false; + + protected static final String[] ENCODING_STRING = new String[] { + "chunked", "identity", "gzip", "compressed", "deflate"}; + + protected static final byte ENCODING_CHUNKED = 0; + protected static final byte ENCODING_IDENTITY = 1; + protected static final byte ENCODING_GZIP = 2; + protected static final byte ENCODING_COMPRESSED = 3; + protected static final byte ENCODING_DEFLATE = 4; + +/* change: +Referer: http://localhost:8081/index.html +Host: localhost:8081 +*/ +/* The Connection header has the following grammar: + + Connection = "Connection" ":" 1#(connection-token) + connection-token = token + + HTTP/1.1 proxies MUST parse the Connection header field before a + message is forwarded and, for each connection-token in this field, + remove any header field(s) from the message with the same name as the + connection-token. */ + + /** + * MonitorThread constructor comment. + */ + public HTTPThread(Connection conn2, InputStream in, OutputStream out, HTTPConnection conn, boolean isRequest, String host, int port) { + super(); + this.conn2 = conn2; + this.in = in; + this.out = out; + this.conn = conn; + this.isRequest = isRequest; + this.host = host; + this.port = port; + + setName("HTTP (" + host + ":" + port + ") " + (isRequest ? "REQUEST" : "RESPONSE") + " " + (threadCount++)); + setPriority(Thread.NORM_PRIORITY + 1); + setDaemon(true); + + Trace.trace(Trace.PARSING, "Started: " + this); + } + + /** + * MonitorThread constructor comment. + */ + public HTTPThread(Connection conn2, InputStream in, OutputStream out, HTTPConnection conn, boolean isRequest, String host, int port, HTTPThread request) { + this(conn2, in, out, conn, isRequest, host, port); + + this.request = request; + } + + /** + * Add a line feed to the end of the byte array. + * @return byte[] + * @param b byte[] + */ + protected static byte[] convert(byte[] b) { + if (b == null || b.length == 0) + return b; + + int size = b.length; + byte[] x = new byte[size + 2]; + System.arraycopy(b, 0, x, 0, size); + x[size] = (byte) '\r'; // CR + x[size + 1] = (byte) '\n'; // LF + return x; + } + + /** + * Read more data into the buffer. + * + * @return byte[] + */ + protected void fillBuffer() throws IOException { + int n = in.read(readBuffer); + + if (n <= 0) + throw new IOException("End of input"); + + // add to full buffer + int len = buffer.length - bufferIndex; + if (len < 0) + len = 0; + byte[] x = new byte[n + len]; + System.arraycopy(buffer, bufferIndex, x, 0, len); + System.arraycopy(readBuffer, 0, x, len, n); + bufferIndex = 0; + buffer = x; + } + + /** + * Returns the first location of a CRLF. + * + * @return int + */ + protected int getFirstCRLF() { + int size = buffer.length; + int i = bufferIndex + 1; + while (i < size) { + if (buffer[i - 1] == CR && buffer[i] == LF) + return i; + i++; + } + return -1; + } + + /** + * Output the given bytes. + * @param b byte[] + */ + protected void outputBytes(byte[] b, boolean isNew) throws IOException { + out.write(b); + if (isRequest) + conn.addRequest(b, isNew); + else + conn.addResponse(b, isNew); + } + + /** + * Parse the HTTP body. + */ + public void parseBody() throws IOException { + Trace.trace(Trace.PARSING, "Parsing body for: " + this); + + if (isRequest) { + if (contentLength != -1) { + byte[] b = readBytes(contentLength); + out.write(b); + conn.addRequest(b, false); + setHTTPBody(b); + } else if (transferEncoding != -1 && transferEncoding != ENCODING_IDENTITY) { + parseChunk(); + } + + Trace.trace(Trace.PARSING, "Done parsing request body for: " + this); + return; + } + + // just return body for HTTP 1.0 responses + if (!isRequest && !keepAlive && contentLength == -1 && transferEncoding == -1) { + Trace.trace(Trace.PARSING, "Assuming HTTP 1.0 for: " + this); + int n = buffer.length - bufferIndex; + byte[] b = readBytes(n); + byte[] body = new byte[0]; + while (n >= 0) { + Trace.trace(Trace.PARSING, "Bytes read: " + n + " " + this); + if (b != null && n > 0) { + byte[] x = null; + if (n == b.length) + x = b; + else { + x = new byte[n]; + System.arraycopy(b, 0, x, 0, n); + } + outputBytes(x, false); + + // copy to HTTP body + byte[] temp = new byte[body.length + x.length]; + System.arraycopy(body, 0, temp, 0, body.length); + System.arraycopy(x, 0, temp, body.length, x.length); + body = temp; + } + if (b.length < BUFFER) + b = new byte[BUFFER]; + n = in.read(b); + Thread.yield(); + } + out.flush(); + setHTTPBody(body); + return; + } + + // spec 4.4.1 + if (responseType != null && (responseType.startsWith("1") || "204".equals(responseType) || "304".equals(responseType))) { + setHTTPBody(new byte[0]); + return; + } + + // spec 4.4.2 + if (transferEncoding != -1 && transferEncoding != ENCODING_IDENTITY) { + parseChunk(); + return; + } + + // spec 4.4.3 + if (contentLength != -1) { + byte[] b = readBytes(contentLength); + out.write(b); + if (isRequest) + conn.addRequest(b, false); + else + conn.addResponse(b, false); + setHTTPBody(b); + return; + } + + // spec 4.4.4 (?) + + Trace.trace(Trace.PARSING, "Unknown body for: " + this); + } + + /** + * Parse an HTTP chunk. + */ + public void parseChunk() throws IOException { + Trace.trace(Trace.PARSING, "Parsing chunk for: " + this); + boolean done = false; + byte[] body = new byte[0]; + + while (!done) { + // read chunk size + byte[] b = readLine(); + + String s = new String(b); + int index = s.indexOf(" "); + int length = -1; + try { + if (index > 0) + s = s.substring(0, index); + length = Integer.parseInt(s.trim(), 16); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error chunk for: " + this, e); + } + + // output bytes + outputBytes(b, false); + + if (length <= 0) + done = true; + else { + // read and output chunk data plus CRLF + b = readBytes(length + 2); + outputBytes(b, false); + + // copy to HTTP body + byte[] temp = new byte[body.length + b.length - 2]; + System.arraycopy(body, 0, temp, 0, body.length); + System.arraycopy(b, 0, temp, body.length, b.length - 2); + body = temp; + } + } + + // read trailer + byte[] b = readLine(); + while (b.length > 2) { + outputBytes(b, false); + b = readLine(); + } + + outputBytes(b, false); + setHTTPBody(body); + } + + /** + * Parse an HTTP header. + */ + public void parseHeader() throws IOException { + Trace.trace(Trace.PARSING, "Parsing header for: " + this); + + // read until first blank line + boolean isFirstLine = true; + boolean isNew = true; + + byte[] b = readLine(); + while (b.length > 5) { + Trace.trace(Trace.PARSING, "Parsing header line: '" + new String(b) + "'"); + + if (isFirstLine) { + String s = new String(b); + if (isRequest) { + setLabel(s); + isNew = false; + } + + if (!isRequest) { + int index1 = s.indexOf(' '); + int index2 = s.indexOf(' ', index1 + 1); + + try { + responseType = s.substring(index1 + 1, index2).trim(); + Trace.trace(Trace.PARSING, "Response Type: " + this + " " + responseType); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error parsing response type for: " + this, e); + } + if (responseType != null && responseType.equals("100")) { + outputBytes(b, isNew); + isNew = false; + + b = readLine(); + outputBytes(b, false); + + b = readLine(); + + index1 = s.indexOf(' '); + index2 = s.indexOf(' ', index1 + 1); + + try { + responseType = s.substring(index1 + 1, index2).trim(); + Trace.trace(Trace.PARSING, "Response Type: " + this + " " + responseType); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error parsing response type for: " + this, e); + } + } + } + isFirstLine = false; + } + + // translate + b = translateHeaderLine(b); + + outputBytes(b, isNew); + isNew = false; + + b = readLine(); + } + + Trace.trace(Trace.PARSING, "Parsing final header line: '" + new String(b) + "'"); + + outputBytes(b, false); + + IRequest rr = conn.getRequestResponse(isRequest); + Trace.trace(Trace.PARSING, "Setting header length: " + rr.getRequest(IRequest.ALL).length); + + setHTTPHeader(rr); + } + + /** + * Read bytes from the stream. + * @return byte[] + */ + protected byte[] readBytes(int n) throws IOException { + Trace.trace(Trace.PARSING, "readBytes() " + n + " for: " + this); + while (buffer.length - bufferIndex < n) + fillBuffer(); + + return removeFromBuffer(bufferIndex + n); + } + + /** + * Read and return the next full line. + * + * @return byte[] + */ + protected byte[] readLine() throws IOException { + Trace.trace(Trace.PARSING, "readLine() for: " + this); + + int n = getFirstCRLF(); + while (n < 0) { + fillBuffer(); + n = getFirstCRLF(); + } + return removeFromBuffer(n + 1); + } + + /** + * Remove data from the buffer up to the absolute index n. + * Return the data from between bufferIndex and n. + * + * @return byte[] + * @param index int + */ + protected byte[] removeFromBuffer(int n) { + // copy line out of buffer + byte[] b = new byte[n - bufferIndex]; + System.arraycopy(buffer, bufferIndex, b, 0, n - bufferIndex); + + if (buffer.length > BUFFER * 2 || bufferIndex > BUFFER) { + // remove line from buffer + int size = buffer.length; + byte[] x = new byte[size - n]; + System.arraycopy(buffer, n, x, 0, size - n); + buffer = x; + bufferIndex = 0; + } else + bufferIndex = n; + + return b; + } + + /** + * Listen for input, save it, and pass to the output stream. + * Philosophy: Read a single line separately and translate. + * When blank line is reached, just pass all other data through. + */ + public void run() { + try { + try { + while (true) { + contentLength = -1; + transferEncoding = -1; + keepAlive = false; + + parseHeader(); + parseBody(); + + if (isRequest && keepAlive) + waitForResponse(); + + IRequest r = conn.getRequestResponse(true); + r.fireChangedEvent(); + + Trace.trace(Trace.PARSING, "Done HTTP request for " + this + " " + keepAlive); + if (!isRequest && !keepAlive) { + conn2.close(); + break; + } + + if (!isRequest) + notifyRequest(); + + Thread.yield(); + } + } catch (IOException e) { + // reached end of input + Trace.trace(Trace.PARSING, "End of buffer for: " + this + " " + e.getMessage()); + } + + // send rest of buffer + out.write(buffer, bufferIndex, buffer.length - bufferIndex); + out.flush(); + } catch (IOException e) { + Trace.trace(Trace.PARSING, "Error in: " + this, e); + } + Trace.trace(Trace.PARSING, "Closing thread " + this); + } + + /** + * Sets the title of the call. + * + * @param s java.lang.String + */ + protected void setLabel(String s) { + try { + int index1 = s.indexOf(' '); + if (index1 < 0 || index1 > 15) + return; + int index2 = s.indexOf(' ', index1 + 1); + if (index2 < 0) + return; + + conn.setLabel(s.substring(index1 + 1, index2), true); + } catch (Exception e) { } + } + + /** + * Translate the header line. + * + * @return byte[] + * @param b byte[] + */ + protected byte[] translateHeaderLine(byte[] b) { + String s = new String(b); + + if (isRequest && s.startsWith("Host: ")) { + String t = "Host: " + host; + if (port != 80) + t += ":" + port; + return convert(t.getBytes()); + } else if (s.startsWith("Content-Length: ")) { + try { + contentLength = Integer.parseInt(s.substring(16).trim()); + Trace.trace(Trace.PARSING, "Content length: " + this + " " + contentLength); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Content length error", e); + } + } else if (s.startsWith("Connection: ")) { + try { + String t = s.substring(11).trim(); + if (t.equalsIgnoreCase("Keep-Alive")) + keepAlive = true; + Trace.trace(Trace.PARSING, "Keep alive: " + keepAlive); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error getting Connection: from header", e); + } + } else if (s.startsWith("Transfer-Encoding: ")) { + String t = s.substring(19).trim(); + int size = ENCODING_STRING.length; + for (int i = 0; i < size; i++) { + if (ENCODING_STRING[i].equalsIgnoreCase(t)) { + transferEncoding = (byte) i; + Trace.trace(Trace.PARSING, "Transfer encoding: " + ENCODING_STRING[i]); + } + } + } + + return b; + } + + protected void close() { + try { + out.close(); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error closing connection " + this + " " + e.getMessage()); + } + } + + protected void waitForResponse() { + Trace.trace(Trace.PARSING, "Waiting for response " + this); + synchronized (this) { + try { + isWaiting = true; + wait(); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error in waitForResponse() " + this + " " + e.getMessage()); + } + isWaiting = false; + } + Trace.trace(Trace.PARSING, "Done waiting for response " + this); + } + + protected void notifyRequest() { + Trace.trace(Trace.PARSING, "Notifying request " + this); + while (request.keepAlive && !request.isWaiting) { + Trace.trace(Trace.PARSING, "Waiting for request " + this); + try { + Thread.sleep(100); + } catch (Exception e) { } + } + synchronized (request) { + try { + request.notify(); + } catch (Exception e) { + Trace.trace(Trace.PARSING, "Error in notifyRequest() " + this + " " + e.getMessage()); + } + } + Trace.trace(Trace.PARSING, "Done notifying request " + this); + } + + protected void setHTTPHeader(IRequest rr) { + if (isRequest) { + byte[] b = rr.getRequest(IRequest.ALL); + byte[] h = new byte[b.length]; + System.arraycopy(b, 0, h, 0, b.length); + rr.addProperty(HTTPRequest.HTTP_REQUEST_HEADER, h); + } else { + byte[] b = rr.getResponse(IRequest.ALL); + byte[] h = new byte[b.length]; + System.arraycopy(b, 0, h, 0, b.length); + rr.addProperty(HTTPRequest.HTTP_RESPONSE_HEADER, h); + } + } + + protected void setHTTPBody(byte[] b) { + IRequest rr = conn.getRequestResponse(isRequest); + if (isRequest) + rr.addProperty(HTTPRequest.HTTP_REQUEST_BODY, b); + else + rr.addProperty(HTTPRequest.HTTP_RESPONSE_BODY, b); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/.classpath b/archive/net.sourceforge.phpeclipse.monitor.ui/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/.project b/archive/net.sourceforge.phpeclipse.monitor.ui/.project new file mode 100644 index 0000000..eb4b5b5 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/.project @@ -0,0 +1,28 @@ + + + net.sourceforge.phpeclipse.monitor.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/build.properties b/archive/net.sourceforge.phpeclipse.monitor.ui/build.properties new file mode 100644 index 0000000..142800d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/build.properties @@ -0,0 +1,10 @@ +bin.includes = plugin.xml,\ + *.jar,\ + monitorui.jar,\ + plugin.properties,\ + icons/ +jars.compile.order = +src.includes = schema/,\ + build.properties +output.monitorui.jar = bin/ +source.monitorui.jar = monitorui/ diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/clear.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/clear.gif new file mode 100644 index 0000000000000000000000000000000000000000..389954fbba93b65ff8200423c7f5daa1f1e303b4 GIT binary patch literal 553 zcmZ?wbhEHb6krfwc*el+|KI=VJ^8bG3#NDFt(a9kr6YH8d(O7y?duja&YM`ec7Efw zr7a64mP~2SSum+|YDey_RbA7&3Z`}DZ&}*5c}eT?nKd(eie_{d?q1!qYgPBG-r_xL zde_cxS~06`*^Js^$n^AFY z?~+?*cKrPMesO2o!F5y4?_2)j&Y7#nHb1zy|Ngn%_s;EkeC5caD@UGQKk@kLv8Ojq zJ~+GU0Z{zR&WGpsKE8DD|L^aAeth};{qv76AO8RQ`}o}MN9XoDxv=lyxxJ4s9(;0s z@52j+{(k@T|M!nSKfeC|^Xu2gH~)Wq|MTth|KC6V{rd6u_phHH-u(Ic>Cd+>e?Gnc z|L4ztFkqk;Q2fcl$iNW8paZfH6ekSqZ4EI^%`L5MP0|AL@&eNBO%l}XX>Ms@ zs3F(R=iq7VZDyd@&m3f9YG<#`+0GPbZEND8&DgKt>+0s^t|s0u$j`>c%PJHjCdI&P KS0%#1U=0A0pZOF3 literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/httpHeader.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/clcl16/httpHeader.gif new file mode 100644 index 0000000000000000000000000000000000000000..fb20c389db009accc8a469277f123d28a8cce673 GIT binary patch literal 556 zcmZ?wbhEHb6krfwc*el+{p0_4ul~G${pa|L^yIzrX$cHECww(nbB-R@ZJ{Q@3q(-S#yN z+t)ViSl6T9T}s;D%HSp~@H1SshR1UNanxHKu-$!G^iYTlK0G;)$?GIqH8 cUAZOeT6_l5Ls3+~z!+Os93dvkEt#@c0j z%NFmx@a*H|7oVHf9%xy2@an5CcRv2U_3rzlum2u?`TOAWpKGtbJpA_m?x)|6zWsaj z{r`)f|6lz2Kkx9FT{j<2KX7vE)jKbL|DS#2%@Bjb*`2YXc|NsB~1C9Fr@aw0WZ(h9k`Ss!FckllG zy!H0kxBtIC`~|870S1}@#h)yU3=D}3Iv^WBal*hpt0A$exuvzOy2txczy zTQM#nUYWO5vq>a2AuM5$yL5|oqM=G?U@&V)Py)YEvsR)+w4Zk%dyuz(jQo~Ft_U*= zdkzcs#6 literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/cview16/monitorView.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/cview16/monitorView.gif new file mode 100644 index 0000000000000000000000000000000000000000..c374f1349b143a99066ef553f396dd4c1954879d GIT binary patch literal 590 zcmZ?wbhEHb6krfwc*ej`kdRT4QP5COQI}WOQPELRP|?xQ(NNJap<}|14LdGexWOgi z%Pr|Aqm!zk@1benscGP$ZR91bpQ-OsZ|2jXYaXOw;Gtvcr)%b?ZxLW%?qeO);~Y7W zL9I&Hz1h$<(#kEt)+32cyMo_s6Tj<5F8wkAx6S-c%lYgV@Y+lhaN8u{vYy|50iR_r zpJ}U!L!?_!HlOV@UaNj?gEBtzRzA~Oe$yI7ugTW_1-1bNj==@aAq5^0g)Tu^UXg`Y z@4dB*?hlAB2}mq?_v8QjpZ`Dp`v3X&{|~?afBy6T>%aeJfB!%K=l_Mj|1bUjfBFCa zYybaW|NsBb|NkP{E~44aqB+hog&s16o+{=3+BKmn<$l^VAqEW*1se(~HWVy4(eVHG zx&L6mKr^8DlZBCiA(24`WCJKp7}!@gBsMvyX{ofgE2}v)^=eBA3h;>u@C!<5_cp0Z z1o-;;`T6>btItZ*k@S%f5$5Gi5Y5}wMJpl%50COF_qW}N^ literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/clear.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/clear.gif new file mode 100644 index 0000000000000000000000000000000000000000..3bf98c0ec34d537df8a18a3338fd900e5ac1bad1 GIT binary patch literal 326 zcmZ?wbhEHb6krfwxXQrr_wS$IzkmJs@%`?dn+Nyre)aPCi|0?DKYOxs+s5-}Pu;$G z?dJ6>H?Cd2e)ZDxr;ndKdGz%0!zYg(Jbrlp(Sv&r?%lb2`{vId-=95x`1H|(ClBuf z4f^*NXyl*YzkdDt`Sa%wpuyh{9X$B||NnpgKr%oE166_IPZmZ722}kl#mdg66EE*)Z541k--`O D$jXUt literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/httpHeader.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/httpHeader.gif new file mode 100644 index 0000000000000000000000000000000000000000..6d71a8b8aae4198a429806c099998b5232af8d57 GIT binary patch literal 327 zcmZ?wbhEHb6krfwxXQrr``4fE-+p}m{`2eC?|=UM{r&sTuV25v|M>L{DDv&cm#^QO zIwxGcar?^kTQ~3Azj6EC^;>tZ-MsVT=dbTSfC|31^h|EUW>My#4t3&4*8~ zKYV)s`ODi+pa1^*_xsPE-+z7|I(YE^|NsB~{R5H=)CP(_Sr{1@R2XzX27~;>z?R}L zslY==s{h22AjvGN`TmI>n^$I8&FGu9YC@I}R|`v!rh^W<>vR)d4VH;q4-*+V*j}$Z zC?Ib6giTnaQc{UWREfVsNlsp&Qi4}ZNpP|fx3ajLV33T``~?e@Dg&1Kdaqcy(viU$ E00^vy@Bjb+ literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/sortResponseTime.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/dlcl16/sortResponseTime.gif new file mode 100644 index 0000000000000000000000000000000000000000..06e0c7326ec3150fac79a56f715797349e20e143 GIT binary patch literal 339 zcmZ?wbhEHb6krfwxXQp#-`rEz)YZ`1+t}XU)-z?_kyCpQpWJik#Nm_YzWw<5_4|)6 z-@bqT`t8G~&tJa(`1JML$1h*se)#z2{fF1@-ru?Z;Qr$$cOE?a{_EGTKYxDy{{7?E zudm;~fBN#}{l|}g|NZ;(_wVmNe}4S>`SJ6ox9{Km{QdLL!Gr(*|Nr;zACP3A22lLT z!pOj&!Jq>&4CE&UwgQJK1s*z5{l|qi9!Zg!s`2b$vXbN+=Zwr0tC{;mRs=+9RXEH) zz@DPjadJ@)8w*3G!9w#@2O^$n^AFY z?~+?*cKrPMesO2o!F5y4?_2)j&Y7#nHb1zy|Ngn%_s;EkeC5caD@UGQKk@kLv8Ojq zJ~+GU0Z{zR&WGpsKE8DD|L^aAeth};{qv76AO8RQ`}o}MN9XoDxv=lyxxJ4s9(;0s z@52j+{(k@T|M!nSKfeC|^Xu2gH~)Wq|MTth|KC6V{rd6u_phHH-u(Ic>Cd+>e?Gnc z|L4ztFkqk;Q2fcl$iNW8paZfH6ekSqZ4EI^%`L5MP0|AL@&eNBO%l}XX>Ms@ zs3F(R=iq7VZDyd@&m3f9YG<#`+0GPbZEND8&DgKt>+0s^t|s0u$j`>c%PJHjCdI&P KS0%#1U=0A0pZOF3 literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/elcl16/httpHeader.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/elcl16/httpHeader.gif new file mode 100644 index 0000000000000000000000000000000000000000..fb20c389db009accc8a469277f123d28a8cce673 GIT binary patch literal 556 zcmZ?wbhEHb6krfwc*el+{p0_4ul~G${pa|L^yIzrX$cHECww(nbB-R@ZJ{Q@3q(-S#yN z+t)ViSl6T9T}s;D%HSp~@H1SshR1UNanxHKu-$!G^iYTlK0G;)$?GIqH8 cUAZOeT6_l5Ls3+~z!+Os93dvkEt#@c0j z%NFmx@a*H|7oVHf9%xy2@an5CcRv2U_3rzlum2u?`TOAWpKGtbJpA_m?x)|6zWsaj z{r`)f|6lz2Kkx9FT{j<2KX7vE)jKbL|DS#2%@Bjb*`2YXc|NsB~1C9Fr@aw0WZ(h9k`Ss!FckllG zy!H0kxBtIC`~|870S1}@#h)yU3=D}3Iv^WBal*hpt0A$exuvzOy2txczy zTQM#nUYWO5vq>a2AuM5$yL5|oqM=G?U@&V)Py)YEvsR)+w4Zk%dyuz(jQo~Ft_U*= zdkzcs#6 literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/eview16/monitorView.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/eview16/monitorView.gif new file mode 100644 index 0000000000000000000000000000000000000000..c374f1349b143a99066ef553f396dd4c1954879d GIT binary patch literal 590 zcmZ?wbhEHb6krfwc*ej`kdRT4QP5COQI}WOQPELRP|?xQ(NNJap<}|14LdGexWOgi z%Pr|Aqm!zk@1benscGP$ZR91bpQ-OsZ|2jXYaXOw;Gtvcr)%b?ZxLW%?qeO);~Y7W zL9I&Hz1h$<(#kEt)+32cyMo_s6Tj<5F8wkAx6S-c%lYgV@Y+lhaN8u{vYy|50iR_r zpJ}U!L!?_!HlOV@UaNj?gEBtzRzA~Oe$yI7ugTW_1-1bNj==@aAq5^0g)Tu^UXg`Y z@4dB*?hlAB2}mq?_v8QjpZ`Dp`v3X&{|~?afBy6T>%aeJfB!%K=l_Mj|1bUjfBFCa zYybaW|NsBb|NkP{E~44aqB+hog&s16o+{=3+BKmn<$l^VAqEW*1se(~HWVy4(eVHG zx&L6mKr^8DlZBCiA(24`WCJKp7}!@gBsMvyX{ofgE2}v)^=eBA3h;>u@C!<5_cp0Z z1o-;;`T6>btItZ*k@S%f5$5Gi5Y5}wMJpl%50COF_qW}N^ literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/host.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/host.gif new file mode 100644 index 0000000000000000000000000000000000000000..b51ae39b8ae4cb2db729d93a7b77a64cdb239423 GIT binary patch literal 568 zcmZ?wbhEHb6krfwc*el+|KI-u+b`_ce)9CWkGu9<+`RL~!es|eoO`=v$C*vL?yg*a z>ci*%i&mXDdhYG&O{bQwJ~U&|!F?xQ&04g3;mX4cR~|Zl?d_$TAC6r3wC&)7gJ)jP zUAkxP(%rKc?>ut$#oDcBk6(Cs;pXRK=byj-{Qtw3|GSRAn6YTrk#o;aUV3@z>f8ON z9v(jb^!xAspML%S{^$Sa-~Ye;`Tzaz|6l)sj{3jt)rD;@&-*MX@>^QOFoA)gpP_qd z!K67AwH>hyU5VXObNgo&PMB5FH>0R`T4Dc;;_fL0ljoFAm{~e`PQ|3zub>)mOGi;tOGD<-B0qg~P6-w1S2O$! m6$B;4MLzdAunS4?_#`B>PHm8lToJJHP_y9b_9iAq25SH$B>DsZ literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/monitorOff.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/monitorOff.gif new file mode 100644 index 0000000000000000000000000000000000000000..42e5f318ae0d0c3621517d841d2b1dbd85abedfb GIT binary patch literal 209 zcmZ?wbhEHb6krfwIKsft*FUMZZ(?^(e^+;3XIJl(sWT={n%X~MQfKd!_n*FZ^h}yG zWqSX_DGL@Yows1|{b%nF9X$9S3>b(5ia%Kx85o2ZbU?~Mb~3Q~El}x8$(*OYWSvfk zQ@eq{7X=wTPFDZ-_KkNqm?~8Ij=`FpN(sc YYIIn$){1q{mUWBY{n!&H!o*+=00VqV{Qv*} literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/monitorOn.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/monitorOn.gif new file mode 100644 index 0000000000000000000000000000000000000000..2ff3974ef67824ba3845758fcd4dbaea01daeea5 GIT binary patch literal 545 zcmZ?wbhEHb6krfwc*elMCE?30=_jL;s-f?pY2c}8;Gu2gC9R*S?^18()1hk~q+#Hp zW9p}C=BIBFU|{ZJ9n|9-Iq}Q4-wbM1y6(+}wvkqD3AP?dY}yt4ZkzaBH*)Eh3Ak|4aY>U;h99+W-I8|APR-pa+USSr{1@JQ;LAE(OI2 z1AASAXH#=aYg>D}rHq19Z?B|`Wve1T8!Iz6D+?RHVyi5#hpVfbo2xsIY^xHViy$Wl z6N5UJT&sqvlZB&@g`JS7e5OV literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/tcp.gif b/archive/net.sourceforge.phpeclipse.monitor.ui/icons/obj16/tcp.gif new file mode 100644 index 0000000000000000000000000000000000000000..8a6e219123808023f3a6eb4d9204a246bac22ea7 GIT binary patch literal 586 zcmZ?wbhEHb6krfwc*ej`kdRT4QP5CO(NWRR0VIHohK`1ch6x=Lc5K*j;lhnC-+q7m z^84G5KR+|>DBH1pY+0LRl&N77_GKHQh z<^I|=p(^Em+BG2t4G{$!3Mw`fEI85d|M$7NeCv)9vz8)@<|2#!a+6i9It%IzX4e`n zY&Mx)XSAZ-VrrG~qhrl$Tea4;X|HY5Uf-d=q0?Y#qwe}ngALs#8@f&J>@K;rtN6yI zk(sOc5`%C0Cbr4m$M0s3Jnd+Y+6el7A{I&+ONRO$Y2cs;wILQ literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/plugin.properties b/archive/net.sourceforge.phpeclipse.monitor.ui/plugin.properties new file mode 100644 index 0000000..9ab09e7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/plugin.properties @@ -0,0 +1,68 @@ +pluginName=TCP/IP Monitor +providerName=IBM + +# --------------- TCP/IP Monitor view --------------- + +# Labels +viewTitle=TCP/IP Monitor +viewRequest=Request: {0} +viewResponse=Response: {0} +viewTime=Time of request: {0} +viewType=Type: {0} +viewResponseTime=Response Time: {0} +viewSize=Size: {0} +viewResponseTimeFormat={0} ms +viewSizeFormat={0} ({1}) bytes +viewDateFormat=h:mm.s.S a +viewResponseTypeUnknown=Unknown + +# Actions +actionSortByResponseTime=Sort by response time +actionClearToolTip=Clear +actionShowHeader=Show header +actionProperties=Properties... + + +# --------------- RequestResponse Viewers --------------- +byteView=Byte View +imageView=Image View +xmlView=XML View +headerLabel=Header +imageViewInvalid=Not a valid image file +xmlViewInvalid=Not a valid XML file + +# --------------- Errors --------------- +errorPortInUse=The TCP/IP monitor could not start because the port is in use. +errorCouldNotStart=TCP/IP monitor could not start correctly. +errorGeneral=Error: {0} +errorInvalidRemotePort=The remote port number is invalid. +errorInvalidLocalPort=The local port number is invalid. +errorDialogTitle=Error + +# --------------- General UI --------------- +monitorList=TCP/IP Monitors: +columnLocal=Local Port +columnRemote=Host name +columnType=Type +columnStatus=Status +add=Add... +edit=Edit... +remove=Remove +start=Start +stop=Stop +started=Started +stopped=Stopped + +newMonitor=New Monitor +editMonitor=Edit Monitor + +localPort=Local monitoring port: +remoteGroup=Monitor +remoteHost=Host name: +remotePort=Port: +parseType=Type: + +preferenceTitle=TCP/IP Monitor +preferenceDescription=Configure TCP/IP monitors on local and remote ports. + +prefShowView=&Show the TCP/IP Monitor view when there is activity \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/plugin.xml b/archive/net.sourceforge.phpeclipse.monitor.ui/plugin.xml new file mode 100644 index 0000000..da8d607 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/plugin.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/schema/viewers.exsd b/archive/net.sourceforge.phpeclipse.monitor.ui/schema/viewers.exsd new file mode 100644 index 0000000..a175038 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/schema/viewers.exsd @@ -0,0 +1,128 @@ + + + + + + + + + This extension point is used to provide a viewer for a specific type of content. (e.g. a viewer for a particular image format) + + + + + + + + + + + + a fully qualified identifier of the target extension point + + + + + + + an optional identifier of the extension instance + + + + + + + an optional name of the extension instance + + + + + + + + + + + + + + + + + + + specifies a unique identifier for this extension point + + + + + + + specifies the fully qualified name of the Java class that implements <samp>IContentViewer</samp> + + + + + + + + + + a translatable name used to identify the content viewer + + + + + + + + + + + + + + + + + + + The following is an example of a content viewer extension point: + +<p> +<pre> +<extension point="net.sourceforge.phpeclipse.monitor.ui.viewers"> + <viewer + id="com.example.byteviewer" + class="com.example.ByteContentViewer" + type="requestresponse" + label="%byteView"/> +</extension> +</pre> +</p> + + + + + + + + + Value of the attribute <b>class</b> must be a fully qualified name of a Java class that implements the interface <b>net.sourceforge.phpdt.monitor.ui.IContentViewer</b>. + + + + + + + + + Copyright (c) 2000, 2003 IBM Corporation and others.<br> +All rights reserved. This program and the accompanying materials are made +available under the terms of the Common Public License v1.0 which accompanies +this distribution, and is available at +<a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a> + + + + diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/IContentViewer.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/IContentViewer.java new file mode 100644 index 0000000..05316c2 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/IContentViewer.java @@ -0,0 +1,46 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui; + +import org.eclipse.swt.widgets.Composite; +/** + * Viewer interface for displaying request and response messages + */ +public interface IContentViewer { + //message to display + //public static final byte REQUEST_MSG = 0; + //public static final byte RESPONSE_MSG = 1; + + /** + * Initializes the viewer so it can be used to display + * TCP/IP messages. Requires the parent Composite that the + * viewer will display its information in, and a byte message + * (IRequestResponseViewer.REQUEST_MSG or IRequestResponseViewer.RESPONSE_MSG) + * to display either the tcpip request information, or the tcpip response + * information + * @param parent org.eclipse.widgets.Composite + * @param message byte + */ + public void init(Composite parent); + + /** + * Sets the IRequest object that the viewer is + * currently displaying. The parameter should be null if + * no IRequest object is to be displayed. + * @param reqresp org.eclipse.tcpip.monitor.IRequest + */ + public void setContent(byte[] b); + + /** + * Disposes the Composite containing this viewer's TCP/IP message display + */ + public void dispose(); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/ContextIds.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/ContextIds.java new file mode 100644 index 0000000..56dd2f1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/ContextIds.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; +/** + * Constant ids for context help. + */ +public interface ContextIds { + public static final String VIEW = MonitorUIPlugin.PLUGIN_ID + ".tmvw0000"; + public static final String VIEW_TREE = MonitorUIPlugin.PLUGIN_ID + ".tmvw0002"; + public static final String VIEW_REQUEST = MonitorUIPlugin.PLUGIN_ID + ".tmvw0004"; + public static final String VIEW_RESPONSE = MonitorUIPlugin.PLUGIN_ID + ".tmvw0006"; + + public static final String PREF = MonitorUIPlugin.PLUGIN_ID + ".tmpr0000"; + public static final String PREF_SHOW = MonitorUIPlugin.PLUGIN_ID + ".tmpr0002"; + public static final String PREF_MONITORS = MonitorUIPlugin.PLUGIN_ID + ".tmpr0004"; + public static final String PREF_DIALOG = MonitorUIPlugin.PLUGIN_ID + ".tmpr0006"; +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorComposite.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorComposite.java new file mode 100644 index 0000000..ec1d9a6 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorComposite.java @@ -0,0 +1,254 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +import net.sourceforge.phpdt.monitor.core.IMonitorWorkingCopy; +import net.sourceforge.phpdt.monitor.core.MonitorCore; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.*; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.help.WorkbenchHelp; +/** + * + */ +public class MonitorComposite extends Composite { + protected Table table; + protected TableViewer tableViewer; + + protected Button edit; + protected Button remove; + protected Button start; + protected Button stop; + + protected List selection2; + + public MonitorComposite(Composite parent, int style) { + super(parent, style); + + createWidgets(); + } + + protected void createWidgets() { + GridLayout layout = new GridLayout(); + layout.horizontalSpacing = 6; + layout.verticalSpacing = 6; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.numColumns = 2; + setLayout(layout); + + GridData data = new GridData(GridData.FILL_BOTH); + setLayoutData(data); + + Label label = new Label(this, SWT.WRAP); + label.setText(MonitorUIPlugin.getResource("%monitorList")); + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER)); + + label = new Label(this, SWT.NONE); + + table = new Table(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); + data.widthHint = 300; + WorkbenchHelp.setHelp(table, ContextIds.PREF_MONITORS); + + table.setLayoutData(data); + table.setHeaderVisible(true); + table.setLinesVisible(true); + + TableLayout tableLayout = new TableLayout(); + + TableColumn statusColumn = new TableColumn(table, SWT.NONE); + statusColumn.setText(MonitorUIPlugin.getResource("%columnStatus")); + ColumnWeightData colData = new ColumnWeightData(6, 60, true); + tableLayout.addColumnData(colData); + + TableColumn remoteColumn = new TableColumn(table, SWT.NONE); + remoteColumn.setText(MonitorUIPlugin.getResource("%columnRemote")); + colData = new ColumnWeightData(12, 120, true); + tableLayout.addColumnData(colData); + + TableColumn httpColumn = new TableColumn(table, SWT.NONE); + httpColumn.setText(MonitorUIPlugin.getResource("%columnType")); + colData = new ColumnWeightData(5, 55, true); + tableLayout.addColumnData(colData); + + TableColumn localColumn = new TableColumn(table, SWT.NONE); + localColumn.setText(MonitorUIPlugin.getResource("%columnLocal")); + colData = new ColumnWeightData(5, 50, true); + tableLayout.addColumnData(colData); + + table.setLayout(tableLayout); + + tableViewer = new TableViewer(table); + tableViewer.setContentProvider(new MonitorContentProvider()); + tableViewer.setLabelProvider(new MonitorTableLabelProvider()); + tableViewer.setInput("root"); + + tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + setSelection(event.getSelection()); + } + }); + + Composite buttonComp = new Composite(this, SWT.NONE); + layout = new GridLayout(); + layout.horizontalSpacing = 0; + layout.verticalSpacing = 8; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.numColumns = 1; + buttonComp.setLayout(layout); + data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL); + buttonComp.setLayoutData(data); + + Button add = SWTUtil.createButton(buttonComp, MonitorUIPlugin.getResource("%add")); + add.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + MonitorDialog dialog = new MonitorDialog(getShell()); + if (dialog.open() == Window.CANCEL) + return; + tableViewer.refresh(); + + List list = MonitorCore.getMonitors(); + Object monitor = list.get(list.size() - 1); + tableViewer.setSelection(new StructuredSelection(monitor)); + } + }); + + edit = SWTUtil.createButton(buttonComp, MonitorUIPlugin.getResource("%edit")); + edit.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + IMonitor monitor = (IMonitor) getSelection().get(0); + IMonitorWorkingCopy wc = monitor.getWorkingCopy(); + + MonitorDialog dialog = new MonitorDialog(getShell(), wc); + if (dialog.open() != Window.CANCEL) { + try { + tableViewer.refresh(wc.save()); + } catch (Exception ex) { } + } + } + }); + edit.setEnabled(false); + + remove = SWTUtil.createButton(buttonComp, MonitorUIPlugin.getResource("%remove")); + remove.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Iterator iterator = getSelection().iterator(); + while (iterator.hasNext()) { + IMonitor monitor = (IMonitor) iterator.next(); + try { + monitor.delete(); + } catch (Exception ex) { } + tableViewer.remove(monitor); + + List list = MonitorCore.getMonitors(); + Object monitor2 = list.get(list.size() - 1); + tableViewer.setSelection(new StructuredSelection(monitor2)); + } + } + }); + remove.setEnabled(false); + + start = SWTUtil.createButton(buttonComp, MonitorUIPlugin.getResource("%start")); + start.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Iterator iterator = getSelection().iterator(); + while (iterator.hasNext()) { + IMonitor monitor = (IMonitor) iterator.next(); + try { + MonitorCore.startMonitor(monitor); + } catch (CoreException ce) { + MessageDialog.openError(getShell(), MonitorUIPlugin.getResource("%errorDialogTitle"), ce.getStatus().getMessage()); + } catch (Exception ce) { + MessageDialog.openError(getShell(), MonitorUIPlugin.getResource("%errorDialogTitle"), ce.getMessage()); + } + tableViewer.refresh(monitor, true); + } + tableViewer.setSelection(tableViewer.getSelection()); + } + }); + start.setEnabled(false); + + stop = SWTUtil.createButton(buttonComp, MonitorUIPlugin.getResource("%stop")); + stop.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Iterator iterator = getSelection().iterator(); + while (iterator.hasNext()) { + IMonitor monitor = (IMonitor) iterator.next(); + try { + MonitorCore.stopMonitor(monitor); + } catch (Exception ex) { } + tableViewer.refresh(monitor, true); + } + tableViewer.setSelection(tableViewer.getSelection()); + } + }); + stop.setEnabled(false); + } + + protected List getSelection() { + return selection2; + } + + protected void setSelection(ISelection sel2) { + IStructuredSelection sel = (IStructuredSelection) sel2; + Iterator iterator = sel.iterator(); + selection2 = new ArrayList(); + + while (iterator.hasNext()) { + Object obj = iterator.next(); + if (obj instanceof IMonitor) + selection2.add(obj); + } + + if (!selection2.isEmpty()) { + remove.setEnabled(true); + + boolean allStopped = true; + boolean allStarted = true; + + iterator = selection2.iterator(); + while (iterator.hasNext()) { + IMonitor monitor = (IMonitor) iterator.next(); + if (monitor.isRunning()) + allStopped = false; + else + allStarted = false; + } + start.setEnabled(allStopped); + stop.setEnabled(allStarted); + edit.setEnabled(selection2.size() == 1 && allStopped); + } else { + edit.setEnabled(false); + remove.setEnabled(false); + start.setEnabled(false); + stop.setEnabled(false); + } + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorContentProvider.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorContentProvider.java new file mode 100644 index 0000000..aa08b4f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorContentProvider.java @@ -0,0 +1,73 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import java.util.*; + +import net.sourceforge.phpdt.monitor.core.IMonitor; +import net.sourceforge.phpdt.monitor.core.MonitorCore; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.IStructuredContentProvider; +/** + * Monitor content provider. + */ +public class MonitorContentProvider implements IStructuredContentProvider { + /** + * MonitorContentProvider constructor comment. + */ + public MonitorContentProvider() { + super(); + } + + /** + * Disposes of this content provider. + * This is called by the viewer when it is disposed. + */ + public void dispose() { } + + /** + * Returns the elements to display in the viewer + * when its input is set to the given element. + * These elements can be presented as rows in a table, items in a list, etc. + * The result is not modified by the viewer. + * + * @param inputElement the input element + * @return the array of elements to display in the viewer + */ + public Object[] getElements(Object inputElement) { + List list = new ArrayList(); + Iterator iterator = MonitorCore.getMonitors().iterator(); + while (iterator.hasNext()) { + IMonitor monitor = (IMonitor) iterator.next(); + list.add(monitor); + } + return list.toArray(); + } + + /** + * Notifies this content provider that the given viewer's input + * has been switched to a different element. + *

+ * A typical use for this method is registering the content provider as a listener + * to changes on the new input (using model-specific means), and deregistering the viewer + * from the old input. In response to these change notifications, the content provider + * propagates the changes to the viewer. + *

+ * + * @param viewer the viewer + * @param oldInput the old input element, or null if the viewer + * did not previously have an input + * @param newInput the new input element, or null if the viewer + * does not have an input + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorDialog.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorDialog.java new file mode 100644 index 0000000..9ef6c99 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorDialog.java @@ -0,0 +1,266 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import java.net.InetAddress; + +import net.sourceforge.phpdt.monitor.core.IMonitorWorkingCopy; +import net.sourceforge.phpdt.monitor.core.IProtocolAdapter; +import net.sourceforge.phpdt.monitor.core.MonitorCore; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.help.WorkbenchHelp; +/** + * + */ +public class MonitorDialog extends Dialog { + protected IMonitorWorkingCopy monitor; + protected boolean isEdit; + + private Button okButton; + private Text monitorPort; + private Text remoteHostname; + private Text remotePort; + + interface StringModifyListener { + public void valueChanged(String s); + } + + interface BooleanModifyListener { + public void valueChanged(boolean b); + } + + interface TypeModifyListener { + public void valueChanged(IProtocolAdapter type); + } + + /** + * @param parentShell + */ + public MonitorDialog(Shell parentShell, IMonitorWorkingCopy monitor) { + super(parentShell); + this.monitor = monitor; + isEdit = true; + } + + public MonitorDialog(Shell parentShell) { + super(parentShell); + monitor = MonitorCore.createMonitor(); + isEdit = false; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + if (isEdit) + shell.setText(MonitorUIPlugin.getResource("%editMonitor")); + else + shell.setText(MonitorUIPlugin.getResource("%newMonitor")); + } + + protected Label createLabel(Composite comp, String txt) { + Label label = new Label(comp, SWT.NONE); + label.setText(txt); + label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING)); + return label; + } + + protected Text createText(Composite comp, String txt, final StringModifyListener listener) { + final Text text = new Text(comp, SWT.BORDER); + if (txt != null) + text.setText(txt); + GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.widthHint = 150; + text.setLayoutData(data); + if (listener != null) + text.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + listener.valueChanged(text.getText()); + } + }); + return text; + } + + protected Combo createTypeCombo(Composite comp, final IProtocolAdapter[] types, IProtocolAdapter sel, final TypeModifyListener listener) { + final Combo combo = new Combo(comp, SWT.DROP_DOWN | SWT.READ_ONLY); + int size = types.length; + String[] items = new String[size]; + int index = -1; + for (int i = 0; i < size; i++) { + items[i] = types[i].getName(); + if (types[i].equals(sel)) + index = i; + } + combo.setItems(items); + if (index >= 0) + combo.select(index); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); + data.widthHint = 150; + combo.setLayoutData(data); + if (listener != null) + combo.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + listener.valueChanged(types[combo.getSelectionIndex()]); + } + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + }); + return combo; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + ((GridLayout)composite.getLayout()).numColumns = 2; + + WorkbenchHelp.setHelp(composite, ContextIds.PREF_DIALOG); + + createLabel(composite, MonitorUIPlugin.getResource("%localPort")); + monitorPort = createText(composite, monitor.getLocalPort() + "", new StringModifyListener() { + public void valueChanged(String s) { + try { + monitor.setLocalPort(Integer.parseInt(s)); + } catch (Exception e) { } + validateFields(); + } + }); + + Group group = new Group(composite, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + group.setLayout(layout); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + group.setLayoutData(data); + group.setText(MonitorUIPlugin.getResource("%remoteGroup")); + + createLabel(group, MonitorUIPlugin.getResource("%remoteHost")); + remoteHostname = createText(group, monitor.getRemoteHost(), new StringModifyListener() { + public void valueChanged(String s) { + monitor.setRemoteHost(s); + validateFields(); + } + }); + + createLabel(group, MonitorUIPlugin.getResource("%remotePort")); + remotePort = createText(group, monitor.getRemotePort() + "", new StringModifyListener() { + public void valueChanged(String s) { + try { + monitor.setRemotePort(Integer.parseInt(s)); + } catch (Exception e) { } + validateFields(); + } + }); + + createLabel(group, MonitorUIPlugin.getResource("%parseType")); + createTypeCombo(group, MonitorCore.getProtocolAdapters(), monitor.getProtocolAdapter(), new TypeModifyListener() { + public void valueChanged(IProtocolAdapter type) { + monitor.setProtocolAdapter(type); + } + }); + + return composite; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() { + monitor.save(); + super.okPressed(); + } + + protected Control createButtonBar(Composite parent) { + Control buttonControl = super.createButtonBar(parent); + validateFields(); + return buttonControl; + } + + private void setOKButtonEnabled(boolean curIsEnabled) { + if (okButton == null) + okButton = getButton(IDialogConstants.OK_ID); + + if (okButton != null) + okButton.setEnabled(curIsEnabled); + } + + protected void validateFields() { + if (monitorPort == null) + return; + + boolean result = true; + + String currHostname = remoteHostname.getText(); + if (!isValidHostname(currHostname)) + result = false; + + String currHostnamePort = remotePort.getText(); + try { + Integer.parseInt(currHostnamePort); + } catch (Exception any) { + result = false; + } + + String currMonitorPort = monitorPort.getText(); + try { + Integer.parseInt(currMonitorPort); + } catch (Exception any) { + result = false; + } + + if (result && isLocalhost(currHostname)) { + if (currHostnamePort.equals(currMonitorPort)) + result = false; + } + setOKButtonEnabled(result); + } + + protected static boolean isValidHostname(String host) { + if (host == null || host.trim().length() < 1) + return false; + if (host.indexOf("/") >= 0) + return false; + if (host.indexOf("\\") >= 0) + return false; + if (host.indexOf(" ") >= 0) + return false; + return true; + } + + protected static boolean isLocalhost(String host) { + if (host == null) + return false; + try { + if ("localhost".equals(host) || "127.0.0.1".equals(host)) + return true; + InetAddress localHostaddr = InetAddress.getLocalHost(); + if (localHostaddr.getHostName().equals(host)) + return true; + } catch (Exception e) { + Trace.trace(Trace.WARNING, "Error checking for localhost", e); + } + return false; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPreferencePage.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPreferencePage.java new file mode 100644 index 0000000..86ba1aa --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPreferencePage.java @@ -0,0 +1,111 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import org.eclipse.swt.*; +import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.help.WorkbenchHelp; +/** + * The preference page that holds monitor properties. + */ +public class MonitorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + protected Button displayButton; + + /** + * MonitorPreferencePage constructor comment. + */ + public MonitorPreferencePage() { + super(); + noDefaultAndApplyButton(); + } + + /** + * Create the preference options. + * + * @param parent org.eclipse.swt.widgets.Composite + * @return org.eclipse.swt.widgets.Control + */ + protected Control createContents(Composite parent) { + initializeDialogUnits(parent); + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.horizontalSpacing = convertHorizontalDLUsToPixels(4); + layout.verticalSpacing = convertVerticalDLUsToPixels(4); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); + composite.setLayoutData(data); + WorkbenchHelp.setHelp(composite, ContextIds.PREF); + + Label label = new Label(composite, SWT.WRAP); + label.setText(MonitorUIPlugin.getResource("%preferenceDescription")); + data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + label.setLayoutData(data); + + displayButton = new Button(composite, SWT.CHECK); + displayButton.setText(MonitorUIPlugin.getResource("%prefShowView")); + displayButton.setSelection(MonitorUIPlugin.getShowOnActivityPreference()); + WorkbenchHelp.setHelp(displayButton, ContextIds.PREF_SHOW); + + label = new Label(composite, SWT.NONE); + label.setText(""); + + MonitorComposite monitorComp = new MonitorComposite(composite, SWT.NONE); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + monitorComp.setLayoutData(data); + + Dialog.applyDialogFont(composite); + + return composite; + } + + /** + * Initializes this preference page using the passed desktop. + * + * @param desktop the current desktop + */ + public void init(IWorkbench workbench) { + } + + /** + * Performs special processing when this page's Defaults button has been pressed. + *

+ * This is a framework hook method for sublcasses to do special things when + * the Defaults button has been pressed. + * Subclasses may override, but should call super.performDefaults. + *

+ */ + protected void performDefaults() { + displayButton.setSelection(MonitorUIPlugin.getDefaultShowOnActivityPreference()); + super.performDefaults(); + } + + /** + * Method declared on IPreferencePage. + * Subclasses should override + */ + public boolean performOk() { + MonitorUIPlugin.setShowOnActivityPreference(displayButton.getSelection()); + MonitorUIPlugin.getInstance().savePluginPreferences(); + return true; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPrefrencesDialog.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPrefrencesDialog.java new file mode 100644 index 0000000..8e50b5a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorPrefrencesDialog.java @@ -0,0 +1,82 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import net.sourceforge.phpdt.monitor.core.IMonitorWorkingCopy; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.help.WorkbenchHelp; +/** + * + */ +public class MonitorPrefrencesDialog extends Dialog { + protected IMonitorWorkingCopy monitor; + protected boolean isEdit; + + /** + * @param parentShell + */ + public MonitorPrefrencesDialog(Shell parentShell, IMonitorWorkingCopy monitor) { + super(parentShell); + this.monitor = monitor; + isEdit = true; + } + + public MonitorPrefrencesDialog(Shell composite) { + super(composite); + isEdit=false; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(MonitorUIPlugin.getResource("%preferenceTitle")); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite compositeParent = (Composite) super.createDialogArea(parent); + + Composite composite = new Composite(compositeParent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = convertHorizontalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertVerticalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + composite.setLayout(layout); + GridData data = new GridData(GridData.FILL_BOTH); + composite.setLayoutData(data); + WorkbenchHelp.setHelp(composite, ContextIds.PREF); + + MonitorComposite monitorComp = new MonitorComposite(composite, SWT.NONE); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + monitorComp.setLayoutData(data); + + Dialog.applyDialogFont(composite); + + return composite; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() { + MonitorUIPlugin.getInstance().savePluginPreferences(); + super.okPressed(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorTableLabelProvider.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorTableLabelProvider.java new file mode 100644 index 0000000..0832a84 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorTableLabelProvider.java @@ -0,0 +1,127 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import net.sourceforge.phpdt.monitor.core.IMonitor; + +import org.eclipse.jface.viewers.ILabelProviderListener; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.viewers.ITableLabelProvider; +/** + * Monitor table label provider. + */ +public class MonitorTableLabelProvider implements ITableLabelProvider { + /** + * MonitorTableLabelProvider constructor comment. + */ + public MonitorTableLabelProvider() { + super(); + } + + /** + * Adds a listener to this label provider. + * Has no effect if an identical listener is already registered. + *

+ * Label provider listeners are informed about state changes + * that affect the rendering of the viewer that uses this label provider. + *

+ * + * @param listener a label provider listener + */ + public void addListener(ILabelProviderListener listener) { } + + /** + * Disposes of this label provider. When a label provider is + * attached to a viewer, the viewer will automatically call + * this method when the viewer is being closed. When label providers + * are used outside of the context of a viewer, it is the client's + * responsibility to ensure that this method is called when the + * provider is no longer needed. + */ + public void dispose() { } + + /** + * Returns the label image for the given column of the given element. + * + * @param element the object representing the entire row, or + * null indicating that no input object is set + * in the viewer + * @param columnIndex the zero-based index of the column in which + * the label appears + */ + public Image getColumnImage(Object element, int columnIndex) { + if (columnIndex == 0) { + IMonitor monitor = (IMonitor) element; + if (monitor.isRunning()) + return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_MONITOR_ON); + else + return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_MONITOR_OFF); + } + return null; + } + + /** + * Returns the label text for the given column of the given element. + * + * @param element the object representing the entire row, or + * null indicating that no input object is set + * in the viewer + * @param columnIndex the zero-based index of the column in which the label appears + */ + public String getColumnText(Object element, int columnIndex) { + IMonitor monitor = (IMonitor) element; + if (columnIndex == 0) { + if (monitor.isRunning()) + return MonitorUIPlugin.getResource("%started"); + else + return MonitorUIPlugin.getResource("%stopped"); + } else if (columnIndex == 1) + return monitor.getRemoteHost() + ":" + monitor.getRemotePort(); + else if (columnIndex == 2) + return monitor.getProtocolAdapter().getName(); + else if (columnIndex == 3) + return monitor.getLocalPort() + ""; + else + return "X"; + } + + protected String notNull(String s) { + if (s != null) + return s; + else + return ""; + } + + /** + * Returns whether the label would be affected + * by a change to the given property of the given element. + * This can be used to optimize a non-structural viewer update. + * If the property mentioned in the update does not affect the label, + * then the viewer need not update the label. + * + * @param element the element + * @param property the property + * @return true if the label would be affected, + * and false if it would be unaffected + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * Removes a listener to this label provider. + * Has no affect if an identical listener is not registered. + * + * @param listener a label provider listener + */ + public void removeListener(ILabelProviderListener listener) { } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorUIPlugin.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorUIPlugin.java new file mode 100644 index 0000000..0f9f5f3 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/MonitorUIPlugin.java @@ -0,0 +1,225 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import java.util.*; +import java.net.URL; +import java.text.MessageFormat; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.core.runtime.*; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +/** + * The TCP/IP monitor UI plugin. + */ +public class MonitorUIPlugin extends AbstractUIPlugin { + private static MonitorUIPlugin singleton; + + protected Map imageDescriptors = new HashMap(); + + private static URL ICON_BASE_URL; + + private static final String URL_CLCL = "clcl16/"; + private static final String URL_ELCL = "elcl16/"; + private static final String URL_DLCL = "dlcl16/"; + private static final String URL_OBJ = "obj16/"; + + public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.monitor.ui"; + + public static final String IMG_ELCL_SORT_RESPONSE_TIME = "IMG_ELCL_SORT_RESPONSE_TIME"; + public static final String IMG_ELCL_CLEAR = "IMG_ELCL_CLEAR"; + public static final String IMG_ELCL_HTTP_HEADER = "IMG_ELCL_HTTP_HEADER"; + public static final String IMG_CLCL_SORT_RESPONSE_TIME = "IMG_CLCL_SORT_RESPONSE_TIME"; + public static final String IMG_CLCL_CLEAR = "IMG_CLCL_CLEAR"; + public static final String IMG_CLCL_HTTP_HEADER = "IMG_CLCL_HTTP_HEADER"; + public static final String IMG_DLCL_SORT_RESPONSE_TIME = "IMG_DLCL_SORT_RESPONSE_TIME"; + public static final String IMG_DLCL_CLEAR = "IMG_DLCL_CLEAR"; + public static final String IMG_DLCL_HTTP_HEADER = "IMG_DLCL_HTTP_HEADER"; + + public static final String IMG_REQUEST_RESPONSE = "requestResponse"; + public static final String IMG_HOST = "host"; + public static final String IMG_MONITOR_ON = "monitorOn"; + public static final String IMG_MONITOR_OFF = "monitorOff"; + + private static final String SHOW_VIEW_ON_ACTIVITY = "show-view"; + private static final String SHOW_HEADER = "show-header"; + + /** + * MonitorUIPlugin constructor comment. + */ + public MonitorUIPlugin() { + super(); + singleton = this; + } + + /** + * Creates and pre-loads the image registry. + * + * @return ImageRegistry + */ + protected ImageRegistry createImageRegistry() { + ImageRegistry registry = super.createImageRegistry(); + + registerImage(registry, IMG_REQUEST_RESPONSE, URL_OBJ + "tcp.gif"); + registerImage(registry, IMG_HOST, URL_OBJ + "host.gif"); + registerImage(registry, IMG_MONITOR_ON, URL_OBJ + "monitorOn.gif"); + registerImage(registry, IMG_MONITOR_OFF, URL_OBJ + "monitorOff.gif"); + + registerImage(registry, IMG_CLCL_CLEAR, URL_CLCL + "clear.gif"); + registerImage(registry, IMG_CLCL_SORT_RESPONSE_TIME, URL_CLCL + "sortResponseTime.gif"); + registerImage(registry, IMG_CLCL_HTTP_HEADER, URL_CLCL + "httpHeader.gif"); + + registerImage(registry, IMG_ELCL_CLEAR, URL_ELCL + "clear.gif"); + registerImage(registry, IMG_ELCL_SORT_RESPONSE_TIME, URL_ELCL + "sortResponseTime.gif"); + registerImage(registry, IMG_ELCL_HTTP_HEADER, URL_ELCL + "httpHeader.gif"); + + registerImage(registry, IMG_DLCL_CLEAR, URL_DLCL + "clear.gif"); + registerImage(registry, IMG_DLCL_SORT_RESPONSE_TIME, URL_DLCL + "sortResponseTime.gif"); + registerImage(registry, IMG_DLCL_HTTP_HEADER, URL_DLCL + "httpHeader.gif"); + + return registry; + } + + /** + * Return the image with the given key from the image registry. + * + * @param key java.lang.String + * @return org.eclipse.jface.parts.IImage + */ + public static Image getImage(String key) { + return getInstance().getImageRegistry().get(key); + } + + /** + * Return the image with the given key from the image registry. + * + * @param key java.lang.String + * @return org.eclipse.jface.parts.IImage + */ + public static ImageDescriptor getImageDescriptor(String key) { + try { + getInstance().getImageRegistry(); + return (ImageDescriptor) getInstance().imageDescriptors.get(key); + } catch (Exception e) { + return null; + } + } + + /** + * Returns the singleton instance of this plugin. + * + * @return org.eclipse.tcpip.monitor.MonitorServerPlugin + */ + public static MonitorUIPlugin getInstance() { + return singleton; + } + + /** + * Returns the translated String found with the given key. + * + * @return java.lang.String + * @param key java.lang.String + */ + public static String getResource(String key) { + try { + return Platform.getResourceString(getInstance().getBundle(), key); + } catch (Exception e) { + return key; + } + } + + /** + * Returns the translated String found with the given key, + * and formatted with the given object. + * + * @param key java.lang.String + * @param obj java.lang.Object[] + * @return java.lang.String + */ + public static String getResource(String key, Object[] obj) { + try { + return MessageFormat.format(getResource(key), obj); + } catch (Exception e) { + return key; + } + } + + /** + * Returns the translated String found with the given key, + * and formatted with the given object. + * + * @param key java.lang.String + * @param s java.lang.String + * @return java.lang.String + */ + public static String getResource(String key, String s) { + try { + return MessageFormat.format(getResource(key), new String[] {s}); + } catch (Exception e) { + return key; + } + } + + /** + * Register an image with the registry. + * + * @param key java.lang.String + * @param partialURL java.lang.String + */ + private void registerImage(ImageRegistry registry, String key, String partialURL) { + if (ICON_BASE_URL == null) { + String pathSuffix = "icons/"; + ICON_BASE_URL = singleton.getBundle().getEntry(pathSuffix); + } + + try { + ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL)); + registry.put(key, id); + imageDescriptors.put(key, id); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error registering image", e); + } + } + + /** + * Start this plug-in. + */ + public void start(BundleContext context) throws Exception { + super.start(context); + + getPreferenceStore().setDefault(MonitorUIPlugin.SHOW_VIEW_ON_ACTIVITY, true); + } + + public static boolean getDefaultShowOnActivityPreference() { + return getInstance().getPreferenceStore().getDefaultBoolean(SHOW_VIEW_ON_ACTIVITY); + } + + public static boolean getShowOnActivityPreference() { + return getInstance().getPreferenceStore().getBoolean(SHOW_VIEW_ON_ACTIVITY); + } + + public static void setShowOnActivityPreference(boolean b) { + getInstance().getPreferenceStore().setValue(SHOW_VIEW_ON_ACTIVITY, b); + getInstance().savePluginPreferences(); + } + + public static boolean getShowHeaderPreference() { + return getInstance().getPreferenceStore().getBoolean(SHOW_HEADER); + } + + public static void setShowHeaderPreference(boolean b) { + getInstance().getPreferenceStore().setValue(SHOW_HEADER, b); + getInstance().savePluginPreferences(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/RequestListener.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/RequestListener.java new file mode 100644 index 0000000..d176f71 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/RequestListener.java @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.core.IRequestListener; +import net.sourceforge.phpdt.monitor.ui.internal.view.MonitorView; + +/** + * Open the monitor view if there is new activity. + */ +public class RequestListener implements IRequestListener { + public void requestAdded(IRequest rr) { + if (MonitorUIPlugin.getShowOnActivityPreference()) { + MonitorView.open(rr); + } + } + + public void requestChanged(IRequest rr) { } + + public void requestRemoved(IRequest rr) { } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/SWTUtil.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/SWTUtil.java new file mode 100644 index 0000000..3e4dbb9 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/SWTUtil.java @@ -0,0 +1,77 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved.   This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.FontMetrics; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +/** + * SWT Utility class. + */ +public class SWTUtil { + private static FontMetrics fontMetrics; + + protected static void initializeDialogUnits(Control testControl) { + // Compute and store a font metric + GC gc = new GC(testControl); + gc.setFont(JFaceResources.getDialogFont()); + fontMetrics = gc.getFontMetrics(); + gc.dispose(); + } + + /** + * Returns a width hint for a button control. + */ + protected static int getButtonWidthHint(Button button) { + int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); + return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); + } + + public static Button createButton(Composite comp, String label) { + Button b = new Button(comp, SWT.PUSH); + b.setText(label); + if (fontMetrics == null) + initializeDialogUnits(comp); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); + data.widthHint = getButtonWidthHint(b); + data.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT); + b.setLayoutData(data); + return b; + } + + public static Button createCheckbox(Composite comp, String txt, boolean isSelected){ + Button button = new Button(comp, SWT.CHECK); + button.setText(txt); + GridLayout layout = new GridLayout(); + comp.setLayout(layout); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); + data.horizontalIndent = 10; + button.setLayoutData(data); + button.setSelection(isSelected); + return button; + } + + public static Label createLabel(Composite comp, String txt) { + Label label = new Label(comp, SWT.NONE); + label.setText(txt); + label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING)); + return label; + } +} diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/Trace.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/Trace.java new file mode 100644 index 0000000..8358b1d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/Trace.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal; +/** + * Helper class to route trace output. + */ +public class Trace { + public static byte CONFIG = 0; + public static byte WARNING = 1; + public static byte SEVERE = 2; + public static byte FINEST = 3; + + /** + * Trace constructor comment. + */ + private Trace() { + super(); + } + + /** + * Trace the given text. + * + * @param s java.lang.String + */ + public static void trace(byte level, String s) { + trace(level, s, null); + } + + /** + * Trace the given message and exception. + * + * @param s java.lang.String + * @param t java.lang.Throwable + */ + public static void trace(byte level, String s, Throwable t) { + if (!MonitorUIPlugin.getInstance().isDebugging()) + return; + + System.out.println(s); + if (t != null) + t.printStackTrace(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/FilterAction.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/FilterAction.java new file mode 100644 index 0000000..43075aa --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/FilterAction.java @@ -0,0 +1,27 @@ +package net.sourceforge.phpdt.monitor.ui.internal.view; + +import net.sourceforge.phpdt.monitor.core.IContentFilter; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +/** + * + */ +public class FilterAction extends Action { + protected IViewerManager vm; + protected IContentFilter filter; + protected boolean enabled; + + public FilterAction(IViewerManager vm, IContentFilter filter) { + super(filter.getName(), IAction.AS_CHECK_BOX); + this.vm = vm; + this.filter = filter; + } + + public void run() { + if (!isChecked()) + vm.removeFilter(filter); + else + vm.addFilter(filter); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/IViewerManager.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/IViewerManager.java new file mode 100644 index 0000000..18a21d7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/IViewerManager.java @@ -0,0 +1,82 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.view; + +import java.util.List; + +import net.sourceforge.phpdt.monitor.core.IContentFilter; +import net.sourceforge.phpdt.monitor.core.IRequest; + +import org.eclipse.core.runtime.IConfigurationElement; + +/** + * Manager interface for TCP/IP request and response message viewers + */ +public interface IViewerManager { + /** + * Displays the HTTP header viewers if they are hidden. + * If the viewers are not hidden, do nothing. + */ + //public void showHeader(); + + /** + * Hides the HTTP header viewers if they are showing. + * If the viewers are already hidden, do nothing. + */ + //public void hideHeader(); + + /** + * Set whether or not to show HTTP header details + * @param b boolean + */ + public void setDisplayHeaderInfo(boolean b); + + /** + * Returns whether or not HTTP header details is showing + * @return boolean + */ + public boolean getDisplayHeaderInfo(); + + /** + * Show the TCP/IP request message in a parent Composite + * @param rr org.eclipse.tcpip.monitor.internal.RequestResponse + * @param parent org.eclipse.swt.widgets.Composite + */ + public void setRequest(IRequest rr); + + /** + * Returns an array of the available TCP/IP request viewer ids + * @return java.lang.String[] + */ + public List getRequestViewers(); + + /** + * Returns an array of the available TCP/IP response viewer ids + * @return java.lang.String[] + */ + public List getResponseViewers(); + + /** + * Set the TCP/IP request message viewer + * @param id java.lang.String + */ + public void setRequestViewer(IConfigurationElement element); + + /** + * Set the TCP/IP response message viewer + * @param id java.lang.String + */ + public void setResponseViewer(IConfigurationElement element); + + public void addFilter(IContentFilter filter); + + public void removeFilter(IContentFilter filter); +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorTreeContentProvider.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorTreeContentProvider.java new file mode 100644 index 0000000..b73ed65 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorTreeContentProvider.java @@ -0,0 +1,213 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.view; + +import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; + +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.core.MonitorCore; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ITreeContentProvider; +/** + * Content provider for the monitor server view. + */ +public class MonitorTreeContentProvider implements ITreeContentProvider { + protected static final String ROOT = "root"; + + protected boolean sortByResponseTime; + + /** + * ProxyTreeContentProvider constructor comment. + */ + public MonitorTreeContentProvider() { + super(); + } + + /** + * Disposes of this content provider. + *

+ * [Issue: This method should be changed to take a Viewer, + * renamed and repurposed to disconnect a content provider from + * a viewer. This is over and above what inputChanged does, + * which is disconnecting a content provider from the viewer's + * input (but not the viewer itself). + * ] + *

+ */ + public void dispose() { } + + /** + * Returns an iterator over the child elements of the given element. + *

+ * Note: The difference between this method and + * IStructuredContentProvider.getElements is + * that getElements is called to obtain the + * tree viewer's root elements, whereas getChildren is used + * to obtain the children of a given node in the tree + * (including a root). + *

+ *

+ * [Issue: Don't know what above is trying to say. + * See IStructuredContentProvider.getElements. + * ] + *

+ * + * @param element the element + * @return an iterator over the child elements + * (element type: Object) + */ + public Object[] getChildren(Object element) { + if (element instanceof Integer) { + Integer in = (Integer) element; + List list = new ArrayList(); + Iterator iterator = MonitorCore.getRequests().iterator(); + while (iterator.hasNext()) { + IRequest call = (IRequest) iterator.next(); + if (call.getLocalPort() == in.intValue()) + list.add(call); + } + if (sortByResponseTime) + sortByResponseTime(list); + return list.toArray(); + } + return null; + } + + /** + * Returns an iterator over the elements belonging to the + * given element. These elements can be presented as rows in a table, + * items in a list, etc. + *

+ * [Issue: Should return Object[] rather than Iterator. + * ] + *

+ *

+ * [Issue: Not clear what "belonging to the given element" + * means. See ITreeContentProvider.getChildren. + * ] + *

+ * + * @param element the element + * @return an iterator over the elements + * (element type: Object) + */ + public Object[] getElements(Object element) { + if (ROOT.equals(element)) { + List list = new ArrayList(); + Iterator iterator = MonitorCore.getRequests().iterator(); + while (iterator.hasNext()) { + IRequest call = (IRequest) iterator.next(); + Integer in = new Integer(call.getLocalPort()); + if (!list.contains(in)) + list.add(in); + } + + if (sortByResponseTime) + sortByResponseTime(list); + + return list.toArray(); + } else + return null; + } + + /** + * Returns the parent for the given element, or null + * indicating that the parent can't be computed. + * In this case the tree-structured viewer can't expand + * a given node correctly if requested. + * + * @param element the element + * @return the parent element, or null if it + * has none or if the parent cannot be computed + */ + public Object getParent(Object element) { + if (element != null) { + if (element instanceof Integer) + return ROOT; + else { + IRequest call = (IRequest) element; + return new Integer(call.getLocalPort()); + } + } else + return null; + } + + /** + * Returns true if the elements are currently being sorted by response time. + * @return boolean + */ + public boolean getSortByResponseTime() { + return sortByResponseTime; + } + + /** + * Returns whether the given element has children. + *

+ * [Issue: This method may not be warranted if getChildren + * return Object[]. + * ] + *

+ * + * @param element the element + * @return true if the given element has children, + * and false if it has no children + */ + public boolean hasChildren(Object element) { + return (element instanceof Integer); + } + + /** + * Notifies this content provider that the given viewer's input + * has been switched to a different element. + *

+ * A typical use for this method is registering the content provider as a listener + * to changes on the new input (using model-specific means), and deregistering the viewer + * from the old input. In response to these change notifications, the content provider + * propagates the changes to the viewer. + *

+ * + * @param viewer the viewer + * @param oldInput the old input element, or null if the viewer + * did not previously have an input + * @param newInput the new input element, or null if the viewer + * does not have an input + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + /** + * Sets the sort by response time option. + * @param b boolean + */ + public void setSortByResponseTime(boolean b) { + sortByResponseTime = b; + } + + /** + * + */ + protected void sortByResponseTime(List list) { + int size = list.size(); + for (int i = 0; i < size - 1; i++) { + for (int j = i + 1; j < size; j++) { + IRequest c1 = (IRequest) list.get(i); + IRequest c2 = (IRequest) list.get(j); + if (c1.getResponseTime() < c2.getResponseTime()) { + list.set(i, c2); + list.set(j, c1); + } + } + } + + } +} diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorView.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorView.java new file mode 100644 index 0000000..1fe3a56 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/MonitorView.java @@ -0,0 +1,540 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.view; + +import java.text.SimpleDateFormat; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.phpdt.monitor.core.*; +import net.sourceforge.phpdt.monitor.ui.internal.*; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; + +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.part.ViewPart; +/** + * View of TCP/IP activity. + */ +public class MonitorView extends ViewPart { + protected Tree tree; + protected TreeViewer treeViewer; + protected MonitorTreeContentProvider contentProvider; + + protected IRequestListener listener; + protected IViewerManager vm; + protected List requestViewers; + protected List responseViewers; + + protected static SimpleDateFormat format = new SimpleDateFormat(MonitorUIPlugin.getResource("%viewDateFormat")); + protected static final String VIEW_ID = "net.sourceforge.phpeclipse.monitor.core.view"; + protected static final String DEFAULT_VIEWER = "net.sourceforge.phpeclipse.monitor.core.viewers.byteviewer"; + + protected IAction httpHeaderAction; + + protected static MonitorView view; + + /** + * MonitorView constructor comment. + */ + public MonitorView() { + super(); + view = this; + } + + protected void addListener() { + listener = new IRequestListener() { + public void requestAdded(final IRequest rr) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + Integer in = new Integer(rr.getLocalPort()); + treeViewer.add(MonitorTreeContentProvider.ROOT, in); + treeViewer.add(in, rr); + treeViewer.setSelection(new StructuredSelection(rr), true); + } + }); + } + + public void requestChanged(final IRequest rr) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + IStructuredSelection sel = (IStructuredSelection) treeViewer.getSelection(); + + treeViewer.refresh(rr); + if (!sel.isEmpty()) + treeViewer.setSelection(sel); + } + }); + } + + public void requestRemoved(final IRequest rr) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + treeViewer.remove(rr); + } + }); + } + }; + + MonitorCore.addRequestListener(listener); + } + + /** + * Clear the view. + */ + protected void clear() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + treeViewer.setSelection(null); + treeViewer.setInput(MonitorTreeContentProvider.ROOT); + } + }); + } + + protected void setSelection(IRequest request) { + if (treeViewer != null) + treeViewer.setSelection(new StructuredSelection(request)); + } + + + /** + * Returns the inner component in a desktop part. + */ + public void createPartControl(Composite parent) { + SashForm sashFparent = new SashForm(parent, SWT.VERTICAL); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.horizontalSpacing = 4; + layout.verticalSpacing = 4; + sashFparent.setLayout(layout); + sashFparent.setLayoutData(new GridData(GridData.FILL_BOTH)); + WorkbenchHelp.setHelp(sashFparent, ContextIds.VIEW); + + // create tree panel + Composite treePanel = new Composite(sashFparent, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + treePanel.setLayout(layout); + GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.heightHint = 110; + data.horizontalSpan = 2; + treePanel.setLayoutData(data); + + tree = new Tree(treePanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); + data = new GridData(GridData.FILL_BOTH); + //data.widthHint = 120; + tree.setLayoutData(data); + treeViewer = new TreeViewer(tree); + contentProvider = new MonitorTreeContentProvider(); + treeViewer.setContentProvider(contentProvider); + treeViewer.setInput(MonitorTreeContentProvider.ROOT); + treeViewer.setLabelProvider(new TreeLabelProvider()); + WorkbenchHelp.setHelp(tree, ContextIds.VIEW_TREE); + + Composite detailsPanel = new Composite(treePanel, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 2; + layout.marginWidth = 0; + detailsPanel.setLayout(layout); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); + data.widthHint = 200; + detailsPanel.setLayoutData(data); + + final Label label = new Label(detailsPanel, SWT.NONE); + label.setText(MonitorUIPlugin.getResource("%viewTime", "")); + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); + + final Label label2 = new Label(detailsPanel, SWT.NONE); + label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", "")); + label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); + + final Label label3 = new Label(detailsPanel, SWT.NONE); + label3.setText(MonitorUIPlugin.getResource("%viewType", "")); + label3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); + + // create center and right panels + SashForm sashFchild = new SashForm(sashFparent, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.horizontalSpacing = 2; + layout.verticalSpacing = 4; + sashFchild.setLayout(layout); + sashFparent.setWeights(new int[] { 30, 70 }); + + // request panel + Composite request = new Composite(sashFchild, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 3; + layout.marginHeight = 2; + layout.marginWidth = 0; + request.setLayout(layout); + request.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Composite requestHeader = new Composite(request, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 0; + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 2; + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.heightHint = 30; + requestHeader.setLayout(layout); + requestHeader.setLayoutData(data); + + Composite requestHeaderLeft = new Composite(requestHeader, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + data.heightHint = 30; + requestHeaderLeft.setLayout(layout); + requestHeaderLeft.setLayoutData(data); + + Label empty1 = new Label(requestHeaderLeft, SWT.NONE); + empty1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + + final Label requestLabel = new Label(requestHeaderLeft, SWT.NONE); + requestLabel.setText(MonitorUIPlugin.getResource("%viewRequest", "")); + requestLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END)); + + final Label requestSizeLabel = new Label(requestHeaderLeft, SWT.NONE); + requestSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", "")); + requestSizeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END)); + + Composite requestHeaderRight = new Composite(requestHeader, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL); + data.heightHint = 30; + requestHeaderRight.setLayout(layout); + requestHeaderRight.setLayoutData(data); + + Label empty2 = new Label(requestHeaderRight, SWT.NONE); + empty2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + + Combo requestViewerCombo = new Combo(requestHeaderRight, SWT.DROP_DOWN | SWT.READ_ONLY); + requestViewerCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END)); + + // response panel + Composite response = new Composite(sashFchild, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 3; + layout.marginHeight = 2; + layout.marginWidth = 0; + response.setLayout(layout); + response.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Composite responseHeader = new Composite(response, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 0; + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 2; + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.heightHint = 30; + responseHeader.setLayout(layout); + responseHeader.setLayoutData(data); + + Composite responseHeaderLeft = new Composite(responseHeader, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + data.heightHint = 30; + responseHeaderLeft.setLayout(layout); + responseHeaderLeft.setLayoutData(data); + + Label empty3 = new Label(responseHeaderLeft, SWT.NONE); + empty3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + + final Label responseLabel = new Label(responseHeaderLeft, SWT.NONE); + responseLabel.setText(MonitorUIPlugin.getResource("%viewResponse", "")); + responseLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); + + final Label responseSizeLabel = new Label(responseHeaderLeft, SWT.NONE); + responseSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", "")); + responseSizeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END)); + + Composite responseHeaderRight = new Composite(responseHeader, SWT.NONE); + layout = new GridLayout(); + layout.verticalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL); + data.heightHint = 30; + responseHeaderRight.setLayout(layout); + responseHeaderRight.setLayoutData(data); + + Label empty4 = new Label(responseHeaderRight, SWT.NONE); + empty4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + + Combo responseViewerCombo = new Combo(responseHeaderRight, SWT.DROP_DOWN | SWT.READ_ONLY); + responseViewerCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END)); + + //Viewer manager + vm = new ViewerManager(request, request, response, response); + requestViewers = vm.getRequestViewers(); + responseViewers = vm.getResponseViewers(); + + //Set up the viewer combo boxes + Iterator iterator = requestViewers.iterator(); + int ctr = 0; + while(iterator.hasNext()) { + IConfigurationElement element = (IConfigurationElement) iterator.next(); + requestViewerCombo.add(element.getAttribute("label"), ctr); + if (element.getAttribute("id").equals(DEFAULT_VIEWER)) { + requestViewerCombo.select(ctr); + vm.setRequestViewer(element); + } + ctr++; + } + requestViewerCombo.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + Combo rvCombo = (Combo) arg0.getSource(); + vm.setRequestViewer((IConfigurationElement) requestViewers.get(rvCombo.getSelectionIndex())); + } + }); + requestHeader.layout(true); + + iterator = responseViewers.iterator(); + ctr = 0; + while(iterator.hasNext()) { + IConfigurationElement element = (IConfigurationElement) iterator.next(); + responseViewerCombo.add(element.getAttribute("label"), ctr); + if(element.getAttribute("id").equals(DEFAULT_VIEWER)) { + responseViewerCombo.select(ctr); + vm.setResponseViewer(element); + } + ctr++; + } + responseViewerCombo.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + Combo rvCombo = (Combo) arg0.getSource(); + vm.setResponseViewer((IConfigurationElement) requestViewers.get(rvCombo.getSelectionIndex())); + } + }); + responseHeader.layout(true); + + // selection listener + treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection = event.getSelection(); + + IRequest req = null; + if (selection != null && !selection.isEmpty()) { + StructuredSelection sel = (StructuredSelection) selection; + Object obj = sel.iterator().next(); + if (obj instanceof IRequest) + req = (IRequest) obj; + } + + if (req != null) { + label.setText(MonitorUIPlugin.getResource("%viewTime", format.format(req.getDate()))); + + if (req.getResponseTime() == -1) + label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", "")); + else { + String time = MonitorUIPlugin.getResource("%viewResponseTimeFormat", req.getResponseTime() + ""); + label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", time)); + } + label3.setText(MonitorUIPlugin.getResource("%viewType", req.getType().getName())); + + // request information + requestLabel.setText(MonitorUIPlugin.getResource("%viewRequest", "localhost:" + req.getLocalPort())); + requestSizeLabel.setText(getSizeString(req.getRequest(IRequest.CONTENT), req.getRequest(IRequest.ALL))); + + // response information + responseLabel.setText(MonitorUIPlugin.getResource("%viewResponse", req.getRemoteHost() + ":" + req.getRemotePort())); + responseSizeLabel.setText(getSizeString(req.getResponse(IRequest.CONTENT), req.getResponse(IRequest.ALL))); + + vm.setRequest(req); + } else { + label.setText(MonitorUIPlugin.getResource("%viewTime", "")); + label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", "")); + requestLabel.setText(MonitorUIPlugin.getResource("%viewRequest", "")); + requestSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", "")); + responseLabel.setText(MonitorUIPlugin.getResource("%viewResponse", "")); + responseSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", "")); + vm.setRequest(req); + } + } + }); + + treeViewer.expandToLevel(2); + + initializeActions(); + + addListener(); + } + + protected String getSizeString(byte[] a, byte[] b) { + String aa = "0"; + String bb = "0"; + if (a != null) + aa = a.length + ""; + if (b != null) + bb = b.length + ""; + String size = MonitorUIPlugin.getResource("%viewSizeFormat", new Object[] { aa, bb}); + return MonitorUIPlugin.getResource("%viewSize", size); + } + + public void dispose() { + super.dispose(); + treeViewer = null; + MonitorCore.removeRequestListener(listener); + } + + /** + * + */ + public void initializeActions() { + final IAction sortByResponseTimeAction = new Action() { + public void run() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + boolean b = contentProvider.getSortByResponseTime(); + contentProvider.setSortByResponseTime(!b); + treeViewer.refresh(); + setChecked(!b); + } + }); + } + }; + sortByResponseTimeAction.setChecked(false); + sortByResponseTimeAction.setToolTipText(MonitorUIPlugin.getResource("%actionSortByResponseTime")); + sortByResponseTimeAction.setImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_ELCL_SORT_RESPONSE_TIME)); + sortByResponseTimeAction.setHoverImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_CLCL_SORT_RESPONSE_TIME)); + sortByResponseTimeAction.setDisabledImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_DLCL_SORT_RESPONSE_TIME)); + + IAction clearAction = new Action() { + public void run() { + MonitorCore.removeAllRequests(); + } + }; + clearAction.setToolTipText(MonitorUIPlugin.getResource("%actionClearToolTip")); + clearAction.setImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_ELCL_CLEAR)); + clearAction.setHoverImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_CLCL_CLEAR)); + clearAction.setDisabledImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_DLCL_CLEAR)); + + httpHeaderAction = new Action() { + public void run() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + boolean b = vm.getDisplayHeaderInfo(); + vm.setDisplayHeaderInfo(!b); + setChecked(!b); + } + }); + } + }; + httpHeaderAction.setChecked(vm.getDisplayHeaderInfo()); + httpHeaderAction.setText(MonitorUIPlugin.getResource("%actionShowHeader")); + + IAction preferenceAction = new Action() { + public void run() { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); + + MonitorPrefrencesDialog monitorPrefDialog = new MonitorPrefrencesDialog(workbenchWindow.getShell()); + if (monitorPrefDialog.open() == Window.CANCEL) + return; + } + }; + preferenceAction.setText(MonitorUIPlugin.getResource("%actionProperties")); + + + IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager(); + tbm.add(sortByResponseTimeAction); + tbm.add(clearAction); + + IContentFilter[] filters = MonitorCore.getContentFilters(); + IMenuManager menuManager = getViewSite().getActionBars().getMenuManager(); + menuManager.add(httpHeaderAction); + int size = filters.length; + for (int i = 0; i < size; i++) { + FilterAction action = new FilterAction(vm, filters[i]); + menuManager.add(action); + } + menuManager.add(preferenceAction); + } + + /** + * + */ + public static void open(final IRequest request) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + try { + IWorkbench workbench = MonitorUIPlugin.getInstance().getWorkbench(); + IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); + //if (workbenchWindow == null) + // workbenchWindow = workbench.getWorkbenchWindows()[0]; + + IWorkbenchPage page = workbenchWindow.getActivePage(); + + IViewPart view2 = page.findView(VIEW_ID); + + if (view2 != null) + page.bringToTop(view2); + else + page.showView(VIEW_ID); + + if (view != null) + view.setSelection(request); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error opening TCP/IP view", e); + } + } + }); + } + + /** + * + */ + public void setFocus() { + if (tree != null) + tree.setFocus(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/TreeLabelProvider.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/TreeLabelProvider.java new file mode 100644 index 0000000..1a8cdb7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/TreeLabelProvider.java @@ -0,0 +1,108 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.view; + +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.ui.internal.*; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; +/** + * A label provider for the monitor server view. + */ +public class TreeLabelProvider implements ILabelProvider { + /** + * TreeLabelProvider constructor comment. + */ + public TreeLabelProvider() { + super(); + } + + /** + * Adds a listener to this label provider. Label provider listeners are + * informed about state changes that affect the rendering of the viewer + * that uses this label provider. + * + * @param listener a label provider listener + */ + public void addListener(ILabelProviderListener listener) {} + + /** + * Disposes of this label provider. + *

+ * [Issue: This method should be changed to take a Viewer, + * renamed and repurposed to disconnect a label provider from + * a viewer. + * ] + *

+ */ + public void dispose() {} + + /** + * Returns the image for the label of the given element for use + * in the given viewer. + * + * @param element the element for which to provide the label image + * @return the image used to label the element, or null + * if these is no image for the given object + */ + public Image getImage(Object element) { + if (element instanceof IRequest) + return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_REQUEST_RESPONSE); + else + return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_HOST); + } + + /** + * Returns the text for the label of the given element for use + * in the given viewer. + * + * @param viewer the viewer that displays the element + * @param element the element for which to provide the label text + * @return the text string used to label the element, or null + * if these is no text label for the given object + */ + public String getText(Object element) { + if (element instanceof IRequest) { + IRequest call = (IRequest) element; + return call.getLabel(); + } else if (element instanceof Integer) { + Integer in = (Integer) element; + return "localhost:" + in.intValue(); + } else + return element.toString(); + } + + /** + * Returns whether the label would be affected + * by a change to the given property of the given element. + * This can be used to optimize a non-structural viewer update. + * If the property mentioned in the update does not affect the label, + * then the viewer need not update the label. + * + * @param element the element + * @param property the property + * @return true if the label would be affected, + * and false if it would be unaffected + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * Removes a listener to this label provider. + * Has no affect if the listener is not registered. + * + * @param listener a label provider listener + */ + public void removeListener(ILabelProviderListener listener) {} +} diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/ViewerManager.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/ViewerManager.java new file mode 100644 index 0000000..039a376 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/view/ViewerManager.java @@ -0,0 +1,226 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.view; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.phpdt.monitor.core.IContentFilter; +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.ui.IContentViewer; +import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin; +import net.sourceforge.phpdt.monitor.ui.internal.Trace; +import net.sourceforge.phpdt.monitor.ui.internal.viewers.ByteViewer; +import net.sourceforge.phpdt.monitor.ui.internal.viewers.HeaderViewer; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.widgets.Composite; + +/** + * + */ +public class ViewerManager implements IViewerManager { + private boolean displayHeaderInf; + protected IContentViewer reqViewer; + protected IContentViewer respViewer; + protected HeaderViewer reqHeader; + protected HeaderViewer respHeader; + + protected Composite reqHComp; + protected Composite reqVComp; + protected Composite respHComp; + protected Composite respVComp; + + protected List viewers; + protected IRequest request; + protected List filters = new ArrayList(); + + public ViewerManager(Composite reqHeadParent, Composite reqViewParent, Composite respHeadParent, Composite respViewParent) { + reqHComp = reqHeadParent; + respHComp = respHeadParent; + reqVComp = reqViewParent; + respVComp = respViewParent; + reqHeader = new HeaderViewer(reqHComp, HeaderViewer.REQUEST_HEADER); + respHeader = new HeaderViewer(respHComp, HeaderViewer.RESPONSE_HEADER); + reqViewer = new ByteViewer(); + reqViewer.init(reqVComp); + respViewer = new ByteViewer(); + respViewer.init(respVComp); + setDisplayHeaderInfo(MonitorUIPlugin.getShowHeaderPreference()); + setAvailableViewers(); + } + + private void setAvailableViewers() { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorUIPlugin.PLUGIN_ID, "viewers"); + + int size = cf.length; + viewers = new ArrayList(size); + for (int i = 0; i < size; i++) { + viewers.add(cf[i]); + } + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.view.IViewerManager#hideHeader() + */ + /*public void hideHeader() { + displayHeaderInf = false; + if (!reqHeader.isHidden()) + reqHeader.hideViewer(); + if (!respHeader.isHidden()) + respHeader.hideViewer(); + }*/ + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.view.IViewerManager#showHeader() + */ + /*public void showHeader() { + if (reqHeader.isHidden()) + reqHeader.showViewer(); + if (respHeader.isHidden()) + respHeader.showViewer(); + }*/ + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.view.IViewerManager#setDisplayHeaderInfo(boolean) + */ + public void setDisplayHeaderInfo(boolean b) { + displayHeaderInf = b; + reqHeader.setDisplayHeader(b); + respHeader.setDisplayHeader(b); + MonitorUIPlugin.setShowHeaderPreference(b); + } + + /* (non-Javadoc) + * @see org.eclipse.monitor.internal.view.IViewerManager#getDisplayHeaderInfo() + */ + public boolean getDisplayHeaderInfo() { + return displayHeaderInf; + } + + public void setRequest(IRequest rr) { + reqHeader.setRequestResponse(rr); + respHeader.setRequestResponse(rr); + + byte[] b = null; + if (rr != null) + b = filter(rr.getRequest(IRequest.CONTENT)); + reqViewer.setContent(b); + + b = null; + if (rr != null) + b = filter(rr.getResponse(IRequest.CONTENT)); + respViewer.setContent(b); + + request = rr; + } + + public void addFilter(IContentFilter filter) { + filters.add(filter); + setRequest(request); + } + + public void removeFilter(IContentFilter filter) { + filters.remove(filter); + setRequest(request); + } + + protected byte[] filter(byte[] b) { + if (b == null) + return null; + + Iterator iterator = filters.iterator(); + while (iterator.hasNext()) { + IContentFilter filter = (IContentFilter) iterator.next(); + try { + b = filter.filter(request, false, b); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error while filtering with " + filter.getId(), e); + } + } + return b; + } + + /* (non-Javadoc) + * @see org.eclipse.tcpip.monitor.internal.view.IViewerManager#getRequestViewers() + */ + public List getRequestViewers() { + IConfigurationElement element; + Iterator iterator = viewers.iterator(); + List temp = new ArrayList(); + + while (iterator.hasNext()) { + element = (IConfigurationElement) iterator.next(); + if (element.getAttribute("type").toLowerCase().indexOf("request") >= 0) + temp.add(element); + } + return temp; + } + + /* (non-Javadoc) + * @see org.eclipse.tcpip.monitor.internal.view.IViewerManager#getResponseViewers() + */ + public List getResponseViewers() { + IConfigurationElement element; + Iterator iterator = viewers.iterator(); + List temp = new ArrayList(); + + while (iterator.hasNext()) { + element = (IConfigurationElement) iterator.next(); + if (element.getAttribute("type").toLowerCase().indexOf("response") >= 0) + temp.add(element); + } + return temp; + } + + /* (non-Javadoc) + * @see org.eclipse.tcpip.monitor.internal.view.IViewerManager#setRequestViewer(java.lang.String) + */ + public void setRequestViewer(IConfigurationElement element) { + reqViewer.dispose(); + try { + reqViewer = (IContentViewer) element.createExecutableExtension("class"); + } catch (CoreException e) { + Trace.trace(Trace.SEVERE, "Error", e); + } + reqViewer.init(reqVComp); + //reqViewer.setRequestResponse(rr); + byte[] b = null; + if (request != null) + b = filter(request.getRequest(IRequest.CONTENT)); + reqViewer.setContent(b); + reqVComp.layout(true); + } + + /* (non-Javadoc) + * @see org.eclipse.tcpip.monitor.internal.view.IViewerManager#setResponseViewer(java.lang.String) + */ + public void setResponseViewer(IConfigurationElement element) { + respViewer.dispose(); + try { + respViewer = (IContentViewer) element.createExecutableExtension("class"); + } catch (CoreException e){ + Trace.trace(Trace.SEVERE, "Error", e); + } + respViewer.init(respVComp); + //respViewer.setRequestResponse(rr); + byte[] b = null; + if (request != null) + b = filter(request.getResponse(IRequest.CONTENT)); + respViewer.setContent(b); + respVComp.layout(true); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ByteViewer.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ByteViewer.java new file mode 100644 index 0000000..7684ed7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ByteViewer.java @@ -0,0 +1,79 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.viewers; + +import net.sourceforge.phpdt.monitor.core.MonitorCore; +import net.sourceforge.phpdt.monitor.ui.IContentViewer; +import net.sourceforge.phpdt.monitor.ui.internal.ContextIds; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * A basic byte viewer. + */ +public class ByteViewer implements IContentViewer { + protected Text text; + protected Composite comp; + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#dispose() + */ + public void dispose() { + comp.dispose(); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#setContent() + */ + public void setContent(byte[] b) { + String out = ""; + if (b != null) + out = MonitorCore.parse(b); + + String lineSeparator = System.getProperty("line.separator"); + int ls = lineSeparator.length(); + if (out.length() > ls) { + while (out.substring(0, ls).indexOf(lineSeparator) >= 0) + out = out.substring(ls, out.length()); + } + + text.setText(out); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#init(Composite) + */ + public void init(Composite parent) { + comp = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 0; + comp.setLayout(layout); + GridData data = new GridData(GridData.FILL_BOTH); + comp.setLayoutData(data); + + text = new Text(comp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); + Display display = comp.getDisplay(); + text.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + text.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + text.setFont(JFaceResources.getTextFont()); + WorkbenchHelp.setHelp(text, ContextIds.VIEW_RESPONSE); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/HeaderViewer.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/HeaderViewer.java new file mode 100644 index 0000000..e1f98dc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/HeaderViewer.java @@ -0,0 +1,202 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.viewers; + +import net.sourceforge.phpdt.monitor.core.IRequest; +import net.sourceforge.phpdt.monitor.core.MonitorCore; +import net.sourceforge.phpdt.monitor.ui.internal.ContextIds; +import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * An transport (header) viewer. + */ +public class HeaderViewer { + protected boolean displayHeader; + + protected Composite headerComp; + protected Composite innerComp; + protected Composite rootComp; + + protected Label headerLabel; + protected Text headerText; + protected IRequest rr; + protected byte msg; + protected GridLayout layout; + protected GridData data; + + protected boolean hidden; + + protected static int HEADER_LABEL_SIZE = 15; + protected static int HEADER_TEXT_SIZE = 110; + public static byte REQUEST_HEADER = 0; + public static byte RESPONSE_HEADER = 1; + + public HeaderViewer(Composite parent, byte message) { + rootComp = parent; + displayHeader = true; + hidden = false; + + headerComp = new Composite(parent, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 0; + headerComp.setLayout(layout); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + headerComp.setLayoutData(data); + + innerComp = new Composite(headerComp, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 2; + innerComp.setLayout(layout); + data = new GridData(GridData.FILL_BOTH); + data.heightHint = HEADER_LABEL_SIZE; + innerComp.setLayoutData(data); + + rr = null; + msg = message; + + setDisplayHeader(false); + } + + /*public boolean isHidden() { + return hidden; + }*/ + + /*public void hideViewer() { + hidden = true; + innerComp.dispose(); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.heightHint = 0; + headerComp.setLayoutData(data); + rootComp.layout(true); + } + + public void showViewer() { + hidden = false; + + innerComp = new Composite(headerComp, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 2; + innerComp.setLayout(layout); + data = new GridData(GridData.FILL_BOTH); + data.heightHint = HEADER_LABEL_SIZE; + innerComp.setLayoutData(data); + + displayHeader = true; + setDisplayHeader(false); + }*/ + + public void setRequestResponse(IRequest reqresp) { + rr = reqresp; + if (!hidden) + getView(); + } + + public void setDisplayHeader(boolean b) { + if (displayHeader != b) { + displayHeader = b; + if (displayHeader) { + innerComp.dispose(); + + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.heightHint = HEADER_TEXT_SIZE; + headerComp.setLayoutData(data); + + innerComp = new Composite(headerComp, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 0; + innerComp.setLayout(layout); + data = new GridData(GridData.FILL_BOTH); + data.heightHint = HEADER_TEXT_SIZE; + innerComp.setLayoutData(data); + + headerText = new Text(innerComp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); + Display display = innerComp.getDisplay(); + headerText.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + headerText.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); + headerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + headerText.setFont(JFaceResources.getTextFont()); + WorkbenchHelp.setHelp(headerText, ContextIds.VIEW_RESPONSE); + + rootComp.layout(true); + } else { + innerComp.dispose(); + + data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.heightHint = HEADER_LABEL_SIZE; + headerComp.setLayoutData(data); + + innerComp = new Composite(headerComp, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 2; + innerComp.setLayout(layout); + data = new GridData(GridData.FILL_BOTH); + data.heightHint = HEADER_LABEL_SIZE; + innerComp.setLayoutData(data); + + headerLabel = new Label(innerComp, SWT.NONE); + headerLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); + + rootComp.layout(true); + } + } + getView(); + } + + /*public boolean getDisplayHeader() { + return displayHeader; + }*/ + + private void getView() { + String out = ""; + if (rr != null) { + if (msg == REQUEST_HEADER) { + out = MonitorCore.parse(rr.getRequest(IRequest.TRANSPORT)); + } else if (msg == RESPONSE_HEADER) { + out = MonitorCore.parse(rr.getResponse(IRequest.TRANSPORT)); + } + } + + if (displayHeader) { + headerText.setText(out); + } else { + String lineSeparator = System.getProperty("line.separator"); + int index = out.indexOf(lineSeparator); + if(index > 0) + headerLabel.setText(MonitorUIPlugin.getResource("%headerLabel") + ": " + out.substring(0, index)); + else + headerLabel.setText(MonitorUIPlugin.getResource("%headerLabel") + ": " + out); + } + } + + public void dispose() { + headerComp.dispose(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ImageViewer.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ImageViewer.java new file mode 100644 index 0000000..b8d5bb4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/ImageViewer.java @@ -0,0 +1,95 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.viewers; + +import java.io.ByteArrayInputStream; + +import net.sourceforge.phpdt.monitor.ui.IContentViewer; +import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * An image viewer. + */ +public class ImageViewer implements IContentViewer { + protected Composite rootComp; + protected Composite viewerComp; + protected Label messageLabel; + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#init(Composite) + */ + public void init(Composite parent) { + rootComp = parent; + + viewerComp = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 0; + viewerComp.setLayout(layout); + GridData data = new GridData(GridData.FILL_BOTH); + viewerComp.setLayoutData(data); + + messageLabel = new Label(viewerComp, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING)); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#setContent() + */ + public void setContent(byte[] b) { + if (b == null || b.length == 0) { + messageLabel.setText("<" + MonitorUIPlugin.getResource("%imageViewInvalid") + ">"); + } else { + byte cr = '\r'; + byte lf = '\n'; + int trimFront = 0; + int trimBack = 0; + int len = b.length - 1; + while(b[trimFront] == cr || b[trimFront] == lf) + trimFront++; + while(b[len - trimBack] == cr || b[len - trimBack] == lf) + trimBack++; + + if (trimFront + trimBack > 0) { + byte[] temp = b; + b = new byte[temp.length - trimBack - trimFront]; + for(int i = trimFront; i < temp.length - trimBack; i++) { + b[i - trimFront] = temp[i]; + } + } + try { + ImageData imgD = new ImageData(new ByteArrayInputStream(b)); + Image img = new Image(null, imgD); + messageLabel.setImage(img); + } catch(Exception e) { + messageLabel.setText("<" + MonitorUIPlugin.getResource("%imageViewInvalid") + ">"); + } + } + + viewerComp.layout(true); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#dispose() + */ + public void dispose() { + viewerComp.dispose(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/XMLViewer.java b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/XMLViewer.java new file mode 100644 index 0000000..a8a0a40 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.monitor.ui/src/net/sourceforge/phpdt/monitor/ui/internal/viewers/XMLViewer.java @@ -0,0 +1,227 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package net.sourceforge.phpdt.monitor.ui.internal.viewers; + +import java.io.*; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import net.sourceforge.phpdt.monitor.core.MonitorCore; +import net.sourceforge.phpdt.monitor.ui.IContentViewer; +import net.sourceforge.phpdt.monitor.ui.internal.ContextIds; + +import org.eclipse.jface.resource.JFaceResources; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.help.WorkbenchHelp; + + +import org.w3c.dom.*; +import org.xml.sax.*; +/** + * XML Viewer. + */ +public class XMLViewer implements IContentViewer { + protected GridData data; + protected StackLayout layout; + protected Text messageText; + + protected Composite rootComp; + protected Composite viewerComp; + protected Label messageLabel; + + protected boolean xmlTagMissing = false; + protected boolean setEncoding = false; + protected boolean missingEncoding = false; + protected String originalEncoding; + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#dispose() + */ + public void dispose() { + viewerComp.dispose(); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#setContent() + */ + public void setContent(byte[] b) { + String out = ""; + if (b != null) + out = MonitorCore.parse(b); + + String lineSeparator = System.getProperty("line.separator"); + int ls = lineSeparator.length(); + if (out.length() > ls) { + while (out.substring(0, ls).indexOf(lineSeparator) >= 0) + out = out.substring(ls, out.length()); + } + + String out_temp = out.toLowerCase(); + if (out_temp.indexOf(" 0) { + byte[] b1 = createDocument(out); + String finalMsg = new String (b1); + if (finalMsg.startsWith("Invalid XML")) { + //case: error parsing + messageText.setVisible(false); + layout.topControl = messageLabel; + messageLabel.setVisible(true); + messageLabel.setText(""); + + } + else if (xmlTagMissing && finalMsg.startsWith("")) { + int x = finalMsg.indexOf("\n") + 1; + String Msg = finalMsg.substring(x); + finalMsg = Msg; + + messageText.setText(finalMsg); + } + + else if (setEncoding) { + //change back to original Encoding + int begin = finalMsg.indexOf("UTF-8"); //location of opening " + int last = begin + 5; //location of closing " + String first_half = finalMsg.substring(0,begin); + String second_half = finalMsg.substring(last); + finalMsg = first_half + originalEncoding + second_half; + + messageText.setText(finalMsg); + } + + else if (missingEncoding) { + //remove encoding completely + int begin = finalMsg.indexOf("encoding=\"UTF-8\""); //location of opening " + int last = begin + 16; //location of closing " + String first_half = finalMsg.substring(0,begin); + String second_half = finalMsg.substring(last); + finalMsg = first_half + second_half; + + messageText.setText(finalMsg); + } + } else + messageText.setText(out); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#init(Composite) + */ + public void init(Composite parent) { + rootComp = parent; + + viewerComp = new Composite(parent, SWT.NONE); + layout = new StackLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + viewerComp.setLayout(layout); + data = new GridData(GridData.FILL_BOTH); + viewerComp.setLayoutData(data); + + messageText = new Text(viewerComp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); + Display display = viewerComp.getDisplay(); + messageText.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + messageText.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); + messageText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + messageText.setFont(JFaceResources.getTextFont()); + messageText.setVisible(true); + WorkbenchHelp.setHelp(messageText, ContextIds.VIEW_RESPONSE); + + messageLabel = new Label(viewerComp, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING)); + messageLabel.setVisible(false); + + layout.topControl = messageText; + } + + /* (non-Javadoc) + * @#createDocument(String) + */ + protected byte[] createDocument(String str) { + byte[] parseArray = null; + Document document = null; + byte[] result = null; + + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + try { + factory.setAttribute("http://apache.org/xml/features/allow-java-encodings", new Boolean(true)); + factory.setAttribute("http://apache.org/xml/features/continue-after-fatal-error", new Boolean(true)); + } catch (Exception e) { } + DocumentBuilder parser = factory.newDocumentBuilder(); + + if (xmlTagMissing) { + str = "" + str; + } else { + String str_temp = str.toLowerCase(); + + //if encoding present,then save original Encoding, change to UTF-8 + if (str_temp.indexOf("encoding=") >= 0) { + setEncoding = true; + String temp1 = str.substring(str_temp.indexOf("encoding=")); + int beginIndex = temp1.indexOf("\"") + 1; + String temp2 = temp1.substring(beginIndex); + int endIndex = temp2.indexOf("\""); + originalEncoding = temp2.substring(0, endIndex); + } + + //if no encoding at all,then no changes to be made + else if (str_temp.indexOf("encoding") < 0) { + setEncoding = false; + missingEncoding = true; + } + } + parseArray = str.getBytes(); + document = parser.parse(new InputSource(new ByteArrayInputStream(parseArray))); + result = getContents(document); + + } catch (Exception e) { + result = "Invalid XML".getBytes(); + } + return result; + } + + protected byte[] getContents(Document document) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Result result = new StreamResult(out); + Source source = new DOMSource(document); + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ + transformer.transform(source, result); + } + catch (TransformerConfigurationException e) { + throw (IOException) (new IOException().initCause(e)); + } + catch (TransformerException e) { + throw (IOException) (new IOException().initCause(e)); + } + return out.toByteArray(); + } +} \ No newline at end of file -- 1.7.1