本文整理汇总了Java中org.apache.sling.api.resource.ResourceResolverFactory类的典型用法代码示例。如果您正苦于以下问题:Java ResourceResolverFactory类的具体用法?Java ResourceResolverFactory怎么用?Java ResourceResolverFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceResolverFactory类属于org.apache.sling.api.resource包,在下文中一共展示了ResourceResolverFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: operate
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的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();
}
}
}
示例2: resolve
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的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();
}
}
}
示例3: getResourceResolverForUser
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
/**
* Create a new session for specified user (impersonating).
*/
public static ResourceResolver getResourceResolverForUser(ResourceResolverFactory factory, String userId)
throws LoginException {
ResourceResolver resolver;
if (userId != null) {
Map<String, Object> authenticationInfo = Maps.newHashMap();
authenticationInfo.put(ResourceResolverFactory.USER_IMPERSONATION, userId);
resolver = factory.getAdministrativeResourceResolver(authenticationInfo);
} else {
Map<String, Object> parameters = new HashMap<>();
parameters.put(ResourceResolverFactory.SUBSERVICE, SUBSERVICE_NAME);
resolver = factory.getServiceResourceResolver(parameters);
}
return resolver;
}
示例4: getConnection
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
@Override
public RepositoryConnection getConnection(String subServiceName) {
try {
ResourceResolver administrativeResourceResolver;
if (StringUtils.isNotEmpty(subServiceName)) {
Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) subServiceName);
administrativeResourceResolver = resResFactory.getServiceResourceResolver(authInfo);
} else {
administrativeResourceResolver = resResFactory.getAdministrativeResourceResolver(null);
}
return new RepositoryConnectionImpl(administrativeResourceResolver);
} catch (LoginException e) {
throw new TechnicalException("Unable to login to repository with subservice-name '" + subServiceName + "'.", e);
}
}
示例5: deleteProject
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
@Override
public void deleteProject(SlingHttpServletRequest request) throws OperationException {
if (request.getResource() instanceof NonExistingResource) {
throw new OperationException("Nonexisting resource", 400);
}
if (!mayDelete(request.getResource())) {
throw new OperationException("Not allowed", 400);
}
ResourceResolver serviceUserResolver = null;
try {
serviceUserResolver =
resourceResolverFactory.getServiceResourceResolver(Collections.singletonMap(
ResourceResolverFactory.SUBSERVICE, (Object) UGC_WRITER));
deleteProject(request.getResource().getPath(), serviceUserResolver);
} catch (LoginException e) {
throw new OperationException("Not allowed", e, 400);
} finally {
if (serviceUserResolver != null && serviceUserResolver.isLive()) {
serviceUserResolver.close();
}
}
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-scf-sample-components-customize,代码行数:25,代码来源:TaskServiceImpl.java
示例6: getMailTemplate
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
private MailTemplate getMailTemplate(String templatePath) throws IllegalArgumentException {
MailTemplate mailTemplate = null;
ResourceResolver resourceResolver = null;
try {
Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME);
resourceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);
mailTemplate = MailTemplate.create(templatePath, resourceResolver.adaptTo(Session.class));
if (mailTemplate == null) {
throw new IllegalArgumentException("Mail template path [ "
+ templatePath + " ] could not resolve to a valid template");
}
} catch (LoginException e) {
log.error("Unable to obtain an administrative resource resolver to get the Mail Template at [ "
+ templatePath + " ]", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
return mailTemplate;
}
示例7: getResourceResolver
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
/**
* @return ResourceResolver from factory
*/
public ResourceResolver getResourceResolver(final ResourceResolverFactory resourceResolverFactory) {
if (null == resourceResolverFactory || StringUtils.isBlank(getServiceMapperIdentity())) {
return this.resourceResolver;
}
if (null == this.resourceResolver || !this.resourceResolver.isLive()) {
try {
this.resourceResolver = resourceResolverFactory.getServiceResourceResolver(Collections.unmodifiableMap(
new HashMap<String,Object>() {
private static final long serialVersionUID = 1L;
{ put(ResourceResolverFactory.SUBSERVICE, getServiceMapperIdentity() ); }
}));
} catch (LoginException e) {
LOG.debug("Unable to retrieve resource resolver for {}:", getServiceMapperIdentity(), e.getMessage());
}
}
return this.resourceResolver;
}
示例8: serviceWithRequiredServiceInjectsInstanceVariable
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
@Test
public void serviceWithRequiredServiceInjectsInstanceVariable() throws Exception {
ResourceResolverFactory expected = client.getResourceResolverFactory();
InjectedService<SampleService> actual = client.service(SampleService.class, new SampleServiceImpl(), new InjectedService<ResourceResolverFactory>(ResourceResolverFactory.class, expected));
assertSame(expected, actual.getInstance().getResourceResolverFactory());
}
示例9: getConnection
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
@Override
public RepositoryConnection getConnection(String subServiceName) {
Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) subServiceName);
try {
return new RepositoryConnectionImpl(resResFactory.getResourceResolver(authInfo));
} catch (LoginException e) {
throw new TechnicalException("Unable to login to repository with subservice-name '" + subServiceName + "'.", e);
}
}
示例10: resolveDefault
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
/**
* Retrieve values from repository with wrapped session (automatically opened and closed).
*/
public static <T> T resolveDefault(ResourceResolverFactory factory, String userId, ResolveCallback callback,
T defaultValue) {
try {
return resolve(factory, userId, callback);
} catch (ResolveException e) {
LOG.error(RESOLVE_ERROR_MESSAGE, e);
}
return defaultValue;
}
示例11: operateTraced
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
/**
* Do some operation on repository (delete or update resource etc) with wrapped session (automatically
* opened and closed).
*/
public static void operateTraced(ResourceResolverFactory factory, String userId, OperateCallback callback) {
try {
operate(factory, userId, callback);
} catch (OperateException e) {
LOG.error(OPERATE_ERROR_MESSAGE, e);
}
}
示例12: getResourceResolverForUser
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
/**
* Create a new session for specified user (impersonating).
*/
public static ResourceResolver getResourceResolverForUser(ResourceResolverFactory factory, String userId)
throws LoginException {
ResourceResolver resolver;
if (userId != null) {
Map<String, Object> authenticationInfo = Maps.newHashMap();
authenticationInfo.put(ResourceResolverFactory.USER_IMPERSONATION, userId);
resolver = factory.getServiceResourceResolver(authenticationInfo);
} else {
resolver = factory.getServiceResourceResolver(null);
}
return resolver;
}
示例13: getSubServiceUser
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
/**
* Example for getting the Bundle SubService User
*
* @return the user ID
*/
private final String getSubServiceUser() {
ResourceResolver serviceResolver = null;
try {
// Create the Map to pass in the Service Account Identifier
// Remember, "SERVICE_ACCOUNT_IDENTIFIER" is mapped to the CRX User via a SEPARATE ServiceUserMapper Factory OSGi Config
final Map<String, Object> authInfo = Collections.singletonMap(
ResourceResolverFactory.SUBSERVICE,
(Object) SERVICE_ACCOUNT_IDENTIFIER);
// Get the Service resource resolver
serviceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);
if(serviceResolver != null) {
// Do some work w your service resource resolver
return serviceResolver.getUserID();
} else {
return "Could not obtain a CRX User for the Service: " + SERVICE_ACCOUNT_IDENTIFIER;
}
} catch (LoginException e) {
return "Login Exception when obtaining a CRX User for the Service: " + SERVICE_ACCOUNT_IDENTIFIER + " - " + e.getMessage();
} finally {
// As always, clean up any ResourceResolvers or JCR Sessions you open
if (serviceResolver != null) {
serviceResolver.close();
}
}
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:36,代码来源:SampleServiceLoginResourceResolverImpl.java
示例14: AutomaticPackageReplicatorJob
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
public AutomaticPackageReplicatorJob(final ResourceResolverFactory resolverFactory, final Replicator replicator,
final EventAdmin eventAdmin, final String packagePath) {
this.replicator = replicator;
this.packagePath = packagePath;
this.resolverFactory = resolverFactory;
this.eventAdmin = eventAdmin;
}
示例15: FastActionManagerRunnable
import org.apache.sling.api.resource.ResourceResolverFactory; //导入依赖的package包/类
public FastActionManagerRunnable(Config config,
ResourceResolverFactory resourceResolverFactory,
QueryHelper queryHelper,
ActionManagerFactory actionManagerFactory,
DeferredActions actions,
SyntheticWorkflowRunner syntheticWorkflowRunner) {
this.configPath = config.getPath();
this.resourceResolverFactory = resourceResolverFactory;
this.queryHelper = queryHelper;
this.actionManagerFactory = actionManagerFactory;
this.actions = actions;
this.syntheticWorkflowRunner = syntheticWorkflowRunner;
}