
com.day.cq.dam.video.VideoProfile Maven / Gradle / Ivy
/*
* Copyright 1997-2010 Day Management AG
* Barfuesserplatz 6, 4001 Basel, Switzerland
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Day Management AG, ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Day.
*/
package com.day.cq.dam.video;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;
import com.day.cq.dam.commons.util.PrefixRenditionPicker;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import javax.jcr.Node;
import java.awt.Dimension;
/**
* Describes the transcoding of a video file. Utility wrapper around a video
* profile page/resource.
*/
public class VideoProfile {
public static final String PROFILE_BASE_PATH = "/etc/dam/video";
public static final String PROFILE_TYPE_CQ = "dam/components/video/profile";
public static final String PROFILE_TYPE_S7 = "dam/components/video/s7profile";
/**
* Resolves a video profile by name (relative to the video profile base
* path) or absolute path.
*
* @param name can be a name or an absolute path
* @return a video profile wrapper
*/
public static VideoProfile get(ResourceResolver resolver, String name) {
String path;
if (name.startsWith("/")) {
path = name;
} else {
path = PROFILE_BASE_PATH + "/" + name;
}
Resource resource = resolver.getResource(path);
if (resource != null) {
return new VideoProfile(resource);
}
return null;
}
private Resource resource;
public VideoProfile(Resource resource) {
if (JcrConstants.JCR_CONTENT.equals(resource.getName())) {
this.resource = resource.getParent();
} else {
this.resource = resource;
}
}
public String getName() {
return resource.getName();
}
public String getPath() {
return resource.getPath();
}
public Resource getResource() {
return resource;
}
public Resource getContentResource() {
return resource.getResourceResolver().getResource(resource, JcrConstants.JCR_CONTENT);
}
public ValueMap getProperties() {
return ResourceUtil.getValueMap(getContentResource());
}
public Node getContentNode() {
Resource content = getContentResource();
return content == null ? null : content.adaptTo(Node.class);
}
public String getHtmlType() {
return getProperties().get(VideoConstants.PN_HTML_VIDEO_TYPE, "");
}
public Rendition getRendition(Asset asset) {
if (isCQProfile()) {
String prefix = VideoConstants.RENDITION_PREFIX + getName();
return asset.getRendition(new PrefixRenditionPicker(prefix));
} else if (isS7Profile()) {
String prefix = "cq5dam.video.s7." + getPresetHandle();
return asset.getRendition(new PrefixRenditionPicker(prefix));
} else {
return null;
}
}
public Dimension getOutputSize() {
ValueMap props = getProperties();
Integer width = props.get(VideoConstants.PN_VIDEO_WIDTH, Integer.class);
Integer height = props.get(VideoConstants.PN_VIDEO_HEIGHT, Integer.class);
if (width != null && height != null) {
return new Dimension(width, height);
}
return null;
}
/**
* Get the value for the 'src' attribute for the html <source> element, based on the given rendition.
*/
public String getHtmlSource(Rendition rendition) {
String htmlSource = "";
if (rendition != null && isCQProfile()) {
htmlSource = rendition.getPath();
} else if (rendition != null && isS7Profile()) {
htmlSource = getScene7Url(rendition);
}
return htmlSource;
}
public String getStrobeVideoSource(Rendition rendition) {
String source = "";
if (rendition != null && isCQProfile()) {
source = "../../../../.." + rendition.getPath(); // strobe speciality: path must be relative to swf file
} else if (rendition != null && isS7Profile()) {
source = getScene7Url(rendition);
}
return source;
}
public String getFlvVideoSource(Rendition rendition) {
String source = "";
if (rendition != null && isCQProfile()) {
source = rendition.getPath();
} else if (rendition != null && isS7Profile()) {
source = getScene7Url(rendition);
}
return source;
}
public String getCustomVideoSource(Rendition rendition) {
return getFlvVideoSource(rendition);
}
private boolean isS7Profile() {
return getResourceType().equals(PROFILE_TYPE_S7);
}
private boolean isCQProfile() {
return getResourceType().equals(PROFILE_TYPE_CQ);
}
private String getResourceType() {
String resourcType = "";
Resource content = resource.getChild(JcrConstants.JCR_CONTENT);
if (content != null) {
resourcType = content.getResourceType();
}
return resourcType;
}
private String getPresetHandle() {
String presetHandle = getProperties().get(VideoConstants.S7PN_PRESET_PATH, "");
if (StringUtils.isNotBlank(presetHandle)) {
int lastIndex = presetHandle.lastIndexOf("/");
presetHandle = presetHandle.substring(lastIndex + 1, presetHandle.length());
presetHandle = presetHandle.replaceFirst("ps-", "");
}
return presetHandle;
}
private String getScene7Url(Rendition rendition) {
String scene7Url = "";
if (rendition != null) {
scene7Url = rendition.getProperties().get("scene7.url", "");
}
return scene7Url;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy