@Override public InputStream getImage(String definitionName) { Definition def = getDefinitions().get(definitionName); if (def == null) { throw TalendRuntimeException .createUnexpectedException("fails to retrieve any definition for the name [" + definitionName + "]."); } return ComponentServiceImpl.getImageStream(def, def.getImagePath()); }
@Override public InputStream getImage(String definitionName) { Definition def = getDefinitions().get(definitionName); if (def == null) { throw TalendRuntimeException .createUnexpectedException("fails to retrieve any definition for the name [" + definitionName + "]."); } return ComponentServiceImpl.getImageStream(def, def.getImagePath()); }
@Override public ResponseEntity<InputStreamResource> getIcon(String definitionName, DefinitionImageType imageType) { notNull(definitionName, "Definition name cannot be null."); notNull(imageType, "Definition image type cannot be null."); final Definition<?> definition = propertiesHelpers.getDefinition(definitionName); notNull(definition, "Could not find definition of name %s", definitionName); // Undefined and missing icon resources are simply 404. String imagePath = definition.getImagePath(imageType); if (imagePath == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } InputStream is = definition.getClass().getResourceAsStream(imagePath); if (is == null) { log.info("The image type %s should exist for %s at %s, but is missing. " + "The component should provide this resource.", imageType, definitionName, imagePath); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } // At this point, we have enough information for a correct response. ResponseEntity.BodyBuilder response = ResponseEntity.ok(); // Add the content type if it can be determined. MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); String contentType = mimeTypesMap.getContentType(imagePath); if (contentType != null) { response = response.contentType(MediaType.parseMediaType(contentType)); } return response.body(new InputStreamResource(is)); }
/** * Constructor for the RuntimableDefinition part. * * @param origin the RuntimableDefinition. */ private DefinitionDTO(Definition origin) { this.name = origin.getName(); this.label = origin.getDisplayName(); // Get the first icon URL from the definition. for (DefinitionImageType imageType : DefinitionImageType.values()) { if (origin.getImagePath(imageType) != null) { this.iconURL = buildIconUrl(origin, imageType); break; } } this.iconKey = origin.getIconKey(); }