Search in sources :

Example 6 with RequestProperty

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;
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty)

Example 7 with RequestProperty

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()));
        }
    }
}
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 8 with RequestProperty

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());
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) Test(org.junit.Test)

Example 9 with RequestProperty

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]);
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) Test(org.junit.Test)

Example 10 with RequestProperty

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;
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty)

Aggregations

RequestProperty (org.apache.sling.servlets.post.impl.helper.RequestProperty)26 Test (org.junit.Test)12 RepositoryException (javax.jcr.RepositoryException)5 Resource (org.apache.sling.api.resource.Resource)5 HashMap (java.util.HashMap)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 RequestParameter (org.apache.sling.api.request.RequestParameter)4 Map (java.util.Map)3 Group (org.apache.jackrabbit.api.security.user.Group)3 Session (javax.jcr.Session)2 User (org.apache.jackrabbit.api.security.user.User)2 RequestParameterMap (org.apache.sling.api.request.RequestParameterMap)2 LoginException (org.apache.sling.api.resource.LoginException)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)2 IOException (java.io.IOException)1