@SuppressWarnings("null") protected InputStream getInputStream() { return this.rendition.adaptTo(Resource.class).adaptTo(InputStream.class); }
@Override @SuppressWarnings("null") public @NotNull ValueMap getProperties() { if (this.rendition != null) { return this.rendition.getRendition().adaptTo(Resource.class).getValueMap(); } else { return ValueMap.EMPTY; } }
@Override public Date getModificationDate() { if (this.rendition != null) { return ModificationDate.get(this.rendition.getRendition().adaptTo(Resource.class)); } else { return null; } }
@SuppressWarnings("null") protected Layer getLayer() { if (FileExtension.isImage(getFileExtension())) { return this.rendition.adaptTo(Resource.class).adaptTo(Layer.class); } else { return null; } }
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == Rendition.class) { return (AdapterType)this.rendition; } if (type == Resource.class) { return (AdapterType)this.rendition.adaptTo(Resource.class); } else if (type == Layer.class) { return (AdapterType)getLayer(); } else if (type == InputStream.class) { return (AdapterType)getInputStream(); } return super.adaptTo(type); }
/** * Update the Assets original rendition. * * @param asset the Asset to update * @param fileInputStream the new binary representation of the Asset * @param mimeType the MIME Type of the asset * @return the updated asset * @throws CsvAssetImportException */ private Asset updateAssetOriginal(Asset asset, InputStream fileInputStream, String mimeType) throws CsvAssetImportException { try { if (asset != null) { final Node originalNode = asset.getOriginal().adaptTo(Node.class); if (originalNode != null) { JcrUtils.putFile(originalNode.getParent(), "original", mimeType, fileInputStream, Calendar.getInstance()); log.info("Updated existing Asset's [ {} ] original rendition.", asset.getPath()); } else { log.warn("Could not find original rendition for Asset [ {} ] to update.", asset.getPath()); } } else { log.warn("Could not update a null asset"); } } catch (Exception e) { throw new CsvAssetImportException("Could not update Asset at [ " + asset.getPath() + " ]", e); } return asset; }
/** * Add sources for HTML5 video player * @param video Video * @param media Media metadata */ protected void addSources(Video video, Media media) { Asset asset = getDamAsset(media); if (asset == null) { return; } for (VideoProfile profile : getVideoProfiles()) { com.day.cq.dam.api.Rendition rendition = profile.getRendition(asset); if (rendition != null) { video.createSource() .setType(profile.getHtmlType()) .setSrc(urlHandler.get(rendition.getPath()).buildExternalResourceUrl(rendition.adaptTo(Resource.class))); } } }