List of usage examples for com.google.common.net MediaType JAVASCRIPT_UTF_8
MediaType JAVASCRIPT_UTF_8
To view the source code for com.google.common.net MediaType JAVASCRIPT_UTF_8.
Click Source Link
From source file:com.twitter.common.webassets.jquery.JQueryModule.java
@Override protected void configure() { Registration.registerHttpAsset(binder(), "/js/jquery.min.js", Resources.getResource(JQueryModule.class, "js/jquery-1.8.2.min.js"), MediaType.JAVASCRIPT_UTF_8.toString(), true); }
From source file:com.facebook.buck.httpserver.StaticResourcesHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { if (!"GET".equals(request.getMethod())) { Responses.writeFailedResponse(baseRequest, response); return;/* w ww . j av a 2s . com*/ } String path = baseRequest.getHttpURI().getPath(); if ("/static/test_websocket.html".equals(path)) { String html = getContentsForResource(path); Responses.writeSuccessfulResponse(html, MediaType.HTML_UTF_8, baseRequest, response); } else if ("/static/test_websocket.js".equals(path)) { String js = getContentsForResource(path); Responses.writeSuccessfulResponse(js, MediaType.JAVASCRIPT_UTF_8, baseRequest, response); } else if ("/static/theme.css".equals(path)) { String css = getContentsForResource(path); Responses.writeSuccessfulResponse(css, MediaType.CSS_UTF_8, baseRequest, response); } else if ("/static/trace_viewer.css".equals(path)) { String css = getContentsForResource(path); Responses.writeSuccessfulResponse(css, MediaType.CSS_UTF_8, baseRequest, response); } else if ("/static/trace_viewer.js".equals(path)) { String js = getContentsForResource(path); Responses.writeSuccessfulResponse(js, MediaType.JAVASCRIPT_UTF_8, baseRequest, response); } else { LOG.error("No handler for %s", path); Responses.writeFailedResponse(baseRequest, response); } }
From source file:com.facebook.buck.httpserver.TraceDataHandler.java
private void doGet(Request baseRequest, HttpServletResponse response) throws ServletException, IOException { String path = baseRequest.getPathInfo(); Matcher matcher = ID_PATTERN.matcher(path); if (!matcher.matches()) { Responses.writeFailedResponse(baseRequest, response); return;/*from w w w .j av a 2 s .c o m*/ } String id = matcher.group(1); response.setContentType(MediaType.JAVASCRIPT_UTF_8.toString()); response.setStatus(HttpServletResponse.SC_OK); boolean hasValidCallbackParam = false; Writer responseWriter = response.getWriter(); String callback = baseRequest.getParameter("callback"); if (callback != null) { Matcher callbackMatcher = CALLBACK_PATTERN.matcher(callback); if (callbackMatcher.matches()) { hasValidCallbackParam = true; responseWriter.write(callback); responseWriter.write("("); } } InputSupplier<? extends InputStream> inputSupplier = tracesHelper.getInputForTrace(id); try (InputStreamReader inputStreamReader = new InputStreamReader(inputSupplier.getInput())) { CharStreams.copy(inputStreamReader, responseWriter); } if (hasValidCallbackParam) { responseWriter.write(");\n"); } response.flushBuffer(); baseRequest.setHandled(true); }
From source file:com.twitter.common.webassets.bootstrap.BootstrapModule.java
@Override protected void configure() { register("css/bootstrap-responsive.min.css", version + "/css/bootstrap-responsive.min.css", MediaType.CSS_UTF_8.toString()); register("css/bootstrap.min.css", version + "/css/bootstrap.min.css", MediaType.CSS_UTF_8.toString()); register("img/glyphicons-halflings-white.png", version + "/img/glyphicons-halflings-white.png", MediaType.PNG.toString());/*from w ww . j ava 2 s . c o m*/ register("img/glyphicons-halflings.png", version + "/img/glyphicons-halflings.png", MediaType.PNG.toString()); register("js/bootstrap.min.js", version + "/js/bootstrap.min.js", MediaType.JAVASCRIPT_UTF_8.toString()); }
From source file:org.onlab.stc.MonitorWebSocketServlet.java
private MediaType contentType(String uri) { int sep = uri.lastIndexOf(DOT); String ext = sep > 0 ? uri.substring(sep + 1) : null; return ext == null ? MediaType.APPLICATION_BINARY : ext.equals("html") ? MediaType.HTML_UTF_8 : ext.equals("js") ? MediaType.JAVASCRIPT_UTF_8 : ext.equals("css") ? MediaType.CSS_UTF_8 : MediaType.APPLICATION_BINARY; }
From source file:com.mastfrog.acteur.ClasspathResourcePage.java
protected MediaType getContentType(Path path) { MediaType type = responseHeaders.getContentType(); if (type != null) { return type; }/*from w w w .j a v a2 s. c om*/ String pth = path.toString(); if (pth.endsWith("svg")) { return MediaType.SVG_UTF_8; } else if (pth.endsWith("css")) { return MediaType.CSS_UTF_8; } else if (pth.endsWith("html")) { return MediaType.HTML_UTF_8; } else if (pth.endsWith("json")) { return MediaType.JSON_UTF_8; } else if (pth.endsWith("js")) { return MediaType.JAVASCRIPT_UTF_8; } else if (pth.endsWith("gif")) { return MediaType.GIF; } else if (pth.endsWith("jpg")) { return MediaType.JPEG; } else if (pth.endsWith("png")) { return MediaType.PNG; } return null; }
From source file:com.twitter.aurora.scheduler.http.ServletModule.java
private void registerAsset(String resourceLocation, String registerLocation) { MediaType mediaType;//from www.ja v a 2 s . c o m if (registerLocation.endsWith(".png")) { mediaType = MediaType.PNG; } else if (registerLocation.endsWith(".js")) { mediaType = MediaType.JAVASCRIPT_UTF_8; } else if (registerLocation.endsWith(".html")) { mediaType = MediaType.HTML_UTF_8; } else if (registerLocation.endsWith(".css")) { mediaType = MediaType.CSS_UTF_8; } else { throw new IllegalArgumentException("Could not determine media type for " + registerLocation); } Registration.registerHttpAsset(binder(), registerLocation, ServletModule.class, resourceLocation, mediaType.toString(), true); }
From source file:org.apache.aurora.scheduler.http.ServletModule.java
private MediaType getMediaType(String filePath) { if (filePath.endsWith(".png")) { return MediaType.PNG; } else if (filePath.endsWith(".js")) { return MediaType.JAVASCRIPT_UTF_8; } else if (filePath.endsWith(".html")) { return MediaType.HTML_UTF_8; } else if (filePath.endsWith(".css")) { return MediaType.CSS_UTF_8; } else if (filePath.endsWith(".svg")) { return MediaType.SVG_UTF_8; } else if (filePath.endsWith(".ttf") || filePath.endsWith(".eot") || filePath.endsWith(".woff")) { // MediaType doesn't have any mime types for fonts. Instead of magic strings, we let the // browser interpret the mime type and modern browsers can do this well. return MediaType.ANY_TYPE; } else {/*from w ww . j a v a2 s . c o m*/ throw new IllegalArgumentException("Could not determine media type for " + filePath); } }