List of usage examples for com.vaadin.server ExternalResource ExternalResource
public ExternalResource(String sourceURL, String mimeType)
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; }