@Override public Rendition getRendition(@NotNull MediaArgs mediaArgs) { Rendition rendition = getDamRendition(mediaArgs); // check if rendition is valid - otherwise return null if (StringUtils.isEmpty(rendition.getUrl())) { rendition = null; } return rendition; }
@Override public Rendition getRendition(@NotNull MediaArgs mediaArgs) { Rendition rendition = getInlineRendition(mediaArgs); // check if rendition is valid - otherwise return null if (StringUtils.isEmpty(rendition.getUrl())) { rendition = null; } return rendition; }
/** * Check if a matching rendition is found for any of the provided media formats and other media args. * The first match is returned. * @param media Media * @param asset Asset * @param mediaArgs Media args * @return true if a rendition was found */ private boolean resolveFirstMatchRenditions(Media media, Asset asset, MediaArgs mediaArgs) { Rendition rendition = asset.getRendition(mediaArgs); if (rendition != null) { media.setRenditions(ImmutableList.of(rendition)); media.setUrl(rendition.getUrl()); return true; } return false; }
/** * Iterates over all defined media format and tries to find a matching rendition for each of them * in combination with the other media args. * @param media Media * @param asset Asset * @param mediaArgs Media args * @return true if for *all* media formats a rendition could be found. */ private boolean resolveAllMandatoryRenditions(Media media, Asset asset, MediaArgs mediaArgs) { boolean allResolved = true; List<Rendition> resolvedRenditions = new ArrayList<>(); for (MediaFormat mediaFormat : mediaArgs.getMediaFormats()) { MediaArgs renditionMediaArgs = mediaArgs.clone(); renditionMediaArgs.mediaFormat(mediaFormat); renditionMediaArgs.mediaFormatsMandatory(false); Rendition rendition = asset.getRendition(renditionMediaArgs); if (rendition != null) { resolvedRenditions.add(rendition); } else { allResolved = false; } } media.setRenditions(resolvedRenditions); if (!resolvedRenditions.isEmpty()) { media.setUrl(resolvedRenditions.get(0).getUrl()); } return allResolved; }
/** * Build JSON metadata for one rendition as image source. * @param media Media * @param rendition Rendition * @return JSON metadata */ @SuppressWarnings("null") protected JSONObject toReponsiveImageSource(Media media, Rendition rendition) { try { JSONObject source = new JSONObject(); MediaFormat mediaFormat = rendition.getMediaFormat(); source.put(MediaNameConstants.PROP_BREAKPOINT, mediaFormat.getProperties().get(MediaNameConstants.PROP_BREAKPOINT)); source.put(PROP_SRC, rendition.getUrl()); return source; } catch (JSONException ex) { throw new RuntimeException("Error building JSON source.", ex); } }
url = rendition.getUrl();