# HG changeset patch # User Eugene Ostroukhov # Date 1270672474 25200 # Node ID a240ab689b9b6169404a1833831eae1165063c40 # Parent d4abe1c863d17cb4b70a4fdb63f677a1e1709294 Bug 2441 - Numerous warnings when tracking resources in web inspector diff -r d4abe1c863d1 -r a240ab689b9b org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java Wed Apr 07 11:51:12 2010 -0700 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java Wed Apr 07 13:34:34 2010 -0700 @@ -31,6 +31,7 @@ import java.text.MessageFormat; import java.util.Map; import java.util.StringTokenizer; +import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -61,6 +62,28 @@ private static final Pattern HEAD_TAG_PATTERN = Pattern.compile("", Pattern.CASE_INSENSITIVE); private static final String SCRIPT = ""; + private static final Map EXTENSION_CONTENT_TYPE = new TreeMap(); + static { + EXTENSION_CONTENT_TYPE.put("htm", "text/html"); + EXTENSION_CONTENT_TYPE.put("html", "text/html"); + EXTENSION_CONTENT_TYPE.put("xml", "text/xml"); + EXTENSION_CONTENT_TYPE.put("plist", "application/octet-stream"); + EXTENSION_CONTENT_TYPE.put("gif", "image/gif"); + EXTENSION_CONTENT_TYPE.put("jpg", "image/jpeg"); + EXTENSION_CONTENT_TYPE.put("jpeg", "image/jpeg"); + EXTENSION_CONTENT_TYPE.put("png", "application/octet-stream"); + EXTENSION_CONTENT_TYPE.put("css", "text/css"); + EXTENSION_CONTENT_TYPE.put("js", "application/x-javascript"); + } + + public static String getMimeTypeByExtension(String extension) { + if (extension != null) { + return EXTENSION_CONTENT_TYPE.get(extension.toLowerCase()); + } else { + return null; + } + } + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -73,8 +96,15 @@ try { contents = getSpecialResource(path, req.getParameterMap()); if (contents == null) { - contents = getWorkspaceResourceContents(path); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); + if (file.isAccessible()) { + contents = file.getContents(); + } } + String mimeType = getMimeTypeByExtension(path.getFileExtension()); + if (mimeType != null) { + resp.setContentType(mimeType); + } if (contents != null) { copyData(contents, resp.getOutputStream()); } else { @@ -156,16 +186,6 @@ } } - 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() : "/");