|
1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.wrttools.previewer.http.handlers; |
|
20 |
|
21 import java.io.ByteArrayInputStream; |
|
22 import java.io.IOException; |
|
23 import java.io.InputStream; |
|
24 import java.net.URL; |
|
25 import java.util.Map; |
|
26 |
|
27 import org.eclipse.core.resources.IProject; |
|
28 import org.eclipse.core.runtime.CoreException; |
|
29 import org.eclipse.core.runtime.FileLocator; |
|
30 import org.eclipse.core.runtime.IPath; |
|
31 import org.eclipse.core.runtime.Path; |
|
32 import org.json.simple.JSONObject; |
|
33 import org.symbian.tools.wrttools.previewer.PreviewerPlugin; |
|
34 import org.symbian.tools.wrttools.previewer.http.HttpPreviewer; |
|
35 import org.symbian.tools.wrttools.previewer.http.WebAppInterface; |
|
36 |
|
37 public class DebuggerResourceProvider implements IResourceProvider { |
|
38 public static final String DEBUG_SESSION_ID_PARAMETER = "debugSessionId"; |
|
39 |
|
40 public String[] getPaths() { |
|
41 return new String[] { HttpPreviewer.DEBUG_STARTING_PAGE, "__sym-debug" }; |
|
42 } |
|
43 |
|
44 public InputStream getResourceStream(IProject project, IPath resource, Map<String, String[]> parameters) |
|
45 throws IOException, CoreException { |
|
46 if (resource.toString().equals(HttpPreviewer.DEBUG_STARTING_PAGE)) { |
|
47 URL url = FileLocator.find(PreviewerPlugin.getDefault().getBundle(), new Path( |
|
48 PreviewerStaticResourceProvider.PREVIEW_START), null); |
|
49 if (url != null) { |
|
50 return url.openStream(); |
|
51 } |
|
52 } else if (resource.segmentCount() == 2) { |
|
53 if ("index.html".equals(resource.segment(1))) { |
|
54 String[] sessionId = parameters.get(DEBUG_SESSION_ID_PARAMETER); |
|
55 if (sessionId != null && sessionId.length == 1) { |
|
56 WebAppInterface.connectDebugger(project.getName(), sessionId[0]); |
|
57 } |
|
58 URL url = FileLocator.find(PreviewerPlugin.getDefault().getBundle(), new Path( |
|
59 "http-content/wrtdebugger/debugger.htm"), null); |
|
60 if (url != null) { |
|
61 return url.openStream(); |
|
62 } |
|
63 } else if ("testConnection".equals(resource.segment(1))) { |
|
64 String[] sessionId = parameters.get(DEBUG_SESSION_ID_PARAMETER); |
|
65 if (sessionId != null & sessionId.length == 1) { |
|
66 if (!WebAppInterface.isConnected(project.getName(), sessionId[0])) { |
|
67 return null; |
|
68 } |
|
69 } |
|
70 return new ByteArrayInputStream("Ok".getBytes()); |
|
71 } |
|
72 } |
|
73 return null; |
|
74 } |
|
75 |
|
76 public void post(IProject project, IPath resource, Map<String, String[]> parameterMap, JSONObject object) |
|
77 throws IOException, CoreException { |
|
78 // TODO Auto-generated method stub |
|
79 |
|
80 } |
|
81 |
|
82 } |