public void setProperty()

in src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java [112:157]


    public void setProperty(final Resource parent, final RequestProperty prop) throws PersistenceException {
        final Modifiable mod = new Modifiable();
        mod.resource = parent;
        mod.node = jcrSupport.getNode(parent);
        mod.valueMap = parent.adaptTo(ModifiableValueMap.class);
        if (mod.valueMap == null) {
            throw new PreconditionViolatedPersistenceException(
                    "Resource at '" + parent.getPath() + "' is not modifiable.");
        }

        final String name = prop.getName();
        if (prop.providesValue()) {
            // if user provided a value, don't mess with it
            setPropertyAsIs(mod, prop);

        } else if (AUTO_PROPS.containsKey(name)) {
            // check if this is a JCR resource and check node type
            if (this.jcrSupport.isPropertyProtectedOrNewAutoCreated(mod.node, name)) {
                return;
            }

            // avoid collision with protected properties
            final boolean isNew = jcrSupport.isNewNode(mod.node);
            switch (getAutoType(name)) {
                case CREATED:
                    if (isNew) {
                        setCurrentDate(mod, name);
                    }
                    break;
                case CREATED_BY:
                    if (isNew) {
                        setCurrentUser(mod, name);
                    }
                    break;
                case MODIFIED:
                    setCurrentDate(mod, name);
                    break;
                case MODIFIED_BY:
                    setCurrentUser(mod, name);
                    break;
            }
        } else {
            // no magic field, set value as provided
            setPropertyAsIs(mod, prop);
        }
    }