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


Java ResourceResolver.getResource方法代码示例

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


在下文中一共展示了ResourceResolver.getResource方法的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)) {
  Resource res = resolver.getResource(path);
  if (res != null) {
    Asset asset = res.adaptTo(Asset.class);
    if (asset != null) {
      IndexEntry ret = new IndexEntry("idx", "asset", path);
      ret.addContent(getProperties(res, indexRules));
      return ret;
    }
    LOG.error("Could not adapt asset");
    }
  }
  return null;
}
 
开发者ID:deveth0,项目名称:elasticsearch-aem,代码行数:18,代码来源:DAMAssetContentBuilder.java

示例2: 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

示例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();
        log.debug("for {}", resource.getPath());
        if (resource != null) {
            ResourceResolver resourceResolver = request.getResourceResolver();
            String globalPropertiesPath = ResourceUtils.getGlobalPropertiesPath(resource, resourceResolver);

            if (globalPropertiesPath != null) {
                Resource globalPropertiesResource = resourceResolver.getResource(globalPropertiesPath);
                Map<String, Object> globalProperties = (globalPropertiesResource != null) ? PropertyUtils.propsToMap(globalPropertiesResource) : new HashMap<String, Object>();
                contentModel.set(GLOBAL_PROPERTIES_KEY, globalProperties);
            }
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }

}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:23,代码来源:AddGlobalPropertiesContextProcessor.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();
        Style style = GeneralRequestObjects.getCurrentStyle(request);
        if (style != null) {
            Resource designResource = resourceResolver.getResource(style.getPath()); //get design resource
            if (designResource != null) {
                String imagePath = assetPathService.getComponentImagePath(designResource);
                contentModel.set(DESIGN_PROPERTIES_KEY + DOT + IMAGE_PATH, imagePath);
            }
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:19,代码来源:AddTransformedImagePathFromDesignContextProcessor.java

示例5: 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;
}
 
开发者ID:quatico-solutions,项目名称:aem-testing,代码行数:26,代码来源:Resources.java

示例6: find

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public Script find(String path, boolean skipIgnored, ResourceResolver resolver) {
	Script result = null;
	if (StringUtils.isNotEmpty(path) && (!skipIgnored || isNotIgnoredPath(path))) {
		Resource resource = null;
		if (path.contains(ROOT_PATH)) {
			resource = resolver.getResource(path);
		}
		if (resource == null) {
			path = path.startsWith("/") ? path.substring(1) : path;
			for (String searchPath : getSearchPaths()) {
				resource = resolver.getResource(searchPath + "/" + path);
				if (resource != null) {
					break;
				}
			}
		}
		if (resource != null) {
			result = resource.adaptTo(ScriptImpl.class);
		}
	}
	return result;
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:24,代码来源:ScriptFinderImpl.java

示例7: 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

示例8: 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

示例9: activate

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void activate() throws Exception {
    Resource resource = getResource();
    ValueMap properties = getProperties();
    ResourceResolver resolver = getResourceResolver();
    buttonLinkTo = properties.get(PROP_BUTTON_LINK_TO, "");
    buttonLabel = properties.get(PROP_BUTTON_LABEL, "");
    if (StringUtils.isNotEmpty(buttonLinkTo)) {
        // if button label is not set, try to get it from target page's title
        if (StringUtils.isEmpty(buttonLabel)) {
            Resource linkResource = resolver.getResource(buttonLinkTo);
            if (linkResource != null) {
                Page targetPage = linkResource.adaptTo(Page.class);
                if (targetPage != null) {
                    buttonLabel = targetPage.getTitle();
                }
            }
        }
        buttonLinkTo = buttonLinkTo + ".html";
    }
    log.debug("resource: {}", resource.getPath());
    log.debug("buttonLinkTo: {}", buttonLinkTo);
    log.debug("buttonLabel: {}", buttonLabel);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:25,代码来源:CategoryTeaser.java

示例10: 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

示例11: 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

示例12: getParentPost

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Get the blog post associated with the given comment.
 *
 * There are only two levels of comments. You can reply to a post
 * and you can reply to a top level comment.
 *
 * @param comment The current comment
 * @return the number of replies to the given comment
 */
public Resource getParentPost(final Resource comment) {
    final ResourceResolver resolver = comment.getResourceResolver();
    Resource parent = comment.getParent();

    // Try one level up
    Resource post = resolver.getResource(parent.getPath().replace("/comments/", "/blog/"));

    if (post == null) {
        //try two levels up
        parent = parent.getParent();
        post = resolver.getResource(parent.getPath().replace("/comments/", "/blog/"));
    }

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

示例13: getBlog

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
 * Get the blog post properties if resource already exists otherwise
 * set the month and year properties to the current date.
 *
 * @param path The resource path to the blog post.
 */
private void getBlog(String path) {
    ResourceResolver resolver = resource.getResourceResolver();
    Resource blog = resolver.getResource(path);

    if (blog != null) {
        ValueMap properties = blog.adaptTo(ValueMap.class);
        title = properties.get("title", String.class);
        month = properties.get("month", Long.class);
        year = properties.get("year", Long.class);
        url = properties.get("url", String.class);
        visible = Boolean.valueOf(properties.get("visible", false));
        keywords = properties.get("keywords", String[].class);
        image = properties.get("image", String.class);
        content = properties.get("content", String.class);
        description = properties.get("description", String.class);
        url = blog.getName();
    } else {
        /* Populate dropdowns with current date if creating new blog. */
        month = ((long)Calendar.getInstance().get(Calendar.MONTH)) + 1;
        year = (long)Calendar.getInstance().get(Calendar.YEAR);
    }
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:29,代码来源:BlogEdit.java

示例14: 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

示例15: getGlobalDialogPath

import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
private String getGlobalDialogPath(Resource resource, ResourceResolver resourceResolver, SlingHttpServletRequest request) {
    String currentGlobalDialogPath = GLOBAL_DIALOG_PATH;
    if (AuthoringUIMode.fromRequest(request) == AuthoringUIMode.TOUCH) {
        currentGlobalDialogPath = GLOBAL_DIALOG_PATH_TOUCH;
    }
    String globalDialogPath = APPS_ROOT + "/" + ResourceUtils.getAppName(resource) + currentGlobalDialogPath;
    if (null == resourceResolver.getResource(globalDialogPath)) {
        globalDialogPath = BLANK;
    }
    return globalDialogPath;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:12,代码来源:AddComponentPropertiesContextProcessor.java


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