/** * Get the size of the Asset (the original rendition). * * @param asset * @return */ private static long getSize(final Asset asset) { final Rendition original = asset.getOriginal(); if (original == null) { return 0; } return original.getSize(); }
/** * @return Mime type */ public String getMimeType() { return this.rendition.getMimeType(); }
/** * @return File size */ public long getFileSize() { return this.rendition.getSize(); }
private long getTotalAssetSize(Asset asset) { long size = asset.getRenditions().stream().collect(Collectors.summingLong(r -> r.getSize())); if (includeSubassets && !asset.isSubAsset()) { size += DamUtil.getSubAssets(asset.adaptTo(Resource.class)).stream().collect(Collectors.summingLong(this::getTotalAssetSize)); } return size; }
public String getTitle() { return StringUtils.defaultIfBlank(StringUtils.defaultIfBlank(asset.getMetadataValue("dc:title"), asset.getName()), asset.getName()); }
/** * Given an {@link Asset}, this method will return the first web {@link Rendition} it finds in the asset's renditions list. * * @param asset the asset for which to retrieve the web rendition * @return the rendition, if found, {@code null} otherwise */ private Rendition getAWebRendition(Asset asset) { List<Rendition> renditions = asset.getRenditions(); for (Rendition rendition : renditions) { if (rendition.getName().startsWith(DamConstants.PREFIX_ASSET_WEB)) { return rendition; } } return null; }
/** * @param asset DAM asset */ DefaultRenditionHandler(Asset asset) { this.asset = asset; Rendition damOriginalRendition = asset.getOriginal(); originalRendition = damOriginalRendition != null ? new RenditionMetadata(damOriginalRendition) : null; }
public String getPath() { return asset.getPath(); }
@Override public String toString() { return this.rendition.getPath() + " (" + this.width + "x" + this.height + ")"; }
private FrozenAsset(Asset head, Revision revision) throws RepositoryException { final Node frozenNode = revision.getVersion().getFrozenNode(); this.head = head; frozenResource = head.adaptTo(Resource.class).getResourceResolver().getResource(frozenNode.getPath()); }
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == com.day.cq.dam.api.Asset.class) { return (AdapterType)this.damAsset; } if (type == Resource.class) { return (AdapterType)this.damAsset.adaptTo(Resource.class); } return super.adaptTo(type); }
/** * @param value DAM rendition * @return true if rendition is the original file that was uploaded initially */ private boolean isOriginalRendition(Rendition value) { return StringUtils.equals(value.getName(), ORIGINAL_FILE); }
// rendition = ...; // original rendition object created as above // newInputStream = ...; // new asset received from your webservice Asset asset = rendition.getAsset(); asset.addRendition("original", newInputStream, rendition.getMimeType());
@SuppressWarnings("null") protected InputStream getInputStream() { return this.rendition.adaptTo(Resource.class).adaptTo(InputStream.class); }
/** * Get the size of the Asset (the original rendition). * * @param asset * @return */ private static long getSize(final Asset asset) { final Rendition original = asset.getOriginal(); if (original == null) { return 0; } return original.getSize(); }
/** * Return the title or name of the asset, if the title is not defined. * * @param asset the asset * @return the asset title or name */ @Function public static String getTitleOrName(Asset asset) { String title = asset.getMetadataValue(DamConstants.DC_TITLE); return StringUtils.isNotBlank(title) ? title : asset.getName(); }
@Override public @NotNull String getPath() { return this.damAsset.getPath(); }
@Override public int hashCode() { return new HashCodeBuilder() .append(this.rendition.getPath()) .hashCode(); }
Resource r = resourceResolver.getResource(path); Asset a = r.adaptTo(Asset.class); Rendition rnd = a.getOriginal(); long size = rnd.getSize();
@Override public String getPath() { if (this.rendition != null) { return this.rendition.getRendition().getPath(); } else { return null; } }