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);
}
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;
}
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()));
}
}
}
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);
}
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;
}
Aggregations