public Object jsGet_properties() { if (properties == null) { properties = resource.adaptTo(ValueMap.class); } return properties; }
@Override public boolean test(Resource resource) { Page page = resource.adaptTo(Page.class); if (page == null) { return false; } if (filter == null) { return true; } return filter.test(page); } };
private T seek() { T result = null; while (result == null && iterator.hasNext()) { final Resource r = iterator.next(); result = r.adaptTo(type); } return result; } };
/** * Returns the value of calling <code>adaptTo</code> on the * {@link #getResource() wrapped resource}. */ @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { return getResource().adaptTo(type); }
public Workspace(Resource resource) { this.resource = resource; this.properties = resource.adaptTo(ModifiableValueMap.class); this.jobName = "acs-commons@bulk-workflow-execution:/" + this.resource.getPath(); }
public Workspace getWorkspace() { // Collecting workspace on get to avoid cyclic recursion between models if (this.workspace == null) { this.workspace = this.resource.getChild(Workspace.NN_WORKSPACE).adaptTo(Workspace.class); } return this.workspace; }
/** * Returns first non-null value from the resource property. * * @param <T> * @param resource * @param klass * @param keys * @return */ public static <T> T getFirstProperty(Resource resource, Class<T> klass, String... keys) { return getFirstProperty(resource.adaptTo(ValueMap.class), klass, keys); }
@PostConstruct protected void activate() { this.config = resource.getParent().adaptTo(Config.class); for (BulkWorkflowRunner candidate : runners) { if (StringUtils.equals(this.config.getRunnerType(), candidate.getClass().getName())) { runner = candidate; break; } } }
protected static final List<String> readEntries(SlingHttpServletRequest request) throws IOException { List<String> lines = new ArrayList<>(); Resource redirectMap = request.getResource().getChild(RedirectMapModel.MAP_FILE_NODE); if (redirectMap != null) { lines = IOUtils.readLines(redirectMap.adaptTo(InputStream.class), StandardCharsets.UTF_8); } log.trace("Loaded lines: {}", lines); return lines; }
private void buildResourceList(ResourceResolver resolver, Resource res, List<Resource> resources) throws RepositoryException { Node node = res.adaptTo(Node.class); if (!node.isNodeType(JcrConstants.NT_HIERARCHYNODE)) { return; } resources.add(res); for (Iterator<Resource> iter = resolver.listChildren(res); iter.hasNext();) { Resource resChild = iter.next(); buildResourceList(resolver, resChild, resources); } }
public static boolean isActivated(ResourceResolver rr, String path) { Resource res = rr.getResource(path); if (res == null) { return false; } ReplicationStatus replicationStatus = res.adaptTo(ReplicationStatus.class); if (replicationStatus == null) { return false; } return replicationStatus.isActivated(); }
protected Resource getFragmentTemplateResource(ResourceResolver rr, String templatePath) { Resource template = rr.resolve(templatePath); if (template.adaptTo(FragmentTemplate.class) != null) { return template; } else { return template.getChild("jcr:content"); } } }
@Override public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) { if (type == ResourceAdapterUseObject.class && adaptable instanceof Resource) { Resource resource = (Resource) adaptable; ValueMap properties = resource.adaptTo(ValueMap.class); String title = (String) properties.get("jcr:title"); return (AdapterType) new ResourceAdapterUseObjectImpl(title); } return null; } }
Resource childResource = resourceResolver.getResource(child.getPath()); Node childNode = childResource.adaptTo(Node.class); Node jcrContent = childNode.getNode("jcr:content"); NodeIterator childrenNodes = jcrContent.getNodes(); while(childrenNodes.hasNext()){ Node next = childrenNodes.nextNode(); String resourceType = next.getProperty("sling:resourceType").getString(); if(resourceType.equals("foundation/components/parsys")){ %><cq:include path="<%= next.getPath() %>" resourceType="foundation/components/parsys" /><% break; } }
/** * {@inheritDoc} */ public boolean contains(Resource res) { if (res != null) { ValueMap vm = membersResource.adaptTo(ValueMap.class); String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{}); int index = ArrayUtils.indexOf(order, res.getPath(), 0); return index >= 0 ? true: false; } return false; }
@SuppressWarnings("null") protected Layer getLayer() { if (FileExtension.isImage(getFileExtension())) { return this.rendition.adaptTo(Resource.class).adaptTo(Layer.class); } else { return null; } }
public boolean isVersionable(final Resource rsrc) throws PersistenceException { try { final Node node = rsrc.adaptTo(Node.class); return node != null && isVersionable(node); } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re, rsrc.getPath(), null); } }
@Override public Page getParent(int level) { String parentPath = Text.getRelativeParent(resource.getPath(), level); Resource parentResource = resource.getResourceResolver().getResource(parentPath); if (parentResource != null) { return parentResource.adaptTo(Page.class); } return null; }
public void addFailure(String payloadPath, String trackPath, Calendar failedAt) throws RepositoryException { Node failure = JcrUtils.getOrCreateByPath(resource.getChild(Workspace.NN_FAILURES).adaptTo(Node.class), Workspace.NN_FAILURE, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false); JcrUtil.setProperty(failure, Failure.PN_PAYLOAD_PATH, payloadPath); if (StringUtils.isNotBlank(trackPath)) { JcrUtil.setProperty(failure, Failure.PN_PATH, Payload.dereference(trackPath)); } if (failedAt != null) { JcrUtil.setProperty(failure, Failure.PN_FAILED_AT, failedAt); } }
@Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); bulkWorkflowEngine.stopping(request.getResource().adaptTo(Config.class)); response.sendRedirect(request.getResourceResolver().map(request, request.getResource().getPath()) + ".status.json"); } }