You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by vr...@apache.org on 2009/10/28 11:40:23 UTC
svn commit: r830495 - in /sling/trunk/bundles/jcr/contentloader/src:
main/java/org/apache/sling/jcr/contentloader/internal/readers/
test/java/org/apache/sling/jcr/contentloader/internal/readers/
test/resources/reader/
Author: vramdal
Date: Wed Oct 28 10:40:23 2009
New Revision: 830495
URL: http://svn.apache.org/viewvc?rev=830495&view=rev
Log:
SLING-1165 Last modifie date reported by the filesystem is now used, instead of current date
Added:
sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/datefallbacksample.xml
Modified:
sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java
sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java?rev=830495&r1=830494&r2=830495&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java Wed Oct 28 10:40:23 2009
@@ -24,8 +24,10 @@
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.io.File;
import java.net.URL;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
@@ -498,7 +500,8 @@
* <nt:file src="../../image.png" mimeType="image/png" lastModified="1977-06-01T07:00:00+0100" />
* </pre>
* The date format for <code>lastModified</code> is <code>yyyy-MM-dd'T'HH:mm:ssZ</code>.
- * The <code>lastModified</code> attribute is optional. If missing, it will be set to the current time.
+ * The <code>lastModified</code> attribute is optional. If missing, the last modified date reported by the
+ * filesystem will be used.
*/
protected static final class FileDescription {
@@ -535,7 +538,15 @@
String[] parts = url.getPath().split("/");
String name = parts[parts.length - 1];
InputStream stream = url.openStream();
- creator.createFileAndResourceNode(name, stream, mimeType, lastModified != null ? lastModified : Calendar.getInstance().getTimeInMillis());
+ if (lastModified == null) {
+ try {
+ lastModified = new File(url.toURI()).lastModified();
+ } catch (Throwable ignore) {
+ // Could not get lastModified from file system, so we'll use current date
+ lastModified = Calendar.getInstance().getTimeInMillis();
+ }
+ }
+ creator.createFileAndResourceNode(name, stream, mimeType, lastModified);
closeStream(stream);
creator.finishNode();
creator.finishNode();
Modified: sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java?rev=830495&r1=830494&r2=830495&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java Wed Oct 28 10:40:23 2009
@@ -69,6 +69,18 @@
}
+ public void testUseOSLastModified() throws RepositoryException, IOException {
+ File input = new File("src/test/resources/reader/datefallbacksample.xml");
+ final URL testdata = input.toURI().toURL();
+ reader.parse(testdata, creator);
+ File file = new File("src/test/resources/reader/testfile.txt");
+ long originalLastModified = file.lastModified();
+ assertEquals("Did not create expected number of files", 1, creator.filesCreated.size());
+ MockContentCreator.FileDescription fileDescription = creator.filesCreated.get(0);
+ assertEquals("Did not pick up last modified date from file", originalLastModified, fileDescription.lastModified);
+
+ }
+
protected void setUp() throws Exception {
super.setUp();
reader = new XmlReader();
Added: sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/datefallbacksample.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/datefallbacksample.xml?rev=830495&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/datefallbacksample.xml (added)
+++ sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/datefallbacksample.xml Wed Oct 28 10:40:23 2009
@@ -0,0 +1,20 @@
+<node xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+ <name>nodeName</name>
+ <primaryNodeType>type</primaryNodeType>
+ <mixinNodeTypes>
+ <mixinNodeType>mixtype1</mixinNodeType>
+ <mixinNodeType>mixtype2</mixinNodeType>
+ </mixinNodeTypes>
+ <properties>
+ <property>
+ <name>propName</name>
+ <value>propValue</value>
+ <type>String</type>
+ </property>
+ <!-- more properties -->
+ </properties>
+ <nodes>
+ <!-- child nodes -->
+ <nt:file src="testfile.txt" mimeType="application/test"/>
+ </nodes>
+</node>