Search in sources :

Example 1 with WorkspaceFilter

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

the class VltUtilsTest method testDeepFilter.

@Test
public void testDeepFilter() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(ADD, true, "/foo");
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    nodeFilters.put("/foo", Arrays.asList("/foo/bar", "/foo/bar1"));
    NavigableMap<String, List<String>> propFilters = new TreeMap<String, List<String>>();
    propFilters.put("/", Arrays.asList("^.*/prop1", "^.*/prop2"));
    WorkspaceFilter wsFilter = VltUtils.createFilter(request, nodeFilters, propFilters);
    assertNotNull(wsFilter);
    assertNotNull(wsFilter.getPropertyFilterSets());
    List<PathFilterSet> propFilterSet = wsFilter.getPropertyFilterSets();
    assertEquals(1, propFilterSet.size());
    PathFilterSet propFilter = propFilterSet.get(0);
    assertEquals(2, propFilter.getEntries().size());
    PathFilter filter = propFilter.getEntries().get(0).getFilter();
    assertTrue(filter.matches("/foo/bar/prop1"));
    assertTrue(filter.matches("/foo/prop1"));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) PathFilter(org.apache.jackrabbit.vault.fs.api.PathFilter) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) List(java.util.List) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 2 with WorkspaceFilter

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

the class VltUtils method getPaths.

public static String[] getPaths(MetaInf metaInf) {
    if (metaInf == null) {
        return null;
    }
    WorkspaceFilter filter = metaInf.getFilter();
    if (filter == null) {
        filter = new DefaultWorkspaceFilter();
    }
    List<PathFilterSet> filterSets = filter.getFilterSets();
    String[] paths = new String[filterSets.size()];
    for (int i = 0; i < paths.length; i++) {
        paths[i] = filterSets.get(i).getRoot();
    }
    return paths;
}
Also used : DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)

Example 3 with WorkspaceFilter

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

the class FileVaultContentSerializer method exportToStream.

@Override
public void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions exportOptions, OutputStream outputStream) throws DistributionException {
    Session session = null;
    try {
        session = getSession(resourceResolver);
        String packageGroup = PACKAGE_GROUP;
        String packageName = TYPE + "_" + System.currentTimeMillis() + "_" + UUID.randomUUID();
        WorkspaceFilter filter = VltUtils.createFilter(exportOptions.getRequest(), nodeFilters, propertyFilters);
        ExportOptions opts = VltUtils.getExportOptions(filter, packageRoots, packageGroup, packageName, VERSION, useBinaryReferences);
        log.debug("assembling package {} user {}", packageGroup + '/' + packageName + "-" + VERSION, resourceResolver.getUserID());
        packaging.getPackageManager().assemble(session, opts, outputStream);
    } catch (Exception e) {
        throw new DistributionException(e);
    } finally {
        ungetSession(session);
    }
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) ExportOptions(org.apache.jackrabbit.vault.packaging.ExportOptions) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter) DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionException(org.apache.sling.distribution.common.DistributionException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 4 with WorkspaceFilter

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

the class VltUtilsTest method testEmptyFilter.

@Test
public void testEmptyFilter() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(ADD, true, "/foo");
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    NavigableMap<String, List<String>> propFilters = new TreeMap<String, List<String>>();
    WorkspaceFilter filter = VltUtils.createFilter(request, nodeFilters, propFilters);
    assertNotNull(filter);
    assertNotNull(filter.getPropertyFilterSets());
    List<PathFilterSet> propFilterSet = filter.getPropertyFilterSets();
    assertEquals(1, propFilterSet.size());
    PathFilterSet propFilter = propFilterSet.get(0);
    assertTrue(propFilter.getEntries().isEmpty());
    assertEquals("/", propFilter.getRoot());
    assertNotNull(filter.getFilterSets());
    List<PathFilterSet> nodeFilterSet = filter.getFilterSets();
    assertEquals(1, nodeFilterSet.size());
    PathFilterSet nodeFilter = nodeFilterSet.get(0);
    assertTrue(nodeFilter.getEntries().isEmpty());
    assertEquals("/foo", nodeFilter.getRoot());
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) List(java.util.List) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 5 with WorkspaceFilter

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

the class FileVaultXmlMounter method mount.

/**
     * Add configurations to a running OSGi instance for FileVault XML
     * @param targetUrl The web console base url
     * @param jcrRootFile jcr_root directory
     * @param filterXmlFile FileVault Filter XML file
     * @throws MojoExecutionException
     */
public void mount(final String targetUrl, final File jcrRootFile, final File filterXmlFile) throws MojoExecutionException {
    log.info("Trying to configure file system provider...");
    // create config for each path defined in filter
    final List<FsResourceConfiguration> cfgs = new ArrayList<>();
    WorkspaceFilter workspaceFilter = getWorkspaceFilter(filterXmlFile);
    for (PathFilterSet filterSet : workspaceFilter.getFilterSets()) {
        cfgs.add(new FsResourceConfiguration().fsMode(FsMode.FILEVAULT_XML).contentRootDir(jcrRootFile.getAbsolutePath()).providerRootPath(filterSet.getRoot()).fileVaultFilterXml(filterXmlFile.getAbsolutePath()));
    }
    if (!cfgs.isEmpty()) {
        helper.addConfigurations(targetUrl, cfgs);
    }
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) ArrayList(java.util.ArrayList) DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)

Aggregations

WorkspaceFilter (org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)5 PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)4 List (java.util.List)2 TreeMap (java.util.TreeMap)2 DefaultWorkspaceFilter (org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter)2 DistributionRequest (org.apache.sling.distribution.DistributionRequest)2 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 PathFilter (org.apache.jackrabbit.vault.fs.api.PathFilter)1 ExportOptions (org.apache.jackrabbit.vault.packaging.ExportOptions)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 DistributionExportOptions (org.apache.sling.distribution.serialization.DistributionExportOptions)1