本文整理汇总了Java中org.apache.sling.api.resource.Resource.getResourceResolver方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getResourceResolver方法的具体用法?Java Resource.getResourceResolver怎么用?Java Resource.getResourceResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.resource.Resource
的用法示例。
在下文中一共展示了Resource.getResourceResolver方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
if (resource != null) {
ResourceResolver resourceResolver = resource.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
String pathRefListContentKeyName = getPathRefListKeyName(resource);
if (contentModel.has(pathRefListContentKeyName)) {
String pathRef = contentModel.getAsString(pathRefListContentKeyName);
Collection<Map<String, Object>> pathList = new ArrayList<>();
if (pathRef != null) {
Page page = pageManager.getContainingPage(pathRef);
int depth = LIST_DEFAULT_DEPTH;
String depthListContentKeyName = getDepthKeyName(resource);
if (contentModel.has(depthListContentKeyName)) {
depth = Integer.parseInt(contentModel.getAsString(depthListContentKeyName));
}
if (null != page) {
String currentPage = contentModel.getAsString(PAGE + DOT + PATH);
boolean removeCurrentPage = false;
if (contentModel.has(REMOVE_CURRENT_PAGE_PATH_CONFIG_KEY) &&
contentModel.getAsString(REMOVE_CURRENT_PAGE_PATH_CONFIG_KEY).equals(TRUE)){
removeCurrentPage = true;
}
pathList = extractPathList(page, depth, currentPage, removeCurrentPage);
}
}
contentModel.set(LIST_PROPERTIES_KEY + DOT + PAGEREFS_CONTENT_KEY_NAME, pathList);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例2: findContainingComponent
import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
/**
* Takes resource and returns component
*
* @param resource The resource to fetch the component from
* @return null or component
*/
public static Component findContainingComponent(final Resource resource) {
ResourceResolver resourceResolver = resource.getResourceResolver();
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
Resource componentResource = findParentAs(resource, NT_COMPONENT);
if (componentResource != null) {
String componentPath = componentResource.getPath();
if (StringUtils.isNotBlank(componentPath)) {
return componentManager.getComponent(componentPath);
}
}
return null;
}
示例3: getDamAssetResource
import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
/**
* Looks for a fileReference property on the resource sent as argument and returns the DAM resource referenced.
* @param resource a resource with a fileReference property.
* @return the DAM asset resource referenced or null if the path stored in fileReference is invalid or the
* fileReference property doesn't exist.
*/
public static Resource getDamAssetResource(Resource resource) {
Resource damAssetResource = null;
if(null != resource) {
ResourceResolver resourceResolver = resource.getResourceResolver();
String fileReference = ResourceUtils.getPropertyAsString(resource, FILE_REFERENCE);
if(StringUtils.isNotEmpty(fileReference)) {
damAssetResource = resourceResolver.getResource(fileReference);
}
}
return damAssetResource;
}
示例4: constructCategories
import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
private void constructCategories(Resource pageContentResource) throws IOException {
categories = Lists.newArrayList();
final ResourceResolver resourceResolver = pageContentResource.getResourceResolver();
final Resource patternsPathResource = resourceResolver.getResource(patternsPath);
final Iterator<Resource> appsIterator = patternsPathResource.listChildren();
while (appsIterator.hasNext()) {
final PatternCategoryModel category = patternCategoryFactory.createCategory(appsIterator.next(), patternsPath, patternId);
if (category != null && category.isValid()) {
categories.add(category);
}
}
}
示例5: JcrQueryIterator
import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
public JcrQueryIterator(List<SelectorSegment> segments, Resource root, JcrTypeResolver typeResolver) {
JcrQueryBuilder builder = new JcrQueryBuilder(typeResolver);
query = builder.buildQuery(segments, root.getPath());
resolver = root.getResourceResolver();
}
示例6: findContainingPage
import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
/**
* Takes resource and returns page
*
* @param resource The resource to adapt into page
* @return page
*/
public static Page findContainingPage(final Resource resource) {
ResourceResolver resourceResolver = resource.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
return pageManager.getContainingPage(resource);
}