一旦用户在 cq 对话框中提供文件路径,我需要获取父文件夹名称(字符串类型)。这是我的方法:
import lombok.Getter;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.*;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@Getter
@Model(adaptables = {
Resource.class,
SlingHttpServletRequest.class
},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class Test {
@SlingObject
private Resource resource;
@OSGiService
private ResourceResolver resourceResolver;
@ValueMapValue
private String fileUrl;
@PostConstruct
public String getData() {
Resource resource = resourceResolver.getResource(fileUrl);
Resource parentProps = resource.getParent();
System.out.println("parent node is =>" + parentProps);
}
}
有问题吗?我的代码正确构建但不返回任何内容