Bug 2898 - Previewer http server is case-sensitive
authorEugene Ostroukhov <eugeneo@symbian.org>
Wed, 09 Jun 2010 14:22:40 -0700
changeset 365 46cd6227d4f4
parent 364 84c00c972166
child 366 715f288b552a
Bug 2898 - Previewer http server is case-sensitive
org.symbian.tools.wrttools.previewer/preview/script/nokia.js
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/WorkspaceResourceProvider.java
--- a/org.symbian.tools.wrttools.previewer/preview/script/nokia.js	Wed Jun 09 13:50:25 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/nokia.js	Wed Jun 09 14:22:40 2010 -0700
@@ -214,7 +214,7 @@
 					clearInterval(NOKIA.helper.intervalId);
 				}
 				NOKIA.helper.intervalId = setTimeout(function(){
-					NOKIA.menu.cancel()
+					NOKIA.menu.cancel();
 				}, 500);
 			});
 
@@ -793,7 +793,7 @@
 							}
 						}
 	
-				}
+				};
 				xhr.send(null);
 			} catch (e) {
 				if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
@@ -915,7 +915,7 @@
 									//	call the native XmlHttpRequest.open method
 									this._open(method, url, flag);
 								}
-							}
+							};
 						}
 					}
 					catch(e)
@@ -1410,7 +1410,7 @@
 			var p = document.createElement('p');
 			p.className = type;
 			p.innerHTML = msg;
-			var divBody = $('#preview-ui-bottom-body')
+			var divBody = $('#preview-ui-bottom-body');
 			divBody.append(p);
 			divBody[0].scrollTop = divBody[0].scrollHeight;
 		},
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/WorkspaceResourceProvider.java	Wed Jun 09 13:50:25 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/WorkspaceResourceProvider.java	Wed Jun 09 14:22:40 2010 -0700
@@ -22,8 +22,10 @@
 import java.io.InputStream;
 import java.util.Map;
 
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.json.simple.JSONObject;
@@ -38,16 +40,48 @@
     public InputStream getResourceStream(IProject project, IPath resource, Map<String, String[]> parameters,
             String sessionId)
             throws IOException, CoreException {
-        IFile file = project.getFile(resource);
-        if (file.isAccessible() && !ProjectUtils.isExcluded(file)) {
+        IFile file = getFile(project, resource);
+        if (file != null) {
             return file.getContents();
         } else {
-            PreviewerPlugin.print(String.format("%s was not found in the workspace. It was requested by the previewer.\n", file
-                    .getFullPath().toString()));
+            PreviewerPlugin.print(String.format(
+                    "%s was not found in the workspace. It was requested by the previewer.\n", resource.toString()));
             return null;
         }
     }
 
+    private IFile getFile(IProject project, IPath resource) throws CoreException {
+        final IFile file = project.getFile(resource);
+        if (!file.isAccessible()) {
+            IContainer container = project;
+            for (int i = 0; i < resource.segmentCount() - 1; i++) {
+                String name = resource.segment(i).toLowerCase();
+                container = (IContainer) getResource(container, name, false);
+                if (container == null) {
+                    return null;
+                }
+            }
+            return (IFile) getResource(container, resource.lastSegment().toLowerCase(), true);
+        } else {
+            return file;
+        }
+    }
+
+    private IResource getResource(final IContainer container, final String name, final boolean isFile) throws CoreException {
+        IResource[] members = container.members();
+        for (IResource resource : members) {
+            if (resource.getName().toLowerCase().equals(name)) {
+                if (resource.isAccessible() && ((resource.getType() == IResource.FILE) == isFile)
+                        && !ProjectUtils.isExcluded(resource)) {
+                    return resource;
+                } else {
+                    return null;
+                }
+            }
+        }
+        return null;
+    }
+
     public void post(IProject project, IPath resource, Map<String, String[]> parameterMap, JSONObject object,
             String sessionId)
             throws IOException, CoreException {