You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2013/07/04 06:38:06 UTC
svn commit: r1499651 - in
/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource: ./
src/main/java/org/apache/sling/jcr/resource/
src/main/java/org/apache/sling/jcr/resource/internal/
src/main/java/org/apache/sling/jcr/resource/internal...
Author: fmeschbe
Date: Thu Jul 4 04:38:05 2013
New Revision: 1499651
URL: http://svn.apache.org/r1499651
Log:
Implement support for service based ResourceResolver and Session access
- Update with latest changes from trunk
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/ (props changed)
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
Propchange: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/
------------------------------------------------------------------------------
svn:mergeinfo = /sling/trunk/bundles/jcr/resource:1458701-1499650
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml Thu Jul 4 04:38:05 2013
@@ -22,12 +22,12 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>15</version>
+ <version>16</version>
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
<artifactId>org.apache.sling.jcr.resource</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.9-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling JCR Resource Resolver</name>
@@ -146,7 +146,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.4.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java Thu Jul 4 04:38:05 2013
@@ -28,6 +28,7 @@ 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.List;
import java.util.Map;
@@ -259,7 +260,7 @@ public class JcrPropertyMap
final String name = prop.getName();
String key = null;
if ( name.indexOf("_x") != -1 ) {
- // for compatiblity with older versions we use the (wrong)
+ // for compatibility with older versions we use the (wrong)
// ISO9075 path encoding
key = ISO9075.decode(name);
if ( key.equals(name) ) {
@@ -351,7 +352,7 @@ public class JcrPropertyMap
}
try {
- // for compatiblity with older versions we use the (wrong) ISO9075 path
+ // for compatibility with older versions we use the (wrong) ISO9075 path
// encoding
final String oldKey = ISO9075.encodePath(name);
if (node.hasProperty(oldKey)) {
@@ -547,6 +548,14 @@ public class JcrPropertyMap
} else if (Property.class == type) {
return (T) entry.property;
+ } else if (ObjectInputStream.class == type) {
+ if ( jcrValue.getType() == PropertyType.BINARY ) {
+ try {
+ return (T) new ObjectInputStream(jcrValue.getBinary().getStream(), this.dynamicClassLoader);
+ } catch (IOException ioe) {
+ // ignore and use fallback
+ }
+ }
} else if (Serializable.class.isAssignableFrom(type)
&& jcrValue.getType() == PropertyType.BINARY) {
ObjectInputStream ois = null;
@@ -597,6 +606,30 @@ public class JcrPropertyMap
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();
+ }
+
+
/**
* This is an extended version of the object input stream which uses the
* thread context class loader.
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java Thu Jul 4 04:38:05 2013
@@ -88,7 +88,23 @@ public class JcrResourceUtil {
// multi-value property: return an array of values
if (property.isMultiple()) {
Value[] values = property.getValues();
- Object[] result = new Object[values.length];
+ 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) {
@@ -127,6 +143,10 @@ public class JcrResourceUtil {
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) {
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java Thu Jul 4 04:38:05 2013
@@ -343,7 +343,7 @@ public final class JcrModifiableValueMap
}
try {
- // for compatiblity with older versions we use the (wrong) ISO9075 path
+ // for compatibility with older versions we use the (wrong) ISO9075 path
// encoding
final String oldKey = ISO9075.encodePath(name);
if (node.hasProperty(oldKey)) {
@@ -521,6 +521,14 @@ public final class JcrModifiableValueMap
} else if (Property.class == type) {
return (T) entry.property;
+ } else if (ObjectInputStream.class == type) {
+ if ( jcrValue.getType() == PropertyType.BINARY ) {
+ try {
+ return (T) new ObjectInputStream(jcrValue.getBinary().getStream(), this.dynamicClassLoader);
+ } catch (IOException ioe) {
+ // ignore and use fallback
+ }
+ }
} else if (Serializable.class.isAssignableFrom(type)
&& jcrValue.getType() == PropertyType.BINARY) {
ObjectInputStream ois = null;
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java Thu Jul 4 04:38:05 2013
@@ -34,7 +34,7 @@ import org.apache.sling.jcr.resource.Jcr
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-abstract class JcrItemResource extends AbstractResource implements Resource {
+public abstract class JcrItemResource extends AbstractResource implements Resource {
/**
* default log
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java Thu Jul 4 04:38:05 2013
@@ -118,6 +118,7 @@ public class JcrNodeResource extends Jcr
return resourceSuperType;
}
+ @Override
@SuppressWarnings("unchecked")
public <Type> Type adaptTo(Class<Type> type) {
if (type == Node.class || type == Item.class) {
@@ -168,6 +169,7 @@ public class JcrNodeResource extends Jcr
return super.adaptTo(type);
}
+ @Override
public String toString() {
return getClass().getSimpleName()
+ ", type=" + getResourceType()
@@ -273,7 +275,10 @@ public class JcrNodeResource extends Jcr
// continue our stuff with the jcr:content node
// which might be nt:resource, which we support below
- node = node.getNode(JCR_CONTENT);
+ // if the node is new, the content node might not exist yet
+ if ( !node.isNew() || node.hasNode(JCR_CONTENT) ) {
+ node = node.getNode(JCR_CONTENT);
+ }
}
// check stuff for nt:resource (or similar) nodes
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java Thu Jul 4 04:38:05 2013
@@ -60,8 +60,8 @@ public class JcrNodeResourceIterator imp
final ClassLoader dynamicClassLoader) {
this.resourceResolver = resourceResolver;
this.nodes = nodes;
- this.nextResult = seek();
this.dynamicClassLoader = dynamicClassLoader;
+ this.nextResult = seek();
}
public boolean hasNext() {
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1499651&r1=1499650&r2=1499651&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Thu Jul 4 04:38:05 2013
@@ -45,6 +45,7 @@ import org.apache.sling.api.resource.Mod
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.QueriableResourceProvider;
import org.apache.sling.api.resource.QuerySyntaxException;
+import org.apache.sling.api.resource.RefreshableResourceProvider;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceProvider;
import org.apache.sling.api.resource.ResourceResolver;
@@ -70,6 +71,7 @@ public class JcrResourceProvider
DynamicResourceProvider,
AttributableResourceProvider,
QueriableResourceProvider,
+ RefreshableResourceProvider,
ModifyingResourceProvider {
/** column name for node path */
@@ -81,6 +83,14 @@ public class JcrResourceProvider
@SuppressWarnings("deprecation")
private static final String DEFAULT_QUERY_LANGUAGE = Query.XPATH;
+ private static final Set<String> IGNORED_PROPERTIES = new HashSet<String>();
+ static {
+ IGNORED_PROPERTIES.add(NodeUtil.MIXIN_TYPES);
+ IGNORED_PROPERTIES.add(NodeUtil.NODE_TYPE);
+ IGNORED_PROPERTIES.add("jcr:created");
+ IGNORED_PROPERTIES.add("jcr:createdBy");
+ }
+
/** Default logger */
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -411,6 +421,7 @@ public class JcrResourceProvider
nodeType = null;
}
}
+ Node node = null;
try {
final int lastPos = path.lastIndexOf('/');
final Node parent;
@@ -420,7 +431,6 @@ public class JcrResourceProvider
parent = (Node)this.session.getItem(path.substring(0, lastPos));
}
final String name = path.substring(lastPos + 1);
- final Node node;
if ( nodeType != null ) {
node = parent.addNode(name, nodeType);
} else {
@@ -436,10 +446,15 @@ public class JcrResourceProvider
jcrMap.put(NodeUtil.MIXIN_TYPES, value);
}
for(final Map.Entry<String, Object> entry : properties.entrySet()) {
- if ( !NodeUtil.NODE_TYPE.equals(entry.getKey()) && !NodeUtil.MIXIN_TYPES.equals(entry.getKey())) {
+ if ( !IGNORED_PROPERTIES.contains(entry.getKey()) ) {
try {
jcrMap.put(entry.getKey(), entry.getValue());
} catch (final IllegalArgumentException iae) {
+ try {
+ node.remove();
+ } catch ( final RepositoryException re) {
+ // we ignore this
+ }
throw new PersistenceException(iae.getMessage(), iae, path, entry.getKey());
}
}
@@ -448,6 +463,13 @@ public class JcrResourceProvider
return new JcrNodeResource(resolver, node, this.dynamicClassLoader);
} catch (final RepositoryException e) {
+ if ( node != null ) {
+ try {
+ node.remove();
+ } catch ( final RepositoryException re) {
+ // we ignore this
+ }
+ }
throw new PersistenceException("Unable to create node at " + path, e, path, null);
}
}
@@ -501,4 +523,15 @@ public class JcrResourceProvider
}
return false;
}
+
+ /**
+ * @see org.apache.sling.api.resource.RefreshableResourceProvider#refresh()
+ */
+ public void refresh() {
+ try {
+ this.session.refresh(true);
+ } catch (final RepositoryException ignore) {
+ log.warn("Unable to refresh session.", ignore);
+ }
+ }
}