use of org.apache.jackrabbit.vault.fs.api.Aggregate in project sling by apache.
the class VltSerializationDataBuilder method findAggregateChain.
/**
* Returns the aggregates for a specific resource
*
* <p>
* In the simplest case, a single element is returned in the chain, signalling that the aggregate is a top-level
* one.
* </p>
*
* <p>
* For leaf aggregates, the list contains the top-most aggregates first and ends up with the leaf-most ones.
* </p>
*
* @param resource the resource to find the aggregate chain for
* @return a list of aggregates
* @throws IOException
* @throws RepositoryException
*/
private List<Aggregate> findAggregateChain(ResourceProxy resource) throws IOException, RepositoryException {
VaultFile vaultFile = fs.getFile(PlatformNameFormat.getPlatformPath(resource.getPath()));
if (vaultFile == null || vaultFile.getAggregate() == null) {
// this file might be a leaf aggregate of a vaultfile higher in the resource path ; so look for a
// parent higher
String parentPath = Text.getRelativeParent(resource.getPath(), 1);
while (!parentPath.equals("/")) {
VaultFile parentFile = fs.getFile(PlatformNameFormat.getPlatformPath(parentPath));
if (parentFile != null) {
Aggregate parentAggregate = parentFile.getAggregate();
ArrayList<Aggregate> parents = new ArrayList<>();
parents.add(parentAggregate);
List<Aggregate> chain = lookForAggregateInLeaves(resource, parentAggregate, parents);
if (chain != null) {
return chain;
}
}
parentPath = Text.getRelativeParent(parentPath, 1);
}
return null;
}
return Collections.singletonList(vaultFile.getAggregate());
}
use of org.apache.jackrabbit.vault.fs.api.Aggregate in project sling by apache.
the class VltSerializationDataBuilder method calculateFileOrFolderPathHint.
private String calculateFileOrFolderPathHint(List<Aggregate> chain) throws RepositoryException {
ListIterator<Aggregate> aggs = chain.listIterator();
StringBuilder out = new StringBuilder();
while (aggs.hasNext()) {
Aggregate cur = aggs.next();
if (aggs.previousIndex() == 0) {
out.append(PlatformNameFormat.getPlatformPath(cur.getPath()));
} else {
out.append("/");
out.append(PlatformNameFormat.getPlatformPath(cur.getRelPath()));
}
if (needsDir(cur)) {
SerializationKind serializationKind = getSerializationKind(cur);
if (serializationKind == SerializationKind.FILE) {
out.append(".dir");
}
if (!aggs.hasNext() && serializationKind == SerializationKind.METADATA_FULL) {
out.delete(out.lastIndexOf("/"), out.length());
}
}
}
return out.toString();
}
use of org.apache.jackrabbit.vault.fs.api.Aggregate in project sling by apache.
the class VltSerializationDataBuilder method buildSerializationData.
@Override
public SerializationData buildSerializationData(File contentSyncRoot, ResourceProxy resource) throws SerializationException {
try {
List<Aggregate> chain = findAggregateChain(resource);
if (chain == null) {
return null;
}
Aggregate aggregate = chain.get(chain.size() - 1);
String fileOrFolderPathHint = calculateFileOrFolderPathHint(chain);
String nameHint = PlatformNameFormat.getPlatformName(aggregate.getName());
SerializationKind serializationKind = getSerializationKind(aggregate);
if (resource.getPath().equals("/") || serializationKind == SerializationKind.METADATA_PARTIAL || serializationKind == SerializationKind.FILE || serializationKind == SerializationKind.FOLDER) {
nameHint = Constants.DOT_CONTENT_XML;
} else if (serializationKind == SerializationKind.METADATA_FULL) {
nameHint += ".xml";
}
Activator.getDefault().getPluginLogger().trace("Got location {0} for path {1}", fileOrFolderPathHint, resource.getPath());
if (!needsDir(aggregate)) {
return SerializationData.empty(fileOrFolderPathHint, serializationKind);
}
DocViewSerializer s = new DocViewSerializer(aggregate);
ByteArrayOutputStream out = new ByteArrayOutputStream();
s.writeContent(out);
byte[] result = out.toByteArray();
return new SerializationData(fileOrFolderPathHint, nameHint, result, serializationKind);
} catch (RepositoryException e) {
throw new SerializationException(e);
} catch (IOException e) {
throw new SerializationException(e);
}
}
Aggregations