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;
}
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);
}
Aggregations