/** * Get the current component context. * * @param adaptable a SlingHttpServletRequest * @return the ComponentContext if the adaptable was a SlingHttpServletRequest, or null otherwise */ public static ComponentContext getComponentContext(Object adaptable) { if (adaptable instanceof SlingHttpServletRequest) { SlingHttpServletRequest request = ((SlingHttpServletRequest) adaptable); return WCMUtils.getComponentContext(request); } // ComponentContext is not reachable from Resource return null; }
public void findReferences(ResourceResolver rr, String referenceSearchRoot, int maxReferences) throws IllegalAccessException { ReferenceSearch refSearch = new ReferenceSearch(); refSearch.setExact(true); refSearch.setHollow(true); refSearch.setMaxReferencesPerPage(maxReferences); refSearch.setSearchRoot(referenceSearchRoot); refSearch.search(rr, sourcePath).values().stream() .peek(p -> allReferences.add(p.getPagePath())) .filter(p -> isActivated(rr, p.getPagePath())) .map(ReferenceSearch.Info::getPagePath) .collect(Collectors.toCollection(() -> publishedReferences)); }
/** * Searches for references to the given path and invalidates them in the cache * * @param path the path to search for */ void invalidateReferences(String path) { try (ResourceResolver adminResolver = resolverFactory.getServiceResourceResolver(null)){ Collection<ReferenceSearch.Info> refs = new ReferenceSearch() .search(adminResolver, path).values(); for (ReferenceSearch.Info info : refs) { String refPath = info.getPage().getPath(); invalidate(refPath); } } catch (Exception e){ log.debug("failed to invalidate references of {}", path); } } }
@Override public void addBindings(Bindings bindings) { Resource resource = (Resource) bindings.get("resource"); Component component = WCMUtils.getComponent(resource); if (component != null) { if (pageRootProvider != null) { setSharedProperties(bindings, resource, component); } else { log.debug("Page Root Provider must be configured for shared component properties to be supported"); } setMergedProperties(bindings, resource); } }
@Override public Iterator<Page> listChildren(final Filter<Page> filter, final boolean deep) { Iterator<Resource> resources; if (deep) { resources = new DeepResourceIterator(resource); } else { resources = resource.getResourceResolver().listChildren(resource); } // return filtered page iterator return new PageIterator(resources, filter); }
@Override protected void visit(Resource resource) { final ValueMap properties = resource.adaptTo(ValueMap.class); final String[] resourceViews = properties.get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(resourceViews)) { this.views.addAll(Arrays.asList(resourceViews)); } final Component component = WCMUtils.getComponent(resource); if (component != null) { final String[] componentViews = component.getProperties().get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(componentViews)) { this.views.addAll(Arrays.asList(componentViews)); } } } }
/** * Get the current component context. * * @param adaptable a SlingHttpServletRequest * @return the ComponentContext if the adaptable was a SlingHttpServletRequest, or null otherwise */ private ComponentContext getComponentContext(Object adaptable) { if (adaptable instanceof SlingHttpServletRequest) { SlingHttpServletRequest request = ((SlingHttpServletRequest) adaptable); return WCMUtils.getComponentContext(request); } // ComponentContext is not reachable from Resource return null; }
/** * Searches for references to the given path and invalidates them in the cache * * @param path the path to search for */ void invalidateReferences(String path){ ResourceResolver adminResolver = null; try { adminResolver = resolverFactory.getServiceResourceResolver(null); Collection<ReferenceSearch.Info> refs = new ReferenceSearch() .search(adminResolver, path).values(); for (ReferenceSearch.Info info : refs) { String refPath = info.getPage().getPath(); invalidate(refPath); } } catch (Exception e){ log.debug("failed to invalidate references of {}", path); } finally { if(adminResolver != null) adminResolver.close(); } } }
@Override protected void visit(Resource resource) { final ValueMap properties = resource.adaptTo(ValueMap.class); final String[] resourceViews = properties.get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(resourceViews)) { this.views.addAll(Arrays.asList(resourceViews)); } final Component component = WCMUtils.getComponent(resource); if (component != null) { final String[] componentViews = component.getProperties().get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(componentViews)) { this.views.addAll(Arrays.asList(componentViews)); } } } }
public String getName() { Page currentPage = WCMUtils.getComponentContext(request).getPage(); return currentPage.getTitle(); } }
/** * Get the WCM Views for the component; Looks at both the content resource for the special wcmViews property * and looks up to the resourceType's cq:Component properties for wcmViews. * * @param request the request * @return the WCM Views for the component */ private List<String> getComponentViews(final SlingHttpServletRequest request) { final Set<String> views = new HashSet<String>(); final Resource resource = request.getResource(); if (resource == null) { return new ArrayList<String>(views); } final Component component = WCMUtils.getComponent(resource); final ValueMap properties = resource.adaptTo(ValueMap.class); if (component != null) { views.addAll(Arrays.asList(component.getProperties().get(PN_WCM_VIEWS, new String[]{}))); } if (properties != null) { views.addAll(Arrays.asList(properties.get(PN_WCM_VIEWS, new String[]{}))); } return new ArrayList<String>(views); }
protected final boolean accepts(final SlingHttpServletRequest request, final SlingHttpServletResponse response) { if (!StringUtils.endsWith(request.getRequestURI(), ".html") || !StringUtils.contains(response.getContentType(), "html")) { // Do not inject around non-HTML requests return false; } final ComponentContext componentContext = WCMUtils.getComponentContext(request); if (componentContext == null // ComponentContext is null || componentContext.getComponent() == null // Component is null || componentContext.isRoot()) { // Suppress on root context return false; } // Check to make sure the suppress key has not been added to the request if (this.isComponentErrorHandlingSuppressed(request)) { // Suppress key is detected, skip handling return false; } // Check to make sure the SlingRequest's resource isn't in the suppress list final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; for (final String suppressedResourceType : suppressedResourceTypes) { if (slingRequest.getResource().isResourceType(suppressedResourceType)) { return false; } } return true; }
/** * Get the WCM Views for the component; Looks at both the content resource for the special wcmViews property * and looks up to the resourceType's cq:Component properties for wcmViews. * * @param request the request * @return the WCM Views for the component */ private List<String> getComponentViews(final SlingHttpServletRequest request) { final Set<String> views = new HashSet<String>(); final Resource resource = request.getResource(); if (resource == null) { return new ArrayList<String>(views); } final Component component = WCMUtils.getComponent(resource); final ValueMap properties = resource.adaptTo(ValueMap.class); if (component != null) { views.addAll(Arrays.asList(component.getProperties().get(PN_WCM_VIEWS, new String[]{}))); } if (properties != null) { views.addAll(Arrays.asList(properties.get(PN_WCM_VIEWS, new String[]{}))); } return new ArrayList<String>(views); }
final ComponentContext componentContext = WCMUtils.getComponentContext(request); if (componentContext == null) {
private Optional<String> addMediaDroptarget(String refProperty, String cropProperty, String rotationProperty, String name) { Component componentDefinition = WCMUtils.getComponent(resource); // set drop target - with path of current component as default resource type Map<String, String> params = new HashMap<String, String>(); if (componentDefinition != null) { params.put("./" + ResourceResolver.PROPERTY_RESOURCE_TYPE, componentDefinition.getPath()); // clear cropping parameters if a new image is inserted via drag&drop params.put(cropProperty, ""); params.put(rotationProperty, ""); } DropTarget dropTarget = new DropTargetImpl(name, refProperty).setAccept(new String[] { "image/.*" // allow all image mime types }).setGroups(new String[] { "media" // allow drop from DAM contentfinder tab }).setParameters(params); componentContext.getEditContext().getEditConfig().getDropTargets().put(dropTarget.getId(), dropTarget); return Optional.of(dropTarget.getId()); }
final com.day.cq.wcm.api.components.Component component = WCMUtils.getComponent(resource); if (!isAuthoringMode(request) || conditionAndCheck(isConfigured)) {
final com.day.cq.wcm.api.components.Component component = WCMUtils.getComponent(resource);
final com.day.cq.wcm.api.components.Component component = WCMUtils.getComponent(resource);
/** * {@inheritDoc} */ @Override public int doEndTag() throws JspException { SlingHttpServletRequest request = TagUtil.getRequest(pageContext); Component component = WCMUtils.getComponent(request.getResource()); if (componentHelper.isEditMode(request)) { JspWriter writer = pageContext.getOut(); String placeholder; String bodyContentString = bodyContent != null ? bodyContent.getString() : null; if (StringUtils.isNotBlank(bodyContentString)) { // use the body content as the default placeholder placeholder = Placeholder.getDefaultPlaceholder(request, component, bodyContentString, getDdClass()); } else { String classicUIPlaceholder = componentHelper.generateClassicUIPlaceholder(getAllClassNames(), null); placeholder = Placeholder.getDefaultPlaceholder(request, component, classicUIPlaceholder, getDdClass()); } try { writer.print(placeholder); } catch (IOException e) { throw new JspException(e); } } reset(); return EVAL_PAGE; }
/** * {@inheritDoc} */ @Override public int doEndTag() throws JspException { SlingHttpServletRequest request = TagUtil.getRequest(pageContext); Component component = WCMUtils.getComponent(request.getResource()); if (ModeUtil.isEdit(request)) { JspWriter writer = pageContext.getOut(); String placeholder; String bodyContentString = bodyContent != null ? bodyContent.getString() : null; if (StringUtils.isNotBlank(bodyContentString)) { // use the body content as the default placeholder placeholder = Placeholder.getDefaultPlaceholder(request, component, bodyContentString, getDdClass()); } else { String classicUIPlaceholder = componentHelper.generateClassicUIPlaceholder(getAllClassNames(), null); placeholder = Placeholder.getDefaultPlaceholder(request, component, classicUIPlaceholder, getDdClass()); } try { writer.print(placeholder); } catch (IOException e) { throw new JspException(e); } } reset(); return EVAL_PAGE; }