use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class AbstractAuthorizablePostServlet method getOrCreateRequestProperty.
/**
* Returns the request property for the given property path. If such a
* request property does not exist yet it is created and stored in the
* <code>props</code>.
*
* @param props The map of already seen request properties
* (key is the property path).
* @param paramPath The absolute path of the property including the
* <code>suffix</code> to be looked up.
* @param suffix The (optional) suffix to remove from the
* <code>paramName</code> before looking it up.
* @return The {@link RequestProperty} for the <code>paramName</code>.
*/
private RequestProperty getOrCreateRequestProperty(Map<String, RequestProperty> props, String paramPath, String suffix) {
if (suffix != null && paramPath.endsWith(suffix)) {
paramPath = paramPath.substring(0, paramPath.length() - suffix.length());
}
RequestProperty prop = props.get(paramPath);
if (prop == null) {
prop = new RequestProperty(paramPath);
props.put(paramPath, prop);
}
return prop;
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty 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.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method testSingleValueWithDefaultToNull.
@Test
public void testSingleValueWithDefaultToNull() throws Throwable {
Map<String, RequestProperty> props = collectContent(p("./param", ""), p("./param@DefaultValue", ":null"));
assertEquals(1, props.size());
RequestProperty prop = props.get("/test/path/param");
assertTrue(prop.hasValues());
assertTrue(prop.providesValue());
assertNull(prop.getStringValues());
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method testMultiValueWithBlanksIgnoringBlanks.
@Test
public void testMultiValueWithBlanksIgnoringBlanks() throws Throwable {
Map<String, RequestProperty> props = collectContent(p("./param", "true", "", ""), p("./param@IgnoreBlanks", "true"));
assertEquals(1, props.size());
RequestProperty prop = props.get("/test/path/param");
assertTrue(prop.hasValues());
assertTrue(prop.providesValue());
assertEquals(1, prop.getStringValues().length);
assertEquals("true", prop.getStringValues()[0]);
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class AbstractCreateOperation method getOrCreateRequestProperty.
/**
* Returns the request property for the given property path. If such a
* request property does not exist yet it is created and stored in the
* <code>props</code>.
*
* @param props The map of already seen request properties.
* @param paramName The absolute path of the property including the
* <code>suffix</code> to be looked up.
* @param suffix The (optional) suffix to remove from the
* <code>paramName</code> before looking it up.
* @return The {@link RequestProperty} for the <code>paramName</code>.
*/
private RequestProperty getOrCreateRequestProperty(Map<String, RequestProperty> props, String paramName, String suffix) {
if (suffix != null && paramName.endsWith(suffix)) {
paramName = paramName.substring(0, paramName.length() - suffix.length());
}
RequestProperty prop = props.get(paramName);
if (prop == null) {
prop = new RequestProperty(paramName);
props.put(paramName, prop);
}
return prop;
}
Aggregations