Merge pull request #9 from apache/bugfix/rely-on-jcr-constants-instead-of-jackrabbit-ones
SLING-9440 clean up usage of constants
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
index 376d7b5..f02a170 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
@@ -18,7 +18,7 @@
*/
package org.apache.sling.jcr.resource.internal.helper.jcr;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import javax.jcr.Item;
@@ -28,7 +28,6 @@
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
-import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.AbstractResource;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
@@ -125,8 +124,8 @@
if (result == null || result.length() == 0) {
// Do not load the relatively expensive NodeType object unless necessary. See OAK-2441 for the reason why it
// cannot only use getProperty here.
- if (node.hasProperty(JcrConstants.JCR_PRIMARYTYPE)) {
- result = node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString();
+ if (node.hasProperty(Property.JCR_PRIMARY_TYPE)) {
+ result = node.getProperty(Property.JCR_PRIMARY_TYPE).getString();
} else {
result = node.getPrimaryNodeType().getName();
}
@@ -140,27 +139,21 @@
return -1;
}
- try {
- long length = -1;
- if (property.getType() == PropertyType.BINARY ) {
- // we're interested in the number of bytes, not the
- // number of characters
- try {
- length = property.getLength();
- } catch (final ValueFormatException vfe) {
- LOGGER.debug(
- "Length of Property {} cannot be retrieved, ignored ({})",
- property.getPath(), vfe);
- }
- } else {
- length = property.getString().getBytes("UTF-8").length;
+ long length = -1;
+ if (property.getType() == PropertyType.BINARY ) {
+ // we're interested in the number of bytes, not the
+ // number of characters
+ try {
+ length = property.getLength();
+ } catch (final ValueFormatException vfe) {
+ LOGGER.debug(
+ "Length of Property {} cannot be retrieved, ignored ({})",
+ property.getPath(), vfe);
}
- return length;
- } catch (UnsupportedEncodingException uee) {
- LOGGER.warn("getPropertyContentLength: Cannot determine length of non-binary property {}: {}",
- property, uee);
+ } else {
+ length = property.getString().getBytes(StandardCharsets.UTF_8).length;
}
- return -1;
+ return length;
}
/**
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 abdef92..22b210e 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
@@ -26,11 +26,11 @@
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionManager;
import org.apache.commons.lang3.StringUtils;
-import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
@@ -170,7 +170,7 @@
}
private static boolean isVersionable(Item item) throws RepositoryException {
- return item.isNode() && ((Node) item).isNodeType(JcrConstants.MIX_VERSIONABLE);
+ return item.isNode() && ((Node) item).isNodeType(NodeType.MIX_VERSIONABLE);
}
Item getItemOrNull(String path) throws RepositoryException {
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 0612dde..70596ad 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
@@ -16,10 +16,10 @@
*/
package org.apache.sling.jcr.resource.internal.helper.jcr;
-import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT;
-import static org.apache.jackrabbit.JcrConstants.JCR_DATA;
-import static org.apache.jackrabbit.JcrConstants.NT_FILE;
-import static org.apache.jackrabbit.JcrConstants.NT_LINKEDFILE;
+import static javax.jcr.Property.JCR_CONTENT;
+import static javax.jcr.Property.JCR_DATA;
+import static javax.jcr.nodetype.NodeType.NT_FILE;
+import static javax.jcr.nodetype.NodeType.NT_LINKED_FILE;
import static javax.jcr.nodetype.NodeType.NT_FROZEN_NODE;
import static javax.jcr.Property.JCR_FROZEN_PRIMARY_TYPE;
@@ -34,7 +34,6 @@
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
-import javax.jcr.Value;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adapter;
@@ -188,7 +187,7 @@
(node.isNodeType(NT_FROZEN_NODE) &&
node.getProperty(JCR_FROZEN_PRIMARY_TYPE).getString().equals(NT_FILE)))
? node.getNode(JCR_CONTENT)
- : node.isNodeType(NT_LINKEDFILE) ? node.getProperty(JCR_CONTENT).getNode() : node;
+ : node.isNodeType(NT_LINKED_FILE) ? node.getProperty(JCR_CONTENT).getNode() : node;
Property data;
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceMetadata.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceMetadata.java
index 06ac04e..e1bff89 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceMetadata.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceMetadata.java
@@ -18,15 +18,15 @@
*/
package org.apache.sling.jcr.resource.internal.helper.jcr;
-import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT;
-import static org.apache.jackrabbit.JcrConstants.JCR_CREATED;
-import static org.apache.jackrabbit.JcrConstants.JCR_DATA;
-import static org.apache.jackrabbit.JcrConstants.JCR_ENCODING;
-import static org.apache.jackrabbit.JcrConstants.JCR_LASTMODIFIED;
-import static org.apache.jackrabbit.JcrConstants.JCR_MIMETYPE;
-import static org.apache.jackrabbit.JcrConstants.NT_FILE;
-import static javax.jcr.nodetype.NodeType.NT_FROZEN_NODE;
+import static javax.jcr.Property.JCR_CONTENT;
+import static javax.jcr.Property.JCR_CREATED;
+import static javax.jcr.Property.JCR_DATA;
+import static javax.jcr.Property.JCR_ENCODING;
import static javax.jcr.Property.JCR_FROZEN_PRIMARY_TYPE;
+import static javax.jcr.Property.JCR_LAST_MODIFIED;
+import static javax.jcr.Property.JCR_MIMETYPE;
+import static javax.jcr.nodetype.NodeType.NT_FILE;
+import static javax.jcr.nodetype.NodeType.NT_FROZEN_NODE;
import java.util.Collection;
import java.util.Map;
@@ -134,9 +134,9 @@
long modificationTime = -1;
final Node targetNode = promoteNode();
try {
- if (targetNode.hasProperty(JCR_LASTMODIFIED)) {
+ if (targetNode.hasProperty(JCR_LAST_MODIFIED)) {
// We don't check node type, so JCR_LASTMODIFIED might not be a long
- final Property prop = targetNode.getProperty(JCR_LASTMODIFIED);
+ final Property prop = targetNode.getProperty(JCR_LAST_MODIFIED);
try {
modificationTime = prop.getLong();
} catch (final ValueFormatException vfe) {