--- a/org.symbian.tools.wrttools.debug.core/META-INF/MANIFEST.MF Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.debug.core/META-INF/MANIFEST.MF Thu Jan 21 17:49:50 2010 -0800
@@ -13,13 +13,8 @@
org.chromium.sdk;bundle-version="0.1.3",
org.eclipse.core.expressions;bundle-version="3.4.100",
org.eclipse.wst.jsdt.ui;bundle-version="1.0.200",
- org.eclipse.equinox.http.registry,
- org.eclipse.equinox.http.jetty;bundle-version="2.0.0",
org.eclipse.ui.editors;bundle-version="3.5.0",
- org.eclipse.jface.text;bundle-version="3.5.0"
+ org.eclipse.jface.text;bundle-version="3.5.0",
+ org.symbian.tools.wrttools.previewer;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
-Import-Package: javax.servlet;version="2.5.0",
- javax.servlet.http;version="2.5.0",
- org.eclipse.equinox.jsp.jasper;version="1.0.0",
- org.osgi.service.http;version="1.2.1"
--- a/org.symbian.tools.wrttools.debug.core/http-content/wrtdebugger/connectionTest.jsp Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-<%@ page import="org.symbian.tools.wrttools.debug.internal.web.WebAppInterface, javax.servlet.http.HttpServletResponse" %>
-<%
- String widget = WebAppInterface.decode(request.getParameter("widget"));
- String id = request.getParameter("session");
-
- if (WebAppInterface.isConnected(widget, id)) {
- response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
- }
-%>
\ No newline at end of file
--- a/org.symbian.tools.wrttools.debug.core/http-content/wrtdebugger/debugger.jsp Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-<%@ page import="org.symbian.tools.wrttools.debug.internal.web.WebAppInterface" %>
-<%
- String widget = WebAppInterface.decode(request.getParameter("widget"));
- String id = request.getParameter("session");
-%>
-<html>
-<head>
- <title><%=widget %></title>
- <% WebAppInterface.connectDebugger(widget, id); %>
- <script type="text/javascript">
- var req;
-
- function connect() {
- req = new XMLHttpRequest();
- req.onreadystatechange = testconnection;
- req.open("GET", "<%=WebAppInterface.getAjaxUri(widget, id) %>", true);
- req.send(null);
- }
-
- function testconnection() {
- if (req.readyState == 4) {
- if (req.status == 200) {
- window.setTimeout(connect, 200);
- } else {
- window.location = '<%=WebAppInterface.getUrl(widget, id) %>';
- }
- }
- }
- </script>
-</head>
-<body onload="connect()">
-Establishing debug connection...
-</body>
\ No newline at end of file
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugConnectionJob.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugConnectionJob.java Thu Jan 21 17:49:50 2010 -0800
@@ -29,51 +29,46 @@
import org.chromium.sdk.ConnectionLogger;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
-import org.symbian.tools.wrttools.debug.internal.Activator;
import org.symbian.tools.wrttools.debug.internal.model.DebugTargetImpl;
+import org.symbian.tools.wrttools.previewer.http.IPreviewStartupListener;
-public class DebugConnectionJob extends Job {
+public class DebugConnectionJob implements IPreviewStartupListener {
static final NamedConnectionLoggerFactory NO_CONNECTION_LOGGER_FACTORY = new NamedConnectionLoggerFactory() {
public ConnectionLogger createLogger(String title) {
return null;
}
};
- private URI uri;
private final int port;
private final ILaunch launch;
private final IProject project;
- private boolean connected = false;
public DebugConnectionJob(IProject project, final int port, final ILaunch launch) {
- super("Establish debug connection");
this.project = project;
this.port = port;
this.launch = launch;
- setUser(false);
+ }
+
+ protected ConnectionToRemote createConnectionToRemote(int port,
+ ILaunch launch, URI uri) throws CoreException {
+ return JavascriptVmEmbedderFactory.connectToChromeDevTools(port,
+ NO_CONNECTION_LOGGER_FACTORY, new WidgetTabSelector(uri));
+ }
+
+ private static void terminateTarget(DebugTargetImpl target) {
+ target.setDisconnected(true);
+ target.fireTerminateEvent();
}
@Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- connect(monitor);
- } catch (CoreException e) {
- return e.getStatus();
- }
- return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
- }
-
- private void connect(IProgressMonitor monitor) throws CoreException {
+ public boolean browserRunning(URI uri) throws CoreException {
final DebugTargetImpl target = new DebugTargetImpl(launch, project);
final JavascriptVmEmbedder.ConnectionToRemote remoteServer = createConnectionToRemote(
port, launch, uri);
try {
-
+
DestructingGuard destructingGuard = new DestructingGuard();
try {
Destructable lauchDestructor = new Destructable() {
@@ -84,9 +79,9 @@
}
}
};
-
+
destructingGuard.addValue(lauchDestructor);
-
+
Destructable targetDestructor = new Destructable() {
public void destruct() {
terminateTarget(target);
@@ -96,51 +91,27 @@
boolean attached = target.attach(project.getName(), remoteServer,
destructingGuard, new Runnable() {
public void run() {
- openProjectExplorerView(target);
+ target.setupBreakpointsFromResources();
}
- }, monitor);
+ }, new NullProgressMonitor());
if (!attached) {
// Error
- return;
+ return false;
}
-
+
launch.setSourceLocator(target.getSourceLocator());
-
+
launch.addDebugTarget(target);
- monitor.done();
-
+
// All OK
destructingGuard.discharge();
} finally {
destructingGuard.doFinally();
}
-
+
} finally {
remoteServer.disposeConnection();
}
- }
-
- protected ConnectionToRemote createConnectionToRemote(int port,
- ILaunch launch, URI uri) throws CoreException {
- return JavascriptVmEmbedderFactory.connectToChromeDevTools(port,
- NO_CONNECTION_LOGGER_FACTORY, new WidgetTabSelector(uri));
- }
-
- protected void openProjectExplorerView(final DebugTargetImpl target) {
- target.setupBreakpointsFromResources();
- connected = true;
- }
-
- public boolean isConnected() {
- return connected;
- }
-
- private static void terminateTarget(DebugTargetImpl target) {
- target.setDisconnected(true);
- target.fireTerminateEvent();
- }
-
- public void setTabUri(URI uri) {
- this.uri = uri;
+ return true;
}
}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java Thu Jan 21 17:49:50 2010 -0800
@@ -38,7 +38,7 @@
import org.symbian.tools.wrttools.debug.internal.Activator;
import org.symbian.tools.wrttools.debug.internal.ChromeDebugUtils;
import org.symbian.tools.wrttools.debug.internal.IConstants;
-import org.symbian.tools.wrttools.debug.internal.web.WebAppInterface;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
public class WidgetLaunchDelegate implements
ILaunchConfigurationDelegate {
@@ -141,15 +141,12 @@
private URI prepareDebugger(IProject project, boolean debug,
final ILaunch launch, final int port) {
- final DebugConnectionJob job;
if (debug) {
- job = new DebugConnectionJob(project, port, launch);
+ final DebugConnectionJob job = new DebugConnectionJob(project, port, launch);
+ return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, job);
} else {
- job = null;
+ return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project);
}
- final URI uri = WebAppInterface.getInstance().prepareDebugger(project,
- job);
- return uri;
}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/ResourceManager.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/ResourceManager.java Thu Jan 21 17:49:50 2010 -0800
@@ -11,7 +11,7 @@
import org.chromium.sdk.Script;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.symbian.tools.wrttools.debug.internal.web.WorkspaceResourcesServlet;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
/**
* This object handles the mapping between {@link Script}s and their
@@ -100,7 +100,7 @@
if (name == null) {
return null;
}
- IFile file = WorkspaceResourcesServlet.getFileFromUrl(name);
+ IFile file = PreviewerPlugin.getDefault().getHttpPreviewer().getFileFromUrl(name);
if (file != null && !file.isAccessible()) {
file = null;
}
@@ -133,6 +133,6 @@
}
public String translateResourceToScript(IResource resource) {
- return WorkspaceResourcesServlet.getHttpUrl(resource);
+ return PreviewerPlugin.getDefault().getHttpPreviewer().getHttpUrl(resource);
}
}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/StackFrame.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/StackFrame.java Thu Jan 21 17:49:50 2010 -0800
@@ -46,8 +46,9 @@
script);
int line = script.getStartLine() + getLineNumber();
if (line != -1) {
+ String resourcePath = resource != null ? resource.getProjectRelativePath().toString() : script.getName();
name = NLS.bind("{0} [{1}:{2}]", new Object[] { name,
- resource.getProjectRelativePath().toString(), line });
+ resourcePath, line });
}
return name;
}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/web/EmulatorContext.java Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- *******************************************************************************/
-package org.symbian.tools.wrttools.debug.internal.web;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.osgi.service.http.HttpContext;
-
-public class EmulatorContext implements HttpContext {
-
- public String getMimeType(String name) {
- return null;
- }
-
- public URL getResource(String name) {
- try {
- return new URL("file:///e:/maven-prefs.png");
- } catch (MalformedURLException e) {
- return null;
- }
- }
-
- public boolean handleSecurity(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- return true;
- }
-
-}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/web/WebAppInterface.java Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- *******************************************************************************/
-package org.symbian.tools.wrttools.debug.internal.web;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.jobs.Job;
-import org.symbian.tools.wrttools.debug.internal.Activator;
-import org.symbian.tools.wrttools.debug.internal.launch.DebugConnectionJob;
-
-public class WebAppInterface {
- private static WebAppInterface INSTANCE;
-
- public static void connectDebugger(String widget, String id) {
- getInstance().connect(widget, id);
- }
-
- public static String decode(String value) {
- try {
- return URLDecoder.decode(value, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static String encode(String project) {
- try {
- return URLEncoder.encode(project, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static String getAjaxUri(String widget, String id) {
- return getInstance().createAjaxUri(widget, id).toASCIIString();
- }
-
- public synchronized static WebAppInterface getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new WebAppInterface();
- }
- return INSTANCE;
- }
-
- public static String getUrl(String widget, String id) {
- return getInstance().complete(widget, id);
- }
-
- public static boolean isConnected(String widget, String id) {
- return getInstance().isJobComplete(widget, id);
- }
-
- private final Map<String, DebugConnectionJob> debuggerJobs = new TreeMap<String, DebugConnectionJob>();
-
- private WebAppInterface() {
- try {
- WebappManager.start("wrtbrowser");
- } catch (Exception e) {
- Activator.log(e);
- }
- }
-
- private synchronized String complete(String widget, String id) {
- IFile file = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(widget).getFile("wrt_preview_frame.html");
- if (file.isAccessible()) {
- return WorkspaceResourcesServlet.getHttpUrl(file);
- }
- return "";
- }
-
- private synchronized void connect(String widget, String id) {
- Job job = debuggerJobs.get(getId(widget, id));
- if (job != null) {
- job.schedule();
- }
- }
-
- private URI createAjaxUri(String widget, String id) {
- try {
- return createUri("connectionTest.jsp", widget, id);
- } catch (URISyntaxException e) {
- Activator.log(e);
- return null;
- }
- }
-
- private URI createUri(String page, String project, String session)
- throws URISyntaxException {
- URI uri = new URI("http", null, WebappManager.getHost(), WebappManager
- .getPort(), "/wrtdebugger/" + page, "widget=" + encode(project)
- + "&session=" + session, null);
- return uri;
- }
-
- private String getId(String name, String session) {
- return name + "$" + session;
- }
-
- private synchronized boolean isJobComplete(String widget, String id) {
- DebugConnectionJob job = debuggerJobs.get(getId(widget, id));
- boolean isComplete = job == null || job.isConnected();
- return isComplete;
- }
-
- public synchronized URI prepareDebugger(IProject project,
- DebugConnectionJob job) {
- try {
- String session = Long.toHexString(System.currentTimeMillis());
- URI uri = createUri("debugger.jsp", project.getName(), session);
- if (job != null) {
- debuggerJobs.put(getId(project.getName(), session), job);
- job.setTabUri(uri);
- }
- return uri;
- } catch (URISyntaxException e) {
- Activator.log(e);
- }
- return null;
- }
-}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/web/WebappManager.java Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- *******************************************************************************/
-package org.symbian.tools.wrttools.debug.internal.web;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.equinox.http.jetty.JettyConfigurator;
-import org.eclipse.equinox.jsp.jasper.JspServlet;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.HttpService;
-import org.symbian.tools.wrttools.debug.internal.Activator;
-
-/**
- * Copy from the WS Explorer
- *
- * @author Eugene Ostroukhov
- *
- */
-public class WebappManager {
- public static final String WORKSPACE_RESOURCES_CONTEXT = "/wspace";
- public static final String STATIC_RESOURCES_CONTEXT = "/wrtdebugger";
- public static final String WEB_CONTENT_ROOT = "/http-content";
-
- private static String host;
- private static int port = -1;
- private static final int AUTO_SELECT_JETTY_PORT = 0;
-
- @SuppressWarnings("unchecked")
- public static void start(String webappName) throws Exception {
- Dictionary d = new Hashtable();
-
- d.put("http.port", new Integer(getPortParameter())); //$NON-NLS-1$
-
- // set the base URL
-// d.put("context.path", "/wrtdebugger"); //$NON-NLS-1$ //$NON-NLS-2$
- d.put("other.info", "org.symbian.wst.debugger"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // suppress Jetty INFO/DEBUG messages to stderr
- Logger.getLogger("org.mortbay").setLevel(Level.WARNING); //$NON-NLS-1$
-
- JettyConfigurator.startServer(webappName, d);
- checkBundle();
- Bundle bundle = Activator.getDefault().getBundle();
- HttpService service = (HttpService) bundle.getBundleContext().getService(getServiceReference());
- HttpContext httpContext = service.createDefaultHttpContext();
- service.registerResources(STATIC_RESOURCES_CONTEXT, WEB_CONTENT_ROOT, httpContext);
- service.registerServlet(WORKSPACE_RESOURCES_CONTEXT, new WorkspaceResourcesServlet(), new Hashtable(), httpContext);
- service.registerServlet(STATIC_RESOURCES_CONTEXT + "/*.jsp", new JspServlet(bundle, WEB_CONTENT_ROOT, STATIC_RESOURCES_CONTEXT + "*.jsp"), new Hashtable(), httpContext);
- }
-
- /*
- * Ensures that the bundle with the specified name and the highest available
- * version is started and reads the port number
- */
- private static void checkBundle() throws InvalidSyntaxException, BundleException {
- Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry"); //$NON-NLS-1$if (bundle != null) {
- if (bundle.getState() == Bundle.RESOLVED) {
- bundle.start(Bundle.START_TRANSIENT);
- }
- if (port == -1) {
- ServiceReference reference = getServiceReference();
- Object assignedPort = reference.getProperty("http.port"); //$NON-NLS-1$
- port = Integer.parseInt((String)assignedPort);
- }
- }
-
- private static ServiceReference getServiceReference()
- throws InvalidSyntaxException {
- Bundle bundle2 = Activator.getDefault().getBundle();
- // Jetty selected a port number for us
- ServiceReference[] reference = bundle2.getBundleContext().getServiceReferences("org.osgi.service.http.HttpService", "(other.info=org.symbian.wst.debugger)"); //$NON-NLS-1$ //$NON-NLS-2$
- return reference[0];
- }
-
- public static void stop(String webappName) throws CoreException {
- try {
- JettyConfigurator.stopServer(webappName);
- }
- catch (Exception e) {
- //HelpBasePlugin.logError("An error occured while stopping the help server", e); //$NON-NLS-1$
- }
- }
-
- public static int getPort() {
- return port;
- }
-
- /*
- * Get the port number which will be passed to Jetty
- */
- private static int getPortParameter() {
- if (port == -1) {
- return AUTO_SELECT_JETTY_PORT;
- }
- return port;
- }
-
- public static String getHost() {
- if (host == null) {
- host = "127.0.0.1"; //$NON-NLS-1$
- }
- return host;
- }
-
- private WebappManager() {
- }
-
-}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/web/WorkspaceResourcesServlet.java Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- *******************************************************************************/
-package org.symbian.tools.wrttools.debug.internal.web;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.StringTokenizer;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.symbian.tools.wrttools.debug.internal.Activator;
-
-public class WorkspaceResourcesServlet extends HttpServlet {
- private static final long serialVersionUID = -3217197074249607950L;
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
- new Path(req.getPathInfo()));
- if (file.isAccessible()) {
- InputStream contents = null;
- try {
- contents = file.getContents();
- byte[] buf = new byte[4048];
- int i;
- while ((i = contents.read(buf)) >= 0) {
- resp.getOutputStream().write(buf, 0, i);
- }
- } catch (CoreException e) {
- Activator.log(e);
- } finally {
- if (contents != null) {
- contents.close();
- }
- }
- } else {
- resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
- }
- }
-
- public static String getHttpUrl(IResource file) {
- try {
- String path = WebappManager.WORKSPACE_RESOURCES_CONTEXT
- + (file != null ? encode(file.getFullPath()) : "/");
- URL url = new URL("http", WebappManager.getHost(), WebappManager
- .getPort(), path);
- return url.toString();
- } catch (MalformedURLException e) {
- return file.getLocationURI().toString();
- }
- }
-
- private static String encode(IPath fullPath) {
- try {
- StringBuffer result = new StringBuffer();
- String[] segments = fullPath.segments();
- for (int i = 0; i < segments.length; i++) {
- String string = segments[i];
- result.append("/");
- // java.net.URLEncoder encodes " " as "+" while Chrome needs "%20"
- StringTokenizer tokenizer = new StringTokenizer(string, " ", false);
- while (tokenizer.hasMoreElements()) {
- result.append(URLEncoder.encode(tokenizer.nextToken(),
- "UTF-8"));
- if (tokenizer.hasMoreTokens()) {
- result.append("%20");
- }
- }
- }
- return result.toString();
- } catch (UnsupportedEncodingException e) {
- // Something is horribly wrong - JRE doesn't have UTF8?
- throw new RuntimeException(e);
- }
- }
-
- public static IFile getFileFromUrl(String name) {
- try {
- String root = getHttpUrl(null);
- IFile file = null;
- if (name.startsWith(root)) {
- String fileName = name.substring(root.length());
- fileName = URLDecoder.decode(fileName, "UTF-8");
- final IPath path = new Path(fileName);
- file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
- if (!file.isAccessible()) {
- return null;
- }
- }
- return file;
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-}
--- a/org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF Thu Jan 21 17:49:50 2010 -0800
@@ -3,11 +3,18 @@
Bundle-Name: Previewer
Bundle-SymbolicName: org.symbian.tools.wrttools.previewer;singleton:=true
Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.symbian.tools.wrttools.previewer.Activator
+Bundle-Activator: org.symbian.tools.wrttools.previewer.PreviewerPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.5.0",
org.eclipse.core.net;bundle-version="1.2.0",
- org.mozilla.xpcom;bundle-version="1.9.1"
+ org.mozilla.xpcom;bundle-version="1.9.1",
+ org.eclipse.equinox.http.jetty;bundle-version="2.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.symbian.tools.wrttools.previewer,
+ org.symbian.tools.wrttools.previewer.http
+Import-Package: javax.servlet;version="2.5.0",
+ javax.servlet.http;version="2.5.0",
+ org.eclipse.equinox.jsp.jasper;version="1.0.0",
+ org.osgi.service.http;version="1.2.1"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/http-content/wrtdebugger/connectionTest.jsp Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,9 @@
+<%@ page import="org.symbian.tools.wrttools.previewer.http.WebAppInterface, javax.servlet.http.HttpServletResponse" %>
+<%
+ String widget = WebAppInterface.decode(request.getParameter("widget"));
+ String id = request.getParameter("session");
+
+ if (WebAppInterface.isConnected(widget, id)) {
+ response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ }
+%>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/http-content/wrtdebugger/debugger.jsp Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,33 @@
+<%@ page import="org.symbian.tools.wrttools.previewer.http.WebAppInterface" %>
+<%
+ String widget = WebAppInterface.decode(request.getParameter("widget"));
+ String id = request.getParameter("session");
+%>
+<html>
+<head>
+ <title><%=widget %></title>
+ <% WebAppInterface.connectDebugger(widget, id); %>
+ <script type="text/javascript">
+ var req;
+
+ function connect() {
+ req = new XMLHttpRequest();
+ req.onreadystatechange = testconnection;
+ req.open("GET", "<%=WebAppInterface.getAjaxUri(widget, id) %>", true);
+ req.send(null);
+ }
+
+ function testconnection() {
+ if (req.readyState == 4) {
+ if (req.status == 200) {
+ window.setTimeout(connect, 200);
+ } else {
+ window.location = '<%=WebAppInterface.getUrl(widget, id) %>';
+ }
+ }
+ }
+ </script>
+</head>
+<body onload="connect()">
+Establishing debug connection...
+</body>
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/plugin.xml Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/plugin.xml Thu Jan 21 17:49:50 2010 -0800
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
-
- <extension
- point="org.eclipse.ui.preferencePages">
- <page
- class="org.symbian.tools.wrttools.previewer.preview.WidgetPreviewPreferencePage"
- id="org.symbian.tools.wrttools.previewer.preview.WidgetPreviewPreferencePage"
- name="Preview"/>
-
- </extension>
<extension
point="org.eclipse.ui.views">
<view
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/Activator.java Thu Jan 21 11:52:32 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-/**
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- */
-package org.symbian.tools.wrttools.previewer;
-
-import org.eclipse.core.net.proxy.IProxyService;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.symbian.tools.wrttools.previewer";
-
- // The shared instance
- private static Activator plugin;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- @Override
- protected void initializeImageRegistry(ImageRegistry reg) {
- addImage(reg, Images.GREEN_SYNC);
- addImage(reg, Images.RED_SYNC);
- addImage(reg, Images.YELLOW_SYNC);
- }
-
- private void addImage(ImageRegistry reg, String path) {
- ImageDescriptor imageDescriptor = imageDescriptorFromPlugin(PLUGIN_ID, path);
- reg.put(path, imageDescriptor);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
- public static void log(Exception e) {
- log(null, e);
- }
-
- public static void log(String message, Exception e) {
- IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e);
- getDefault().getLog().log(status);
- }
-
- public static ImageDescriptor getImageDescriptor(String key) {
- return getDefault().getImageRegistry().getDescriptor(key);
- }
-
- public static IProxyService getProxyService() {
- IProxyService service = (IProxyService) getDefault().getBundle().getBundleContext().getServiceReference(IProxyService.class.getName());
- return service;
- }
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerPlugin.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,113 @@
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.previewer;
+
+import org.eclipse.core.net.proxy.IProxyService;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.symbian.tools.wrttools.previewer.http.HttpPreviewer;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class PreviewerPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.symbian.tools.wrttools.previewer";
+
+ // The shared instance
+ private static PreviewerPlugin plugin;
+
+ private HttpPreviewer previewer = new HttpPreviewer();
+
+ /**
+ * The constructor
+ */
+ public PreviewerPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ @Override
+ protected void initializeImageRegistry(ImageRegistry reg) {
+ addImage(reg, Images.GREEN_SYNC);
+ addImage(reg, Images.RED_SYNC);
+ addImage(reg, Images.YELLOW_SYNC);
+ }
+
+ private void addImage(ImageRegistry reg, String path) {
+ ImageDescriptor imageDescriptor = imageDescriptorFromPlugin(PLUGIN_ID, path);
+ reg.put(path, imageDescriptor);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static PreviewerPlugin getDefault() {
+ return plugin;
+ }
+
+ public static void log(Exception e) {
+ log(null, e);
+ }
+
+ public static void log(String message, Exception e) {
+ IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e);
+ getDefault().getLog().log(status);
+ }
+
+ public static ImageDescriptor getImageDescriptor(String key) {
+ return getDefault().getImageRegistry().getDescriptor(key);
+ }
+
+ public IProxyService getProxyService() {
+ BundleContext bundleContext = getDefault().getBundle().getBundleContext();
+ ServiceReference serviceReference = bundleContext.getServiceReference(IProxyService.class.getName());
+ IProxyService service = (IProxyService) bundleContext.getService(serviceReference);
+ return service;
+ }
+
+ public HttpPreviewer getHttpPreviewer() {
+ return previewer;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/BrowserConnectionJob.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,53 @@
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.net.URI;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+
+public class BrowserConnectionJob extends Job {
+ private final IPreviewStartupListener listener;
+ private final URI uri;
+
+ private boolean ready = false;
+ private boolean success = false;
+
+ public BrowserConnectionJob(IPreviewStartupListener listener, URI uri) {
+ super("Connecting to WRT preview browser");
+ this.listener = listener;
+ this.uri = uri;
+ setUser(false);
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ listener.browserRunning(uri);
+ synchronized (this) {
+ success = true;
+ }
+ } catch (CoreException e) {
+ synchronized (this) {
+ success = false;
+ }
+ return e.getStatus();
+ } finally {
+ synchronized (this) {
+ ready = true;
+ }
+ }
+ return new Status(IStatus.OK, PreviewerPlugin.PLUGIN_ID, "");
+ }
+
+ public synchronized boolean isReady() {
+ return ready;
+ }
+
+ public synchronized boolean isSuccess() {
+ return success;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/EmulatorContext.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ *******************************************************************************/
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.osgi.service.http.HttpContext;
+
+public class EmulatorContext implements HttpContext {
+
+ public String getMimeType(String name) {
+ return null;
+ }
+
+ public URL getResource(String name) {
+ try {
+ return new URL("file:///e:/maven-prefs.png");
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ public boolean handleSecurity(HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ return true;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/HttpPreviewer.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,37 @@
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+
+public class HttpPreviewer {
+
+ public URI previewProject(IProject project) {
+ WebAppInterface.getInstance(); // Ensure server is up
+ try {
+ return new URI(WorkspaceResourcesServlet.getPreviewerStartingPage(project.getName()));
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+
+ public IFile getFileFromUrl(String name) {
+ return WorkspaceResourcesServlet.getFileFromUrl(name);
+ }
+
+ public String getHttpUrl(IResource resource) {
+ return WorkspaceResourcesServlet.getHttpUrl(resource);
+ }
+
+ public URI previewProject(IProject project, IPreviewStartupListener listener) {
+ if (listener == null) {
+ return previewProject(project);
+ } else {
+ return WebAppInterface.getInstance().prepareDebugger(project, listener);
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/IPreviewStartupListener.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,9 @@
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.net.URI;
+
+import org.eclipse.core.runtime.CoreException;
+
+public interface IPreviewStartupListener {
+ boolean browserRunning(URI uri) throws CoreException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebAppInterface.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ *******************************************************************************/
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.eclipse.core.resources.IProject;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+
+public class WebAppInterface {
+ private static WebAppInterface INSTANCE;
+
+ public static void connectDebugger(String widget, String id) {
+ getInstance().connect(widget, id);
+ }
+
+ public static String decode(String value) {
+ try {
+ return URLDecoder.decode(value, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String encode(String project) {
+ try {
+ return URLEncoder.encode(project, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String getAjaxUri(String widget, String id) {
+ return getInstance().createAjaxUri(widget, id).toASCIIString();
+ }
+
+ public synchronized static WebAppInterface getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new WebAppInterface();
+ }
+ return INSTANCE;
+ }
+
+ public static String getUrl(String widget, String id) {
+ return getInstance().complete(widget, id);
+ }
+
+ public static boolean isConnected(String widget, String id) {
+ return getInstance().isJobComplete(widget, id);
+ }
+
+ public static boolean isSuccessful(String widget, String id) {
+ return getInstance().isConnectionSuccessful(widget, id);
+ }
+
+ private final Map<String, BrowserConnectionJob> debuggerJobs = new TreeMap<String, BrowserConnectionJob>();
+
+ private WebAppInterface() {
+ try {
+ WebappManager.start("wrtbrowser");
+ } catch (Exception e) {
+ PreviewerPlugin.log(e);
+ }
+ }
+
+ private synchronized String complete(String widget, String id) {
+ return WorkspaceResourcesServlet.getPreviewerStartingPage(widget);
+ }
+
+ private synchronized void connect(String widget, String id) {
+ BrowserConnectionJob listener = debuggerJobs.get(getId(widget, id));
+ listener.schedule();
+ }
+
+ private URI createAjaxUri(String widget, String id) {
+ try {
+ return createUri("connectionTest.jsp", widget, id);
+ } catch (URISyntaxException e) {
+ PreviewerPlugin.log(e);
+ return null;
+ }
+ }
+
+ private URI createUri(String page, String project, String session)
+ throws URISyntaxException {
+ URI uri = new URI("http", null, WebappManager.getHost(), WebappManager
+ .getPort(), "/wrtdebugger/" + page, "widget=" + encode(project)
+ + "&session=" + session, null);
+ return uri;
+ }
+
+ private String getId(String name, String session) {
+ return name + "$" + session;
+ }
+
+ private boolean isJobComplete(String widget, String id) {
+ BrowserConnectionJob job = debuggerJobs.get(getId(widget, id));
+ return job.isReady();
+ }
+
+ private boolean isConnectionSuccessful(String widget, String id) {
+ BrowserConnectionJob job = debuggerJobs.get(getId(widget, id));
+ return job.isSuccess();
+ }
+
+ public synchronized URI prepareDebugger(IProject project,
+ IPreviewStartupListener listener) {
+ try {
+ String session = Long.toHexString(System.currentTimeMillis());
+ URI uri = createUri("debugger.jsp", project.getName(), session);
+ if (listener != null) {
+ debuggerJobs.put(getId(project.getName(), session), new BrowserConnectionJob(listener, uri));
+ }
+ return uri;
+ } catch (URISyntaxException e) {
+ PreviewerPlugin.log(e);
+ }
+ return null;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebappManager.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ *******************************************************************************/
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.equinox.http.jetty.JettyConfigurator;
+import org.eclipse.equinox.jsp.jasper.JspServlet;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+
+/**
+ * Copy from the WS Explorer
+ *
+ * @author Eugene Ostroukhov
+ *
+ */
+public class WebappManager {
+ public static final String WORKSPACE_RESOURCES_CONTEXT = "/preview";
+ public static final String STATIC_RESOURCES_CONTEXT = "/wrtdebugger";
+ public static final String WEB_CONTENT_ROOT = "/http-content";
+
+ private static String host;
+ private static int port = -1;
+ private static final int AUTO_SELECT_JETTY_PORT = 0;
+
+ @SuppressWarnings("unchecked")
+ public static void start(String webappName) throws Exception {
+ Dictionary d = new Hashtable();
+
+ d.put("http.port", new Integer(getPortParameter())); //$NON-NLS-1$
+
+ // set the base URL
+// d.put("context.path", "/wrtdebugger"); //$NON-NLS-1$ //$NON-NLS-2$
+ d.put("other.info", "org.symbian.wst.debugger"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // suppress Jetty INFO/DEBUG messages to stderr
+ Logger.getLogger("org.mortbay").setLevel(Level.WARNING); //$NON-NLS-1$
+
+ JettyConfigurator.startServer(webappName, d);
+ checkBundle();
+ Bundle bundle = PreviewerPlugin.getDefault().getBundle();
+ HttpService service = (HttpService) bundle.getBundleContext().getService(getServiceReference());
+ HttpContext httpContext = service.createDefaultHttpContext();
+ service.registerResources(STATIC_RESOURCES_CONTEXT, WEB_CONTENT_ROOT, httpContext);
+ service.registerServlet(WORKSPACE_RESOURCES_CONTEXT, new WorkspaceResourcesServlet(), new Hashtable(), httpContext);
+ service.registerServlet(STATIC_RESOURCES_CONTEXT + "/*.jsp", new JspServlet(bundle, WEB_CONTENT_ROOT, STATIC_RESOURCES_CONTEXT + "*.jsp"), new Hashtable(), httpContext);
+ }
+
+ /*
+ * Ensures that the bundle with the specified name and the highest available
+ * version is started and reads the port number
+ */
+ private static void checkBundle() throws InvalidSyntaxException, BundleException {
+ Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry"); //$NON-NLS-1$if (bundle != null) {
+ if (bundle.getState() == Bundle.RESOLVED) {
+ bundle.start(Bundle.START_TRANSIENT);
+ }
+ if (port == -1) {
+ ServiceReference reference = getServiceReference();
+ Object assignedPort = reference.getProperty("http.port"); //$NON-NLS-1$
+ port = Integer.parseInt((String)assignedPort);
+ }
+ }
+
+ private static ServiceReference getServiceReference()
+ throws InvalidSyntaxException {
+ Bundle bundle = PreviewerPlugin.getDefault().getBundle();
+ // Jetty selected a port number for us
+ ServiceReference[] reference = bundle.getBundleContext().getServiceReferences("org.osgi.service.http.HttpService", "(other.info=org.symbian.wst.debugger)"); //$NON-NLS-1$ //$NON-NLS-2$
+ return reference[0];
+ }
+
+ public static void stop(String webappName) throws CoreException {
+ try {
+ JettyConfigurator.stopServer(webappName);
+ }
+ catch (Exception e) {
+ //HelpBasePlugin.logError("An error occured while stopping the help server", e); //$NON-NLS-1$
+ }
+ }
+
+ public static int getPort() {
+ return port;
+ }
+
+ /*
+ * Get the port number which will be passed to Jetty
+ */
+ private static int getPortParameter() {
+ if (port == -1) {
+ return AUTO_SELECT_JETTY_PORT;
+ }
+ return port;
+ }
+
+ public static String getHost() {
+ if (host == null) {
+ host = "127.0.0.1"; //$NON-NLS-1$
+ }
+ return host;
+ }
+
+ private WebappManager() {
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java Thu Jan 21 17:49:50 2010 -0800
@@ -0,0 +1,258 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ *******************************************************************************/
+package org.symbian.tools.wrttools.previewer.http;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+
+public class WorkspaceResourcesServlet extends HttpServlet {
+ private static final String STARTING_PAGE = "preview-frame.html";
+ private static final String INDEX_PAGE = "wrt_preview_main.html";
+ private static final long serialVersionUID = -3217197074249607950L;
+
+ private static final Pattern HTML_FILE_NAME_PROPERTY = Pattern
+ .compile("<key>\\s*MainHTML\\s*</key>\\s*<string>\\s*(.*)\\s*</string>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern HEAD_TAG_PATTERN = Pattern.compile("<head(\\s*\\w*=\"(^\")*\")*\\s*>", Pattern.CASE_INSENSITIVE);
+ private static final String SCRIPT = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"preview/script/lib/loader.js\"></script>";
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ IPath path = new Path(req.getPathInfo());
+ InputStream contents = null;
+ try {
+ contents = getSpecialResource(path);
+ if (contents == null) {
+ contents = getWorkspaceResourceContents(path);
+ }
+ if (contents != null) {
+ copyData(contents, resp.getOutputStream());
+ } else {
+ System.err.println(path);
+ resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+ } catch (CoreException e) {
+ PreviewerPlugin.log(e);
+ } finally {
+ if (contents != null) {
+ contents.close();
+ }
+ }
+ }
+
+ private InputStream getSpecialResource(IPath path) throws IOException,
+ CoreException {
+ IPath relativePath = path.removeFirstSegments(1);
+ if (relativePath.segmentCount() == 1) {
+ if (STARTING_PAGE.equals(relativePath.segment(0))) {
+ return getPluginResourceStream(new Path(
+ "/preview/wrt_preview.html"));
+ } else if (INDEX_PAGE.equals(relativePath.segment(0))) {
+ return getProjectIndexPage(path.segment(0));
+ }
+ } else if ("preview".equals(relativePath.segment(0))) {
+ return getPluginResourceStream(relativePath.makeAbsolute());
+ }
+ return null;
+ }
+
+ private InputStream getProjectIndexPage(String projectName)
+ throws IOException, CoreException {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ projectName);
+ if (project.isAccessible()) {
+ String indexFileName = getIndexFileName(project);
+ if (indexFileName != null) {
+ String string = readFile(project, indexFileName);
+ if (string != null) {
+ Matcher matcher = HEAD_TAG_PATTERN.matcher(string);
+ if (matcher.find()) {
+ string = matcher.replaceFirst(matcher.group() + SCRIPT);
+ }
+ return new ByteArrayInputStream(string.getBytes("UTF-8"));
+ }
+ }
+ }
+ return null;
+ }
+
+ private String getIndexFileName(IProject project) throws CoreException,
+ UnsupportedEncodingException, IOException {
+ String buffer = readFile(project, "Info.plist");
+ if (buffer != null) {
+ Matcher matcher = HTML_FILE_NAME_PROPERTY.matcher(buffer);
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+ }
+ return null;
+ }
+
+ private String readFile(IProject project, String fileName)
+ throws CoreException, UnsupportedEncodingException, IOException {
+ IFile file = project.getFile(fileName);
+ if (file.isAccessible()) {
+ InputStream contents = file.getContents();
+ final BufferedReader reader = new BufferedReader(
+ new InputStreamReader(contents, file.getCharset()));
+ StringBuffer buffer = new StringBuffer();
+ try {
+ int c = 0;
+ char[] buf = new char[4096];
+ while ((c = reader.read(buf)) > 0) {
+ buffer.append(buf, 0, c);
+ }
+ return buffer.toString();
+ } finally {
+ reader.close();
+ }
+ }
+ return null;
+ }
+
+ private InputStream getPluginResourceStream(IPath path) throws IOException {
+ URL url = FileLocator.find(PreviewerPlugin.getDefault().getBundle(),
+ path, null);
+ if (url != null) {
+ return url.openStream();
+ } else {
+ return null;
+ }
+ }
+
+ private void copyData(InputStream contents, OutputStream ouput)
+ throws IOException {
+ byte[] buf = new byte[4048];
+ int i;
+ while ((i = contents.read(buf)) >= 0) {
+ ouput.write(buf, 0, i);
+ }
+ }
+
+ private InputStream getWorkspaceResourceContents(IPath path)
+ throws CoreException {
+ InputStream contents = null;
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if (file.isAccessible()) {
+ contents = file.getContents();
+ }
+ return contents;
+ }
+
+ public static String getHttpUrl(IResource file) {
+ String uri = getServerURIForResource(file != null ? file.getFullPath()
+ .toString() : "/");
+ if (uri != null) {
+ return uri;
+ } else {
+ return file.getLocationURI().toString();
+ }
+ }
+
+ private static String getServerURIForResource(String resourcePath) {
+ String uri = null;
+ try {
+ String path = WebappManager.WORKSPACE_RESOURCES_CONTEXT
+ + resourcePath;
+ URL url = new URL("http", WebappManager.getHost(), WebappManager
+ .getPort(), encode(path));
+ uri = url.toString();
+ } catch (MalformedURLException e) {
+ uri = null;
+ }
+ return uri;
+ }
+
+ private static String encode(String path) {
+ try {
+ StringBuffer result = new StringBuffer();
+ String[] segments = new Path(path).segments();
+ for (int i = 0; i < segments.length; i++) {
+ String string = segments[i];
+ result.append("/");
+ // java.net.URLEncoder encodes " " as "+" while Chrome needs
+ // "%20"
+ StringTokenizer tokenizer = new StringTokenizer(string, " ",
+ false);
+ while (tokenizer.hasMoreElements()) {
+ result.append(URLEncoder.encode(tokenizer.nextToken(),
+ "UTF-8"));
+ if (tokenizer.hasMoreTokens()) {
+ result.append("%20");
+ }
+ }
+ }
+ return result.toString();
+ } catch (UnsupportedEncodingException e) {
+ // Something is horribly wrong - JRE doesn't have UTF8?
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static IFile getFileFromUrl(String name) {
+ try {
+ String root = getHttpUrl(null);
+ IFile file = null;
+ if (name.startsWith(root)) {
+ String fileName = name.substring(root.length());
+ fileName = URLDecoder.decode(fileName, "UTF-8");
+ final IPath path = new Path(fileName);
+ file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if (!file.isAccessible()) {
+ return null;
+ }
+ }
+ return file;
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String getPreviewerStartingPage(String widget) {
+ return getServerURIForResource(new Path(widget).append(STARTING_PAGE)
+ .makeAbsolute().toString());
+ }
+}
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preferences/WrtEditingPreferencePage.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preferences/WrtEditingPreferencePage.java Thu Jan 21 17:49:50 2010 -0800
@@ -8,7 +8,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.symbian.tools.wrttools.previewer.Activator;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
import org.symbian.tools.wrttools.previewer.IWrtEditingPreferences;
/**
@@ -33,7 +33,7 @@
public WrtEditingPreferencePage() {
super(GRID);
- setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setPreferenceStore(PreviewerPlugin.getDefault().getPreferenceStore());
}
/**
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewPage.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewPage.java Thu Jan 21 17:49:50 2010 -0800
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;
@@ -31,7 +32,7 @@
import org.mozilla.interfaces.nsIServiceManager;
import org.mozilla.xpcom.Mozilla;
import org.osgi.framework.Bundle;
-import org.symbian.tools.wrttools.previewer.Activator;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
import org.symbian.tools.wrttools.previewer.Images;
public class PreviewPage extends Page implements IPageBookViewPage, ISelectionProvider {
@@ -98,14 +99,13 @@
browser = new Browser(parent, SWT.MOZILLA);
bypassSameOriginPolicy();
applyProxySettings();
- browser.setUrl(getURL());
+ browser.setUrl(getURI().toASCIIString());
}
- private String getURL() {
- return project.getFile("wrt_preview_frame.html").getLocationURI().toASCIIString();
+ private URI getURI() {
+ return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project);
}
-
@Override
public Control getControl() {
return browser;
@@ -127,7 +127,7 @@
refresh();
} else {
needsRefresh = true;
- refreshAction.setImageDescriptor(Activator.getImageDescriptor(Images.RED_SYNC));
+ refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.RED_SYNC));
refreshAction.setToolTipText("Refresh the preview browser (there are updated files)");
}
}
@@ -153,7 +153,7 @@
try {
final Control focusControl = browser.getDisplay().getFocusControl();
browser.refresh();
- refreshAction.setImageDescriptor(Activator
+ refreshAction.setImageDescriptor(PreviewerPlugin
.getImageDescriptor(Images.GREEN_SYNC));
asyncExec(new Runnable() {
@Override
@@ -172,13 +172,13 @@
public void init(IPageSite pageSite) {
super.init(pageSite);
IToolBarManager toolBar = pageSite.getActionBars().getToolBarManager();
- refreshAction.setImageDescriptor(Activator.getImageDescriptor(Images.GREEN_SYNC));
+ refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.GREEN_SYNC));
refreshAction.setToolTipText("Refresh the preview browser");
toolBar.add(refreshAction);
toggleState = previewView.getProjectAutorefresh(project);
- toggleRefresh.setImageDescriptor(Activator.getImageDescriptor(Images.YELLOW_SYNC));
+ toggleRefresh.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.YELLOW_SYNC));
toggleRefresh.setToolTipText(getToggleActionTooltip());
toggleRefresh.setChecked(toggleState);
toolBar.add(toggleRefresh);
@@ -214,7 +214,7 @@
private void applyProxySettings() {
- IProxyService px = Activator.getProxyService();
+ IProxyService px = PreviewerPlugin.getDefault().getProxyService();
if(px != null){
boolean proxyEnabled = px.isProxiesEnabled();
@@ -234,7 +234,7 @@
}
else{
Exception e= new Exception();
- Activator.log("Proxy service returned null", e);
+ PreviewerPlugin.log("Proxy service returned null", e);
}
}
@@ -290,7 +290,7 @@
mozillaPrefs.setCharPref("capability.principal.codebase.p0.id", "file://");
mozillaPrefs.setBoolPref("security.fileuri.strict_origin_policy", 0);
} catch (Exception e) {
- Activator.log("Error getting preferences", e);
+ PreviewerPlugin.log("Error getting preferences", e);
}
}
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Thu Jan 21 11:52:32 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Thu Jan 21 17:49:50 2010 -0800
@@ -34,7 +34,7 @@
import org.eclipse.ui.part.MessagePage;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
-import org.symbian.tools.wrttools.previewer.Activator;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
import org.symbian.tools.wrttools.previewer.IWrtEditingPreferences;
public class PreviewView extends PageBookView {
@@ -64,7 +64,7 @@
try {
event.getDelta().accept(visitor);
} catch (CoreException e) {
- Activator.log(e);
+ PreviewerPlugin.log(e);
}
refreshPages(visitor.files);
}
@@ -133,7 +133,7 @@
}
private boolean getDefaultAutorefresh(IProject project) {
- IPreferenceStore preferenceStore = Activator.getDefault()
+ IPreferenceStore preferenceStore = PreviewerPlugin.getDefault()
.getPreferenceStore();
String value = preferenceStore
.getString(IWrtEditingPreferences.PREF_AUTO_REFRESH);
@@ -153,7 +153,7 @@
}
private File getPreferencesFile() {
- return Activator.getDefault().getStateLocation().append(
+ return PreviewerPlugin.getDefault().getStateLocation().append(
"autorefreshState.xml").toFile();
}
@@ -200,13 +200,13 @@
inputStream = new FileInputStream(preferencesFile);
properties.loadFromXML(inputStream);
} catch (IOException e) {
- Activator.log(e);
+ PreviewerPlugin.log(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
- Activator.log(e);
+ PreviewerPlugin.log(e);
}
}
}
@@ -245,13 +245,13 @@
path));
properties.storeToXML(outputStream, null);
} catch (IOException e) {
- Activator.log(e);
+ PreviewerPlugin.log(e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
- Activator.log(e);
+ PreviewerPlugin.log(e);
}
}
}