当前位置: 首页>>代码示例>>Java>>正文


Java ResourceResolver.adaptTo方法代码示例

本文整理汇总了Java中org.apache.sling.api.resource.ResourceResolver.adaptTo方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceResolver.adaptTo方法的具体用法?Java ResourceResolver.adaptTo怎么用?Java ResourceResolver.adaptTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sling.api.resource.ResourceResolver的用法示例。


在下文中一共展示了ResourceResolver.adaptTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public IndexEntry create(String path, @Nonnull ResourceResolver resolver) {
  String[] indexRules = getIndexRules(PRIMARY_TYPE_VALUE);
  if (ArrayUtils.isNotEmpty(indexRules)) {
    PageManager pageManager = resolver.adaptTo(PageManager.class);
    if (pageManager != null) {
      Page page = pageManager.getPage(path);
      if (page != null) {
        IndexEntry ret = new IndexEntry("idx", "page", path);
        Resource res = page.getContentResource();
        if (res != null) {
          ret.addContent(getProperties(res, indexRules));
        }
        return ret;
      }
    }
  }
  else {
    LOG.warn("Could not load indexRules for " + PRIMARY_TYPE_VALUE);
  }
  return null;
}
 
开发者ID:deveth0,项目名称:elasticsearch-aem,代码行数:23,代码来源:PageContentBuilder.java

示例2: hasConfig

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Check if the given resource type has configuration
 *
 * @param resourceType The resource type to check if it has any configuration node
 * @return true if exists; else false
 * @throws Exception
 */
