private PageCompareData load(Resource resource, String version) { if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { try { return loader.load(resource, version); } catch (RepositoryException e) { log.error("Error loading data", e); } } return null; } }
/** * @see org.apache.sling.api.resource.ResourceResolver#delete(org.apache.sling.api.resource.Resource) */ @Override public void delete(final Resource resource) throws PersistenceException { // check if the resource is non existing - throws NPE if resource is null as stated in the API if ( ResourceUtil.isNonExistingResource(resource) ) { // nothing to do return; } // if resource is null, we get an NPE as stated in the API this.control.delete(this.context, resource); }
/** * Gets the resource object for the provided path. * <p> * Performs checks to ensure resource exists and is accessible to user. * * @param resourceResolver * @param path * @return */ private Resource getResource(ResourceResolver resourceResolver, String path) { // Double check that the resource exists and return it as a match final Resource resource = resourceResolver.getResource(path); if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { return resource; } return null; }
public EvolutionContext getEvolution() { if (StringUtils.isNotEmpty(path)) { Resource resource = resolver.resolve(path); if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { return analyser.getEvolutionContext(resource); } log.warn("Could not resolve resource at path={}", path); } log.warn("No path provided"); return null; }
/** * Gets the resource object for the provided path. * <p> * Performs checks to ensure resource exists and is accessible to user. * * @param resourceResolver * @param path * @return */ private Resource getResource(ResourceResolver resourceResolver, String path) { // Double check that the resource exists and return it as a match final Resource resource = resourceResolver.getResource(path); if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { return resource; } return null; }
public EvolutionContext getEvolution() { if (StringUtils.isNotEmpty(path)) { Resource resource = resolver.resolve(path); if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { return analyser.getEvolutionContext(resource); } log.warn("Could not resolve resource at path={}", path); } log.warn("No path provided"); return null; }
/** * Collect broken references from properties of the given resource * * @param resource the resource to check * @param regex regex to to detect properties containing references. Set from @FormField * @param skipList properties to ignore. Set from @FormField * @param htmlFields field containing html . * @return broken references keyed by property. The value is a List because a property can contain multiple links, * e.g. if it is multivalued or it is html containing multiple links. */ static Map<String, List<String>> collectBrokenReferences(Resource resource, Pattern regex, Set<String> skipList, Set<String> htmlFields) { return resource.getValueMap().entrySet().stream() .filter(entry -> !skipList.contains(entry.getKey())) .collect(Collectors.toMap( entry -> resource.getPath() + "/" + entry.getKey(), entry -> { List<String> brokenPaths = collectPaths(entry, htmlFields) .filter(href -> regex.matcher(href).matches()) .filter(path -> ResourceUtil.isNonExistingResource(resource.getResourceResolver().resolve(path))) .collect(Collectors.toList()); return brokenPaths; })).entrySet().stream().filter(e -> !e.getValue().isEmpty()) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); }
public GeometrixxMediaArticleBody(Resource resource) throws SlingModelsException { if (null == resource) { LOG.info("Resource is null"); throw new SlingModelsException("Resource is null"); } if (ResourceUtil.isNonExistingResource(resource)) { LOG.warn("Can't adapt non existent resource: '{}'", resource.getPath()); throw new SlingModelsException( "Can't adapt non existent resource." + resource.getPath()); } this.resource = resource; }
public GeometrixxMediaPage(Resource resource) throws SlingModelsException { if (null == resource) { LOG.debug("resource is null"); throw new SlingModelsException("Resource is null"); } if (ResourceUtil.isNonExistingResource(resource)) { LOG.warn("Can't adapt non existent resource: '{}'", resource.getPath()); throw new SlingModelsException( "Can't adapt non existent resource." + resource.getPath()); } }
if (resource == null || ResourceUtil.isNonExistingResource(resource)) { return false;
public void doHead(SlingHttpServletRequest request, SlingHttpServletResponse response) { try{ //retrieve the requested URL ResourceResolver resourceResolver = request.getResourceResolver(); String requestUri = request.getParameter( "uri" ); log.debug( "Checking access for URI {}", requestUri ); if( isUriValid( requestUri ) ){ Resource requestedResource = resourceResolver.resolve( request, requestUri ); if( !ResourceUtil.isNonExistingResource( requestedResource ) ){ log.debug("Current Session has access to {}", requestUri ); response.setStatus(SlingHttpServletResponse.SC_OK); } else { log.info("Current Session does not have access to {}", requestUri ); response.setStatus(SlingHttpServletResponse.SC_UNAUTHORIZED); } } else { log.debug( "Invalid URI {}", requestUri ); response.setStatus( SlingHttpServletResponse.SC_UNAUTHORIZED ); } } catch(Exception e) { log.error("Authchecker servlet exception", e); response.setStatus( SlingHttpServletResponse.SC_UNAUTHORIZED ); } }
@Override public final void mergeParagraphSystems(final Resource resource, final int textParagraphSize) throws RepositoryException { if (resource == null || ResourceUtil.isNonExistingResource(resource) || !this.isModifiable(resource)) { // Nothing to merge, or user does not have access to merge return; } final Node targetNode = this.getOrCreateLastParagraphSystemResource(resource, textParagraphSize); if (targetNode == null) { log.info("Could not find last target node to merge long-form-text text inline par resources: {}", textParagraphSize); return; } for (final Resource child : resource.getChildren()) { int index = this.getResourceIndex(child); if (index > textParagraphSize) { this.moveChildrenToNode(child, targetNode); } } }
@Override public final void mergeParagraphSystems(final Resource resource, final int textParagraphSize) throws RepositoryException { if (resource == null || ResourceUtil.isNonExistingResource(resource) || !this.isModifiable(resource)) { // Nothing to merge, or user does not have access to merge return; } final Node targetNode = this.getOrCreateLastParagraphSystemResource(resource, textParagraphSize); if (targetNode == null) { log.info("Could not find last target node to merge long-form-text text inline par resources: {}", textParagraphSize); return; } for (final Resource child : resource.getChildren()) { int index = this.getResourceIndex(child); if (index > textParagraphSize) { this.moveChildrenToNode(child, targetNode); } } }
protected void addOrUpdatePage(PageModification modification) { // We need to add the correct page for the add/update. On page moves, we need to use the destination. final String modificationPath = (modification.getType() == PageModification.ModificationType.MOVED) ? modification.getDestination() : modification.getPath(); if (null == resourceResolver) { LOG.warn("Can't perform indexing operation for '{}'", modificationPath); return; } final Resource resource = resourceResolver.getResource(modificationPath); if (ResourceUtil.isNonExistingResource(resource)) { LOG.warn("Can't perform indexing operation for '{}'. Resource does not exist.", modificationPath); return; } GeometrixxMediaContentType contentPage = resource.adaptTo(GeometrixxMediaPage.class); indexService.addAndCommit(contentPage.getSolrDoc()); }
private String buildCrxDeLinkToResourceType(HttpServletRequest request, String type) { return getResourceResolver().map(r -> { try { String path = resourceTypeToPath(type); Resource resource = null; Resource iconResource = null; for (String searchPath : r.getSearchPath()) { resource = r.getResource(searchPath + path); if (resource != null && !isNonExistingResource(resource) && !isSyntheticResource(resource)) { iconResource = resource.getChild("icon.png"); break; } } return resource != null ? "<a href=\"" + request.getContextPath() + "/crx/de/#" + resource.getPath() + "\" " + "class=\"crxdelink\">" + "<img class=\"componentIcon\" src=\"" + getLabel() + API_PATH + API_COMPONENTICON + (iconResource == null ? "" : resource.getPath()) + "\"/>" + type + "</a>" : "<span class=\"unresolved\">" + type + "</span>"; } finally { r.close(); } }).orElse("#"); }
private void includeResource(SlingHttpServletRequest request, final Bindings bindings, PrintWriter out, String path, RequestDispatcherOptions requestDispatcherOptions) { if (StringUtils.isEmpty(path)) { throw new SightlyException("Resource path cannot be empty"); } else { Resource includeRes = request.getResourceResolver().resolve(path); if (ResourceUtil.isNonExistingResource(includeRes)) { String resourceType = request.getResource().getResourceType(); if (requestDispatcherOptions.containsKey(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE)) { resourceType = requestDispatcherOptions.getForceResourceType(); } includeRes = new SyntheticResource(request.getResourceResolver(), path, resourceType); } includeResource(request, bindings, out, includeRes, requestDispatcherOptions); } }
@Override public ProviderOutcome provide(String identifier, RenderContext renderContext, Bindings arguments) { Bindings globalBindings = renderContext.getBindings(); SlingHttpServletRequest request = BindingsUtils.getRequest(globalBindings); String path = normalizePath(request, identifier); try { Resource resource = request.getResourceResolver().getResource(path); if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { return ProviderOutcome.success(resource); } } catch (Exception e) { return ProviderOutcome.failure(e); } return ProviderOutcome.failure(); }
public void render(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws IOException { final Resource r = req.getResource(); if (ResourceUtil.isNonExistingResource(r)) { throw new ResourceNotFoundException("No data to render."); } /* * TODO if(srd != null) { renderSyntheticResource(req, resp, srd); * return; } */ resp.setContentType(req.getResponseContentType()); resp.setCharacterEncoding("UTF-8"); final PrintWriter pw = resp.getWriter(); @SuppressWarnings("unchecked") final Map<String,Object> map = r.adaptTo(Map.class); if ( map != null ) { dump(pw, r, map); } else if ( r.adaptTo(String.class) != null ) { printPropertyValue(pw, r.getName(), r.adaptTo(String.class), false); } else if ( r.adaptTo(String[].class) != null ) { printPropertyValue(pw, r.getName(), r.adaptTo(String[].class), false); } else { resp.sendError(HttpServletResponse.SC_NO_CONTENT); } }
final Resource r = req.getResource(); if (ResourceUtil.isNonExistingResource(r)) { throw new ResourceNotFoundException("No data to render.");
res = resResolver.resolve(new FakeSlingHttpServletRequest(path), path); assertNotNull(res); assertTrue(ResourceUtil.isNonExistingResource(res)); assertEquals(path, res.getPath()); assertEquals(Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());