Search in sources :

Example 1 with ContentFile

use of org.apache.sling.fsprovider.internal.mapper.ContentFile in project sling by apache.

the class FileMonitor method collectResourceChanges.

private List<ResourceChange> collectResourceChanges(final Monitorable monitorable, final ChangeType changeType) {
    List<ResourceChange> changes = new ArrayList<>();
    if (monitorable.status instanceof ContentFileStatus) {
        ContentFile contentFile = ((ContentFileStatus) monitorable.status).contentFile;
        if (changeType == ChangeType.CHANGED) {
            ContentElement content = contentFile.getContent();
            // we cannot easily report the diff of resource changes between two content files
            // so we simulate a removal of the toplevel node and then add all nodes contained in the current content file again.
            changes.add(buildContentResourceChange(ChangeType.REMOVED, transformPath(monitorable.path)));
            addContentResourceChanges(changes, ChangeType.ADDED, content, transformPath(monitorable.path));
        } else {
            addContentResourceChanges(changes, changeType, contentFile.getContent(), transformPath(monitorable.path));
        }
    } else {
        changes.add(buildContentResourceChange(changeType, transformPath(monitorable.path)));
    }
    return changes;
}
Also used : ContentFile(org.apache.sling.fsprovider.internal.mapper.ContentFile) ContentElement(org.apache.sling.fsprovider.internal.parser.ContentElement) ArrayList(java.util.ArrayList) ResourceChange(org.apache.sling.api.resource.observation.ResourceChange)

Example 2 with ContentFile

use of org.apache.sling.fsprovider.internal.mapper.ContentFile in project sling by apache.

the class FsNode method getNode.

@Override
public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
    if (relPath == null) {
        throw new PathNotFoundException();
    }
    // get absolute node path
    String path = relPath;
    if (!StringUtils.startsWith(path, "/")) {
        path = ResourceUtil.normalize(getPath() + "/" + relPath);
    }
    if (StringUtils.equals(path, contentFile.getPath()) || StringUtils.startsWith(path, contentFile.getPath() + "/")) {
        // node is contained in content file
        String subPath;
        if (StringUtils.equals(path, contentFile.getPath())) {
            subPath = null;
        } else {
            subPath = path.substring(contentFile.getPath().length() + 1);
        }
        ContentFile referencedFile = contentFile.navigateToAbsolute(subPath);
        if (referencedFile.hasContent()) {
            return new FsNode(referencedFile, resolver);
        }
    }
    // check if node is outside content file
    Node refNode = null;
    Resource resource = resolver.getResource(path);
    if (resource != null) {
        refNode = resource.adaptTo(Node.class);
        if (refNode != null) {
            return refNode;
        }
    }
    throw new PathNotFoundException(relPath);
}
Also used : ContentFile(org.apache.sling.fsprovider.internal.mapper.ContentFile) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

ContentFile (org.apache.sling.fsprovider.internal.mapper.ContentFile)2 ArrayList (java.util.ArrayList)1 Node (javax.jcr.Node)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceChange (org.apache.sling.api.resource.observation.ResourceChange)1 ContentElement (org.apache.sling.fsprovider.internal.parser.ContentElement)1