我需要在使用touchUI字段
时限制文件类型花岗岩/ UI /组件/基础/形式/ pathbrowser。
路径域有一个功能,
正则表达式:/。(png | jpg | jpeg)$ /, regexText:"请选择正确的文件"
不适用于pathBrowser,TouchUI字段。
有什么建议吗?
答案 0 :(得分:0)
以下是一个可能适合您的示例:
答案 1 :(得分:0)
我在OSGI bundle package上创建了一个谓词类,它限制了文件类型。 java类,
package com.mec.core.utils;
import com.day.cq.commons.predicate.AbstractResourcePredicate;
import org.apache.commons.collections.Predicate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
@Component(label = "Dam Image Predicate",
description = "This predicate is used to display only JPG and PNG files in the pathfield")
@Service(value = Predicate.class)
@Properties({@Property(label = "Predicate Name", name = "predicate.name", value = "damimagepredicate",
propertyPrivate = true)})
public class DamImagePredicate extends AbstractResourcePredicate {
private static final String REP_ACL = "rep:ACL";
private static final String JCR_CONTENT = "jcr:content";
private static final String JCR_PRIMARYTYPE = "jcr:primaryType";
private static final String DAM_ASSET = "dam:Asset";
private static final String PNG = ".png";
private static final String JPG = ".jpg";
private static final String JPEG = ".jpeg";
@Override
public boolean evaluate(Resource resource) {
if(null!= resource){
ValueMap valueMap = resource.getValueMap();
String primaryType = valueMap.get(JCR_PRIMARYTYPE,String.class);
if(null!=primaryType && !primaryType.isEmpty()){
if(primaryType.equalsIgnoreCase(REP_ACL)){
return false;
}
if(resource.getName().equalsIgnoreCase(JCR_CONTENT)){
return false;
}
if(primaryType.equalsIgnoreCase(DAM_ASSET)){
String resourceName = resource.getName();
if(null!=resourceName && !resourceName.isEmpty()){
if(resourceName.lastIndexOf(".")>-1){
String extension = resourceName.substring(resourceName.lastIndexOf("."), resourceName.length());
if(null!=extension && !extension.isEmpty()){
if(extension.equalsIgnoreCase(PNG) || extension.equalsIgnoreCase(JPG) || extension.equalsIgnoreCase(JPEG)){
return true;
}else{
return false;
}
}
}
}
}
}
}
return true;
}
}