當前位置: 首頁>>代碼示例>>Java>>正文


Java SlingHttpServletRequest.getResourceResolver方法代碼示例

本文整理匯總了Java中org.apache.sling.api.SlingHttpServletRequest.getResourceResolver方法的典型用法代碼示例。如果您正苦於以下問題:Java SlingHttpServletRequest.getResourceResolver方法的具體用法?Java SlingHttpServletRequest.getResourceResolver怎麽用?Java SlingHttpServletRequest.getResourceResolver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.sling.api.SlingHttpServletRequest的用法示例。


在下文中一共展示了SlingHttpServletRequest.getResourceResolver方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的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

示例2: process

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的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

示例3: process

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的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

示例4: process

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的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: ImportSummaryModel

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@Inject
public ImportSummaryModel(SlingHttpServletRequest request, @OSGiService ScriptManager scriptManager,
		@OSGiService JobResultsCache jobResultsCache, @OSGiService ScriptFinder scriptFinder)
		throws RepositoryException, PersistenceException {
	ResourceResolver resolver = request.getResourceResolver();
	this.mode = request.getParameter(MODE_PARAMETER) != null ?
			Mode.valueOf(request.getParameter(MODE_PARAMETER)) :
			null;
	final String scriptPath = request.getParameter(FILE_PARAMETER);
	final String progressJobId = request.getParameter(JOB_ID_PARAMETER);

	this.script = scriptFinder.find(scriptPath, resolver);
	Progress progress;
	if (StringUtils.isNotBlank(progressJobId)) {
		progress = jobResultsCache.get(progressJobId);
		if (progress == null) {
			progress = new ProgressImpl(resolver.getUserID());
		}
	} else {
		progress = scriptManager.process(script, mode, resolver);
	}
	this.progressLogger = progress;
}
 
開發者ID:Cognifide,項目名稱:APM,代碼行數:24,代碼來源:ImportSummaryModel.java

示例6: getAllowedTypes

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的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: calculateRelationships

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@Override
protected List<ProductRelationship> calculateRelationships(SlingHttpServletRequest request, CommerceSession session,
                                                           Page currentPage, Product currentProduct)
        throws CommerceException {
    if (currentProduct == null) {
        return null;
    }

    // Add current product to context
    List<Product> contextProducts = new ArrayList<Product>();
    contextProducts.add(currentProduct);

    // Walk content-pages to find similar products
    ResourceResolver resolver = request.getResourceResolver();
    SimilarProductsCollector collector = new SimilarProductsCollector(resolver, session, RELATIONSHIP_TYPE,
            RELATIONSHIP_TITLE, contextProducts);
    final Page root = WeRetailHelper.findRoot(currentPage);
    if (root != null) {
        collector.walk(root.getContentResource().getParent());
    }
    return collector.getRelationships();
}
 
開發者ID:Adobe-Marketing-Cloud,項目名稱:aem-sample-we-retail,代碼行數:23,代碼來源:SimilarToCurrentRelationshipsProvider.java

示例8: calculateRelationships

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@Override
protected List<ProductRelationship> calculateRelationships(SlingHttpServletRequest request, CommerceSession session,
                                                           Page currentPage, Product currentProduct)
        throws CommerceException {
    // Add all products of the current cart to context
    final List<Product> contextProducts = new ArrayList<Product>();
    final List<CommerceSession.CartEntry> cartEntries = session.getCartEntries();
    for (CommerceSession.CartEntry entry : cartEntries) {
        contextProducts.add(entry.getProduct());
    }

    // Walk content-pages to find similar products
    ResourceResolver resolver = request.getResourceResolver();
    SimilarProductsCollector collector = new SimilarProductsCollector(resolver, session, RELATIONSHIP_TYPE,
            RELATIONSHIP_TITLE,
            contextProducts);
    final Page root = WeRetailHelper.findRoot(currentPage);
    if (root != null && root.getContentResource() != null) {
        collector.walk(root.getContentResource().getParent());
    }
    return collector.getRelationships();
}
 
開發者ID:Adobe-Marketing-Cloud,項目名稱:aem-sample-we-retail,代碼行數:23,代碼來源:SimilarToCartRelationshipsProvider.java

示例9: markAsSpam

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的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.SlingHttpServletRequest; //導入方法依賴的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: UptimeEntryModel

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
public UptimeEntryModel(SlingHttpServletRequest request) {
	this.resourceResolver = request.getResourceResolver();
	this.path = request.getParameter("path");
	
	if (this.path != null) {
		this.entryResource = resourceResolver.getResource(this.path);
		this.valueMap = this.entryResource.getValueMap();
	}
}
 
