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


Java ResourceResolver类代码示例

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


ResourceResolver类属于org.apache.sling.api.resource包,在下文中一共展示了ResourceResolver类的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: 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

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

示例4: operate

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
/**
 * Do some operation on repository (delete or update resource etc) with wrapped impersonated session
 * (automatically opened and closed).
 */
public static void operate(ResourceResolverFactory factory, String userId, OperateCallback callback)
		throws OperateException {
	ResourceResolver resolver = null;
	try {
		resolver = getResourceResolverForUser(factory, userId);
		callback.operate(resolver);
		resolver.commit();
	} catch (Exception e) {
		throw new OperateException(OPERATE_ERROR_MESSAGE, e);
	} finally {
		if (resolver != null && resolver.isLive()) {
			resolver.close();
		}
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:20,代码来源:SlingHelper.java

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

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

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

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

示例9: PatternModel

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
public PatternModel(Resource resource, String patternsPath, String patternId, String jsonDataFile, String templateName, ResourceResolver resourceResolver) throws IOException {
    this.id = PatternLabUtils.constructPatternId(resource.getPath(), patternsPath, templateName, jsonDataFile);
    this.name = StringUtils.lowerCase(StringUtils.isBlank(jsonDataFile) ? templateName : jsonDataFile);
    this.template = templateName;
    this.path = resource.getPath();
    this.dataPath = StringUtils.isNotBlank(jsonDataFile) ? resource.getParent().getPath() + PatternLabConstants.SLASH + jsonDataFile : StringUtils.EMPTY;
    this.displayed = StringUtils.isBlank(patternId) || StringUtils.startsWith(getId(), patternId);
    this.breadcrumb = Lists.newArrayList(new BreadcrumbItemModel(PatternLabUtils.constructPatternId(resource.getPath(), patternsPath), PatternLabUtils.getResourceTitleOrName(resource)));
    if (StringUtils.isNotBlank(jsonDataFile)) {
        this.breadcrumb.add(new BreadcrumbItemModel(PatternLabUtils.constructPatternId(resource.getPath(), patternsPath, templateName), templateName));
    }
    this.breadcrumb.add(new BreadcrumbItemModel(id, name));
    this.code = PatternLabUtils.getDataFromFile(path, resourceResolver);
    this.data = PatternLabUtils.getDataFromFile(dataPath, resourceResolver);
    this.description = constructDescription(jsonDataFile, templateName, resourceResolver);
    this.embeddedPatterns = Sets.newHashSet();
    this.includingPatterns = Sets.newHashSet();
}
 
开发者ID:deepthinkit,项目名称:patternlab-for-sling,代码行数:19,代码来源:PatternModel.java

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

示例11: runScript

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
protected void runScript(ResourceResolver resourceResolver, Session session, OnDeployScript script) {
    String statusNodePath = "/var/on-deploy-scripts-status/" + script.getClass().getName();
    Node statusNode = getOrCreateStatusTrackingNode(session, statusNodePath);
    String status = getScriptStatus(resourceResolver, statusNode, statusNodePath);
    if (status == null || status.equals("fail")) {
        trackScriptStart(session, statusNode, statusNodePath);
        try {
            script.execute(resourceResolver, queryBuilder);
            logger.info("On-deploy script completed successfully: {}", statusNodePath);
            trackScriptEnd(session, statusNode, statusNodePath, "success");
        } catch (Exception e) {
            logger.error("On-deploy script failed: {}", statusNodePath, e);
            trackScriptEnd(session, statusNode, statusNodePath, "fail");
        }
    } else if (!status.equals("success")) {
        logger.warn("Skipping on-deploy script as it may already be in progress: {} - status: {}", statusNodePath, status);
    } else {
        logger.debug("Skipping on-deploy script, as it is already complete: {}", statusNodePath);
    }
}
 
开发者ID:HS2-SOLUTIONS,项目名称:hs2-aem-commons,代码行数:21,代码来源:OnDeployExecutorImpl.java

示例12: testHelloWorldModelServerSide

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
@Test
public void testHelloWorldModelServerSide() throws Exception {
    
    assertNotNull("Expecting the ResourceResolverFactory to be injected by Sling test runner", rrf);
    assertNotNull("Expecting the SlingSettingsService to be injected by Sling test runner", settings);
    
    new AdminResolverCallable() {
        @Override
        protected void call0(ResourceResolver rr) throws Exception {
            Resource testResource = rr.getResource("/tmp/testResource");
            
            HelloWorldModel hello = testResource.adaptTo(HelloWorldModel.class);
            
            assertNotNull("Expecting HelloWorldModel to be adapted from Resource", hello);

            assertTrue("Expecting the HelloWorldModel to return the slingId as part of the message", 
                    hello.getMessage().contains(settings.getSlingId()));
        }
    }.call();        
}
 
开发者ID:auniverseaway,项目名称:aem-touch-admin-console,代码行数:21,代码来源:HelloWorldModelServerSideTest.java

示例13: call

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
@Override
public Void call() throws Exception {
    
    if ( rrf == null ) {
        throw new IllegalStateException("ResourceResolverFactory not injected");
    }
    
    @SuppressWarnings("deprecation") // fine for testing
    ResourceResolver rr = rrf.getAdministrativeResourceResolver(null);
    try {
        call0(rr);
        rr.commit();
    } finally {
        if ( rr != null ) {
            rr.close();
        }
    }               
    return null;
}
 
开发者ID:auniverseaway,项目名称:aem-touch-admin-console,代码行数:20,代码来源:HelloWorldModelServerSideTest.java

示例14: removeSingleFile

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
private void removeSingleFile(ResourceResolver resolver, SlingHttpServletResponse response,
		String fileName) throws IOException {
	if (StringUtils.isEmpty(fileName)) {
		ServletUtils.writeMessage(response, "error", "File name to be removed cannot be empty");
	} else {
		final Script script = scriptFinder.find(fileName, resolver);
		if (script == null) {
			ServletUtils
					.writeMessage(response, "error", String.format("Script not found: '%s'", fileName));
		} else {
			final String scriptPath = script.getPath();

			try {
				scriptStorage.remove(script, resolver);

				ServletUtils.writeMessage(response, "success",
						String.format("Script removed successfully: %s", scriptPath));
			} catch (RepositoryException e) {
				response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
				ServletUtils.writeJson(response,
						String.format("Cannot remove script: '%s'." + " Repository error: %s", scriptPath,
								e.getMessage()));
			}
		}
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:27,代码来源:ScriptRemoveServlet.java

示例15: resolve

import org.apache.sling.api.resource.ResourceResolver; //导入依赖的package包/类
/**
 * Retrieve values from repository with wrapped impersonated session (automatically opened and closed).
 */
@SuppressWarnings("unchecked")
public static <T> T resolve(ResourceResolverFactory factory, String userId, ResolveCallback callback)
		throws ResolveException {
	ResourceResolver resolver = null;
	try {
		resolver = getResourceResolverForUser(factory, userId);
		return (T) callback.resolve(resolver);
	} catch (Exception e) {
		throw new ResolveException(RESOLVE_ERROR_MESSAGE, e);
	} finally {
		if (resolver != null && resolver.isLive()) {
			resolver.close();
		}
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:19,代码来源:SlingHelper.java


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