--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.monitor.core;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import net.sourceforge.phpdt.monitor.core.internal.MonitorManager;
+import net.sourceforge.phpdt.monitor.core.internal.MonitorPlugin;
+import net.sourceforge.phpdt.monitor.core.internal.Trace;
+/**
+ *
+ */
+public class MonitorCore {
+ public static String TCPIP_PROTOCOL_ID = "TCPIP";
+ public static String HTTP_PROTOCOL_ID = "HTTP";
+
+ private static MonitorManager manager = MonitorManager.getInstance();
+
+ private static final String lineSeparator = System.getProperty("line.separator");
+
+ /**
+ * Return a list of all the existing monitors.
+ *
+ * @return java.util.List
+ */
+ public static List getMonitors() {
+ return manager.getMonitors();
+ }
+
+ /**
+ * Create a new monitor.
+ *
+ * @return working copy
+ */
+ public static IMonitorWorkingCopy createMonitor() {
+ return manager.createMonitor();
+ }
+
+ /**
+ * Start the given monitor.
+ *
+ * @param monitor
+ * @throws Exception
+ */
+ public static void startMonitor(IMonitor monitor) throws Exception {
+ manager.startMonitor(monitor);
+ }
+
+ /**
+ * Stop the given monitor.
+ *
+ * @param monitor
+ */
+ public static void stopMonitor(IMonitor monitor) {
+ manager.stopMonitor(monitor);
+ }
+
+ /**
+ * Return the protocol adapters.
+ *
+ * @return array of protocol adapters
+ */
+ public static IProtocolAdapter[] getProtocolAdapters() {
+ return MonitorPlugin.getInstance().getProtocolAdapters();
+ }
+
+ /**
+ * Return the protocol adapter with the given id.
+ *
+ * @return protocol adapter
+ */
+ public static IProtocolAdapter getProtocolAdapter(String id) {
+ return MonitorPlugin.getInstance().getProtocolAdapter(id);
+ }
+
+ /**
+ * Return the content filters.
+ *
+ * @return array of content filters
+ */
+ public static IContentFilter[] getContentFilters() {
+ return MonitorPlugin.getInstance().getContentFilters();
+ }
+
+ /**
+ * Return the content filter with the given id.
+ *
+ * @return content filter
+ */
+ public static IContentFilter getContentFilter(String id) {
+ return MonitorPlugin.getInstance().getContentFilter(id);
+ }
+
+ /**
+ * Add monitor listener.
+ *
+ * @param listener
+ */
+ public static void addMonitorListener(IMonitorListener listener) {
+ manager.addMonitorListener(listener);
+ }
+
+ /**
+ * Remove monitor listener.
+ *
+ * @param listener
+ */
+ public static void removeMonitorListener(IMonitorListener listener) {
+ manager.removeMonitorListener(listener);
+ }
+
+ /**
+ * Return all requests.
+ *
+ * @return
+ */
+ public static List getRequests() {
+ return manager.getRequests();
+ }
+
+ /**
+ * Remove all requests.
+ */
+ public static void removeAllRequests() {
+ manager.removeAllRequests();
+ }
+
+ /**
+ * Add request listener.
+ *
+ * @param listener
+ */
+ public static void addRequestListener(IRequestListener listener) {
+ manager.addRequestListener(listener);
+ }
+
+ /**
+ * Remove request listener.
+ *
+ * @param listener
+ */
+ public static void removeRequestListener(IRequestListener listener) {
+ manager.removeRequestListener(listener);
+ }
+
+ /**
+ * Parse the given bytes into String form.
+ *
+ * @param b
+ * @return
+ */
+ public static String parse(byte[] b) {
+ if (b == null)
+ return "";
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(b);
+ BufferedReader br = new BufferedReader(new InputStreamReader(bin));
+ StringBuffer sb = new StringBuffer();
+ try {
+ String s = br.readLine();
+
+ while (s != null) {
+ sb.append(s);
+ s = br.readLine();
+ if (s != null)
+ sb.append(lineSeparator);
+ }
+ sb.append(lineSeparator);
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error parsing input", e);
+ }
+
+ return sb.toString();
+ }
+}
\ No newline at end of file