From: axelcl
+ * Mementos were designed with the following requirements in mind:
+ *
+ *
+ *
+ * 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.
+ *
TAG_ID
) and can be retrieved using getId
.
+ *
+ * The getChild
and getChildren
methods
+ * are used to retrieve children of a given type.
+ *
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 @@
+
++ * 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, ornull
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
.
+ *
+ * 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 + * @returntrue
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, ornull
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, ornull
+ * 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("