31 import org.json.simple.JSONObject; |
31 import org.json.simple.JSONObject; |
32 import org.symbian.tools.tmw.previewer.PreviewerException; |
32 import org.symbian.tools.tmw.previewer.PreviewerException; |
33 |
33 |
34 /** |
34 /** |
35 * Path is usually in the form /preview/{project name}/{path} |
35 * Path is usually in the form /preview/{project name}/{path} |
36 * |
36 * |
37 * There are following spacial cases: |
37 * There are following spacial cases: |
38 * - Static previewer resource from plugin is returned when {path} begins with |
38 * - Static previewer resource from plugin is returned when {path} begins with |
39 * "preview" or is "preview-frame.html" |
39 * "preview" or is "preview-frame.html" |
40 * - Preferences resource is "preview/preferences.js" |
40 * - Preferences resource is "preview/preferences.js" |
41 * - Index page (main HTML page of the WRT application) is always wrt_preview_main.html |
41 * - Index page (main HTML page of the WRT application) is always wrt_preview_main.html |
42 * - Debugger commands are submitted to URL __sym_command |
42 * - Debugger commands are submitted to URL __sym_command |
43 * |
43 * |
44 * All other URLs return workspace resources. |
44 * All other URLs return workspace resources. |
45 */ |
45 */ |
46 public class Providers { |
46 public class Providers { |
47 private final Map<String, IResourceProvider> HANDLERS = new TreeMap<String, IResourceProvider>(); |
47 private final Map<String, IResourceProvider> handlers = new TreeMap<String, IResourceProvider>(); |
48 private final IResourceProvider defaultHandler = new WorkspaceResourceProvider(); |
48 private final IResourceProvider defaultHandler = new WorkspaceResourceProvider(); |
49 |
49 |
50 public Providers() { |
50 public Providers() { |
51 addPaths(new MasterScriptProvider()); |
51 addPaths(new MasterScriptProvider()); |
52 addPaths(new PreviewerStaticResourceProvider()); |
52 addPaths(new PreviewerStaticResourceProvider()); |
55 addPaths(new DebuggerResourceProvider()); |
55 addPaths(new DebuggerResourceProvider()); |
56 } |
56 } |
57 |
57 |
58 private void addPaths(IResourceProvider handler) { |
58 private void addPaths(IResourceProvider handler) { |
59 for (String path : handler.getPaths()) { |
59 for (String path : handler.getPaths()) { |
60 HANDLERS.put(path, handler); |
60 handlers.put(path, handler); |
61 } |
61 } |
62 } |
62 } |
63 |
63 |
64 public InputStream get(String url, Map<String, String[]> parameters, String sessionId) throws PreviewerException { |
64 public InputStream get(String url, Map<String, String[]> parameters, String sessionId) throws PreviewerException { |
65 final IProject project = getProject(url); |
65 final IProject project = getProject(url); |
76 |
76 |
77 private IResourceProvider getHandlerForPath(IPath resource) { |
77 private IResourceProvider getHandlerForPath(IPath resource) { |
78 IResourceProvider provider = null; |
78 IResourceProvider provider = null; |
79 IPath mapping = resource; |
79 IPath mapping = resource; |
80 while (mapping.segmentCount() > 0) { |
80 while (mapping.segmentCount() > 0) { |
81 provider = HANDLERS.get(mapping.toString()); |
81 provider = handlers.get(mapping.toString()); |
82 if (provider != null) { |
82 if (provider != null) { |
83 break; |
83 break; |
84 } |
84 } |
85 mapping = mapping.removeLastSegments(1); |
85 mapping = mapping.removeLastSegments(1); |
86 } |
86 } |