本文整理汇总了Java中org.apache.sling.api.resource.ResourceResolver.close方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceResolver.close方法的具体用法?Java ResourceResolver.close怎么用?Java ResourceResolver.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.resource.ResourceResolver
的用法示例。
在下文中一共展示了ResourceResolver.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
}
示例3: 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;
}
示例4: 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();
}
}
}
示例5: 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;
}
示例6: run
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void run() {
// Scheduled services that do not have to be cluster aware do not need
// to implement this check OR extend ClusterAware
if (!isMaster) {
return;
}
// Scheduled service logic, only run on the Master
ResourceResolver adminResourceResolver = null;
try {
// Be careful not to leak the adminResourceResolver
adminResourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
// execute your scheduled service logic here ...
} catch (LoginException e) {
log.error("Error obtaining the admin resource resolver.", e);
} finally {
// ALWAYS close resolvers you open
if (adminResourceResolver != null) {
adminResourceResolver.close();
}
}
}
示例7: run
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void run() {
// Scheduled services that do not have to be cluster aware do not need
// to implement this check OR extend TopologyEventListener
if (!isLeader) {
return;
}
// Scheduled service logic, only run on the Master
ResourceResolver adminResourceResolver = null;
try {
// Be careful not to leak the adminResourceResolver
adminResourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
// execute your scheduled service logic here ...
} catch (LoginException e) {
log.error("Error obtaining the admin resource resolver.", e);
} finally {
// ALWAYS close resolvers you open
if (adminResourceResolver != null) {
adminResourceResolver.close();
}
}
}
示例8: getBundleServiceUser
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
* Example for getting the Bundle Service User
*
* @return the user ID
*/
private final String getBundleServiceUser() {
ResourceResolver serviceResolver = null;
try {
// Get the Service resource resolver
serviceResolver = resourceResolverFactory.getServiceResourceResolver(null);
if(serviceResolver != null) {
// Do some work w your service resource resolver
return serviceResolver.getUserID();
} else {
return "Could not obtain a CRX User for Bundle Service";
}
} catch (LoginException e) {
return "Login Exception when obtaining a CRX User for the Bundle Service - " + 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,代码行数:30,代码来源:SampleServiceLoginResourceResolverImpl.java
示例9: 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();
}
示例10: checkCorrectJumpMethod
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
public void checkCorrectJumpMethod() {
ResourceResolver resourceResolver = null;
try {
resourceResolver = getResourceResolverForUserNested(resourceResolverFactory, null);
} catch (LoginException e) {
e.printStackTrace();
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
示例11: findName
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
public String findName(final String path) {
String name = "";
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverProducer.produce();
name = resourceResolver.getResource(path).getName();
} finally {
if (null != resourceResolver && resourceResolver.isLive()) {
resourceResolver.close();
}
}
return name;
}
示例12: getSubServiceUser
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的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
示例13: process
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
if (resource != null) {
Map<String, Object> authenticationInfo = new HashMap<String, Object>();
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, CONFIG_SERVICE);
ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(authenticationInfo);
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
com.day.cq.wcm.api.components.Component component = componentManager.getComponentOfResource(resource);
if (component != null) {
Configuration configuration = configurationProvider.getFor(resource.getResourceType());
contentModel.setAsIsolated(CONFIG_PROPERTIES_KEY, wrap(configuration.toMap()));
Resource componentResource = component.adaptTo(Resource.class);
Node componentNode = componentResource.adaptTo(Node.class);
Map<String, Object> componentProps = PropertyUtils.propsToMap(componentNode.getProperties());
componentProps.put(PATH, componentResource.getPath());
componentProps.put(APP_NAME_PROPERTY_KEY, ResourceUtils.getAppName(resource));
String globalDialogPath = getGlobalDialogPath(resource, resourceResolver, request);
if (!BLANK.equals(globalDialogPath)) {
componentProps.put(GLOBAL_DIALOG_PATH_PROPERTY_KEY, globalDialogPath);
}
String globalPropertiesPath = ResourceUtils.getGlobalPropertiesPath(resource, resourceResolver);
if (!BLANK.equals(globalPropertiesPath)) {
componentProps.put(GLOBAL_PATH_PROPERTY_KEY, globalPropertiesPath);
}
contentModel.setAsIsolated(COMPONENT_PROPERTIES_KEY, componentProps);
}
resourceResolver.close();
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例14: onEvent
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
* Trigger on event
*
* @param eventIterator The event iterator object
*/
@Override
public void onEvent(EventIterator eventIterator) {
ResourceResolver resourceResolver = null;
try {
Map<String, Object> authenticationInfo = new HashMap<String, Object>();
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, CONFIG_SERVICE);
resourceResolver = resourceResolverFactory.getServiceResourceResolver(authenticationInfo);
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
if (resourceResolver != null) {
while (eventIterator.hasNext()) {
Event event = eventIterator.nextEvent();
String path = event.getPath();
switch (event.getType()) {
case Event.PROPERTY_REMOVED:
case Event.NODE_REMOVED:
case Event.PROPERTY_CHANGED:
case Event.PROPERTY_ADDED:
path = path.substring(0, path.lastIndexOf('/'));
break;
case Event.NODE_MOVED:
path = event.getInfo().get("srcChildRelPath").toString();
break;
case Event.NODE_ADDED:
default:
}
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
com.day.cq.wcm.api.components.Component component = ResourceUtils.findContainingComponent(resource);
if (component != null) {
configCache.clear();
}
}
}
}
} catch (Exception ew) {
LOG.error(ERROR, ew);
} finally {
if (resourceResolver != null)
resourceResolver.close();
}
}