Search in sources :

Example 71 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class RedirectServletTest method assertStatus.

private static void assertStatus(final int expectedStatus, final int testStatus) {
    final ValueMap valueMap;
    if (testStatus == -2) {
        valueMap = null;
    } else if (testStatus == -1) {
        valueMap = new ValueMapDecorator(new HashMap<String, Object>());
    } else {
        valueMap = new ValueMapDecorator(Collections.singletonMap(RedirectServlet.STATUS_PROP, (Object) testStatus));
    }
    final int actualStatus = RedirectServlet.getStatus(valueMap);
    assertEquals(expectedStatus, actualStatus);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator)

Example 72 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class CopyOperation method copy.

/**
     * Copy the source as a child resource to the parent
     */
private Resource copy(final Resource source, final Resource dest) throws PersistenceException {
    final ValueMap vm = source.getValueMap();
    final Resource result = source.getResourceResolver().create(dest, source.getName(), vm);
    for (final Resource c : source.getChildren()) {
        copy(c, result);
    }
    return result;
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 73 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class ModifyOperation method processDeletes.

/**
     * Removes all properties listed as {@link RequestProperty#isDelete()} from
     * the resource.
     *
     * @param resolver The <code>ResourceResolver</code> used to access the
     *            resources to delete the properties.
     * @param reqProperties The map of request properties to check for
     *            properties to be removed.
     * @param response The <code>HtmlResponse</code> to be updated with
     *            information on deleted properties.
     * @throws PersistenceException Is thrown if an error occurs checking or
     *             removing properties.
     */
private void processDeletes(final ResourceResolver resolver, final Map<String, RequestProperty> reqProperties, final List<Modification> changes, final VersioningConfiguration versioningConfiguration) throws PersistenceException {
    for (final RequestProperty property : reqProperties.values()) {
        if (property.isDelete()) {
            final Resource parent = resolver.getResource(property.getParentPath());
            if (parent == null) {
                continue;
            }
            this.jcrSsupport.checkoutIfNecessary(parent, changes, versioningConfiguration);
            final ValueMap vm = parent.adaptTo(ModifiableValueMap.class);
            if (vm == null) {
                throw new PersistenceException("Resource '" + parent.getPath() + "' is not modifiable.");
            }
            if (vm.containsKey(property.getName())) {
                if (JcrConstants.JCR_MIXINTYPES.equals(property.getName())) {
                    vm.put(JcrConstants.JCR_MIXINTYPES, new String[0]);
                } else {
                    vm.remove(property.getName());
                }
            } else {
                final Resource childRsrc = resolver.getResource(parent.getPath() + '/' + property.getName());
                if (childRsrc != null) {
                    resolver.delete(childRsrc);
                }
            }
            changes.add(Modification.onDeleted(property.getPath()));
        }
    }
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource) PersistenceException(org.apache.sling.api.resource.PersistenceException)

Example 74 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class MoveOperation method move.

/**
     * Move the source as a child resource to the parent
     */
private void move(final Resource source, final Resource dest) throws PersistenceException {
    // first copy
    final ValueMap vm = source.getValueMap();
    final Resource result = source.getResourceResolver().create(dest, source.getName(), vm);
    for (final Resource c : source.getChildren()) {
        move(c, result);
    }
    // then delete
    source.getResourceResolver().delete(source);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 75 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class SuperimposingManagerImplTest method prepareSuperimposingResource.

private Resource prepareSuperimposingResource(String superimposedPath, String sourcePath, boolean registerParent, boolean overlayable) {
    Resource resource = mock(Resource.class);
    when(resource.getPath()).thenReturn(superimposedPath);
    ValueMap props = new ValueMapDecorator(new HashMap<String, Object>());
    props.put(PROP_SUPERIMPOSE_SOURCE_PATH, sourcePath);
    props.put(PROP_SUPERIMPOSE_REGISTER_PARENT, registerParent);
    props.put(PROP_SUPERIMPOSE_OVERLAYABLE, overlayable);
    when(resource.adaptTo(ValueMap.class)).thenReturn(props);
    when(resourceResolver.getResource(superimposedPath)).thenReturn(resource);
    return resource;
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator)

Aggregations

ValueMap (org.apache.sling.api.resource.ValueMap)278 Resource (org.apache.sling.api.resource.Resource)205 Test (org.junit.Test)160 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)59 HashMap (java.util.HashMap)54 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)44 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)26 Map (java.util.Map)21 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)21 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)20 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)20 Expectations (org.jmock.Expectations)20 ArrayList (java.util.ArrayList)18 PersistenceException (org.apache.sling.api.resource.PersistenceException)17 Calendar (java.util.Calendar)16 Date (java.util.Date)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)12 InputStream (java.io.InputStream)11 Node (javax.jcr.Node)11