Remove deprecated jcr resource API (SLING-5983).
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/resource@1790951 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java b/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
deleted file mode 100644
index 9eb4fc6..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * 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;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
-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;
-import org.slf4j.LoggerFactory;
-
-/**
- * This implementation of the value map allows to change
- * the properties and save them later on.
- *
- * @deprecated Resources should be adapted to a modifiable value map instead
- */
-@SuppressWarnings("deprecation")
-@Deprecated
-public final class JcrModifiablePropertyMap
- extends JcrPropertyMap
- implements PersistableValueMap {
-
- private static volatile boolean LOG_DEPRECATED = true;
-
- /** Set of removed and changed properties. */
- private Set<String> changedProperties;
-
- /**
- * Constructor
- * @param node The underlying node.
- */
- public JcrModifiablePropertyMap(final Node node) {
- super(node);
- if ( LOG_DEPRECATED ) {
- LOG_DEPRECATED = false;
- LoggerFactory.getLogger(this.getClass()).warn("DEPRECATION WARNING: JcrModifiablePropertyMap is deprecated. Please switch to resource API.");
- }
- }
-
- /**
- * Constructor
- * @param node The underlying node.
- * @param dynamicCL Dynamic class loader for loading serialized objects.
- * @since 2.0.6
- */
- public JcrModifiablePropertyMap(final Node node, final ClassLoader dynamicCL) {
- super(node, dynamicCL);
- if ( LOG_DEPRECATED ) {
- LOG_DEPRECATED = false;
- LoggerFactory.getLogger(this.getClass()).warn("DEPRECATION WARNING: JcrModifiablePropertyMap is deprecated. Please switch to resource API.");
- }
- }
-
- // ---------- Map
- /**
- * @see java.util.Map#clear()
- */
- @Override
- public void clear() {
- // we have to read all properties first
- this.readFully();
- if ( this.changedProperties == null ) {
- this.changedProperties = new HashSet<String>();
- }
- this.changedProperties.addAll(this.cache.keySet());
- this.cache.clear();
- this.valueCache.clear();
- }
-
- /**
- * @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 ) {
- throw new IllegalArgumentException("Invalid key: " + key);
- }
- if ( value == null ) {
- throw new NullPointerException("Value should not be null (key = " + key + ")");
- }
- readFully();
- final Object oldValue = this.get(key);
- try {
- this.cache.put(key, new JcrPropertyMapCacheEntry(value, this.getNode()));
- } catch (final RepositoryException re) {
- throw new IllegalArgumentException("Value for key " + key + " can't be put into node: " + value, re);
- }
- this.valueCache.put(key, value);
- if ( this.changedProperties == null ) {
- this.changedProperties = new HashSet<String>();
- }
- this.changedProperties.add(key);
- return oldValue;
- }
-
- /**
- * @see java.util.Map#putAll(java.util.Map)
- */
- @Override
- public void putAll(Map<? extends String, ? extends Object> t) {
- readFully();
- if ( t != null ) {
- final Iterator<?> i = t.entrySet().iterator();
- while (i.hasNext() ) {
- @SuppressWarnings("unchecked")
- final Map.Entry<? extends String, ? extends Object> entry = (Map.Entry<? extends String, ? extends Object>) i.next();
- put(entry.getKey(), entry.getValue());
- }
- }
- }
-
- /**
- * @see java.util.Map#remove(java.lang.Object)
- */
- @Override
- public Object remove(Object aKey) {
- final String key = checkKey(aKey.toString());
- readFully();
- final Object oldValue = this.cache.remove(key);
- this.valueCache.remove(key);
- if ( this.changedProperties == null ) {
- this.changedProperties = new HashSet<String>();
- }
- this.changedProperties.add(key);
- return oldValue;
- }
-
- /**
- * @see org.apache.sling.api.resource.PersistableValueMap#reset()
- */
- @Override
- public void reset() {
- if ( this.changedProperties != null ) {
- this.changedProperties = null;
- }
- this.cache.clear();
- this.valueCache.clear();
- this.fullyRead = false;
- }
-
- /**
- * @see org.apache.sling.api.resource.PersistableValueMap#save()
- */
- @Override
- @SuppressWarnings("javadoc")
- public void save() throws PersistenceException {
- if ( this.changedProperties == null || this.changedProperties.size() == 0 ) {
- // nothing has changed
- return;
- }
- try {
- final Node node = getNode();
- // check for mixin types
- 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.convertToType(String[].class, node, getDynamicClassLoader()));
- } else {
- // remove all mixin types!
- NodeUtil.handleMixinTypes(node, null);
- }
- }
-
- for(final String key : this.changedProperties) {
- final String name = escapeKeyName(key);
- if ( !NodeUtil.MIXIN_TYPES.equals(name) ) {
- if ( cache.containsKey(key) ) {
- final JcrPropertyMapCacheEntry entry = cache.get(key);
- if ( entry.isArray() ) {
- node.setProperty(name, entry.convertToType(Value[].class, node, getDynamicClassLoader()));
- } else {
- node.setProperty(name, entry.convertToType(Value.class, node, getDynamicClassLoader()));
- }
- } else {
- if ( node.hasProperty(name) ) {
- node.getProperty(name).remove();
- }
- }
- }
- }
- node.getSession().save();
- this.reset();
- } catch (final RepositoryException re) {
- throw new PersistenceException("Unable to persist changes.", re, getPath(), null);
- }
- }
-}
diff --git a/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java b/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
deleted file mode 100644
index d7b49f4..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
+++ /dev/null
@@ -1,513 +0,0 @@
-/*
- * 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;
-
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
-import org.apache.jackrabbit.util.ISO9075;
-import org.apache.jackrabbit.util.Text;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.jcr.resource.internal.helper.JcrPropertyMapCacheEntry;
-import org.slf4j.LoggerFactory;
-
-/**
- * An implementation of the value map based on a JCR node.
- * @see JcrModifiablePropertyMap
- *
- * @deprecated A (JCR) resource should be adapted to a {@link ValueMap}.
- */
-@Deprecated
-public class JcrPropertyMap
- implements ValueMap {
-
- private static volatile boolean LOG_DEPRECATED = true;
-
- /** The underlying node. */
- private final Node node;
-
- /** A cache for the properties. */
- final Map<String, JcrPropertyMapCacheEntry> cache;
-
- /** A cache for the values. */
- final Map<String, Object> valueCache;
-
- /** Has the node been read completely? */
- boolean fullyRead;
-
- /** keep all prefixes for escaping */
- private String[] namespacePrefixes;
-
- private final ClassLoader dynamicClassLoader;
-
- /**
- * Create a new JCR property map based on a node.
- * @param node The underlying node.
- */
- public JcrPropertyMap(final Node node) {
- this(node, null);
- }
-
- /**
- * Create a new JCR property map based on a node.
- * @param node The underlying node.
- * @param dynamicCL Dynamic class loader for loading serialized objects.
- * @since 2.0.8
- */
- public JcrPropertyMap(final Node node, final ClassLoader dynamicCL) {
- this.node = node;
- this.cache = new LinkedHashMap<String, JcrPropertyMapCacheEntry>();
- this.valueCache = new LinkedHashMap<String, Object>();
- this.fullyRead = false;
- this.dynamicClassLoader = dynamicCL;
- if ( LOG_DEPRECATED ) {
- LOG_DEPRECATED = false;
- LoggerFactory.getLogger(this.getClass()).warn("DEPRECATION WARNING: JcrPropertyMap is deprecated. Please switch to resource API.");
- }
- }
-
- protected ClassLoader getDynamicClassLoader() {
- return this.dynamicClassLoader;
- }
-
- /**
- * Get the node.
- *
- * @return the node
- */
- protected Node getNode() {
- return node;
- }
-
- // ---------- ValueMap
-
- String checkKey(final String key) {
- if ( key == null ) {
- throw new NullPointerException("Key must not be null.");
- }
- if ( key.startsWith("./") ) {
- return key.substring(2);
- }
- return key;
- }
-
- /**
- * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Class)
- */
- @Override
- @SuppressWarnings("unchecked")
- public <T> T get(final String aKey, final Class<T> type) {
- final String key = checkKey(aKey);
- if (type == null) {
- return (T) get(key);
- }
-
- final JcrPropertyMapCacheEntry entry = this.read(key);
- if ( entry == null ) {
- return null;
- }
- return entry.convertToType(type, this.node, this.getDynamicClassLoader());
- }
-
- /**
- * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Object)
- */
- @Override
- @SuppressWarnings("unchecked")
- public <T> T get(final String aKey,final T defaultValue) {
- final String key = checkKey(aKey);
- if (defaultValue == null) {
- return (T) get(key);
- }
-
- // special handling in case the default value implements one
- // of the interface types supported by the convertToType method
- Class<T> type = (Class<T>) normalizeClass(defaultValue.getClass());
-
- T value = get(key, type);
- if (value == null) {
- value = defaultValue;
- }
-
- return value;
- }
-
- // ---------- Map
-
- /**
- * @see java.util.Map#get(java.lang.Object)
- */
- @Override
- public Object get(final Object aKey) {
- final String key = checkKey(aKey.toString());
- final JcrPropertyMapCacheEntry entry = this.read(key);
- final Object value = (entry == null ? null : entry.getPropertyValueOrNull());
- return value;
- }
-
- /**
- * @see java.util.Map#containsKey(java.lang.Object)
- */
- @Override
- public boolean containsKey(final Object key) {
- return get(key) != null;
- }
-
- /**
- * @see java.util.Map#containsValue(java.lang.Object)
- */
- @Override
- public boolean containsValue(final Object value) {
- readFully();
- return valueCache.containsValue(value);
- }
-
- /**
- * @see java.util.Map#isEmpty()
- */
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- /**
- * @see java.util.Map#size()
- */
- @Override
- public int size() {
- readFully();
- return cache.size();
- }
-
- /**
- * @see java.util.Map#entrySet()
- */
- @Override
- public Set<java.util.Map.Entry<String, Object>> entrySet() {
- readFully();
- final Map<String, Object> sourceMap;
- if (cache.size() == valueCache.size()) {
- sourceMap = valueCache;
- } else {
- sourceMap = transformEntries(cache);
- }
- return Collections.unmodifiableSet(sourceMap.entrySet());
- }
-
- /**
- * @see java.util.Map#keySet()
- */
- @Override
- public Set<String> keySet() {
- readFully();
- return cache.keySet();
- }
-
- /**
- * @see java.util.Map#values()
- */
- @Override
- public Collection<Object> values() {
- readFully();
- final Map<String, Object> sourceMap;
- if (cache.size() == valueCache.size()) {
- sourceMap = valueCache;
- } else {
- sourceMap = transformEntries(cache);
- }
- return Collections.unmodifiableCollection(sourceMap.values());
- }
-
- /**
- * Return the path of the current node.
- *
- * @return the path
- * @throws IllegalStateException If a repository exception occurs
- * @deprecated
- */
- @Deprecated
- public String getPath() {
- try {
- return node.getPath();
- } catch (final RepositoryException e) {
- throw new IllegalStateException(e);
- }
- }
-
- // ---------- Helpers to access the node's property ------------------------
-
- /**
- * Put a single property into the cache
- * @param prop
- * @return the cached property
- * @throws IllegalArgumentException if a repository exception occurs
- */
- private JcrPropertyMapCacheEntry cacheProperty(final Property prop) {
- try {
- // calculate the key
- final String name = prop.getName();
- String key = null;
- if ( name.indexOf("_x") != -1 ) {
- // for compatibility with older versions we use the (wrong)
- // ISO9075 path encoding
- key = ISO9075.decode(name);
- if ( key.equals(name) ) {
- key = null;
- }
- }
- if ( key == null ) {
- key = Text.unescapeIllegalJcrChars(name);
- }
- JcrPropertyMapCacheEntry entry = cache.get(key);
- if ( entry == null ) {
- entry = new JcrPropertyMapCacheEntry(prop);
- cache.put(key, entry);
-
- final Object defaultValue = entry.getPropertyValue();
- if (defaultValue != null) {
- valueCache.put(key, entry.getPropertyValue());
- }
- }
- return entry;
- } catch (final RepositoryException re) {
- throw new IllegalArgumentException(re);
- }
- }
-
- /**
- * Read a single property.
- * @throws IllegalArgumentException if a repository exception occurs
- */
- JcrPropertyMapCacheEntry read(final String name) {
- // check for empty key
- if ( name.length() == 0 ) {
- return null;
- }
- // if the name is a path, we should handle this differently
- if ( name.indexOf('/') != -1 ) {
- // first a compatibility check with the old (wrong) ISO9075
- // encoding
- final String path = ISO9075.encodePath(name);
- try {
- if ( node.hasProperty(path) ) {
- return new JcrPropertyMapCacheEntry(node.getProperty(path));
- }
- } catch (final RepositoryException re) {
- throw new IllegalArgumentException(re);
- }
- // now we do a proper segment by segment encoding
- final StringBuilder sb = new StringBuilder();
- int pos = 0;
- int lastPos = -1;
- while ( pos < name.length() ) {
- if ( name.charAt(pos) == '/' ) {
- if ( lastPos + 1 < pos ) {
- sb.append(Text.escapeIllegalJcrChars(name.substring(lastPos + 1, pos)));
- }
- sb.append('/');
- lastPos = pos;
- }
- pos++;
- }
- if ( lastPos + 1 < pos ) {
- sb.append(Text.escapeIllegalJcrChars(name.substring(lastPos + 1)));
- }
- final String newPath = sb.toString();
- try {
- if ( node.hasProperty(newPath) ) {
- return new JcrPropertyMapCacheEntry(node.getProperty(newPath));
- }
- } catch (final RepositoryException re) {
- throw new IllegalArgumentException(re);
- }
-
- return null;
- }
-
- // check cache
- JcrPropertyMapCacheEntry cachedValued = cache.get(name);
- if ( fullyRead || cachedValued != null ) {
- return cachedValued;
- }
-
- final String key;
- try {
- key = escapeKeyName(name);
- if (node.hasProperty(key)) {
- final Property prop = node.getProperty(key);
- return cacheProperty(prop);
- }
- } catch (final RepositoryException re) {
- throw new IllegalArgumentException(re);
- }
-
- try {
- // for compatibility with older versions we use the (wrong) ISO9075 path
- // encoding
- final String oldKey = ISO9075.encodePath(name);
- if (!oldKey.equals(key) && node.hasProperty(oldKey)) {
- final Property prop = node.getProperty(oldKey);
- return cacheProperty(prop);
- }
- } catch (final RepositoryException re) {
- // we ignore this
- }
-
- // property not found
- return null;
- }
-
- /**
- * Handles key name escaping by taking into consideration if it contains a
- * registered prefix
- *
- * @param key the key to escape
- * @return escaped key name
- * @throws RepositoryException if the repository's namespaced prefixes cannot be retrieved
- */
- protected String escapeKeyName(final String key) throws RepositoryException {
- final int indexOfPrefix = key.indexOf(':');
- // check if colon is neither the first nor the last character
- if (indexOfPrefix > 0 && key.length() > indexOfPrefix + 1) {
- final String prefix = key.substring(0, indexOfPrefix);
- for (final String existingPrefix : getNamespacePrefixes()) {
- if (existingPrefix.equals(prefix)) {
- return prefix
- + ":"
- + Text.escapeIllegalJcrChars(key
- .substring(indexOfPrefix + 1));
- }
- }
- }
- return Text.escapeIllegalJcrChars(key);
- }
-
- /**
- * Read namespace prefixes and store as member variable to minimize number of JCR API calls
- *
- * @return the namespace prefixes
- * @throws RepositoryException if the namespace prefixes cannot be retrieved
- */
- protected String[] getNamespacePrefixes() throws RepositoryException {
- if (this.namespacePrefixes == null) {
- this.namespacePrefixes = getNode().getSession().getNamespacePrefixes();
- }
- return this.namespacePrefixes;
- }
-
- /**
- * Read all properties.
- * @throws IllegalArgumentException if a repository exception occurs
- */
- void readFully() {
- if (!fullyRead) {
- try {
- final PropertyIterator pi = node.getProperties();
- while (pi.hasNext()) {
- final Property prop = pi.nextProperty();
- this.cacheProperty(prop);
- }
- fullyRead = true;
- } catch (final RepositoryException re) {
- throw new IllegalArgumentException(re);
- }
- }
- }
-
- // ---------- Unsupported Modification methods
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Object put(String key, Object value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void putAll(Map<? extends String, ? extends Object> t) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Object remove(Object key) {
- throw new UnsupportedOperationException();
- }
-
- // ---------- Implementation helper
-
- private Class<?> normalizeClass(Class<?> type) {
- if (Calendar.class.isAssignableFrom(type)) {
- type = Calendar.class;
- } else if (Date.class.isAssignableFrom(type)) {
- type = Date.class;
- } else if (Value.class.isAssignableFrom(type)) {
- type = Value.class;
- } else if (Property.class.isAssignableFrom(type)) {
- type = Property.class;
- }
- return type;
- }
-
- private Map<String, Object> transformEntries( Map<String, JcrPropertyMapCacheEntry> map) {
-
- Map<String, Object> transformedEntries = new LinkedHashMap<String, Object>(map.size());
- for ( Map.Entry<String, JcrPropertyMapCacheEntry> entry : map.entrySet() )
- transformedEntries.put(entry.getKey(), entry.getValue().getPropertyValueOrNull());
-
- return transformedEntries;
- }
-
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("JcrPropertyMap [node=");
- sb.append(this.node);
- sb.append(", values={");
- final Iterator<Map.Entry<String, Object>> iter = this.entrySet().iterator();
- boolean first = true;
- while ( iter.hasNext() ) {
- if ( first ) {
- first = false;
- } else {
- sb.append(", ");
- }
- final Map.Entry<String, Object> e = iter.next();
- sb.append(e.getKey());
- sb.append("=");
- sb.append(e.getValue());
- }
- sb.append("}]");
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/apache/sling/jcr/resource/JcrResourceConstants.java b/src/main/java/org/apache/sling/jcr/resource/JcrResourceConstants.java
deleted file mode 100644
index 81e3669..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/JcrResourceConstants.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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;
-
-import org.apache.sling.api.SlingConstants;
-
-/**
- * The <code>JcrResourceConstants</code> interface provides constant values.
- *
- * @deprecated Use org.apache.sling.jcr.resource.api.JcrResourceConstants instead.
- */
-@Deprecated
-public class JcrResourceConstants {
-
- /**
- * The namespace URI used by Sling JCR for items and node types used by
- * Sling (value is "http://sling.apache.org/jcr/sling/1.0"). This URI is
- * ensured to be mapped to the Sling namespace prefix <em>sling</em> for any
- * session used by the JCR Resource bundle through the
- * <code>Sling-Namespaces</code> bundle manifest header.
- */
- public static final String SLING_NAMESPACE_URI = SlingConstants.NAMESPACE_URI_ROOT
- + "jcr/sling/1.0";
-
- /**
- * The name of the JCR Property that defines the resource type of this node
- * (value is "sling:resourceType"). The resource manager implementation of
- * this bundle uses this property to defined the resource type of a loaded
- * resource. If this property does not exist the primary node type is used
- * as the resource type.
- */
- public static final String SLING_RESOURCE_TYPE_PROPERTY = "sling:resourceType";
-
- /**
- * The name of the JCR Property that defines the resource super type (value
- * is "sling:resourceSuperType"). The resource manager implementation of
- * this bundle uses this property to defined the resource type of a loaded
- * resource. If this property does not exist any non-mixin base type of the
- * the primary node type is used as the resource super type.
- */
- public static final String SLING_RESOURCE_SUPER_TYPE_PROPERTY = "sling:resourceSuperType";
-
- /**
- * The name of the property providing the JCR credentials to be used by the
- * resource resolver factory method instead of the <code>user.name</code>
- * and <code>user.password</code> properties. If this propery is provided
- * and set to an object of type <code>javax.jcr.Credentials</code> the
- * <code>user.name</code> property is ignored.
- * <p>
- * This property is ignored by the
- * {@link org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)}
- * method or if the authentication info has a
- * {@link #AUTHENTICATION_INFO_SESSION} property set to a
- * <code>javax.jcr.Session</code> object.
- * <p>
- * The type of this property, if present, is
- * <code>javax.jcr.Credentials</code>.
- *
- * @since 2.1
- * @see org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map)
- */
- public static final String AUTHENTICATION_INFO_CREDENTIALS = "user.jcr.credentials";
-
- /**
- * The name of the authentication info property containing the workspace
- * name to which the JCR based resource resolver should provide access.
- * <p>
- * The type of this property, if present, is <code>String</code>.
- *
- * @since 2.1
- * @deprecated Workspaces are not supported anymore
- */
- @Deprecated
- public static final String AUTHENTICATION_INFO_WORKSPACE = "user.jcr.workspace";
-
- /**
- * The name of the authentication info property containing a JCR Session to
- * which a JCR based resource resolver should provide access. If this
- * property is set in the authentication info map, all other properties are
- * ignored for the creation of the resource resolver with the exception of
- * the <code>user.impersonation</code> which is still respected.
- * <p>
- * The session provided by as this property and used as the basis of newly
- * created resource resolver must not be logged out before the resource
- * resolver is closed. On the other closing the resource resolver not logout
- * this session.
- * <p>
- * This property is ignored by the
- * {@link org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)}
- * method.
- * <p>
- * The type of this property, if present, is <code>javax.jcr.Session</code>.
- *
- * @since 2.1
- */
- public static final String AUTHENTICATION_INFO_SESSION = "user.jcr.session";
-
- /**
- * Constant for the sling:Folder node type
- * @since 2.2
- */
- public static final String NT_SLING_FOLDER = "sling:Folder";
-
- /**
- * Constant for the sling:OrderedFolder node type
- * @since 2.2
- */
- public static final String NT_SLING_ORDERED_FOLDER = "sling:OrderedFolder";
-}
diff --git a/src/main/java/org/apache/sling/jcr/resource/JcrResourceResolverFactory.java b/src/main/java/org/apache/sling/jcr/resource/JcrResourceResolverFactory.java
deleted file mode 100644
index 7c0c917..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/JcrResourceResolverFactory.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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;
-
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceResolverFactory;
-
-/**
- * The <code>JcrResourceResolverFactory</code> interface defines the service
- * interface to have JCR-based <code>ResourceResolver</code> instances created
- * for JCR sessions.
- * <p>
- * This interface is not intended to be implemented by client applications. It
- * is implemented by this bundle and the implementation registered as a service
- * for use by client applications.
- *
- * This interface is deprecated. You should use
- * {@link org.apache.sling.api.resource.ResourceResolverFactory}
- * instead. If you need a resource resolver based on an existing session
- * you can create an authentication map just containing this session
- * (using the key {@link JcrResourceConstants#AUTHENTICATION_INFO_SESSION})
- * and then call {@link org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map)}
- * with exactly this map.
- *
- * @deprecated Since 2.1. Use the
- * {@link org.apache.sling.api.resource.ResourceResolverFactory}
- */
-@Deprecated
-public interface JcrResourceResolverFactory extends ResourceResolverFactory {
-
- /**
- * Returns a <code>ResourceResolver</code> for the given session. Calling
- * this method repeatedly returns a new instance on each call.
- * <p>
- * This method is equivalent to:
- *
- * <pre>
- * Map<String, Object> authInfo = new HashMap<String, Object>();
- * authInfo.put(SESSION, session);
- * return getResourceResolver(authInfo);
- * </pre>
- * <p>
- * <b>Note:</b> Closing the <code>ResourceResolver</code> returned by this
- * method will <b>not</b> close the provided <code>Session</code> ! Likewise
- * the provided <code>Session</code> should not be logged out before closing
- * the returned <code>ResourceResolver</code>.
- *
- * @param session The JCR <code>Session</code> used by the created resource
- * manager to access the repository.
- * @return the resource resolver
- */
- ResourceResolver getResourceResolver(Session session);
-
-}
diff --git a/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java b/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
deleted file mode 100644
index 45a5753..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * 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;
-
-import java.io.InputStream;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.StringTokenizer;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-import javax.jcr.query.QueryResult;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.jcr.resource.internal.helper.LazyInputStream;
-import org.slf4j.LoggerFactory;
-
-/**
- * The <code>JcrResourceUtil</code> class provides helper methods used
- * throughout this bundle.
- *
- * @deprecated Use the Resource API instead.
- */
-@Deprecated
-public class JcrResourceUtil {
-
- private static volatile boolean LOG_DEPRECATED_QUERY = true;
- private static volatile boolean LOG_DEPRECATED_TO_JAVA_OBJECT_1 = true;
- private static volatile boolean LOG_DEPRECATED_TO_JAVA_OBJECT_2 = true;
- private static volatile boolean LOG_DEPRECATED_CREATE_VALUE = true;
- private static volatile boolean LOG_DEPRECATED_SET_PROPERTY = true;
- private static volatile boolean LOG_DEPRECATED_CREATE_PATH_1 = true;
- private static volatile boolean LOG_DEPRECATED_CREATE_PATH_2 = true;
- private static volatile boolean LOG_DEPRECATED_GET_RST_1 = true;
- private static volatile boolean LOG_DEPRECATED_GET_RST_2 = true;
- private static volatile boolean LOG_DEPRECATED_RT_TO_PATH = true;
-
- /**
- * Helper method to execute a JCR query.
- *
- * @param session the session
- * @param query the query
- * @param language the language
- * @return the query's result
- * @throws RepositoryException if the {@link QueryManager} cannot be retrieved
- */
- public static QueryResult query(Session session, String query,
- String language) throws RepositoryException {
- if ( LOG_DEPRECATED_QUERY ) {
- LOG_DEPRECATED_QUERY = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.query is deprecated. Please use the resource resolver.");
- }
- QueryManager qManager = session.getWorkspace().getQueryManager();
- Query q = qManager.createQuery(query, language);
- return q.execute();
- }
-
- /**
- * Converts a JCR Value to a corresponding Java Object
- *
- * @param value the JCR Value to convert
- * @return the Java Object
- * @throws RepositoryException if the value cannot be converted
- */
- public static Object toJavaObject(Value value) throws RepositoryException {
- if ( LOG_DEPRECATED_TO_JAVA_OBJECT_1 ) {
- LOG_DEPRECATED_TO_JAVA_OBJECT_1 = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.toJavaObject(Value) is deprecated. Please use the resource resolver API.");
- }
- switch (value.getType()) {
- case PropertyType.DECIMAL:
- return value.getDecimal();
- case PropertyType.BINARY:
- return new LazyInputStream(value);
- case PropertyType.BOOLEAN:
- return value.getBoolean();
- case PropertyType.DATE:
- return value.getDate();
- case PropertyType.DOUBLE:
- return value.getDouble();
- case PropertyType.LONG:
- return value.getLong();
- case PropertyType.NAME: // fall through
- case PropertyType.PATH: // fall through
- case PropertyType.REFERENCE: // fall through
- case PropertyType.STRING: // fall through
- case PropertyType.UNDEFINED: // not actually expected
- default: // not actually expected
- return value.getString();
- }
- }
-
- /**
- * Converts the value(s) of a JCR Property to a corresponding Java Object.
- * If the property has multiple values the result is an array of Java
- * Objects representing the converted values of the property.
- *
- * @param property the property to be converted to the corresponding Java Object
- * @throws RepositoryException if the conversion cannot take place
- * @return the Object resulting from the conversion
- */
- public static Object toJavaObject(Property property)
- throws RepositoryException {
- if ( LOG_DEPRECATED_TO_JAVA_OBJECT_2 ) {
- LOG_DEPRECATED_TO_JAVA_OBJECT_2 = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.toJavaObject(Property) is deprecated. Please use the resource resolver API.");
- }
- // multi-value property: return an array of values
- if (property.isMultiple()) {
- Value[] values = property.getValues();
- final Object firstValue = values.length > 0 ? toJavaObject(values[0]) : null;
- final Object[] result;
- if ( firstValue instanceof Boolean ) {
- result = new Boolean[values.length];
- } else if ( firstValue instanceof Calendar ) {
- result = new Calendar[values.length];
- } else if ( firstValue instanceof Double ) {
- result = new Double[values.length];
- } else if ( firstValue instanceof Long ) {
- result = new Long[values.length];
- } else if ( firstValue instanceof BigDecimal) {
- result = new BigDecimal[values.length];
- } else if ( firstValue instanceof InputStream) {
- result = new Object[values.length];
- } else {
- result = new String[values.length];
- }
- for (int i = 0; i < values.length; i++) {
- Value value = values[i];
- if (value != null) {
- result[i] = toJavaObject(value);
- }
- }
- return result;
- }
-
- // single value property
- return toJavaObject(property.getValue());
- }
-
- /**
- * Creates a {@link javax.jcr.Value JCR Value} for the given object with
- * the given Session.
- * Selects the the {@link javax.jcr.PropertyType PropertyType} according
- * the instance of the object's Class
- *
- * @param value object
- * @param session to create value for
- * @return the value or null if not convertible to a valid PropertyType
- * @throws RepositoryException in case of error, accessing the Repository
- */
- public static Value createValue(final Object value, final Session session)
- throws RepositoryException {
- if ( LOG_DEPRECATED_CREATE_VALUE ) {
- LOG_DEPRECATED_CREATE_VALUE = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.createValue is deprecated. Please use the resource resolver API.");
- }
- Value val;
- ValueFactory fac = session.getValueFactory();
- if(value instanceof Calendar) {
- val = fac.createValue((Calendar)value);
- } else if (value instanceof InputStream) {
- val = fac.createValue(fac.createBinary((InputStream)value));
- } else if (value instanceof Node) {
- val = fac.createValue((Node)value);
- } else if (value instanceof BigDecimal) {
- val = fac.createValue((BigDecimal)value);
- } else if (value instanceof Long) {
- val = fac.createValue((Long)value);
- } else if (value instanceof Short) {
- val = fac.createValue((Short)value);
- } else if (value instanceof Integer) {
- val = fac.createValue((Integer)value);
- } else if (value instanceof Number) {
- val = fac.createValue(((Number)value).doubleValue());
- } else if (value instanceof Boolean) {
- val = fac.createValue((Boolean) value);
- } else if ( value instanceof String ) {
- val = fac.createValue((String)value);
- } else {
- val = null;
- }
- return val;
- }
-
- /**
- * Sets the value of the property.
- * Selects the {@link javax.jcr.PropertyType PropertyType} according
- * to the instance of the object's class.
- * @param node The node where the property will be set on.
- * @param propertyName The name of the property.
- * @param propertyValue The value for the property.
- * @throws RepositoryException if the property cannot be set
- */
- public static void setProperty(final Node node,
- final String propertyName,
- final Object propertyValue)
- throws RepositoryException {
- if ( LOG_DEPRECATED_SET_PROPERTY ) {
- LOG_DEPRECATED_SET_PROPERTY = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.setProperty is deprecated. Please use the resource resolver API.");
- }
- if ( propertyValue == null ) {
- node.setProperty(propertyName, (String)null);
- } else if ( propertyValue.getClass().isArray() ) {
- final int length = Array.getLength(propertyValue);
- final Value[] setValues = new Value[length];
- for(int i=0; i<length; i++) {
- final Object value = Array.get(propertyValue, i);
- setValues[i] = createValue(value, node.getSession());
- }
- node.setProperty(propertyName, setValues);
- } else {
- node.setProperty(propertyName, createValue(propertyValue, node.getSession()));
- }
- }
-
- /**
- * Helper method, which returns the given resource type as returned from the
- * {@link org.apache.sling.api.resource.Resource#getResourceType()} as a
- * relative path.
- *
- * @param type The resource type to be converted into a path
- * @return The resource type as a path.
- * @deprecated Use {@link ResourceUtil#resourceTypeToPath(String)}
- */
- @Deprecated
- public static String resourceTypeToPath(String type) {
- if ( LOG_DEPRECATED_RT_TO_PATH ) {
- LOG_DEPRECATED_RT_TO_PATH = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.resourceTypeToPath is deprecated. Please use the resource resolver API.");
- }
- return type.replaceAll("\\:", "/");
- }
-
- /**
- * Returns the super type of the given resource type. This is the result of
- * adapting the child resource
- * {@link JcrResourceConstants#SLING_RESOURCE_SUPER_TYPE_PROPERTY} of the
- * <code>Resource</code> addressed by the <code>resourceType</code> to a
- * string. If no such child resource exists or if the resource does not
- * adapt to a string, this method returns <code>null</code>.
- *
- * @param resourceResolver The <code>ResourceResolver</code> used to
- * access the resource whose path (relative or absolute) is given
- * by the <code>resourceType</code> parameter.
- * @param resourceType The resource type whose super type is to be returned.
- * This type is turned into a path by calling the
- * {@link #resourceTypeToPath(String)} method before trying to
- * get the resource through the <code>resourceResolver</code>.
- * @return the super type of the <code>resourceType</code> or
- * <code>null</code> if the resource type does not have a child
- * resource
- * {@link JcrResourceConstants#SLING_RESOURCE_SUPER_TYPE_PROPERTY}
- * adapting to a string.
- * @deprecated Use {@link ResourceUtil#getResourceSuperType(ResourceResolver, String)}
- */
- @SuppressWarnings("deprecation")
- @Deprecated
- public static String getResourceSuperType(
- ResourceResolver resourceResolver, String resourceType) {
- if ( LOG_DEPRECATED_GET_RST_1) {
- LOG_DEPRECATED_GET_RST_1 = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.getResourceSuperType(String) is deprecated. Please use the resource resolver API.");
- }
- return ResourceUtil.getResourceSuperType(resourceResolver, resourceType);
- }
-
- /**
- * Returns the resource super type of the given resource. This is either the
- * child resource
- * {@link JcrResourceConstants#SLING_RESOURCE_SUPER_TYPE_PROPERTY} if the
- * given <code>resource</code> adapted to a string or the result of
- * calling the {@link #getResourceSuperType(ResourceResolver, String)}
- * method on the resource type of the <code>resource</code>.
- * <p>
- * This mechanism allows to specifically set the resource super type on a
- * per-resource level overwriting any resource super type hierarchy
- * pre-defined by the actual resource type of the resource.
- *
- * @param resource The <code>Resource</code> whose resource super type is
- * requested.
- * @return The resource super type or <code>null</code> if the algorithm
- * described above does not yield a resource super type.
- * @deprecated Call {@link ResourceUtil#findResourceSuperType(Resource)}
- */
- @SuppressWarnings("deprecation")
- @Deprecated
- public static String getResourceSuperType(Resource resource) {
- if ( LOG_DEPRECATED_GET_RST_2) {
- LOG_DEPRECATED_GET_RST_2 = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.getResourceSuperType(Resource) is deprecated. Please use the resource resolver API.");
- }
- String resourceSuperType = resource.getResourceSuperType();
- if ( resourceSuperType == null ) {
- final ResourceResolver resolver = resource.getResourceResolver();
-
- // try explicit resourceSuperType resource
- final String resourceType = resource.getResourceType();
- resourceSuperType = ResourceUtil.getResourceSuperType(resolver, resourceType);
- }
-
- return resourceSuperType;
- }
-
- /**
- * Creates or gets the {@link javax.jcr.Node Node} at the given Path.
- * In case it has to create the Node all non-existent intermediate path-elements
- * will be create with the given intermediate node type and the returned node
- * will be created with the given nodeType
- *
- * @param path to create
- * @param intermediateNodeType to use for creation of intermediate nodes (or null)
- * @param nodeType to use for creation of the final node (or null)
- * @param session to use
- * @param autoSave Should save be called when a new node is created?
- * @return the Node at path
- * @throws RepositoryException in case of exception accessing the Repository
- */
- public static Node createPath(String path,
- String intermediateNodeType,
- String nodeType,
- Session session,
- boolean autoSave)
- throws RepositoryException {
- if ( LOG_DEPRECATED_CREATE_PATH_1 ) {
- LOG_DEPRECATED_CREATE_PATH_1 = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.createPath(String, ...) is deprecated. Please use the resource resolver API.");
- }
- if (path == null || path.length() == 0 || "/".equals(path)) {
- return session.getRootNode();
- }
- // sanitize path if it ends with a slash
- if ( path.endsWith("/") ) {
- path = path.substring(0, path.length() - 1);
- }
-
- if (!session.itemExists(path)) {
- String existingPath = findExistingPath(path, session);
-
-
- String relativePath = null;
- Node parentNode = null;
- if (existingPath != null) {
- parentNode = session.getNode(existingPath);
- relativePath = path.substring(existingPath.length() + 1);
- } else {
- relativePath = path.substring(1);
- parentNode = session.getRootNode();
- }
-
- return createPath(parentNode,
- relativePath,
- intermediateNodeType,
- nodeType,
- autoSave);
- } else {
- return session.getNode(path);
- }
- }
-
- /**
- * Creates or gets the {@link javax.jcr.Node Node} at the given Path.
- * In case it has to create the Node all non-existent intermediate path-elements
- * will be create with the given intermediate node type and the returned node
- * will be created with the given nodeType
- *
- * @param parentNode starting node
- * @param relativePath to create
- * @param intermediateNodeType to use for creation of intermediate nodes (or null)
- * @param nodeType to use for creation of the final node (or null)
- * @param autoSave Should save be called when a new node is created?
- * @return the Node at path
- * @throws RepositoryException in case of exception accessing the Repository
- */
- public static Node createPath(Node parentNode,
- String relativePath,
- String intermediateNodeType,
- String nodeType,
- boolean autoSave)
- throws RepositoryException {
- if ( LOG_DEPRECATED_CREATE_PATH_2 ) {
- LOG_DEPRECATED_CREATE_PATH_2 = false;
- LoggerFactory.getLogger(JcrResourceUtil.class).warn("DEPRECATION WARNING: JcrResourceUtil.createPath(Node,...) is deprecated. Please use the resource resolver API.");
- }
- if (relativePath == null || relativePath.length() == 0 || "/".equals(relativePath)) {
- return parentNode;
- }
- // sanitize path if it ends with a slash
- if ( relativePath.endsWith("/") ) {
- relativePath = relativePath.substring(0, relativePath.length() - 1);
- }
-
- if (!parentNode.hasNode(relativePath)) {
- Session session = parentNode.getSession();
- String path = parentNode.getPath() + "/" + relativePath;
- String existingPath = findExistingPath(path, session);
-
- if (existingPath != null) {
- parentNode = session.getNode(existingPath);
- relativePath = path.substring(existingPath.length() + 1);
- }
-
- Node node = parentNode;
- int pos = relativePath.lastIndexOf('/');
- if ( pos != -1 ) {
- final StringTokenizer st = new StringTokenizer(relativePath.substring(0, pos), "/");
- while ( st.hasMoreTokens() ) {
- final String token = st.nextToken();
- if ( !node.hasNode(token) ) {
- try {
- if ( intermediateNodeType != null ) {
- node.addNode(token, intermediateNodeType);
- } else {
- node.addNode(token);
- }
- if ( autoSave ) session.save();
- } catch (RepositoryException re) {
- // we ignore this as this folder might be created from a different task
- session.refresh(false);
- }
- }
- node = node.getNode(token);
- }
- relativePath = relativePath.substring(pos + 1);
- }
- if ( !node.hasNode(relativePath) ) {
- if ( nodeType != null ) {
- node.addNode(relativePath, nodeType);
- } else {
- node.addNode(relativePath);
- }
- if ( autoSave ) session.save();
- }
- return node.getNode(relativePath);
- } else {
- return parentNode.getNode(relativePath);
- }
- }
-
- private static String findExistingPath(String path, Session session)
- throws RepositoryException {
- //find the parent that exists
- // we can start from the youngest child in tree
- int currentIndex = path.lastIndexOf('/');
- String temp = path;
- String existingPath = null;
- while (currentIndex > 0) {
- temp = temp.substring(0, currentIndex);
- //break when first existing parent is found
- if (session.itemExists(temp)) {
- existingPath = temp;
- break;
- }
- currentIndex = temp.lastIndexOf("/");
- }
-
- return existingPath;
- }
-}
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java b/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
index 53274ee..95928ba 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
@@ -24,7 +24,6 @@
import javax.jcr.Session;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
-import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
/**
* This is a helper class used to pass several services/data to the resource
@@ -34,14 +33,10 @@
private final AtomicReference<DynamicClassLoaderManager> dynamicClassLoaderManagerReference;
- public final PathMapper pathMapper;
-
private volatile String[] namespacePrefixes;
- public HelperData(final AtomicReference<DynamicClassLoaderManager> dynamicClassLoaderManagerReference,
- final PathMapper pathMapper) {
+ public HelperData(final AtomicReference<DynamicClassLoaderManager> dynamicClassLoaderManagerReference) {
this.dynamicClassLoaderManagerReference = dynamicClassLoaderManagerReference;
- this.pathMapper = pathMapper;
}
public String[] getNamespacePrefixes(final Session session)
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/JcrListenerBaseConfig.java b/src/main/java/org/apache/sling/jcr/resource/internal/JcrListenerBaseConfig.java
index bff02bc..0bfc395 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/JcrListenerBaseConfig.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/JcrListenerBaseConfig.java
@@ -35,7 +35,6 @@
import org.apache.sling.api.resource.observation.ResourceChange.ChangeType;
import org.apache.sling.api.resource.path.Path;
import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
import org.apache.sling.spi.resource.provider.ObservationReporter;
import org.apache.sling.spi.resource.provider.ObserverConfiguration;
import org.slf4j.Logger;
@@ -51,17 +50,13 @@
private final Session session;
- private final PathMapper pathMapper;
-
private final ObservationReporter reporter;
@SuppressWarnings("deprecation")
public JcrListenerBaseConfig(
final ObservationReporter reporter,
- final PathMapper pathMapper,
final SlingRepository repository)
throws RepositoryException {
- this.pathMapper = pathMapper;
this.reporter = reporter;
// The session should have read access on the whole repository
this.session = repository.loginService("observation", repository.getDefaultWorkspace());
@@ -191,8 +186,4 @@
public ObservationReporter getReporter() {
return this.reporter;
}
-
- public PathMapper getPathMapper() {
- return this.pathMapper;
- }
}
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java b/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
index 24c7109..01958f7 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
@@ -159,7 +159,7 @@
private ResourceChange createResourceChange(final Event event,
final String path,
final ChangeType changeType) {
- final String fullPath = this.baseConfig.getPathMapper().mapJCRPathToResourcePath(path);
+ final String fullPath = path;
final boolean isExternal = this.isExternal(event);
final String userId;
if (!isExternal) {
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java b/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
deleted file mode 100644
index 2640774..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.HashMap;
-import java.util.Map;
-
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
-import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
-import org.osgi.framework.Constants;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-import org.slf4j.LoggerFactory;
-
-/**
- * The <code>JcrResourceResolverFactoryImpl</code> is the
- * {@link JcrResourceResolverFactory} service providing the following
- * functionality:
- * <ul>
- * <li><code>JcrResourceResolverFactory</code> service
- * </ul>
- */
-@Component(name = "org.apache.sling.jcr.resource.internal.LegacyJcrResourceResolverFactoryImpl",
- service = JcrResourceResolverFactory.class,
- property = {
- Constants.SERVICE_DESCRIPTION + "=Apache Sling JcrResourceResolverFactory Implementation",
- Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
- })
-public class JcrResourceResolverFactoryImpl implements
- JcrResourceResolverFactory {
-
- @Reference
- private ResourceResolverFactory delegatee;
-
- /** The dynamic class loader */
- @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
- private volatile DynamicClassLoaderManager dynamicClassLoaderManager;
-
- @Activate
- protected void activate() {
- LoggerFactory.getLogger(this.getClass()).warn("DEPRECATION WARNING: JcrResourceResolverFactory is deprecated. Please use ResourceResolverFactory instead.");
- }
-
- /**
- * Get the dynamic class loader if available.
- *
- * @return the classloader
- */
- public ClassLoader getDynamicClassLoader() {
- final DynamicClassLoaderManager dclm = this.dynamicClassLoaderManager;
- if (dclm != null) {
- return dclm.getDynamicClassLoader();
- }
- return null;
- }
-
- /**
- * @see org.apache.sling.jcr.resource.JcrResourceResolverFactory#getResourceResolver(javax.jcr.Session)
- */
- @Override
- public ResourceResolver getResourceResolver(final Session session) {
- final Map<String, Object> authInfo = new HashMap<String, Object>(1);
- authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);
- try {
- return getResourceResolver(authInfo);
- } catch (LoginException le) {
- // we don't expect a LoginException here because just a
- // ResourceResolver wrapping the given session is to be created.
- throw new InternalError("Unexpected LoginException");
- }
- }
-
- /**
- * @see org.apache.sling.api.resource.ResourceResolverFactory#getServiceResourceResolver(Map)
- */
- @Override
- public ResourceResolver getServiceResourceResolver(Map<String, Object> authenticationInfo) throws LoginException {
- return delegatee.getServiceResourceResolver(authenticationInfo);
- }
-
- /**
- * @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
- */
- @Override
- public ResourceResolver getAdministrativeResourceResolver(
- final Map<String, Object> authenticationInfo) throws LoginException {
- return delegatee.getAdministrativeResourceResolver(authenticationInfo);
- }
-
- /**
- * @see org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map)
- */
- @Override
- public ResourceResolver getResourceResolver(final Map<String, Object> arg0)
- throws LoginException {
- return delegatee.getResourceResolver(arg0);
- }
-
- /**
- * @see org.apache.sling.api.resource.ResourceResolverFactory#getThreadResourceResolver()
- */
- @Override
- public ResourceResolver getThreadResourceResolver() {
- return delegatee.getThreadResourceResolver();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/BasicQueryLanguageProvider.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/BasicQueryLanguageProvider.java
index b4e3242..20022b6 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/BasicQueryLanguageProvider.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/BasicQueryLanguageProvider.java
@@ -129,7 +129,7 @@
while ( result == null && rows.hasNext() ) {
try {
final Row jcrRow = rows.nextRow();
- final String resourcePath = ctx.getProviderState().getHelperData().pathMapper.mapJCRPathToResourcePath(jcrRow.getPath());
+ final String resourcePath = jcrRow.getPath();
if ( resourcePath != null && providerContext.getExcludedPaths().matches(resourcePath) == null) {
final Map<String, Object> row = new HashMap<String, Object>();
@@ -144,8 +144,7 @@
JcrResourceUtil.toJavaObject(values[i]));
if (colName.equals(QUERY_COLUMN_PATH)) {
didPath = true;
- row.put(colName,
- ctx.getProviderState().getHelperData().pathMapper.mapJCRPathToResourcePath(JcrResourceUtil.toJavaObject(values[i]).toString()));
+ row.put(colName, JcrResourceUtil.toJavaObject(values[i]).toString());
}
if (colName.equals(QUERY_COLUMN_SCORE)) {
didScore = true;
@@ -153,7 +152,7 @@
}
}
if (!didPath) {
- row.put(QUERY_COLUMN_PATH, ctx.getProviderState().getHelperData().pathMapper.mapJCRPathToResourcePath(jcrRow.getPath()));
+ row.put(QUERY_COLUMN_PATH, jcrRow.getPath());
}
if (!didScore) {
row.put(QUERY_COLUMN_SCORE, jcrRow.getScore());
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactory.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactory.java
index 6d7bb26..417f460 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactory.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactory.java
@@ -65,7 +65,7 @@
*/
public JcrItemResource<?> createResource(final ResourceResolver resourceResolver, final String resourcePath,
final Resource parent, final Map<String, String> parameters) throws RepositoryException {
- final String jcrPath = helper.pathMapper.mapResourcePathToJCRPath(resourcePath);
+ final String jcrPath = resourcePath;
if (jcrPath == null) {
log.debug("createResource: {} maps to an empty JCR path", resourcePath);
return null;
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
index 7093f66..1c9b7e0 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
@@ -39,8 +39,7 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.jcr.resource.JcrModifiablePropertyMap;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.jcr.resource.api.JcrResourceConstants;
import org.apache.sling.jcr.resource.internal.HelperData;
import org.apache.sling.jcr.resource.internal.JcrModifiableValueMap;
import org.apache.sling.jcr.resource.internal.JcrValueMap;
@@ -134,27 +133,6 @@
return (Type) getInputStream(); // unchecked cast
} else if (type == Map.class || type == ValueMap.class) {
return (Type) new JcrValueMap(getNode(), this.helper); // unchecked cast
- } else if (type == PersistableValueMap.class ) {
- if ( LOG_DEPRECATED_MAP ) {
- LOG_DEPRECATED_MAP = false;
- LOGGER.warn("DEPRECATION WARNING: PersistableValueMap is deprecated, a JcrResource should not be adapted to this anymore. Please switch to ModifiableValueMap.");
- }
- // check write
- try {
- getNode().getSession().checkPermission(getPath(),
- "set_property");
- return (Type) new JcrModifiablePropertyMap(getNode(), this.helper.getDynamicClassLoader());
- } catch (AccessControlException ace) {
- // the user has no write permission, cannot adapt
- LOGGER.debug(
- "adaptTo(PersistableValueMap): Cannot set properties on {}",
- this);
- } catch (RepositoryException e) {
- // some other problem, cannot adapt
- LOGGER.debug(
- "adaptTo(PersistableValueMap): Unexpected problem for {}",
- this);
- }
} else if (type == ModifiableValueMap.class ) {
// check write
try {
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
index 020bdfe..d23aae9 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
@@ -142,6 +142,6 @@
} else {
path = "/".equals(parentPath) ? '/' + node.getName() : parentPath + '/' + node.getName();
}
- return helper.pathMapper.mapJCRPathToResourcePath(path);
+ return path;
}
}
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
index 7a1a8e1..92e1c94 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
@@ -56,16 +56,12 @@
private final AtomicReference<DynamicClassLoaderManager> dynamicClassLoaderManagerReference;
- private final PathMapper pathMapper;
-
public JcrProviderStateFactory(final ServiceReference<SlingRepository> repositoryReference,
final SlingRepository repository,
- final AtomicReference<DynamicClassLoaderManager> dynamicClassLoaderManagerReference,
- final PathMapper pathMapper) {
+ final AtomicReference<DynamicClassLoaderManager> dynamicClassLoaderManagerReference) {
this.repository = repository;
this.repositoryReference = repositoryReference;
this.dynamicClassLoaderManagerReference = dynamicClassLoaderManagerReference;
- this.pathMapper = pathMapper;
}
/** Get the calling Bundle from auth info, fail if not provided
@@ -146,7 +142,7 @@
@Nullable final BundleContext ctx
) throws LoginException {
final Session session = handleImpersonation(s, authenticationInfo, logoutSession);
- final HelperData data = new HelperData(this.dynamicClassLoaderManagerReference, this.pathMapper);
+ final HelperData data = new HelperData(this.dynamicClassLoaderManagerReference);
return new JcrProviderState(session, data, logoutSession, ctx, ctx == null ? null : repositoryReference);
}
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
index abc2905..1fe4695 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
@@ -101,9 +101,6 @@
@Reference(name = REPOSITORY_REFERNENCE_NAME, service = SlingRepository.class)
private ServiceReference<SlingRepository> repositoryReference;
- @Reference
- private PathMapper pathMapper;
-
/** The JCR listener base configuration. */
private volatile JcrListenerBaseConfig listenerConfig;
@@ -131,7 +128,7 @@
this.repository = repository;
this.stateFactory = new JcrProviderStateFactory(repositoryReference, repository,
- classLoaderManagerReference, pathMapper);
+ classLoaderManagerReference);
}
@Deactivate
@@ -190,7 +187,6 @@
logger.debug("Registering resource listeners...");
try {
this.listenerConfig = new JcrListenerBaseConfig(this.getProviderContext().getObservationReporter(),
- this.pathMapper,
this.repository);
for(final ObserverConfiguration config : this.getProviderContext().getObservationReporter().getObserverConfigurations()) {
logger.debug("Registering listener for {}", config.getPaths());
@@ -406,7 +402,7 @@
nodeType = null;
}
}
- final String jcrPath = pathMapper.mapResourcePathToJCRPath(path);
+ final String jcrPath = path;
if ( jcrPath == null ) {
throw new PersistenceException("Unable to create node at " + path, null, path, null);
}
@@ -463,7 +459,7 @@
Item item = resource.adaptTo(Item.class);
try {
if ( item == null ) {
- final String jcrPath = pathMapper.mapResourcePathToJCRPath(resource.getPath());
+ final String jcrPath = resource.getPath();
if (jcrPath == null) {
logger.debug("delete: {} maps to an empty JCR path", resource.getPath());
throw new PersistenceException("Unable to delete resource", null, resource.getPath(), null);
@@ -552,8 +548,8 @@
public boolean move(final @Nonnull ResolveContext<JcrProviderState> ctx,
final String srcAbsPath,
final String destAbsPath) throws PersistenceException {
- final String srcNodePath = pathMapper.mapResourcePathToJCRPath(srcAbsPath);
- final String dstNodePath = pathMapper.mapResourcePathToJCRPath(destAbsPath + '/' + ResourceUtil.getName(srcAbsPath));
+ final String srcNodePath = srcAbsPath;
+ final String dstNodePath = destAbsPath + '/' + ResourceUtil.getName(srcAbsPath);
try {
ctx.getProviderState().getSession().move(srcNodePath, dstNodePath);
return true;
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/PathMapper.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/PathMapper.java
deleted file mode 100644
index 4d50c2d..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/PathMapper.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * 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.helper.jcr;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.osgi.framework.Constants;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.metatype.annotations.AttributeDefinition;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The {@code PathMapper} allows to
- * - map path from the JCR resource tree to resource paths
- * - hide JCR nodes; however this is not a security feature
- * @deprecated
- */
-@Deprecated
-@Designate(ocd = PathMapper.Config.class)
-@Component(service = PathMapper.class,
- property = {
- Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
- })
-public class PathMapper {
-
- @ObjectClassDefinition(name = "Apache Sling JCR Resource Provider Path Mapper",
- description = "This service provides path mappings for JCR nodes.")
- public @interface Config {
-
- @AttributeDefinition(name = "Path Mapping",
- description = "Defines an obtional path mapping for a path." +
- "Each mapping entry is expressed as follow: <JCRPath>:<resourcePath>. As an example: /foo:/libs, " +
- "this maps the JCR node /foo to the resource /libs. If the resource path is specified as '.', " +
- " the JCR tree is not visible in the resource tree. This should not be considered a security feature " +
- " as the nodes are still accessible through the JCR api. Mapping a JCR path to the root is not allowed. " +
- "The mappings are evaluated as ordered in the configuration.")
- String[] path_mapping();
- }
-
- /** Logger */
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- /** The mappings. */
- private final List<Mapping> mappings = new ArrayList<Mapping>();
-
- private static final class Mapping {
- public final String jcrPath;
- public final String resourcePath;
- public final String jcrPathPrefix;
- public final String resourcePathPrefix;
-
- public Mapping(final String path, final String mappedPath) {
- this.jcrPath = path;
- this.jcrPathPrefix = path.concat("/");
- if ( mappedPath.equals(".") ) {
- this.resourcePath = null;
- this.resourcePathPrefix = null;
- } else {
- this.resourcePath = mappedPath;
- this.resourcePathPrefix = mappedPath.concat("/");
- }
- }
- }
-
- @Activate
- private void activate(final Config configObj) {
- mappings.clear();
- final String[] config = configObj.path_mapping();
- if ( config != null ) {
- log.warn("The Apache Sling JCR Path Mapper is deprecated.");
- for (final String mapping : config) {
- boolean valid = false;
- final String[] parts = mapping.split(":");
- if (parts.length == 2) {
- parts[0] = parts[0].trim();
- parts[1] = parts[1].trim();
- if ( parts[0].startsWith("/") && (parts[1].startsWith("/") || parts[1].equals(".")) ) {
- if ( parts[0].endsWith("/") ) {
- parts[0] = parts[0].substring(0, parts[1].length() - 1);
- }
- if ( parts[1].endsWith("/") ) {
- parts[1] = parts[1].substring(0, parts[1].length() - 1);
- }
- if ( parts[0].length() > 1 && (parts[1].length() > 1 || parts[1].equals(".")) ) {
- mappings.add(new Mapping(parts[0], parts[1]));
- valid = true;
- }
- }
- }
- if ( !valid ) {
- log.warn("Invalid mapping configuration (skipping): {}", mapping);
- }
- }
- }
- }
-
- /**
- * Map a resource path to a JCR path
- * @param resourcePath The resource path
- * @return The JCR path or {@code null}
- */
- public String mapResourcePathToJCRPath(final String resourcePath) {
- String jcrPath = resourcePath;
- if (resourcePath != null && !mappings.isEmpty()) {
- for (final Mapping mapping : mappings) {
- if ( mapping.resourcePath == null ) {
- if ( resourcePath.equals(mapping.jcrPath) || resourcePath.startsWith(mapping.jcrPathPrefix) ) {
- jcrPath = null;
- break;
- }
- } else {
- if (resourcePath.equals(mapping.resourcePath)) {
- jcrPath = mapping.jcrPath;
- break;
- } else if (resourcePath.startsWith(mapping.resourcePathPrefix)) {
- jcrPath = mapping.jcrPathPrefix.concat(resourcePath.substring(mapping.resourcePathPrefix.length()));
- break;
- }
- }
- }
- }
- return jcrPath;
- }
-
- /**
- * Map a JCR path to a resource path
- * @param jcrPath The JCR path
- * @return The resource path or {@code null}
- */
- public String mapJCRPathToResourcePath(final String jcrPath) {
- String resourcePath = jcrPath;
- if (jcrPath != null && !mappings.isEmpty()) {
- for (final Mapping mapping : mappings) {
- if (mapping.resourcePath != null && (jcrPath.equals(mapping.resourcePath) || jcrPath.startsWith(mapping.resourcePathPrefix)) ) {
- resourcePath = null;
- break;
- } else if (jcrPath.equals(mapping.jcrPath)) {
- resourcePath = mapping.resourcePath;
- break;
- } else if (jcrPath.startsWith(mapping.jcrPathPrefix)) {
- if ( mapping.resourcePath == null ) {
- resourcePath = null;
- } else {
- resourcePath = mapping.resourcePathPrefix.concat(jcrPath.substring(mapping.jcrPathPrefix.length()));
- }
- break;
- }
- }
- }
- return resourcePath;
- }
-}
diff --git a/src/main/java/org/apache/sling/jcr/resource/package-info.java b/src/main/java/org/apache/sling/jcr/resource/package-info.java
deleted file mode 100644
index 39dabd1..0000000
--- a/src/main/java/org/apache/sling/jcr/resource/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.
- */
-
-@org.osgi.annotation.versioning.Version("2.4")
-package org.apache.sling.jcr.resource;
-
-
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java
deleted file mode 100644
index 6a04d51..0000000
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * 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.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-
-import org.apache.jackrabbit.util.Text;
-import org.apache.sling.api.resource.PersistableValueMap;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.jcr.resource.JcrModifiablePropertyMap;
-import org.apache.sling.jcr.resource.JcrPropertyMap;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
-
-public class JcrModifiablePropertyMapTest extends JcrPropertyMapTest {
-
- private String rootPath;
-
- private Node rootNode;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- rootPath = "/test_" + System.currentTimeMillis();
- rootNode = getSession().getRootNode().addNode(rootPath.substring(1),
- "nt:unstructured");
-
- final Map<String, Object> values = this.initialSet();
- for(Map.Entry<String, Object> entry : values.entrySet()) {
- JcrResourceUtil.setProperty(rootNode, entry.getKey().toString(), entry.getValue());
- }
- session.save();
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (rootNode != null) {
- rootNode.remove();
- session.save();
- }
-
- super.tearDown();
- }
-
- private Map<String, Object> initialSet() {
- final Map<String, Object> values = new HashMap<String, Object>();
- values.put("string", "test");
- values.put("long", 1L);
- values.put("bool", Boolean.TRUE);
- return values;
- }
-
- public void testPut()
- throws Exception {
- this.rootNode.getSession().refresh(false);
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
- assertContains(pvm, initialSet());
- assertNull(pvm.get("something"));
-
- // now put two values and check set again
- pvm.put("something", "Another value");
- pvm.put("string", "overwrite");
-
- final Map<String, Object> currentlyStored = this.initialSet();
- currentlyStored.put("something", "Another value");
- currentlyStored.put("string", "overwrite");
- assertContains(pvm, currentlyStored);
-
- pvm.save();
- assertContains(pvm, currentlyStored);
-
- final PersistableValueMap pvm2 = new JcrModifiablePropertyMap(this.rootNode);
- assertContains(pvm2, currentlyStored);
- }
-
- public void testReset()
- throws Exception {
- this.rootNode.getSession().refresh(false);
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
- assertContains(pvm, initialSet());
- assertNull(pvm.get("something"));
-
- // now put two values and check set again
- pvm.put("something", "Another value");
- pvm.put("string", "overwrite");
-
- final Map<String, Object> currentlyStored = this.initialSet();
- currentlyStored.put("something", "Another value");
- currentlyStored.put("string", "overwrite");
- assertContains(pvm, currentlyStored);
-
- pvm.reset();
- assertContains(pvm, initialSet());
-
- final PersistableValueMap pvm2 = new JcrModifiablePropertyMap(this.rootNode);
- assertContains(pvm2, initialSet());
- }
-
- public void testSerializable()
- throws Exception {
- this.rootNode.getSession().refresh(false);
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
- assertContains(pvm, initialSet());
- assertNull(pvm.get("something"));
-
- // now put a serializable object
- final List<String> strings = new ArrayList<String>();
- strings.add("a");
- strings.add("b");
- pvm.put("something", strings);
-
- // check if we get the list again
- @SuppressWarnings("unchecked")
- final List<String> strings2 = (List<String>) pvm.get("something");
- assertEquals(strings, strings2);
-
- pvm.save();
-
- final PersistableValueMap pvm2 = new JcrModifiablePropertyMap(this.rootNode);
- // check if we get the list again
- @SuppressWarnings("unchecked")
- final List<String> strings3 = (List<String>) pvm2.get("something", Serializable.class);
- assertEquals(strings, strings3);
-
- }
-
- public void testExceptions() throws Exception {
- this.rootNode.getSession().refresh(false);
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
- try {
- pvm.put(null, "something");
- fail("Put with null key");
- } catch (NullPointerException iae) {}
- try {
- pvm.put("something", null);
- fail("Put with null value");
- } catch (NullPointerException iae) {}
- try {
- pvm.put("something", pvm);
- fail("Put with non serializable");
- } catch (IllegalArgumentException iae) {}
- }
-
- private Set<String> getMixinNodeTypes(final Node node) throws RepositoryException {
- final Set<String> mixinTypes = new HashSet<String>();
- for(final NodeType mixinNodeType : node.getMixinNodeTypes() ) {
- mixinTypes.add(mixinNodeType.getName());
- }
- return mixinTypes;
- }
-
- public void testMixins() throws Exception {
- this.rootNode.getSession().refresh(false);
- final Node testNode = this.rootNode.addNode("testMixins" + System.currentTimeMillis());
- testNode.getSession().save();
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);
-
- final String[] types = pvm.get("jcr:mixinTypes", String[].class);
- final Set<String> exNodeTypes = getMixinNodeTypes(testNode);
-
- assertEquals(exNodeTypes.size(), (types == null ? 0 : types.length));
- if ( types != null ) {
- for(final String name : types) {
- assertTrue(exNodeTypes.contains(name));
- }
- String[] newTypes = new String[types.length + 1];
- System.arraycopy(types, 0, newTypes, 0, types.length);
- newTypes[types.length] = "mix:referenceable";
- pvm.put("jcr:mixinTypes", newTypes);
- } else {
- pvm.put("jcr:mixinTypes", "mix:referenceable");
- }
- pvm.save();
-
- final Set<String> newNodeTypes = getMixinNodeTypes(testNode);
- assertEquals(newNodeTypes.size(), exNodeTypes.size() + 1);
- }
-
- private static final String TEST_PATH = "a<a";
-
- private static final String VALUE = "value";
- private static final String VALUE1 = "value";
- private static final String VALUE2 = "value";
- private static final String VALUE3 = "my title";
- private static final String PROP1 = "-prop";
- private static final String PROP2 = "1prop";
- private static final String PROP3 = "jcr:title";
-
- public void testNamesReverse() throws Exception {
- this.rootNode.getSession().refresh(false);
-
- final Node testNode = this.rootNode.addNode("nameTest" + System.currentTimeMillis());
- testNode.getSession().save();
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);
- pvm.put(TEST_PATH, VALUE);
- pvm.put(PROP1, VALUE1);
- pvm.put(PROP2, VALUE2);
- pvm.put(PROP3, VALUE3);
- pvm.save();
-
- // read with property map
- final ValueMap vm = this.createPropertyMap(testNode);
- assertEquals(VALUE, vm.get(TEST_PATH));
- assertEquals(VALUE1, vm.get(PROP1));
- assertEquals(VALUE2, vm.get(PROP2));
- assertEquals(VALUE3, vm.get(PROP3));
-
- // read properties
- assertEquals(VALUE, testNode.getProperty(TEST_PATH).getString());
- assertEquals(VALUE1, testNode.getProperty(PROP1).getString());
- assertEquals(VALUE2, testNode.getProperty(PROP2).getString());
- assertEquals(VALUE3, testNode.getProperty(PROP3).getString());
- }
-
- /**
- * Checks property names encoding, see SLING-2502.
- */
- public void testNamesUpdate() throws Exception {
- this.rootNode.getSession().refresh(false);
-
- final Node testNode = this.rootNode.addNode("nameUpdateTest"
- + System.currentTimeMillis());
- testNode.setProperty(PROP3, VALUE);
- testNode.getSession().save();
-
- final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);
- pvm.put(PROP3, VALUE3);
- pvm.put("jcr:a:b", VALUE3);
- pvm.put("jcr:", VALUE3);
- pvm.save();
-
- // read with property map
- final ValueMap vm = this.createPropertyMap(testNode);
- assertEquals(VALUE3, vm.get(PROP3));
- assertEquals(VALUE3, vm.get("jcr:a:b"));
- assertEquals(VALUE3, vm.get("jcr:"));
-
- // read properties
- assertEquals(VALUE3, testNode.getProperty(PROP3).getString());
- assertEquals(VALUE3, testNode.getProperty("jcr:"+Text.escapeIllegalJcrChars("a:b")).getString());
- assertEquals(VALUE3, testNode.getProperty(Text.escapeIllegalJcrChars("jcr:")).getString());
- assertFalse(testNode.hasProperty(Text.escapeIllegalJcrChars(PROP3)));
- assertFalse(testNode.hasProperty(Text.escapeIllegalJcrChars("jcr:a:b")));
- }
-
- protected JcrPropertyMap createPropertyMap(final Node node) {
- return new JcrModifiablePropertyMap(node);
- }
-
- /**
- * Check that the value map contains all supplied values
- */
- private void assertContains(ValueMap map, Map<String, Object> values) {
- for(Map.Entry<String, Object> entry : values.entrySet()) {
- final Object stored = map.get(entry.getKey());
- assertEquals(values.get(entry.getKey()), stored);
- }
- }
-}
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java
index 1b5a9c4..9bd04ae 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java
@@ -23,6 +23,8 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -35,6 +37,9 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
import javax.jcr.nodetype.NodeType;
import org.apache.commons.io.IOUtils;
@@ -43,7 +48,6 @@
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
public class JcrModifiableValueMapTest extends RepositoryTestBase {
@@ -63,10 +67,59 @@
final Map<String, Object> values = this.initialSet();
for(Map.Entry<String, Object> entry : values.entrySet()) {
- JcrResourceUtil.setProperty(rootNode, entry.getKey().toString(), entry.getValue());
+ setProperty(rootNode, entry.getKey().toString(), entry.getValue());
}
getSession().save();
}
+
+ private void setProperty(final Node node,
+ final String propertyName,
+ final Object propertyValue)
+ throws RepositoryException {
+ if ( propertyValue == null ) {
+ node.setProperty(propertyName, (String)null);
+ } else if ( propertyValue.getClass().isArray() ) {
+ final int length = Array.getLength(propertyValue);
+ final Value[] setValues = new Value[length];
+ for(int i=0; i<length; i++) {
+ final Object value = Array.get(propertyValue, i);
+ setValues[i] = createValue(value, node.getSession());
+ }
+ node.setProperty(propertyName, setValues);
+ } else {
+ node.setProperty(propertyName, createValue(propertyValue, node.getSession()));
+ }
+ }
+
+ Value createValue(final Object value, final Session session)
+ throws RepositoryException {
+ Value val;
+ ValueFactory fac = session.getValueFactory();
+ if(value instanceof Calendar) {
+ val = fac.createValue((Calendar)value);
+ } else if (value instanceof InputStream) {
+ val = fac.createValue(fac.createBinary((InputStream)value));
+ } else if (value instanceof Node) {
+ val = fac.createValue((Node)value);
+ } else if (value instanceof BigDecimal) {
+ val = fac.createValue((BigDecimal)value);
+ } else if (value instanceof Long) {
+ val = fac.createValue((Long)value);
+ } else if (value instanceof Short) {
+ val = fac.createValue((Short)value);
+ } else if (value instanceof Integer) {
+ val = fac.createValue((Integer)value);
+ } else if (value instanceof Number) {
+ val = fac.createValue(((Number)value).doubleValue());
+ } else if (value instanceof Boolean) {
+ val = fac.createValue((Boolean) value);
+ } else if ( value instanceof String ) {
+ val = fac.createValue((String)value);
+ } else {
+ val = null;
+ }
+ return val;
+ }
@Override
protected void tearDown() throws Exception {
@@ -78,7 +131,7 @@
}
private HelperData getHelperData() throws Exception {
- return new HelperData(new AtomicReference<DynamicClassLoaderManager>(), new PathMapperImpl());
+ return new HelperData(new AtomicReference<DynamicClassLoaderManager>());
}
private Map<String, Object> initialSet() {
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
deleted file mode 100644
index 3d438c2..0000000
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * 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.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Iterator;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.util.ISO9075;
-import org.apache.jackrabbit.util.Text;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
-import org.apache.sling.jcr.resource.JcrPropertyMap;
-
-import static org.apache.sling.jcr.resource.internal.AssertCalendar.assertEqualsCalendar;
-
-public class JcrPropertyMapTest extends RepositoryTestBase {
-
- private static final String PROP_NAME = "prop_name";
-
- private static final String PROP_NAME_NIL = "prop_name_nil";
-
- private String rootPath;
-
- private Node rootNode;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- rootPath = "/test" + System.currentTimeMillis();
- rootNode = getSession().getRootNode().addNode(rootPath.substring(1),
- "nt:unstructured");
- session.save();
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (rootNode != null) {
- rootNode.remove();
- session.save();
- }
-
- super.tearDown();
- }
-
- public void testJCRType() throws Exception {
- this.rootNode.getSession().refresh(false);
- testValue(rootNode, "A String");
- testValue(rootNode, Calendar.getInstance());
- testValue(rootNode, 5L);
- testValue(rootNode, 1.4D);
- testValue(rootNode, true);
- testValue(rootNode, BigDecimal.TEN);
- }
-
- public void testTypeByClass() throws Exception {
- this.rootNode.getSession().refresh(false);
- testValue(rootNode, "A String Value", String.class);
-
- testValue(rootNode, 1l, Byte.class);
- testValue(rootNode, 1l, Short.class);
- testValue(rootNode, 1l, Integer.class);
- testValue(rootNode, 1l, Long.class);
-
- testValue(rootNode, 1.0d, Float.class);
- testValue(rootNode, 1.0d, Double.class);
- testValue(rootNode, 1.0d, BigDecimal.class);
-
- Calendar cal = Calendar.getInstance();
- testValue(rootNode, cal, Calendar.class);
- testValue(rootNode, cal, Date.class);
- testValue(rootNode, cal, Long.class);
-
- testValue(rootNode, BigDecimal.TEN, BigDecimal.class);
- }
-
- public void testTypeByDefaultValue() throws Exception {
- this.rootNode.getSession().refresh(false);
- testValue(rootNode, "A String Value", "default");
-
- testValue(rootNode, 1l, (byte) 10);
- testValue(rootNode, 1l, (short) 10);
- testValue(rootNode, 1l, 10);
- testValue(rootNode, 1l, 10l);
-
- testValue(rootNode, 1.0d, 10.0f);
- testValue(rootNode, 1.0d, 10.0d);
- testValue(rootNode, 1.0d, new BigDecimal("1.0"));
-
- testValue(rootNode, BigDecimal.TEN, 10.0f);
- testValue(rootNode, BigDecimal.TEN, 10.0d);
- testValue(rootNode, BigDecimal.TEN, BigDecimal.TEN);
-
- long refTime = 1000l;
- Date refDate = new Date(refTime);
- Calendar refCal = Calendar.getInstance();
- refCal.setTimeInMillis(refTime);
-
- Calendar cal = Calendar.getInstance();
- testValue(rootNode, cal, refCal);
- testValue(rootNode, cal, refDate);
- testValue(rootNode, cal, refTime);
-
- testValue(rootNode, BigDecimal.TEN, BigDecimal.ONE);
- }
-
- public void testDefaultValue() throws Exception {
- this.rootNode.getSession().refresh(false);
- testDefaultValue(rootNode, "default");
-
- testDefaultValue(rootNode, (byte) 10);
- testDefaultValue(rootNode, (short) 10);
- testDefaultValue(rootNode, 10);
- testDefaultValue(rootNode, 10l);
-
- testDefaultValue(rootNode, 10.0f);
- testDefaultValue(rootNode, 10.0d);
- testDefaultValue(rootNode, new BigDecimal("50.50"));
-
- long refTime = 1000l;
- Date refDate = new Date(refTime);
- Calendar refCal = Calendar.getInstance();
- refCal.setTimeInMillis(refTime);
-
- testDefaultValue(rootNode, refCal);
- testDefaultValue(rootNode, refDate);
- testDefaultValue(rootNode, refTime);
-
- testDefaultValue(rootNode, BigDecimal.TEN);
- }
-
- public void testProperty() throws Exception {
- this.rootNode.getSession().refresh(false);
- ValueMap map = createProperty(rootNode, "Sample Value For Prop");
- Property prop = rootNode.getProperty(PROP_NAME);
-
- // explicit type
- Property result = map.get(PROP_NAME, Property.class);
- assertTrue(prop.isSame(result));
-
- // type by default value
- Property defaultValue = rootNode.getProperty("jcr:primaryType");
- result = map.get(PROP_NAME, defaultValue);
- assertTrue(prop.isSame(result));
-
- // default value
- result = map.get(PROP_NAME_NIL, defaultValue);
- assertSame(defaultValue, result);
- }
-
- public void testInputStream() throws Exception {
- this.rootNode.getSession().refresh(false);
- InputStream instream = new ByteArrayInputStream("this too shall pass".getBytes());
-
- ValueFactory valueFactory = rootNode.getSession().getValueFactory();
-
- rootNode.setProperty("bin", valueFactory.createBinary(instream));
- rootNode.getSession().save();
-
- ValueMap map = new JcrPropertyMap(rootNode);
- instream = map.get("bin", InputStream.class);
- assertNotNull(instream);
- String read = IOUtils.toString(instream);
- assertEquals("Stream read successfully", "this too shall pass", read);
-
- instream = map.get("bin", InputStream.class);
- assertNotNull(instream);
- read = IOUtils.toString(instream);
- assertEquals("Stream read successfully a second time", "this too shall pass", read);
- }
-
- // ---------- internal
-
- private void testValue(Node node, Object value, Object defaultValue) throws RepositoryException {
- ValueMap map = createProperty(rootNode, value);
- assertValueType(value, map.get(PROP_NAME, defaultValue), defaultValue.getClass());
- }
-
- private void testDefaultValue(Node node, Object defaultValue) {
- JcrPropertyMap map = createPropertyMap(rootNode);
- assertSame(defaultValue, map.get(PROP_NAME_NIL, defaultValue));
- }
-
- private void testValue(Node node, Object value, Class<?> type) throws RepositoryException {
- ValueMap map = createProperty(rootNode, value);
- assertValueType(value, map.get(PROP_NAME, type), type);
- }
-
- private void assertValueType(Object value, Object result, Class<?> type) {
- assertTrue(type.isInstance(result));
-
- if (value instanceof Long && result instanceof Number) {
- assertEquals(((Number) value).longValue(), ((Number) result).longValue());
-
- } else if (value instanceof Double && result instanceof Number) {
- assertEquals(((Number) value).doubleValue(), ((Number) result).doubleValue());
-
- } else if (value instanceof BigDecimal && result instanceof Number) {
- assertEquals(((BigDecimal) value).doubleValue(), ((Number) result).doubleValue());
-
- } else if (value instanceof Calendar) {
- long resultTime;
- if (result instanceof Date) {
- resultTime = ((Date) result).getTime();
- } else if (result instanceof Calendar) {
- resultTime = ((Calendar) result).getTimeInMillis();
- } else if (result instanceof Number) {
- resultTime = ((Number) result).longValue();
- } else {
- fail("unexpected result type for Calendar: " + type);
- return;
- }
- assertEquals(((Calendar) value).getTimeInMillis(), resultTime);
-
- } else {
- assertEquals(value, result);
- }
- }
-
- protected JcrPropertyMap createPropertyMap(final Node node) {
- return new JcrPropertyMap(node);
- }
-
- private void testValue(Node node, Object value) throws RepositoryException {
- ValueMap map = createProperty(node, value);
- assertEquals(value, map.get(PROP_NAME));
- }
-
- private void testValue(Node node, Calendar value) throws RepositoryException {
- ValueMap map = createProperty(node, value);
- assertEqualsCalendar(value, map.get(PROP_NAME, Calendar.class));
- }
-
- private ValueMap createProperty(Node node, Object value)
- throws RepositoryException {
- if (node.hasProperty(PROP_NAME)) {
- node.getProperty(PROP_NAME).remove();
- }
-
- Value jcrValue;
- ValueFactory fac = session.getValueFactory();
- if (value instanceof String) {
- jcrValue = fac.createValue((String) value);
- } else if (value instanceof Calendar) {
- jcrValue = fac.createValue((Calendar) value);
- } else if (value instanceof Date) {
- Calendar cal = Calendar.getInstance();
- cal.setTime((Date) value);
- jcrValue = fac.createValue(cal);
- } else if (value instanceof Boolean) {
- jcrValue = fac.createValue(((Boolean) value).booleanValue());
- } else if (value instanceof Double) {
- jcrValue = fac.createValue(((Double) value).doubleValue());
- } else if (value instanceof Long) {
- jcrValue = fac.createValue(((Long) value).longValue());
- } else if (value instanceof BigDecimal) {
- jcrValue = fac.createValue((BigDecimal) value);
- } else {
- fail("Cannot create JCR value from " + value);
- return null;
- }
-
- node.setProperty(PROP_NAME, jcrValue);
- node.getSession().save();
-
- return createPropertyMap(node);
- }
-
- private static final String TEST_PATH = "a<a";
-
- private static final String VALUE = "value";
- private static final String VALUE1 = "value";
- private static final String VALUE2 = "value";
- private static final String VALUE3 = "my title";
- private static final String PROP1 = "-prop";
- private static final String PROP2 = "1prop";
- private static final String PROP3 = "jcr:title";
- private static final String PROP4 = ":prop";
-
- public void testNames() throws Exception {
- this.rootNode.getSession().refresh(false);
- this.rootNode.setProperty(Text.escapeIllegalJcrChars(TEST_PATH), VALUE);
- this.rootNode.setProperty(PROP1, VALUE1);
- this.rootNode.setProperty(PROP2, VALUE2);
- this.rootNode.setProperty(PROP3, VALUE3);
- final ValueMap vm = this.createPropertyMap(this.rootNode);
- assertEquals(VALUE, vm.get(TEST_PATH));
- assertEquals(VALUE1, vm.get(PROP1));
- assertEquals(VALUE2, vm.get(PROP2));
- assertEquals(VALUE3, vm.get(PROP3));
- vm.get(PROP4);
- }
-
- public void testColon() throws Exception {
- this.rootNode.getSession().refresh(false);
- final ValueMap vm = this.createPropertyMap(this.rootNode);
- assertNull(vm.get(":prop"));
- assertNull(vm.get("prop:"));
- assertNull(vm.get("jcr:title"));
- assertNull(vm.get("unknown:prefix"));
- }
-
- public void testIerators() throws Exception {
- this.rootNode.getSession().refresh(false);
- this.rootNode.setProperty(Text.escapeIllegalJcrChars(TEST_PATH), VALUE);
- this.rootNode.setProperty(PROP1, VALUE1);
- this.rootNode.setProperty(PROP2, VALUE2);
- final ValueMap vm = this.createPropertyMap(this.rootNode);
- assertTrue(vm.containsKey(TEST_PATH));
- search(vm.keySet().iterator(), TEST_PATH);
- search(vm.keySet().iterator(), PROP1);
- search(vm.keySet().iterator(), PROP2);
- search(vm.values().iterator(), VALUE);
- search(vm.values().iterator(), VALUE1);
- search(vm.values().iterator(), VALUE2);
- }
-
- public void testContainsKeyEmpty() {
- final JcrPropertyMap map = createPropertyMap(rootNode);
- assertFalse(map.containsKey(""));
- assertNull(map.get(""));
- }
-
- public void testNamesOld() throws Exception {
- this.rootNode.getSession().refresh(false);
- this.rootNode.setProperty(ISO9075.encodePath(TEST_PATH), VALUE);
- final ValueMap vm = this.createPropertyMap(this.rootNode);
- assertEquals(VALUE, vm.get(TEST_PATH));
- }
-
- public void testIeratorsOld() throws Exception {
- this.rootNode.getSession().refresh(false);
- this.rootNode.setProperty(ISO9075.encodePath(TEST_PATH), VALUE);
- final ValueMap vm = this.createPropertyMap(this.rootNode);
- assertTrue(vm.containsKey(TEST_PATH));
- search(vm.keySet().iterator(), TEST_PATH);
- search(vm.values().iterator(), VALUE);
- }
-
- public void testDotSlash() throws Exception {
- this.rootNode.getSession().refresh(false);
- final String prop = "myProp";
- final String value = "value";
- this.rootNode.setProperty(prop, value);
- final ValueMap vm = this.createPropertyMap(this.rootNode);
- assertEquals(value, vm.get(prop));
- assertEquals(value, vm.get("./" + prop));
- assertTrue(vm.containsKey("./" + prop));
- }
-
- protected void search(Iterator<?> i, Object value) {
- boolean found = false;
- while ( !found && i.hasNext() ) {
- final Object current = i.next();
- found = current.equals(value);
- }
- if ( !found ) {
- fail("Value " + value + " is not found in iterator.");
- }
- }
-}
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java
index d5296ae..1d2d341 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java
@@ -73,7 +73,6 @@
final ProviderContext ctx = new SimpleProviderContext();
this.config = new JcrListenerBaseConfig(ctx.getObservationReporter(),
- new PathMapperImpl(),
RepositoryUtil.getRepository());
jcrResourceListener = new JcrResourceListener(this.config, ctx.getObservationReporter().getObserverConfigurations().get(0));
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
index 98153b5..6262d73 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
@@ -75,7 +75,6 @@
RepositoryUtil.registerSlingNodeTypes(adminSession);
final SlingRepository repo = RepositoryUtil.getRepository();
this.config = new JcrListenerBaseConfig(getObservationReporter(),
- new PathMapperImpl(),
new SlingRepository() {
@Override
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceUtilTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceUtilTest.java
deleted file mode 100644
index f6ca20d..0000000
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceUtilTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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 javax.jcr.Node;
-
-import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
-
-/**
- * Test of JcrResourceUtil.
- */
-public class JcrResourceUtilTest extends RepositoryTestBase {
- private String rootPath;
-
- private Node rootNode;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- rootPath = "/test" + System.currentTimeMillis();
- rootNode = getSession().getRootNode().addNode(rootPath.substring(1),
- "nt:unstructured");
- session.save();
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (rootNode != null) {
- rootNode.remove();
- session.save();
- }
-
- super.tearDown();
- }
-
- public void testCreatePathRootExists() throws Exception {
- String pathToCreate = rootPath + "/a/b/c";
- Node created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
-
- //test appending the path
- pathToCreate = pathToCreate + "/d";
- created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
-
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
- assertTrue(session.itemExists(pathToCreate));
- }
-
- public void testCreateRoot() throws Exception {
- String pathToCreate = "/";
- Node created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
-
- assertNotNull(created);
-
- assertEquals(created.getPath(), pathToCreate);
- }
-
-
- public void testCreatePathThatExists() throws Exception {
- String pathToCreate = rootPath + "/a/b/c";
- Node created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
-
- created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
-
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
- assertTrue(session.itemExists(pathToCreate));
- }
-
- public void testCreatePathBoundaryCase() throws Exception {
- String pathToCreate = "/a";
- Node created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
- assertTrue(session.itemExists(pathToCreate));
- }
-
- public void testCreatePathNodeVariant() throws Exception {
- String pathToCreate = rootPath + "/a/b/c";
- Node created = JcrResourceUtil.createPath(pathToCreate, "nt:unstructured", "nt:unstructured", session, true);
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
-
- //test appending the path
- created = JcrResourceUtil.createPath(created, "d/e", "nt:unstructured", "nt:unstructured", true);
-
- pathToCreate = pathToCreate + "/d/e";
- assertNotNull(created);
- assertEquals(created.getPath(), pathToCreate);
- assertTrue(session.itemExists(pathToCreate));
- }
-}
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/PathMapperImpl.java b/src/test/java/org/apache/sling/jcr/resource/internal/PathMapperImpl.java
deleted file mode 100644
index 7946f8c..0000000
--- a/src/test/java/org/apache/sling/jcr/resource/internal/PathMapperImpl.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
-
-
-public class PathMapperImpl extends PathMapper {
-
- @Override
- public String mapResourcePathToJCRPath(String path) {
- return path;
- }
-
- @Override
- public String mapJCRPathToResourcePath(String path) {
- return path;
- }
-}
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
index 0f38668..e7ec605 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
@@ -30,7 +30,6 @@
import org.apache.sling.commons.testing.jcr.MockNode;
import org.apache.sling.commons.testing.jcr.MockNodeIterator;
import org.apache.sling.jcr.resource.internal.HelperData;
-import org.apache.sling.jcr.resource.internal.PathMapperImpl;
import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator;
import junit.framework.TestCase;
@@ -38,7 +37,7 @@
public class JcrNodeResourceIteratorTest extends TestCase {
private HelperData getHelperData() {
- return new HelperData(new AtomicReference<DynamicClassLoaderManager>(), new PathMapperImpl());
+ return new HelperData(new AtomicReference<DynamicClassLoaderManager>());
}
public void testEmpty() {
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactoryTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactoryTest.java
index 4069049..aae9491 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactoryTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceFactoryTest.java
@@ -32,7 +32,6 @@
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
import org.apache.sling.jcr.resource.internal.HelperData;
-import org.apache.sling.jcr.resource.internal.PathMapperImpl;
public class JcrItemResourceFactoryTest extends RepositoryTestBase {
@@ -88,7 +87,7 @@
}
private void compareGetItemOrNull(String path, String expectedPath) throws RepositoryException {
- HelperData helper = new HelperData(new AtomicReference<DynamicClassLoaderManager>(), new PathMapperImpl());
+ HelperData helper = new HelperData(new AtomicReference<DynamicClassLoaderManager>());
Item item1 = new JcrItemResourceFactory(session, helper).getItemOrNull(path);
Item item2 = new JcrItemResourceFactory(nonJackrabbitSession, helper).getItemOrNull(path);
if (expectedPath == null) {
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java
index a43abbf..1bf688d 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java
@@ -26,7 +26,7 @@
import org.apache.sling.api.SlingConstants;
import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.jcr.resource.api.JcrResourceConstants;
import org.junit.Ignore;
@Ignore
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
index cf960f3..e297f6f 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
@@ -33,14 +33,13 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.jcr.resource.api.JcrResourceConstants;
import org.apache.sling.jcr.resource.internal.HelperData;
-import org.apache.sling.jcr.resource.internal.PathMapperImpl;
public class JcrNodeResourceTest extends JcrItemResourceTestBase {
private HelperData getHelperData() throws Exception {
- return new HelperData(new AtomicReference<DynamicClassLoaderManager>(), new PathMapperImpl());
+ return new HelperData(new AtomicReference<DynamicClassLoaderManager>());
}
public void testLinkedFile() throws Exception {
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java
index 26f27cf..3159c2c 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java
@@ -26,13 +26,12 @@
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.jcr.resource.internal.HelperData;
-import org.apache.sling.jcr.resource.internal.PathMapperImpl;
public class JcrTestNodeResource extends JcrNodeResource {
public JcrTestNodeResource(ResourceResolver resourceResolver, Node node,
ClassLoader dynamicClassLoader) throws RepositoryException {
- super(resourceResolver, node.getPath(), null, node, new HelperData(new AtomicReference<DynamicClassLoaderManager>(), new PathMapperImpl()));
+ super(resourceResolver, node.getPath(), null, node, new HelperData(new AtomicReference<DynamicClassLoaderManager>()));
}
}
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/PathMapperTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/PathMapperTest.java
deleted file mode 100644
index 5b9953c..0000000
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/PathMapperTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.helper.jcr;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.lang.annotation.Annotation;
-
-import org.junit.Test;
-
-import junitx.util.PrivateAccessor;
-
-public class PathMapperTest {
-
- @Test public void mappingTest() throws Throwable {
- final PathMapper.Config config = new PathMapper.Config() {
-
- @Override
- public Class<? extends Annotation> annotationType() {
- return null;
- }
-
- @Override
- public String[] path_mapping() {
- return new String[] {"/libs:/foo",
- "/hidden:.",
- "/deep/node:/deep/resource"};
- }
- };
- final PathMapper pm = new PathMapper();
- PrivateAccessor.invoke(pm, "activate", new Class[] {PathMapper.Config.class}, new Object[] {config});
-
- assertEquals("/", pm.mapResourcePathToJCRPath("/"));
- assertEquals("/", pm.mapJCRPathToResourcePath("/"));
-
- assertEquals("/unmapped", pm.mapResourcePathToJCRPath("/unmapped"));
- assertEquals("/unmapped", pm.mapJCRPathToResourcePath("/unmapped"));
- assertEquals("/unmapped/a", pm.mapResourcePathToJCRPath("/unmapped/a"));
- assertEquals("/unmapped/a", pm.mapJCRPathToResourcePath("/unmapped/a"));
-
- assertEquals("/libs", pm.mapResourcePathToJCRPath("/foo"));
- assertEquals("/foo", pm.mapJCRPathToResourcePath("/libs"));
- assertEquals("/foo1", pm.mapResourcePathToJCRPath("/foo1"));
- assertEquals("/libs1", pm.mapJCRPathToResourcePath("/libs1"));
- assertEquals("/libs/a", pm.mapResourcePathToJCRPath("/foo/a"));
- assertEquals("/foo/a", pm.mapJCRPathToResourcePath("/libs/a"));
-
- assertEquals("/deep/node", pm.mapResourcePathToJCRPath("/deep/resource"));
- assertEquals("/deep/resource", pm.mapJCRPathToResourcePath("/deep/node"));
- assertEquals("/deep/node/a", pm.mapResourcePathToJCRPath("/deep/resource/a"));
- assertEquals("/deep/resource/a", pm.mapJCRPathToResourcePath("/deep/node/a"));
-
- assertNull(pm.mapResourcePathToJCRPath("/hidden"));
- assertNull(pm.mapResourcePathToJCRPath("/hidden/a"));
- assertEquals("/hidden1", pm.mapResourcePathToJCRPath("/hidden1"));
- assertNull(pm.mapJCRPathToResourcePath("/hidden"));
- assertNull(pm.mapJCRPathToResourcePath("/hidden/a"));
- assertEquals("/hidden1", pm.mapJCRPathToResourcePath("/hidden1"));
- }
-}