/** * 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 String getTitle() { // default title is the asset name String title = this.damAsset.getName(); Object titleObj = this.properties.get(DamConstants.DC_TITLE); if (titleObj != null) { // it might happen that the adobe xmp lib creates an array, e.g. if the asset file already has a title attribute if (titleObj instanceof Object[]) { Object[] titleArray = (Object[])titleObj; if (titleArray.length > 0) { title = StringUtils.defaultString(titleArray[0].toString(), title); } } else { title = titleObj.toString(); } } return title; }
/** * 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(); }
/** * Extracts the image name from the DAM resource * * @return image name from DAM */ protected String getImageNameFromDam() { String imageName = ""; Resource damResource = request.getResourceResolver().getResource(fileReference); if (damResource != null) { Asset asset = damResource.adaptTo(Asset.class); imageName = asset != null ? StringUtils.trimToNull(asset.getName()) : ""; } return getSeoFriendlyName(FilenameUtils.getBaseName(imageName)); }
/** * Updates AEM System properties of the Asset. * @param asset the asset to update. */ private void updateSystemProperties(final Asset asset) { Resource resource = asset.adaptTo(Resource.class); Resource jcrContentResource = resource.getChild(JcrConstants.JCR_CONTENT); if (jcrContentResource == null) { log.error("Could not find the jcr:content node for asset [ {} ]", asset.getPath()); return; } final ModifiableValueMap properties = jcrContentResource.adaptTo(ModifiableValueMap.class); properties.put("cq:name", asset.getName()); properties.put("cq:parentPath", StringUtils.removeEnd(asset.getPath(), "/" + asset.getName())); }
@SuppressWarnings({"PMD.CollapsibleIfStatements", "squid:S1066"}) @Override public final void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaData) throws WorkflowException { final WorkflowHelper.AssetResourceResolverPair pair = workflowHelper.getAssetFromPayload(workItem, wfSession); if (pair == null) { String wfPayload = workItem.getWorkflowData().getPayload().toString(); String message = "execute: cannot process audio, asset [{" + wfPayload + "}] in payload doesn't exist for workflow [{" + workItem.getId() + "}]."; throw new WorkflowException(message); } final String assetMimeType = pair.asset.getMimeType(); if ((assetMimeType == null || !assetMimeType.startsWith("audio/"))) { if (!pair.asset.getName().endsWith(".wav") || !pair.asset.getName().endsWith(".mp3") || !pair.asset.getName().endsWith(".ogg")) { log.info("execute: asset [{}] is not of a audio mime type, asset ignored.", pair.asset.getPath()); return; } } try { helper.process(pair.asset, pair.resourceResolver, metaData, this); } catch (AudioException e) { throw new WorkflowException("Unable to transcode audio", e); } finally { pair.resourceResolver.close(); } }
@SuppressWarnings("PMD.CollapsibleIfStatements") public final void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaData) throws WorkflowException { final Asset asset = getAssetFromPayload(workItem, wfSession.getSession()); final ResourceResolver resolver = getResourceResolver(wfSession.getSession()); if (asset == null) { String wfPayload = workItem.getWorkflowData().getPayload().toString(); String message = "execute: cannot process audio, asset [{" + wfPayload + "}] in payload doesn't exist for workflow [{" + workItem.getId() + "}]."; throw new WorkflowException(message); } final String assetMimeType = asset.getMimeType(); if (assetMimeType == null || !assetMimeType.startsWith("audio/")) { if (!asset.getName().endsWith(".wav") || !asset.getName().endsWith(".mp3") || !asset.getName().endsWith(".ogg")) { log.info("execute: asset [{}] is not of a audio mime type, asset ignored.", asset.getPath()); return; } } try { helper.process(asset, resolver, metaData, this); } catch (AudioException e) { throw new WorkflowException("Unable to transcode audio", e); } }
final File tmpFile = new File(tmpDir, asset.getName().replace(' ', '_')); fos = new FileOutputStream(tmpFile); is = asset.getOriginal().getStream();
final File tmpFile = new File(tmpDir, asset.getName().replace(' ', '_'));
renditionName = asset.getName();
void saveMigrationInfo(final Source source, final Asset asset) { Resource assetResource = asset.adaptTo(Resource.class); if (assetResource != null) { assetResource = assetResource.getChild(JcrConstants.JCR_CONTENT); } if (assetResource != null) { ValueMap assetProperties = assetResource.adaptTo(ModifiableValueMap.class); if (assetProperties != null) { if (!StringUtils.equals(asset.getName(), source.getName())) { assetProperties.put(JcrConstants.JCR_TITLE, source.getName()); } assetProperties.put(PN_MIGRATED_FROM, source.getElement().getItemName()); } } }
versioned = asset != null; assetManager.createRevision(asset, "initial version of asset", asset.getName()); r.commit(); r.refresh();