本文整理汇总了Java中org.apache.sling.api.SlingHttpServletRequest.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java SlingHttpServletRequest.getResource方法的具体用法?Java SlingHttpServletRequest.getResource怎么用?Java SlingHttpServletRequest.getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.SlingHttpServletRequest
的用法示例。
在下文中一共展示了SlingHttpServletRequest.getResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isApplicable
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
private boolean isApplicable(SlingHttpServletRequest request) {
Object appliable = request.getAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE);
if (appliable == null) {
Resource resource = request.getResource();
PageManager pMgr = resource.getResourceResolver().adaptTo(PageManager.class);
Page page = pMgr.getContainingPage(resource);
AEMDataLayerConfig config = AEMDataLayerConfig.getDataLayerConfig(page);
if (config != null) {
DataLayer dataLayer = new DataLayer(config, page);
request.setAttribute(DataLayerConstants.REQUEST_PROPERTY_AEM_DATALAYER, dataLayer);
request.setAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE, new Boolean(true));
return true;
} else {
request.setAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE, new Boolean(false));
return false;
}
} else {
return new Boolean(true).equals(appliable);
}
}
示例2: getAssetResource
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
private Resource getAssetResource(SlingHttpServletRequest request) {
Resource componentResource = request.getResource();
String damAssetPath = BLANK;
String[] selectors = request.getRequestPathInfo().getSelectors();
int assetIndex = -1;
if(selectors.length == 2) {
assetIndex = Integer.parseInt(selectors[1]);
}
if (assetIndex == -1) {
damAssetPath = ResourceUtils.getPropertyAsString(componentResource, FILE_REFERENCE);
} else {
List<String> fileReferences = ResourceUtils.getPropertyAsStrings(componentResource, FILE_REFERENCES);
if(fileReferences.size() > assetIndex) {
damAssetPath = fileReferences.get(assetIndex);
}
}
return request.getResourceResolver().getResource(damAssetPath);
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: process
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
Collection<String> fileReferences = ResourceUtils.getPropertyAsStrings(resource, FILE_REFERENCES);
Collection<String> imagePathList = new ArrayList<>();
for(int i = 0; i < fileReferences.size(); i++) {
imagePathList.add(assetPathService.getComponentAssetPath(resource, i));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例6: 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);
Resource resource = request.getResource();
List<Resource> imageResources = $(resource).searchStrategy(SearchStrategy.QUERY).find(NT_UNSTRUCTURED).filter(IMAGE_RESOURCES_PREDICATE).asList();
Collection<String> imagePathList = new ArrayList<>();
for (Resource imageResource : imageResources) {
imagePathList.add(assetPathService.getComponentImagePath(imageResource));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS_FROM_RESOURCES, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}
开发者ID:DantaFramework,项目名称:AEM,代码行数:17,代码来源:AddMultipleTransformedImagePathsFromResourcesContextProcessor.java
示例7: 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);
Resource resource = request.getResource();
List<Resource> imageResources = $(resource).searchStrategy(SearchStrategy.QUERY).find(NT_UNSTRUCTURED).filter(IMAGE_RESOURCES_PREDICATE).asList();
Map<String, String> imagePathList = new HashMap<>();
for (Resource imageResource : imageResources) {
imagePathList.put(imageResource.getName(), assetPathService.getComponentImagePath(imageResource));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS_FROM_RESOURCES, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例8: process
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
Map<String, Object> content = (contentModel.has(RESOURCE_CONTENT_KEY)) ? ((Map<String, Object>) contentModel.get(RESOURCE_CONTENT_KEY)) : new HashMap<String, Object>();
if (resource != null) {
Node node = resource.adaptTo(Node.class);
if (node != null) {
String componentContentId = DigestUtils.md5Hex(resource.getPath());
content.put(XK_CONTENT_ID_CP, componentContentId);
} else {
content.put(XK_CONTENT_ID_CP, "_NONE");
}
content.put(PATH, resource.getPath());
content.put(NAME, resource.getName());
}
}
示例9: getContentModel
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
/**
* This method gets the Content Model of a resource.
*
* @param request This is a SlingHttpServletRequest
* @param response This is a SlingHttpServletResponse
* @return contentModel The Content Model of a resource
*/
@Override
public ContentModel getContentModel (final SlingHttpServletRequest request, final SlingHttpServletResponse response) {
final ContentModel contentModel = new TemplateContentModelImpl(request, response);
try {
Resource resource = request.getResource();
if (resource != null) {
ExecutionContextImpl executionContext = new ExecutionContextImpl();
executionContext.put(SLING_HTTP_REQUEST, request);
executionContext.put(ENGINE_RESOURCE, resource.getResourceType());
contextProcessorEngine.execute(executionContext, contentModel);
}
} catch (Exception e) {
LOG.error(e.getMessage());
}
return contentModel;
}
示例10: getSearchContentResource
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
private Resource getSearchContentResource(SlingHttpServletRequest request, Page currentPage) {
Resource searchContentResource = null;
RequestPathInfo requestPathInfo = request.getRequestPathInfo();
Resource resource = request.getResource();
String relativeContentResource = requestPathInfo.getSuffix();
if (StringUtils.startsWith(relativeContentResource, "/")) {
relativeContentResource = StringUtils.substring(relativeContentResource, 1);
}
if (StringUtils.isNotEmpty(relativeContentResource)) {
searchContentResource = resource.getChild(relativeContentResource);
if (searchContentResource == null) {
PageManager pageManager = resource.getResourceResolver().adaptTo(PageManager.class);
if (pageManager != null) {
Template template = currentPage.getTemplate();
if (template != null) {
Resource templateResource = request.getResourceResolver().getResource(template.getPath());
if (templateResource != null) {
searchContentResource = templateResource.getChild(NN_STRUCTURE + "/" + relativeContentResource);
}
}
}
}
}
return searchContentResource;
}
示例11: process
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception {
// First, check if our post processor implementation needs to do anything
// Note: all registered SlingPostProcessor instances are called on all invocations of the Sling POST Servlet
if (accepts(request)) {
// Apply your custom changes: first, adapt the resource to a ModifiableValueMap
final Resource resource = request.getResource();
final ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
// Example: add an additional property to the resource
String uuid = UUID.randomUUID().toString();
properties.put("myapp.versionHash", uuid);
// Record a "MODIFIED" entry in the modifications list
modifications.add(Modification.onModified(resource.getPath()));
}
}
示例12: doGet
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
Resource resource = request.getResource();
if (resource != null && configurationProvider.hasConfig(resource.getResourceType())) {
JSONObject filteredContentMap = new JSONObject();
TemplateContentModel templateContentModel = (TemplateContentModel) contentModelFactoryService.getContentModel(request, response);
boolean clientAccessible = (Boolean) templateContentModel.get(CONFIG_PROPERTIES_KEY + DOT + XK_CLIENT_ACCESSIBLE_CP);
if (clientAccessible) {
// get list of contexts
Configuration configuration = configurationProvider.getFor(resource.getResourceType());
Collection<String> props = configuration.asStrings(XK_CLIENT_MODEL_PROPERTIES_CP, Mode.MERGE);
String[] contexts = props.toArray(new String[0]);
// get content model json with the XK_CLIENT_MODEL_PROPERTIES_CP contexts
filteredContentMap = templateContentModel.toJSONObject(contexts);
// add component id
String componentContentId = DigestUtils.md5Hex(resource.getPath());
filteredContentMap.put(XK_CONTENT_ID_CP, componentContentId);
}
out.write(JSONObject.toJSONString(filteredContentMap));
} else {
out.write(new JSONObject().toJSONString());
}
} catch (Exception ew) {
throw new ServletException(ew);
}
}
示例13: doGet
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
Resource resource = request.getResource();
if (resource != null && configurationProvider.hasConfig(resource.getResourceType())) {
JSONObject filteredContentMap = new JSONObject();
TemplateContentModel templateContentModel = (TemplateContentModel) contentModelFactoryService.getContentModel(request, response);
boolean clientAccessible = (Boolean) templateContentModel.get(CONFIG_PROPERTIES_KEY + DOT + XK_CLIENT_ACCESSIBLE_CP);
if (clientAccessible) {
// get list of contexts
Configuration configuration = configurationProvider.getFor(resource.getResourceType());
Collection<String> props = configuration.asStrings(XK_CLIENT_MODEL_PROPERTIES_CP, Mode.MERGE);
String[] contexts = props.toArray(new String[0]);
// get content model json with the XK_CLIENT_MODEL_PROPERTIES_CP contexts
filteredContentMap = templateContentModel.toJSONObject(contexts);
// add component id
String componentContentId = DigestUtils.md5Hex(resource.getPath());
filteredContentMap.put(XK_CONTENT_ID_CP, componentContentId);
}
// add component list with clientaccessible as true on the resource page
filteredContentMap.put(PAGE_COMPONENT_RESOURCE_LIST_AN, getComponentList(resource));
out.write(JSONObject.toJSONString(filteredContentMap));
} else {
out.write(new JSONObject().toJSONString());
}
} catch (Exception ew) {
throw new ServletException(ew);
}
}
示例14: accepts
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
public boolean accepts(final ExecutionContext executionContext)
throws AcceptsException {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
return (mustExist()) ? (resource != null && (!ResourceUtil.isSyntheticResource(resource))) : true;
}
示例15: process
import org.apache.sling.api.SlingHttpServletRequest; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
Configuration config = configurationProvider.getFor(request.getResource().getResourceType());
Collection<String> models = config.asStrings(SLING_MODELS_CONFIG_PROPERTY_NAME, Mode.MERGE);
Object model;
String modelName = "";
Map<String, Object> modelData = new HashMap<>();
for (String modelId : models) {
Class<?> modelClass= Class.forName(modelId);
if (modelFactory.isModelClass(modelClass)) {
model = resource.adaptTo(modelClass);
modelData = getModelProperties(model);
modelName = modelClass.getSimpleName();
contentModel.set(SLING_MODEL_PROPERTIES_KEY + DOT + modelName, modelData);
} else {
log.error("{} is not a Sling Model", modelClass);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}