Example usage for com.vaadin.server ExternalResource ExternalResource

List of usage examples for com.vaadin.server ExternalResource ExternalResource

Introduction

In this page you can find the example usage for com.vaadin.server ExternalResource ExternalResource.

Prototype

public ExternalResource(String sourceURL, String mimeType) 

Source Link

Document

Creates a new download component for downloading directly from given URL.

Usage

From source file:info.magnolia.ui.imageprovider.DefaultImageProvider.java

License:Open Source License

private Object getThumbnailResource(Node node, String workspace, String generator) {
    Object resource = null;//from www .  ja  v a  2 s  . c  o  m
    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;
}