You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/03/31 05:44:47 UTC
svn commit: r1789614 - in /sling/trunk/bundles/servlets/post: ./
src/main/java/org/apache/sling/servlets/post/impl/helper/
src/main/java/org/apache/sling/servlets/post/impl/operations/
src/test/java/org/apache/sling/servlets/post/impl/operations/
Author: cziegeler
Date: Fri Mar 31 05:44:47 2017
New Revision: 1789614
URL: http://svn.apache.org/viewvc?rev=1789614&view=rev
Log:
SLING-6723 : Make dependency to javax.jcr, jcr.contentloader and jcr.api optional
Modified:
sling/trunk/bundles/servlets/post/pom.xml
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/Chunk.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/DateParser.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/DeleteOperation.java
sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/operations/MockRealResource.java
Modified: sling/trunk/bundles/servlets/post/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/pom.xml?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/pom.xml (original)
+++ sling/trunk/bundles/servlets/post/pom.xml Fri Mar 31 05:44:47 2017
@@ -111,13 +111,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.3.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.jcr.api</artifactId>
- <version>2.0.6</version>
+ <version>2.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/Chunk.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/Chunk.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/Chunk.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/Chunk.java Fri Mar 31 05:44:47 2017
@@ -17,8 +17,8 @@
package org.apache.sling.servlets.post.impl.helper;
/**
- * <code>Chunk</code> enscapsulates all chunk upload attributes.
- *
+ * <code>Chunk</code> encapsulates all chunk upload attributes.
+ *
* @since 2.3.4
*/
public class Chunk {
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java Fri Mar 31 05:44:47 2017
@@ -16,16 +16,14 @@
*/
package org.apache.sling.servlets.post.impl.helper;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-import javax.jcr.query.QueryResult;
+import java.util.Calendar;
+import java.util.Iterator;
-import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@@ -86,7 +84,7 @@ public class ChunkCleanUpTask implements
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference
- private SlingRepository repository;
+ private ResourceResolverFactory rrFactory;
private SlingFileUploadHandler uploadhandler = new SlingFileUploadHandler();
@@ -105,10 +103,10 @@ public class ChunkCleanUpTask implements
}
/**
- * This method deletes chunks which are {@link #isEligibleForCleanUp(Node)}
+ * This method deletes chunks which are {@link #isEligibleForCleanUp(Resource)}
* for cleanup. It queries all
* {@link SlingPostConstants#NT_SLING_CHUNK_MIXIN} nodes and filter nodes
- * which are {@link #isEligibleForCleanUp(Node)} for cleanup. It then
+ * which are {@link #isEligibleForCleanUp(Resource)} for cleanup. It then
* deletes old chunks upload.
*/
private void cleanup() {
@@ -118,31 +116,26 @@ public class ChunkCleanUpTask implements
int numCleaned = 0;
int numLive = 0;
- Session admin = null;
+ ResourceResolver admin = null;
try {
- // assume chunks are stored in the default workspace
- admin = repository.loginAdministrative(null);
- QueryManager qm = admin.getWorkspace().getQueryManager();
-
- QueryResult queryres = qm.createQuery(
- "SELECT * FROM [sling:chunks] ", Query.JCR_SQL2).execute();
- NodeIterator nodeItr = queryres.getNodes();
- while (nodeItr.hasNext()) {
- Node node = nodeItr.nextNode();
- if (isEligibleForCleanUp(node)) {
+ admin = rrFactory.getAdministrativeResourceResolver(null);
+
+ final Iterator<Resource> rsrcIter = admin.findResources(
+ "SELECT * FROM [sling:chunks] ", "sql");
+ while (rsrcIter.hasNext()) {
+ final Resource rsrc = rsrcIter.next();
+ if (isEligibleForCleanUp(rsrc)) {
numCleaned++;
- uploadhandler.deleteChunks(node);
+ uploadhandler.deleteChunks(rsrc);
} else {
numLive++;
}
}
- if (admin.hasPendingChanges()) {
+ if (admin.hasChanges()) {
try {
- admin.refresh(true);
- admin.save();
- } catch (InvalidItemStateException iise) {
- log.info("ChunkCleanUpTask: Concurrent modification to one or more of the chunk to be removed. Retrying later");
- } catch (RepositoryException re) {
+ admin.refresh();
+ admin.commit();
+ } catch (PersistenceException re) {
log.info("ChunkCleanUpTask: Failed persisting chunk removal. Retrying later");
}
}
@@ -153,7 +146,7 @@ public class ChunkCleanUpTask implements
t);
} finally {
if (admin != null) {
- admin.logout();
+ admin.close();
}
}
long end = System.currentTimeMillis();
@@ -163,23 +156,27 @@ public class ChunkCleanUpTask implements
}
/**
- * Check if {@link Node} is eligible of
+ * Check if {@link Resource} is eligible of
* {@link SlingPostConstants#NT_SLING_CHUNK_NODETYPE} cleanup. To be
* eligible the age of last
* {@link SlingPostConstants#NT_SLING_CHUNK_NODETYPE} uploaded should be
* greater than @link {@link #chunkCleanUpAge}
*
- * @param node {@link Node} containing
+ * @param rsrc {@link Resource} containing
* {@link SlingPostConstants#NT_SLING_CHUNK_NODETYPE}
- * {@link Node}s
+ * {@link Resource}s
* @return true if eligible else false.
- * @throws RepositoryException
*/
- private boolean isEligibleForCleanUp(Node node) throws RepositoryException {
- Node lastChunkNode = uploadhandler.getLastChunk(node);
- return lastChunkNode != null
- && (System.currentTimeMillis() - lastChunkNode.getProperty(
- javax.jcr.Property.JCR_CREATED).getDate().getTimeInMillis()) > chunkCleanUpAge;
+ private boolean isEligibleForCleanUp(Resource rsrc) {
+ boolean result = false;
+ final Resource lastChunkNode = uploadhandler.getLastChunk(rsrc);
+ if ( lastChunkNode != null ) {
+ final Calendar created = lastChunkNode.getValueMap().get(JcrConstants.JCR_CREATED, Calendar.class);
+ if ( created != null && System.currentTimeMillis() - created.getTimeInMillis() > chunkCleanUpAge ) {
+ result = true;
+ }
+ }
+ return result;
}
@Activate
@@ -190,5 +187,4 @@ public class ChunkCleanUpTask implements
chunkCleanUpAge);
}
-
}
\ No newline at end of file
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/DateParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/DateParser.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/DateParser.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/DateParser.java Fri Mar 31 05:44:47 2017
@@ -24,9 +24,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-
import org.apache.jackrabbit.util.ISO8601;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,7 +42,7 @@ public class DateParser {
/**
* lits of formats
*/
- private final List<CalendarParserSupport> formats = new LinkedList<CalendarParserSupport>();
+ private final List<CalendarParserSupport> formats = new LinkedList<>();
/**
* Registers a format string to the list of internally checked ones.
@@ -67,12 +64,11 @@ public class DateParser {
* Parses the given source string and returns the respective calendar
* instance. If no format matches returns <code>null</code>.
* <p/>
- * Note: method is synchronized because SimpleDateFormat is not.
*
* @param source date time source string
* @return calendar representation of the source or <code>null</code>
*/
- public synchronized Calendar parse(String source) {
+ public Calendar parse(String source) {
for (CalendarParserSupport fmt : formats) {
try {
final Calendar c = fmt.parse(source);
@@ -95,12 +91,11 @@ public class DateParser {
* instances. If no format matches for any of the sources
* returns <code>null</code>.
* <p/>
- * Note: method is synchronized because SimpleDateFormat is not.
*
* @param sources date time source strings
* @return calendar representations of the source or <code>null</code>
*/
- public synchronized Calendar[] parse(String sources[]) {
+ public Calendar[] parse(String sources[]) {
Calendar ret[] = new Calendar[sources.length];
for (int i=0; i< sources.length; i++) {
if ((ret[i] = parse(sources[i])) == null) {
@@ -110,29 +105,6 @@ public class DateParser {
return ret;
}
- /**
- * Parses the given source strings and returns the respective jcr date value
- * instances. If no format matches for any of the sources
- * returns <code>null</code>.
- * <p/>
- * Note: method is synchronized because SimpleDateFormat is not.
- *
- * @param sources date time source strings
- * @param factory the value factory
- * @return jcr date value representations of the source or <code>null</code>
- */
- public synchronized Value[] parse(String sources[], ValueFactory factory) {
- Value ret[] = new Value[sources.length];
- for (int i=0; i< sources.length; i++) {
- Calendar c = parse(sources[i]);
- if (c == null) {
- return null;
- }
- ret[i] = factory.createValue(c);
- }
- return ret;
- }
-
private static interface CalendarParserSupport {
Calendar parse(String dateTime) throws ParseException;
}
@@ -144,6 +116,7 @@ public class DateParser {
this.dateFormat = new SimpleDateFormat(format, Locale.US);
}
+ @Override
public Calendar parse(String dateTime) throws ParseException {
final Date d;
synchronized (dateFormat) {
@@ -166,6 +139,7 @@ public class DateParser {
static final String FORMAT_MARKER = "ISO8601";
+ @Override
public Calendar parse(String dateTime) throws ParseException {
try {
final Calendar c = ISO8601.parse(dateTime);
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java Fri Mar 31 05:44:47 2017
@@ -40,11 +40,13 @@ import javax.jcr.nodetype.NodeTypeManage
import javax.servlet.ServletContext;
import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.slf4j.Logger;
@@ -213,7 +215,7 @@ public class SlingFileUploadHandler {
+ parentResource.getPath() + "] doesn't exists");
}
// create properties
- final Map<String, Object> props = new HashMap<String, Object>();
+ final Map<String, Object> props = new HashMap<>();
props.put("sling:resourceType", typeHint);
props.put(JCR_LASTMODIFIED, Calendar.getInstance());
props.put(JCR_MIMETYPE, contentType);
@@ -378,7 +380,7 @@ public class SlingFileUploadHandler {
String startPattern = SlingPostConstants.CHUNK_NODE_NAME + "_"
+ "0_*";
NodeIterator nodeItr = parentNode.getNodes(startPattern);
- Set<InputStream> inpStrmSet = new LinkedHashSet<InputStream>();
+ Set<InputStream> inpStrmSet = new LinkedHashSet<>();
while (nodeItr.hasNext()) {
if (nodeItr.getSize() > 1) {
throw new RepositoryException(
@@ -411,90 +413,94 @@ public class SlingFileUploadHandler {
return file;
}
+ private Resource getChunkParent(final Resource rsrc) {
+ // parent resource containing all chunks and has mixin sling:chunks applied
+ // on it.
+ Resource chunkParent = null;
+ Resource jcrContentNode = null;
+ if (hasChunks(rsrc)) {
+ chunkParent = rsrc;
+ } else {
+ jcrContentNode = rsrc.getChild(JCR_CONTENT);
+ if ( hasChunks(jcrContentNode)) {
+ chunkParent = jcrContentNode;
+ }
+ }
+ return chunkParent;
+ }
+
/**
- * Delete all chunks saved within a node. If no chunks exist, it is no-op.
+ * Delete all chunks saved within a resource. If no chunks exist, it is no-op.
*/
- public void deleteChunks(final Node node) throws RepositoryException {
- // parent node containing all chunks and has mixin sling:chunks applied
- // on it.
- Node chunkParent = null;
- Node jcrContentNode = null;
- if (hasChunks(node)) {
- chunkParent = node;
- } else if (node.hasNode(JCR_CONTENT)
- && hasChunks((jcrContentNode = node.getNode(JCR_CONTENT)))) {
- chunkParent = jcrContentNode;
+ public void deleteChunks(final Resource rsrc) throws PersistenceException {
+ final Resource chunkParent = getChunkParent(rsrc);
- }
if (chunkParent != null) {
- NodeIterator nodeItr = chunkParent.getNodes(SlingPostConstants.CHUNK_NODE_NAME
- + "*");
- while (nodeItr.hasNext()) {
- Node rangeNode = nodeItr.nextNode();
- rangeNode.remove();
- }
- if (chunkParent.hasProperty(SlingPostConstants.NT_SLING_FILE_LENGTH)) {
- chunkParent.getProperty(SlingPostConstants.NT_SLING_FILE_LENGTH).remove();
+ for(final Resource c : chunkParent.getChildren()) {
+ if ( c.getName().startsWith(SlingPostConstants.CHUNK_NODE_NAME) ) {
+ c.getResourceResolver().delete(c);
+ }
}
- if (chunkParent.hasProperty(SlingPostConstants.NT_SLING_CHUNKS_LENGTH)) {
- chunkParent.getProperty(
- SlingPostConstants.NT_SLING_CHUNKS_LENGTH).remove();
+ final ModifiableValueMap vm = chunkParent.adaptTo(ModifiableValueMap.class);
+ vm.remove(SlingPostConstants.NT_SLING_FILE_LENGTH);
+ vm.remove(SlingPostConstants.NT_SLING_CHUNKS_LENGTH);
+ final String[] mixins = vm.get(JcrConstants.JCR_MIXINTYPES, String[].class);
+ final String[] newMixins = new String[mixins.length - 1];
+ int i = 0;
+ for(final String mt : mixins) {
+ if ( !SlingPostConstants.NT_SLING_CHUNK_MIXIN.equals(mt) ) {
+ newMixins[i] = mt;
+ i++;
+ }
}
- chunkParent.removeMixin(SlingPostConstants.NT_SLING_CHUNK_MIXIN);
+ vm.put(JcrConstants.JCR_MIXINTYPES, newMixins);
}
}
/**
* Get the last {@link SlingPostConstants#NT_SLING_CHUNK_NODETYPE}
- * {@link Node}.
+ * {@link Resource}.
*
- * @param node {@link Node} containing
+ * @param rsrc {@link Resource} containing
* {@link SlingPostConstants#NT_SLING_CHUNK_NODETYPE}
- * {@link Node}s
+ * {@link Resource}s
* @return the {@link SlingPostConstants#NT_SLING_CHUNK_NODETYPE} chunk
- * node.
- * @throws RepositoryException
+ * resource.
*/
- public Node getLastChunk(Node node) throws RepositoryException {
- // parent node containing all chunks and has mixin sling:chunks applied
- // on it.
- Node chunkParent = null;
- Node jcrContentNode = null;
- if (hasChunks(node)) {
- chunkParent = node;
- } else if (node.hasNode(JCR_CONTENT)
- && hasChunks((jcrContentNode = node.getNode(JCR_CONTENT)))) {
- chunkParent = jcrContentNode;
-
- }
+ public Resource getLastChunk(Resource rsrc) {
+ final Resource chunkParent = getChunkParent(rsrc);
if (chunkParent == null) {
return null;
}
- NodeIterator nodeItr = chunkParent.getNodes(SlingPostConstants.CHUNK_NODE_NAME + "_*");
- Node chunkNode = null;
+ Resource lastChunkRsrc = null;
long lastChunkStartIndex = -1;
- while (nodeItr.hasNext()) {
- Node currentNode = nodeItr.nextNode();
-
- String[] indexBounds = currentNode.getName().substring(
- (SlingPostConstants.CHUNK_NODE_NAME + "_").length()).split("_");
- long chunkStartIndex = Long.valueOf(indexBounds[0]);
- if (chunkStartIndex > lastChunkStartIndex) {
- chunkNode = currentNode;
+ for(final Resource chunkRsrc : chunkParent.getChildren()) {
+ if ( !chunkRsrc.getName().startsWith(SlingPostConstants.CHUNK_NODE_NAME + "_") ) {
+ continue;
+ }
+ final String[] indexBounds = chunkRsrc.getName().substring(
+ (SlingPostConstants.CHUNK_NODE_NAME + "_").length()).split("_");
+ long chunkStartIndex = Long.valueOf(indexBounds[0]);
+ if (chunkStartIndex > lastChunkStartIndex) {
+ lastChunkRsrc = chunkRsrc;
lastChunkStartIndex = chunkStartIndex;
}
}
- return chunkNode;
+
+ return lastChunkRsrc;
}
/**
- * Return true if node has chunks stored in it, otherwise false.
+ * Return true if resource has chunks stored in it, otherwise false.
*/
- private boolean hasChunks(final Node node) throws RepositoryException {
- for (NodeType nodeType : node.getMixinNodeTypes()) {
- if (nodeType.getName().equals(
- SlingPostConstants.NT_SLING_CHUNK_MIXIN)) {
- return true;
+ private boolean hasChunks(final Resource rsrc) {
+ final ValueMap vm = rsrc.getValueMap();
+ final String[] mixinTypes = vm.get(JcrConstants.JCR_MIXINTYPES, String[].class);
+ if ( mixinTypes != null ) {
+ for (final String nodeType : mixinTypes) {
+ if (nodeType.equals(SlingPostConstants.NT_SLING_CHUNK_MIXIN)) {
+ return true;
+ }
}
}
return false;
@@ -583,7 +589,7 @@ public class SlingFileUploadHandler {
throws PersistenceException {
Map<String, Object> properties = null;
if ( typeHint != null ) {
- properties = new HashMap<String, Object>();
+ properties = new HashMap<>();
if ( parent.adaptTo(Node.class) != null ) {
properties.put("jcr:primaryType", typeHint);
} else {
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java Fri Mar 31 05:44:47 2017
@@ -50,7 +50,7 @@ public class SlingPropertyValueHandler {
/**
* Defins a map of auto properties
*/
- private static final Map<String, AutoType> AUTO_PROPS = new HashMap<String, AutoType>();
+ private static final Map<String, AutoType> AUTO_PROPS = new HashMap<>();
static {
AUTO_PROPS.put("created", AutoType.CREATED);
AUTO_PROPS.put("createdBy", AutoType.CREATED_BY);
@@ -316,7 +316,7 @@ public class SlingPropertyValueHandler {
// add/remove patch operations; e.g. if the value "foo" occurs twice
// in the existing array, and is not touched, afterwards there should
// still be two times "foo" in the list, even if this is not a real set.
- List<String> oldValues = new ArrayList<String>();
+ List<String> oldValues = new ArrayList<>();
if (parent.valueMap.containsKey(name)) {
if ( parent.node != null ) {
@@ -496,15 +496,38 @@ public class SlingPropertyValueHandler {
}
/**
+ * Parses the given source strings and returns the respective jcr date value
+ * instances. If no format matches for any of the sources
+ * returns <code>null</code>.
+ * <p/>
+ *
+ * @param sources date time source strings
+ * @param factory the value factory
+ * @return jcr date value representations of the source or <code>null</code>
+ */
+ private Value[] parse(String sources[], ValueFactory factory) {
+ Value ret[] = new Value[sources.length];
+ for (int i=0; i< sources.length; i++) {
+ Calendar c = dateParser.parse(sources[i]);
+ if (c == null) {
+ return null;
+ }
+ ret[i] = factory.createValue(c);
+ }
+ return ret;
+ }
+
+
+ /**
* Stores property value(s) as date(s). Will parse the date(s) from the string
* value(s) in the {@link RequestProperty}.
*
- * @return true only if parsing was successfull and the property was actually changed
+ * @return true only if parsing was successful and the property was actually changed
*/
private boolean storeAsDate(final Modifiable parent, String name, String[] values, boolean multiValued, ValueFactory valFac)
throws RepositoryException, PersistenceException {
if (multiValued) {
- final Value[] array = dateParser.parse(values, valFac);
+ final Value[] array = parse(values, valFac);
if (array != null) {
if ( parent.node != null ) {
parent.node.setProperty(name, array);
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/DeleteOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/DeleteOperation.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/DeleteOperation.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/DeleteOperation.java Fri Mar 31 05:44:47 2017
@@ -19,8 +19,6 @@ package org.apache.sling.servlets.post.i
import java.util.Iterator;
import java.util.List;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
import javax.servlet.http.HttpServletResponse;
import org.apache.sling.api.SlingHttpServletRequest;
@@ -69,21 +67,17 @@ public class DeleteOperation extends Abs
final VersioningConfiguration versioningConfiguration = getVersioningConfiguration(request);
final boolean deleteChunks = isDeleteChunkRequest(request);
final Iterator<Resource> res = getApplyToResources(request);
- try {
- if (res == null) {
- final Resource resource = request.getResource();
+ if (res == null) {
+ final Resource resource = request.getResource();
+ deleteResource(resource, changes, versioningConfiguration,
+ deleteChunks);
+ } else {
+ while (res.hasNext()) {
+ final Resource resource = res.next();
deleteResource(resource, changes, versioningConfiguration,
deleteChunks);
- } else {
- while (res.hasNext()) {
- final Resource resource = res.next();
- deleteResource(resource, changes, versioningConfiguration,
- deleteChunks);
- }
-
}
- } catch ( final RepositoryException re) {
- throw new PersistenceException(re.getMessage(), re);
+
}
}
@@ -96,12 +90,9 @@ public class DeleteOperation extends Abs
final List<Modification> changes,
final VersioningConfiguration versioningConfiguration,
final boolean deleteChunks)
- throws PersistenceException, RepositoryException {
+ throws PersistenceException {
if (deleteChunks) {
- final Node node = resource.adaptTo(Node.class);
- if (node != null) {
- uploadHandler.deleteChunks(node);
- }
+ uploadHandler.deleteChunks(resource);
} else {
this.jcrSsupport.checkoutIfNecessary(resource.getParent(), changes,
versioningConfiguration);
Modified: sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/operations/MockRealResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/operations/MockRealResource.java?rev=1789614&r1=1789613&r2=1789614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/operations/MockRealResource.java (original)
+++ sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/operations/MockRealResource.java Fri Mar 31 05:44:47 2017
@@ -19,17 +19,17 @@
package org.apache.sling.servlets.post.impl.operations;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceMetadata;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ValueMap;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Map;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+
/**
* MockResource is synthetic, which doesnt work here.
*/
@@ -132,4 +132,14 @@ public class MockRealResource implements
}
return null;
}
+
+ @Override
+ public boolean hasChildren() {
+ return resourceResolver.listChildren(this).hasNext();
+ }
+
+ @Override
+ public ValueMap getValueMap() {
+ return adaptTo(ValueMap.class);
+ }
}