Search in sources :

Example 1 with VaultFile

use of org.apache.jackrabbit.vault.fs.api.VaultFile in project sling by apache.

the class VltSerializationManager method main.

public static void main(String[] args) throws RepositoryException, URISyntaxException, IOException {
    RepositoryAddress address = new RepositoryAddress("http://localhost:8080/server/root");
    Repository repo = new RepositoryProvider().getRepository(address);
    Session session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
    VaultFileSystem fs = Mounter.mount(null, null, address, "/", session);
    String[] attempts = new String[] { "/rep:policy", "/var" };
    for (String attempt : attempts) {
        VaultFile vaultFile = fs.getFile(attempt);
        System.out.println(attempt + " -> " + vaultFile);
    }
    for (String attempt : attempts) {
        attempt = PlatformNameFormat.getPlatformPath(attempt) + EXTENSION_XML;
        VaultFile vaultFile = fs.getFile(attempt);
        System.out.println(attempt + " -> " + vaultFile);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) Repository(javax.jcr.Repository) VaultFileSystem(org.apache.jackrabbit.vault.fs.api.VaultFileSystem) VaultFile(org.apache.jackrabbit.vault.fs.api.VaultFile) RepositoryProvider(org.apache.jackrabbit.vault.util.RepositoryProvider) Session(javax.jcr.Session)

Example 2 with VaultFile

use of org.apache.jackrabbit.vault.fs.api.VaultFile 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());
}
Also used : ArrayList(java.util.ArrayList) VaultFile(org.apache.jackrabbit.vault.fs.api.VaultFile) Aggregate(org.apache.jackrabbit.vault.fs.api.Aggregate)

Aggregations

VaultFile (org.apache.jackrabbit.vault.fs.api.VaultFile)2 ArrayList (java.util.ArrayList)1 Repository (javax.jcr.Repository)1 Session (javax.jcr.Session)1 SimpleCredentials (javax.jcr.SimpleCredentials)1 Aggregate (org.apache.jackrabbit.vault.fs.api.Aggregate)1 RepositoryAddress (org.apache.jackrabbit.vault.fs.api.RepositoryAddress)1 VaultFileSystem (org.apache.jackrabbit.vault.fs.api.VaultFileSystem)1 RepositoryProvider (org.apache.jackrabbit.vault.util.RepositoryProvider)1