suppose i am dropping video component on page. while authoring that component i am choosing video path from dam as pathfield but it is supporting all extensions file type .i have to restrict it should support only .mp4 or mov file type. how to do that thing in AEM. As i am new to AEM please help me on this.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @prachiat ,
To restrict a pathfield in an AEM dialog to accept only .mp4 or .mov file extensions from DAM, you can use a custom validator. Here's how you can achieve this:
Open the dialog XML file for your video component. This file is typically located in the /apps folder of your AEM project.
Locate the pathfield element in the dialog XML file that represents the video path selection.
Add a validator property to the pathfield element and set it to the path of your custom validator. For example:
<pathfield
jcr:primaryType="nt:unstructured"
fieldLabel="Video Path"
name="./videoPath"
validator="myproject.validators.VideoPathValidator"
/>
Create a new Java class for your custom validator. In this example, the class is named VideoPathValidator. This class should implement the Validator interface and override the validate method. Here's an example implementation:
package myproject.validators;
import com.adobe.granite.ui.components.Value;
import com.adobe.granite.ui.components.Validator;
import org.apache.commons.lang3.StringUtils;
public class VideoPathValidator implements Validator {
private static final String[] ALLOWED_EXTENSIONS = {".mp4", ".mov"};
@Override
public String validate(Value value) {
String path = value.getString();
if (StringUtils.isNotBlank(path)) {
String extension = StringUtils.substringAfterLast(path, ".");
if (!isValidExtension(extension)) {
return "Invalid file extension. Only .mp4 and .mov files are allowed.";
}
}
return null;
}
private boolean isValidExtension(String extension) {
for (String allowedExtension : ALLOWED_EXTENSIONS) {
if (allowedExtension.equalsIgnoreCase(extension)) {
return true;
}
}
return false;
}
}
In this example, the validate method checks if the selected file path has a valid extension. If the extension is not .mp4 or .mov, it returns an error message.
Build and deploy your project to see the changes take effect.
With this implementation, the pathfield in your AEM dialog will only accept .mp4 or .mov file extensions from DAM. If any other file extension is selected, an error message will be displayed.
Views
Replies
Total Likes
Hi @prachiat ,
To restrict a pathfield in an AEM dialog to accept only .mp4 or .mov file extensions from DAM, you can use a custom validator. Here's how you can achieve this:
Open the dialog XML file for your video component. This file is typically located in the /apps folder of your AEM project.
Locate the pathfield element in the dialog XML file that represents the video path selection.
Add a validator property to the pathfield element and set it to the path of your custom validator. For example:
<pathfield
jcr:primaryType="nt:unstructured"
fieldLabel="Video Path"
name="./videoPath"
validator="myproject.validators.VideoPathValidator"
/>
Create a new Java class for your custom validator. In this example, the class is named VideoPathValidator. This class should implement the Validator interface and override the validate method. Here's an example implementation:
package myproject.validators;
import com.adobe.granite.ui.components.Value;
import com.adobe.granite.ui.components.Validator;
import org.apache.commons.lang3.StringUtils;
public class VideoPathValidator implements Validator {
private static final String[] ALLOWED_EXTENSIONS = {".mp4", ".mov"};
@Override
public String validate(Value value) {
String path = value.getString();
if (StringUtils.isNotBlank(path)) {
String extension = StringUtils.substringAfterLast(path, ".");
if (!isValidExtension(extension)) {
return "Invalid file extension. Only .mp4 and .mov files are allowed.";
}
}
return null;
}
private boolean isValidExtension(String extension) {
for (String allowedExtension : ALLOWED_EXTENSIONS) {
if (allowedExtension.equalsIgnoreCase(extension)) {
return true;
}
}
return false;
}
}
In this example, the validate method checks if the selected file path has a valid extension. If the extension is not .mp4 or .mov, it returns an error message.
Build and deploy your project to see the changes take effect.
With this implementation, the pathfield in your AEM dialog will only accept .mp4 or .mov file extensions from DAM. If any other file extension is selected, an error message will be displayed.
Views
Replies
Total Likes
@prachiat Did you find the suggestions from users helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies