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

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

Introduction

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

Prototype

MediaType SVG_UTF_8

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

Click Source Link

Usage

From source file:be.nbb.cli.util.Utils.java

private static MediaType getMediaTypeByExtension(File file) {
    String fileName = file.getName().toLowerCase(Locale.ROOT);
    if (fileName.endsWith(".json")) {
        return MediaType.JSON_UTF_8;
    }/*from   w  w w .j a v a 2s  .  co m*/
    if (fileName.endsWith(".xml")) {
        return MediaType.XML_UTF_8;
    }
    if (fileName.endsWith(".png")) {
        return MediaType.PNG;
    }
    if (fileName.endsWith(".svg")) {
        return MediaType.SVG_UTF_8;
    }
    if (fileName.endsWith(".yaml")) {
        return YAML;
    }
    return null;
}

From source file:com.mastfrog.acteur.ClasspathResourcePage.java

protected MediaType getContentType(Path path) {
    MediaType type = responseHeaders.getContentType();
    if (type != null) {
        return type;
    }//from w ww.j ava2  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:info.magnolia.ui.imageprovider.DefaultImageProvider.java

private Object getThumbnailResource(Node node, String workspace, String generator) {
    Object resource = null;//w  ww.ja va 2 s. c  om
    try {
        final Node imageNode = node.getNode(definition.getOriginalImageNodeName());
        String mimeType = imageNode.getProperty(FileProperties.PROPERTY_CONTENTTYPE).getString();

        if (isImage(mimeType)) {
            if (MediaType.SVG_UTF_8.is(MediaType.parse(mimeType))) {
                ImageStreamSource iss = new ImageStreamSource(imageNode.getIdentifier(), workspace);
                // By default a StreamResource is cached for one year - filename contains the last modified date so that image is cached by the browser until changed.
                String filename = imageNode.getIdentifier()
                        + LastModified.getLastModified(imageNode).getTimeInMillis();
                StreamResource streamResource = new StreamResource(iss, filename);
                streamResource.setMIMEType(mimeType);
                resource = streamResource;
            } else {
                String path = getGeneratorImagePath(workspace, node, generator);
                if (StringUtils.isNotBlank(path)) {
                    resource = new ExternalResource(path, MediaType.PNG.toString());
                }
            }
        } else {
            resource = createIconFontResource(mimeType);
        }
    } catch (RepositoryException e) {
        log.debug("Could not get name or identifier from imageNode: {}", e.getMessage());
    }
    return resource;
}

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 ww w . j  av a 2s . co  m*/
        throw new IllegalArgumentException("Could not determine media type for " + filePath);
    }
}