@Override
public boolean hasConfig(String resourceType)
        throws Exception {
    boolean hasConfigNode = false;
    ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(RESOURCE_RESOLVER_PARAMS);

    ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
    com.day.cq.wcm.api.components.Component component = componentManager.getComponent(resourceType);

    if (component != null) {
        Resource configResource = component.getLocalResource(XK_CONFIG_RESOURCE_NAME);
        if (configResource != null) {
            hasConfigNode = true;
        }
    }
    resourceResolver.close();

    return hasConfigNode;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:27,代码来源:AEMConfigurationProviderImpl.java

示例3: process

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
        throws ProcessException {
    try {
        SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
        Resource resource = request.getResource();
        ResourceResolver resourceResolver = request.getResourceResolver();

        final Designer designer = resourceResolver.adaptTo(Designer.class);
        Style style = designer.getStyle(resource);

        if (style.getPath() != null) {
            Resource designResource = resourceResolver.getResource(style.getPath());
            Map<String, Object> designMap = (designResource != null) ? PropertyUtils.propsToMap(designResource) : new HashMap<String, Object>();
            contentModel.set(DESIGN_PROPERTIES_KEY, designMap);
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:21,代码来源:AddDesignPropertiesContextProcessor.java

示例4: process

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
        throws ProcessException {
    try {
        SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
        ResourceResolver resourceResolver = request.getResourceResolver();
        PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
        if (contentModel.has(LIST_PROPERTIES_KEY + DOT + PAGEREFS_CONTENT_KEY_NAME)) {
            Collection<Map<String,Object>> pathList = contentModel.getAs(LIST_PROPERTIES_KEY + DOT + PAGEREFS_CONTENT_KEY_NAME, Collection.class);
            List<Map<String, Object>> allPageDetailList = new ArrayList<>();
            String currentPage = GeneralRequestObjects.getCurrentPage(request).getPath();
            for (Map<String,Object> pathInfo: pathList) {
                allPageDetailList.add(extractPageDetails(pathInfo, pageManager, request.getResource(), currentPage));
            }
            contentModel.set(PAGE_DETAILS_LIST_CONTEXT_PROPERTY_NAME, allPageDetailList);
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:21,代码来源:AddPageDetailsContextProcessor.java

示例5: getSettingsDialogs

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
private List<Resource> getSettingsDialogs(ResourceResolver resourceResolver) {
    List<Resource> actionTypeSettingsResources = new ArrayList<>();
    FormsManager formsManager = resourceResolver.adaptTo(FormsManager.class);
    if (formsManager != null) {
        Iterator<FormsManager.ComponentDescription> actions = formsManager.getActions();
        while (actions.hasNext()) {
            FormsManager.ComponentDescription componentDescription = actions.next();
            Resource dialogResource = resourceResolver.getResource(componentDescription.getResourceType() + "/" +
                    FormConstants.NN_DIALOG);
            if (dialogResource != null) {
                actionTypeSettingsResources.add(dialogResource);
            }
        }
    }
    return actionTypeSettingsResources;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:17,代码来源:FormActionTypeSettingsDataSourceServlet.java

示例6: getAllowedTypes

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
private List<Resource> getAllowedTypes(@Nonnull SlingHttpServletRequest request) {
    List<Resource> allowedTypes = new ArrayList<>();
    ResourceResolver resolver = request.getResourceResolver();
    Resource contentResource = resolver.getResource((String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE));
    ContentPolicyManager policyMgr = resolver.adaptTo(ContentPolicyManager.class);
    if (policyMgr != null) {
        ContentPolicy policy = policyMgr.getPolicy(contentResource);
        if (policy != null) {
            ValueMap props = policy.getProperties();
            if (props != null) {
                String[] titleTypes = props.get("allowedTypes", String[].class);
                if (titleTypes != null && titleTypes.length > 0) {
                    for (String titleType : titleTypes) {
                        allowedTypes.add(new TitleTypeResource(titleType, resolver));
                    }
                }
            }
        }
    }
    return allowedTypes;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:22,代码来源:AllowedTitleSizesDataSourceServlet.java

示例7: findTag

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
public Tag findTag(String tagId, Asset asset, Session session) {
	Tag tag = null;
	ResourceResolver resourceResolver = null;

	try {
		resourceResolver = getResourceResolver(session);
		TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
		tag = tagManager.resolve(tagId);
	} finally {
		if (null != resourceResolver && resourceResolver.isLive()) {
			resourceResolver.close();
		}
	}

	return tag;
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:17,代码来源:ResourceResolverConsumer.java

示例8: SimilarProductsCollector

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
SimilarProductsCollector(ResourceResolver resolver, CommerceSession session, String relationshipType, String relationshipTitle,
                         List<Product> contextProducts) {
    this.resolver = resolver;
    this.pageManager = resolver.adaptTo(PageManager.class);
    this.commerceSession = session;

    this.relationshipType = relationshipType;
    this.relationshipTitle = relationshipTitle;

    matchTagSets = new ArrayList<List<String>>();
    exclusionSKUs = new ArrayList<String>();
    for (Product product : contextProducts) {
        List<String> matchTags = new ArrayList<String>();
        Collections.addAll(matchTags, product.getProperty("cq:tags", String[].class));
        matchTagSets.add(matchTags);

        try {
            exclusionSKUs.add(product.getBaseProduct().getSKU());
        } catch (CommerceException e) {
            exclusionSKUs.add(product.getSKU());    // not perfect, but better than nothing
        }
    }

    this.relationships = new HashMap<String, ProductRelationship>();
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:26,代码来源:SimilarProductsCollector.java

示例9: markAsSpam

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Mark comment as spam, submit it to Akismet and delete it by setting
 * it's display property to false.
 *
 * @param request The current request to get session and Resource Resolver
 * @param id The comment UUID
 * @return true if the operation was successful
 */
public boolean markAsSpam(final SlingHttpServletRequest request, final String id) {
    boolean result = false;

    try {
        final ResourceResolver resolver = request.getResourceResolver();
        final Session session = resolver.adaptTo(Session.class);
        final Node node = session.getNodeByIdentifier(id);

        if (node != null) {
            final Resource resource = resolver.getResource(node.getPath());
            result = akismetService.submitSpam(resource);
        }
    } catch (RepositoryException e) {
        LOGGER.error("Could not submit spam.", e);
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:27,代码来源:CommentServiceImpl.java

示例10: markAsHam

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Mark comment as ham, submit it to Akismet and mark it valid it by setting
 * it's display property to true.
 *
 * @param request The current request to get session and Resource Resolver
 * @param id The comment UUID
 * @return true if the operation was successful
 */
public boolean markAsHam(final SlingHttpServletRequest request, final String id) {
    boolean result = false;

    try {
        final ResourceResolver resolver = request.getResourceResolver();
        final Session session = resolver.adaptTo(Session.class);
        final Node node = session.getNodeByIdentifier(id);

        if (node != null) {
            final Resource resource = resolver.getResource(node.getPath());
            result = akismetService.submitHam(resource);
        }
    } catch (RepositoryException e) {
        LOGGER.error("Could not submit ham.", e);
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:27,代码来源:CommentServiceImpl.java

示例11: getTaskManager

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Sample helper method that shows the 2 main ways to get
 *
 * @param resourceResolver the security context the TaskManager will operate under
 * @param path             the path where new Tasks will be created; if null the default Task location will be used (/etc/taskmanagement/tasks)
 * @return a TaskManager
 */
private TaskManager getTaskManager(ResourceResolver resourceResolver, String path) {
    Resource tasksResource = resourceResolver.getResource(path);

    if (tasksResource != null) {
        // TaskManagers adapted from a Resource, will store their directs directly below this resource.
        // The most common use case is creating tasks under a project @ `<path-to-project>/jcr:content/tasks`
        return tasksResource.adaptTo(TaskManager.class);
    }

    // TaskManagers adapted from the ResourceResolver will store its tasks under /etc/taskmanagement/tasks
    // /etc/taskmanagement/tasks is OSGi configurable via com.adobe.granite.taskmanagement.impl.jcr.TaskStorageProvider along w the default archived tasks location (/etc/taskmanagement/archivedtasks)
    // These are non-project related tasks.

    // Note that a JCR Session may be used to adapt to a TaskManager as well to the same effect as the ResourceResolver method.
    return resourceResolver.adaptTo(TaskManager.class);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:24,代码来源:SampleTaskManagementImpl.java

示例12: process

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的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);
    }
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:39,代码来源:AddTraversedPageReferencesContextProcessor.java

示例13: ConfigurationImpl

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
private ConfigurationImpl(String resourceType)
        throws Exception {
    ResourceResolver resourceResolver =
            resourceResolverFactory.getServiceResourceResolver(RESOURCE_RESOLVER_PARAMS);
    ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
    loadConfigHierarchy(componentManager, resourceType);
    resourceResolver.close();
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:9,代码来源:AEMConfigurationProviderImpl.java

示例14: getGlobalPropertiesPath

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Takes resource and resource resolver return the global property path from the resource
 *
 * @param resource The resource to get the global property path from
 * @return globalPropertiesPath
 */
public static String getGlobalPropertiesPath(Resource resource, ResourceResolver resourceResolver)
        throws RepositoryException, PersistenceException {
    String globalPropertiesPath = "";
    Designer designer = resourceResolver.adaptTo(Designer.class);
    Style style = designer.getStyle(resource);
    Design design;
    if (null != style) {
        design = style.getDesign();
        if (null != design) {
            if (null != design.getContentResource()) {
                if (null != design.getContentResource().getPath()) {
                    //add global node in design when it does not exist
                    Resource designResource = resourceResolver.getResource(design.getContentResource().getPath());
                    Node designNode = designResource.adaptTo(Node.class);
                    if (!designNode.hasNode(GLOBAL_PROPERTIES_KEY)) {
                        designNode.addNode(GLOBAL_PROPERTIES_KEY);
                        resourceResolver.commit();
                    }
                    // set global path
                    globalPropertiesPath = design.getContentResource().getPath() + GLOBAL_PATH;
                }
            }
        }
    }
    return globalPropertiesPath;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:33,代码来源:ResourceUtils.java

示例15: findContainingComponent

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的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;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:19,代码来源:ResourceUtils.java


注:本文中的org.apache.sling.api.resource.ResourceResolver.adaptTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。