Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C47779894 for ; Fri, 1 Mar 2013 09:58:20 +0000 (UTC) Received: (qmail 60560 invoked by uid 500); 1 Mar 2013 09:58:20 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 60471 invoked by uid 500); 1 Mar 2013 09:58:19 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 60443 invoked by uid 99); 1 Mar 2013 09:58:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 09:58:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 09:58:13 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 50DDB23889DE; Fri, 1 Mar 2013 09:57:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1451548 - in /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource: JcrModifiablePropertyMap.java internal/JcrModifiableValueMap.java internal/NodeUtil.java internal/helper/jcr/JcrResourceProvider.java Date: Fri, 01 Mar 2013 09:57:53 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130301095753.50DDB23889DE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Fri Mar 1 09:57:52 2013 New Revision: 1451548 URL: http://svn.apache.org/r1451548 Log: SLING-2761 : JcrResourceProvider.create should filter protected properties Added: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java (with props) Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java?rev=1451548&r1=1451547&r2=1451548&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java (original) +++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java Fri Mar 1 09:57:52 2013 @@ -25,16 +25,15 @@ import java.util.Set; import javax.jcr.Node; import javax.jcr.RepositoryException; -import javax.jcr.Value; -import javax.jcr.nodetype.NodeType; import org.apache.sling.api.resource.PersistableValueMap; import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.jcr.resource.internal.NodeUtil; import org.apache.sling.jcr.resource.internal.helper.JcrPropertyMapCacheEntry; /** * This implementation of the value map allows to change - * the properies and save them later on. + * the properties and save them later on. */ public final class JcrModifiablePropertyMap extends JcrPropertyMap @@ -65,6 +64,7 @@ public final class JcrModifiableProperty /** * @see java.util.Map#clear() */ + @Override public void clear() { // we have to read all properties first this.readFully(); @@ -79,6 +79,7 @@ public final class JcrModifiableProperty /** * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ + @Override public Object put(String aKey, Object value) { final String key = checkKey(aKey); if ( key.indexOf('/') != -1 ) { @@ -105,6 +106,7 @@ public final class JcrModifiableProperty /** * @see java.util.Map#putAll(java.util.Map) */ + @Override public void putAll(Map t) { readFully(); if ( t != null ) { @@ -120,6 +122,7 @@ public final class JcrModifiableProperty /** * @see java.util.Map#remove(java.lang.Object) */ + @Override public Object remove(Object aKey) { final String key = checkKey(aKey.toString()); readFully(); @@ -144,35 +147,6 @@ public final class JcrModifiableProperty this.fullyRead = false; } - /** Property for the mixin node types. */ - private static final String MIXIN_TYPES = "jcr:mixinTypes"; - - /** - * Update the mixin node types - */ - private void handleMixinTypes(final Node node, final Value[] mixinTypes) throws RepositoryException { - final Set newTypes = new HashSet(); - if ( mixinTypes != null ) { - for(final Value value : mixinTypes ) { - newTypes.add(value.getString()); - } - } - final Set oldTypes = new HashSet(); - for(final NodeType mixinType : node.getMixinNodeTypes()) { - oldTypes.add(mixinType.getName()); - } - for(final String name : oldTypes) { - if ( !newTypes.contains(name) ) { - node.removeMixin(name); - } else { - newTypes.remove(name); - } - } - for(final String name : newTypes) { - node.addMixin(name); - } - } - /** * @see org.apache.sling.api.resource.PersistableValueMap#save() */ @@ -185,19 +159,19 @@ public final class JcrModifiableProperty try { final Node node = getNode(); // check for mixin types - if ( this.changedProperties.contains(MIXIN_TYPES) ) { - if ( cache.containsKey(MIXIN_TYPES) ) { - final JcrPropertyMapCacheEntry entry = cache.get(MIXIN_TYPES); - handleMixinTypes(node, entry.values); + if ( this.changedProperties.contains(NodeUtil.MIXIN_TYPES) ) { + if ( cache.containsKey(NodeUtil.MIXIN_TYPES) ) { + final JcrPropertyMapCacheEntry entry = cache.get(NodeUtil.MIXIN_TYPES); + NodeUtil.handleMixinTypes(node, entry.values); } else { // remove all mixin types! - handleMixinTypes(node, null); + NodeUtil.handleMixinTypes(node, null); } } for(final String key : this.changedProperties) { final String name = escapeKeyName(key); - if ( !MIXIN_TYPES.equals(name) ) { + if ( !NodeUtil.MIXIN_TYPES.equals(name) ) { if ( cache.containsKey(key) ) { final JcrPropertyMapCacheEntry entry = cache.get(key); if ( entry.isMulti ) { @@ -210,7 +184,7 @@ public final class JcrModifiableProperty } } } - getNode().getSession().save(); + node.getSession().save(); this.reset(); } catch (final RepositoryException re) { throw new PersistenceException("Unable to persist changes.", re, getPath(), null); Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java?rev=1451548&r1=1451547&r2=1451548&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java (original) +++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java Fri Mar 1 09:57:52 2013 @@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory; /** * This implementation of the value map allows to change - * the properies. + * the properties. * * TODO : This adds a lot of duplicate code - we should consolidate. */ @@ -65,13 +65,13 @@ public final class JcrModifiableValueMap private final Node node; /** A cache for the properties. */ - final Map cache; + private final Map cache; /** A cache for the values. */ - final Map valueCache; + private final Map valueCache; - /** Has the node been read completly? */ - boolean fullyRead; + /** Has the node been read completely? */ + private boolean fullyRead; private final ClassLoader dynamicClassLoader; @@ -251,7 +251,7 @@ public final class JcrModifiableValueMap final String name = prop.getName(); String key = null; if ( name.indexOf("_x") != -1 ) { - // for compatiblity with older versions we use the (wrong) + // for compatibility with older versions we use the (wrong) // ISO9075 path encoding key = ISO9075.decode(name); if ( key.equals(name) ) { @@ -562,7 +562,7 @@ public final class JcrModifiableValueMap return type; } - private Map transformEntries( Map map) { + private Map transformEntries(final Map map) { Map transformedEntries = new LinkedHashMap(map.size()); for ( Map.Entry entry : map.entrySet() ) @@ -608,7 +608,7 @@ public final class JcrModifiableValueMap /** * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ - public Object put(String aKey, Object value) { + public Object put(final String aKey, final Object value) { final String key = checkKey(aKey); if ( key.indexOf('/') != -1 ) { throw new IllegalArgumentException("Invalid key: " + key); @@ -622,10 +622,16 @@ public final class JcrModifiableValueMap final JcrPropertyMapCacheEntry entry = new JcrPropertyMapCacheEntry(value, getNode().getSession()); this.cache.put(key, entry); final String name = escapeKeyName(key); - if ( entry.isMulti ) { - node.setProperty(name, entry.values); + if ( NodeUtil.MIXIN_TYPES.equals(name) ) { + NodeUtil.handleMixinTypes(node, entry.values); + } else if ( "jcr:primaryType".equals(name) ) { + node.setPrimaryType(entry.values[0].getString()); } else { - node.setProperty(name, entry.values[0]); + if ( entry.isMulti ) { + node.setProperty(name, entry.values); + } else { + node.setProperty(name, entry.values[0]); + } } } catch (final RepositoryException re) { throw new IllegalArgumentException("Value for key " + key + " can't be put into node: " + value, re); @@ -638,8 +644,7 @@ public final class JcrModifiableValueMap /** * @see java.util.Map#putAll(java.util.Map) */ - public void putAll(Map t) { - readFully(); + public void putAll(final Map t) { if ( t != null ) { final Iterator i = t.entrySet().iterator(); while (i.hasNext() ) { @@ -653,7 +658,7 @@ public final class JcrModifiableValueMap /** * @see java.util.Map#remove(java.lang.Object) */ - public Object remove(Object aKey) { + public Object remove(final Object aKey) { final String key = checkKey(aKey.toString()); readFully(); final Object oldValue = this.cache.remove(key); Added: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java?rev=1451548&view=auto ============================================================================== --- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java (added) +++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java Fri Mar 1 09:57:52 2013 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.jcr.resource.internal; + +import java.util.HashSet; +import java.util.Set; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.nodetype.NodeType; + +public abstract class NodeUtil { + + /** Property for the mixin node types. */ + public static final String MIXIN_TYPES = "jcr:mixinTypes"; + + /** Property for the node type. */ + public static final String NODE_TYPE = "jcr:primaryType"; + + /** + * Update the mixin node types + */ + public static void handleMixinTypes(final Node node, final Value[] mixinTypes) + throws RepositoryException { + final Set newTypes = new HashSet(); + if ( mixinTypes != null ) { + for(final Value value : mixinTypes ) { + newTypes.add(value.getString()); + } + } + final Set oldTypes = new HashSet(); + for(final NodeType mixinType : node.getMixinNodeTypes()) { + oldTypes.add(mixinType.getName()); + } + for(final String name : oldTypes) { + if ( !newTypes.contains(name) ) { + node.removeMixin(name); + } else { + newTypes.remove(name); + } + } + for(final String name : newTypes) { + node.addMixin(name); + } + } +} Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/NodeUtil.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1451548&r1=1451547&r2=1451548&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original) +++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Fri Mar 1 09:57:52 2013 @@ -53,6 +53,7 @@ import org.apache.sling.api.resource.Val import org.apache.sling.api.wrappers.ValueMapDecorator; import org.apache.sling.jcr.resource.JcrResourceUtil; import org.apache.sling.jcr.resource.internal.JcrModifiableValueMap; +import org.apache.sling.jcr.resource.internal.NodeUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -386,7 +387,7 @@ public class JcrResourceProvider public Resource create(final ResourceResolver resolver, final String path, final Map properties) throws PersistenceException { // check for node type - final Object nodeObj = (properties != null ? properties.get("jcr:primaryType") : null); + final Object nodeObj = (properties != null ? properties.get(NodeUtil.NODE_TYPE) : null); final String nodeType = (nodeObj != null ? nodeObj.toString() : null); try { final int lastPos = path.lastIndexOf('/'); @@ -407,8 +408,13 @@ public class JcrResourceProvider if ( properties != null ) { // create modifiable map final JcrModifiableValueMap jcrMap = new JcrModifiableValueMap(node, this.dynamicClassLoader); + // check mixin types first + final Object value = properties.get(NodeUtil.MIXIN_TYPES); + if ( value != null ) { + jcrMap.put(NodeUtil.MIXIN_TYPES, value); + } for(final Map.Entry entry : properties.entrySet()) { - if ( !"jcr:primaryType".equals(entry.getKey()) ) { + if ( !NodeUtil.NODE_TYPE.equals(entry.getKey()) && !NodeUtil.MIXIN_TYPES.equals(entry.getKey())) { try { jcrMap.put(entry.getKey(), entry.getValue()); } catch (final IllegalArgumentException iae) {