開發者ID:auniverseaway,項目名稱:aem-touch-admin-console,代碼行數:10,代碼來源:UptimeEntryModel.java

示例12: doPost

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
		throws ServletException, IOException {
	final String all = request.getParameter("confirmation");
	final String fileName = request.getParameter("file");
	ResourceResolver resolver = request.getResourceResolver();
	if (fileName != null) {
		removeSingleFile(resolver, response, fileName);
	} else if (all != null) {
		removeAllFiles(resolver, response, all);
	} else {
		response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
		ServletUtils.writeMessage(response, "error", "Invalid arguments specified");
	}
}
 
開發者ID:Cognifide,項目名稱:APM,代碼行數:16,代碼來源:ScriptRemoveServlet.java

示例13: doPost

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
		throws ServletException, IOException {
	final ResourceResolver resolver = request.getResourceResolver();
	final String searchPath = request.getParameter("scriptPath");
	final Script script = scriptFinder.find(searchPath, resolver);
	if (script == null) {
		ServletUtils.writeMessage(response, "error", "Script not found: " + searchPath);
		return;
	}
	final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script);
	try {
		final String executionMode = request.getParameter("executionMode");
		if (executionMode != null) {
			modifiableScript.setExecutionMode(ExecutionMode.valueOf(executionMode.toUpperCase()));
		}

		final String executionEnabled = request.getParameter("executionEnabled");
		if (executionEnabled != null) {
			modifiableScript.setExecutionEnabled(BooleanUtils.toBoolean(executionEnabled));
		}

		ServletUtils.writeMessage(response, "success", "Script configuration updated");
	} catch (PersistenceException e) {
		response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		ServletUtils
				.writeMessage(response, "error", "Cannot update script configuration: " + e.getMessage());
	}
}
 
開發者ID:Cognifide,項目名稱:APM,代碼行數:30,代碼來源:ScriptConfigServlet.java

示例14: doGet

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response)
        throws ServletException, IOException {
    boolean hasImageDelegation = false;
    ResourceResolver resourceResolver = request.getResourceResolver();
    ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
    String suffix = request.getRequestPathInfo().getSuffix();
    if (componentManager != null && StringUtils.isNotEmpty(suffix)) {
        Resource policiesRootPage = getPoliciesRootPage(resourceResolver, suffix);
        if (policiesRootPage != null) {
            String resourceType = suffix.substring(policiesRootPage.getPath().length() + 1, suffix.lastIndexOf('/'));
            com.day.cq.wcm.api.components.Component component = componentManager.getComponent(resourceType);
            if (component != null && component.isAccessible()) {
                String imageDelegate = component.getProperties().get(AbstractImageDelegatingModel.IMAGE_DELEGATE, String.class);
                if (StringUtils.isNotEmpty(imageDelegate)) {
                    hasImageDelegation = true;
                    com.day.cq.wcm.api.components.Component delegate = componentManager.getComponent(imageDelegate);
                    if (delegate != null && delegate.isAccessible()) {
                        ExpressionCustomizer customizer = ExpressionCustomizer.from(request);
                        customizer.setVariable(AbstractImageDelegatingModel.IMAGE_DELEGATE, delegate);
                    }
                }
            }
        }
    }
    request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(hasImageDelegation));
}
 
開發者ID:Adobe-Marketing-Cloud,項目名稱:aem-core-wcm-components,代碼行數:28,代碼來源:ImageDelegateRenderCondition.java

示例15: TagSearchController

import org.apache.sling.api.SlingHttpServletRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public TagSearchController(SlingHttpServletRequest request) {
  Resource resource = request.getResource();
  ResourceResolver resolver = request.getResourceResolver();

  // get tag name to search for form suffix
  String suffix = request.getRequestPathInfo().getSuffix();
  this.tag = StringUtils.substringAfter(suffix, "/");

  // execute JCR query via Sling API
  String xpathQuery = "/jcr:root" + resource.getPath() + "//*[tags='" + this.tag + "']";
  this.result = IteratorUtils.toList(resolver.findResources(xpathQuery, "xpath"));
}
 
開發者ID:adaptto,項目名稱:2015-sling-rookie-session,代碼行數:14,代碼來源:TagSearchController.java


注:本文中的org.apache.sling.api.SlingHttpServletRequest.getResourceResolver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。