Example usage for com.google.common.net MediaType CSS_UTF_8

List of usage examples for com.google.common.net MediaType CSS_UTF_8

Introduction

In this page you can find the example usage for com.google.common.net MediaType CSS_UTF_8.

Prototype

MediaType CSS_UTF_8

To view the source code for com.google.common.net MediaType CSS_UTF_8.

Click Source Link

Usage

From source file:com.bennavetta.appsite.postprocessor.CssMinifier.java

@Override
public void postProcess(InputStream in, OutputStream out, Request request, Response response)
        throws IOException {
    Charset inEncoding = request.getCharacterEncoding() != null ? request.getCharacterEncoding()
            : Charsets.UTF_8;/*w ww  . j  a  v a2 s.  c om*/
    response.setCharacterEncoding(Charsets.UTF_8);
    response.setContentType(MediaType.CSS_UTF_8);
    Reader inReader = new InputStreamReader(in, inEncoding);
    Writer outWriter = new OutputStreamWriter(out, Charsets.UTF_8);
    processor.process(Resource.create(request.getURI(), ResourceType.CSS), inReader, outWriter);
}

From source file:com.bennavetta.appsite.postprocessor.CssMinifier.java

@Override
public boolean canPostProcess(String path, Request request, Response response) {
    if (path.endsWith(".css"))
        return true;
    if (response.getContentType() != null
            && response.getContentType().withoutParameters().equals(MediaType.CSS_UTF_8))
        return true;
    return false;
}

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());//  w w w .  jav a  2 s.  c  om
    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: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 w  w .  jav  a2 s  .co m
    }

    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: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;
    }//  www.j  a va  2 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;/*  w  ww .  j  a  v a 2s  .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 {//w  w  w.  j a  v  a  2 s.c om
        throw new IllegalArgumentException("Could not determine media type for " + filePath);
    }
}