Search in sources :

Example 6 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet 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)

Example 7 with PathFilterSet

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

the class VltUtils method createFilter.

public static WorkspaceFilter createFilter(DistributionRequest distributionRequest, NavigableMap<String, List<String>> nodeFilters, NavigableMap<String, List<String>> propertyFilters) {
    DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
    for (String path : distributionRequest.getPaths()) {
        // Set node path filters
        List<String> patterns = new ArrayList<String>();
        patterns.addAll(Arrays.asList(distributionRequest.getFilters(path)));
        boolean deep = distributionRequest.isDeep(path);
        PathFilterSet nodeFilterSet = new PathFilterSet(path);
        if (!deep) {
            nodeFilterSet.addInclude(new DefaultPathFilter(path));
        }
        initFilterSet(nodeFilterSet, nodeFilters, patterns);
        filter.add(nodeFilterSet);
        // Set property path filters
        PathFilterSet propertyFilterSet = new PathFilterSet("/");
        initFilterSet(propertyFilterSet, propertyFilters, new ArrayList<String>());
        filter.addPropertyFilterSet(propertyFilterSet);
    }
    return filter;
}
Also used : DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) ArrayList(java.util.ArrayList) DefaultPathFilter(org.apache.jackrabbit.vault.fs.filter.DefaultPathFilter)

Example 8 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet 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 9 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractPackagerServlet method getPackagerPageResource.

/**
 * Gets the Packager Page resource.
 *
 * @param request the Sling HTTP Servlet Request object
 * @return a the PathFilterSet wrapping the cq:Page or null
 */
protected PathFilterSet getPackagerPageResource(final SlingHttpServletRequest request) {
    final ResourceResolver resourceResolver = request.getResourceResolver();
    final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    final Page page = pageManager.getContainingPage(request.getResource());
    if (page != null) {
        return new PathFilterSet(page.getPath());
    }
    return null;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Page(com.day.cq.wcm.api.Page)

Example 10 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractPackagerServlet method doPackaging.

protected void doPackaging(SlingHttpServletRequest request, SlingHttpServletResponse response, boolean preview, ValueMap properties, List<PathFilterSet> packageResources) throws IOException, JSONException, RepositoryException {
    // Add the ACL Packager Configuration page
    if (properties.get(INCLUDE_CONFIGURATION, DEFAULT_INCLUDE_CONFIGURATION)) {
        final PathFilterSet tmp = this.getPackagerPageResource(request);
        if (tmp != null) {
            packageResources.add(tmp);
        }
    }
    final Map<String, String> packageDefinitionProperties = new HashMap<String, String>();
    // ACL Handling
    packageDefinitionProperties.put(JcrPackageDefinition.PN_AC_HANDLING, properties.get(PACKAGE_ACL_HANDLING, AccessControlHandling.OVERWRITE.toString()));
    // Package Description
    packageDefinitionProperties.put(JcrPackageDefinition.PN_DESCRIPTION, properties.get(PACKAGE_DESCRIPTION, getDefaultPackageDescription()));
    if (preview) {
        // Handle preview mode
        response.getWriter().print(getPackageHelper().getPathFilterSetPreviewJSON(packageResources));
    } else if (packageResources == null || packageResources.isEmpty()) {
        // Do not create empty packages; This will only clutter up CRX Package Manager
        response.getWriter().print(getPackageHelper().getErrorJSON("Refusing to create a package with no filter " + "set rules."));
    } else {
        // Create JCR Package; Defaults should always be passed in via Request Parameters, but just in case
        final JcrPackage jcrPackage = getPackageHelper().createPackageFromPathFilterSets(packageResources, request.getResourceResolver().adaptTo(Session.class), properties.get(PACKAGE_GROUP_NAME, getDefaultPackageGroupName()), properties.get(PACKAGE_NAME, getDefaultPackageName()), properties.get(PACKAGE_VERSION, DEFAULT_PACKAGE_VERSION), PackageHelper.ConflictResolution.valueOf(properties.get(CONFLICT_RESOLUTION, PackageHelper.ConflictResolution.IncrementVersion.toString())), packageDefinitionProperties);
        String thumbnailPath = getPackageThumbnailPath();
        if (thumbnailPath != null) {
            // Add thumbnail to the package definition
            getPackageHelper().addThumbnail(jcrPackage, request.getResourceResolver().getResource(thumbnailPath));
        }
        log.debug("Successfully created JCR package");
        response.getWriter().print(getPackageHelper().getSuccessJSON(jcrPackage));
    }
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) HashMap(java.util.HashMap) JcrPackage(org.apache.jackrabbit.vault.packaging.JcrPackage)

Aggregations

PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)18 ArrayList (java.util.ArrayList)7 RepositoryException (javax.jcr.RepositoryException)4 WorkspaceFilter (org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)4 DefaultWorkspaceFilter (org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter)4 Test (org.junit.Test)4 DefaultPathFilter (org.apache.jackrabbit.vault.fs.filter.DefaultPathFilter)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 JSONArray (org.apache.sling.commons.json.JSONArray)3 JSONObject (org.apache.sling.commons.json.JSONObject)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 JcrPackage (org.apache.jackrabbit.vault.packaging.JcrPackage)2 Resource (org.apache.sling.api.resource.Resource)2 JSONException (org.apache.sling.commons.json.JSONException)2