本文整理汇总了Java中org.apache.sling.api.resource.ResourceResolver.create方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceResolver.create方法的具体用法?Java ResourceResolver.create怎么用?Java ResourceResolver.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.resource.ResourceResolver
的用法示例。
在下文中一共展示了ResourceResolver.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreate
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
private Resource getOrCreate(String path, Map<String, Object> properties) throws PersistenceException, RepositoryException {
ResourceResolver resolver = client.getResourceResolver();
Resource resource = resolver.getResource(path);
if (properties.containsKey("unit:vanityTarget")) {
resource = resolver.resolve((String) properties.get("unit:vanityTarget"));
} else {
Resource parent = resolver.getResource("/");
PathIterator it = new PathIterator(path);
it.first();
while (it.hasNext()) {
String curPath = it.next();
String segment = StringUtils.substringAfterLast(curPath, "/");
resource = resolver.getResource(curPath);
if (resource == null) {
if (it.hasNext()) {
resource = resolver.create(parent, segment, new HashMap<>());
} else {
resource = resolver.create(parent, segment, properties);
}
}
parent = resource;
}
}
return resource;
}
示例2: copy
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
private Resource copy(ResourceResolver resolver, String sourcePath, Resource destParent)
throws PersistenceException {
Resource source = resolver.getResource(sourcePath);
Map<String, Object> properties = Maps.newHashMap(source.getValueMap());
properties.remove(JcrConstants.JCR_UUID);
Resource dest = resolver.create(destParent, source.getName(), properties);
if (source.getChild(JcrConstants.JCR_CONTENT) != null) {
copy(resolver, sourcePath + "/" + JcrConstants.JCR_CONTENT, dest);
}
return dest;
}