incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1351670 - in /sling/trunk/bundles/jcr/contentloader: pom.xml src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
Date Tue, 19 Jun 2012 12:25:38 GMT
Author: justin
Date: Tue Jun 19 12:25:37 2012
New Revision: 1351670

URL: http://svn.apache.org/viewvc?rev=1351670&view=rev
Log:
SLING-2512 - only support file elements in XML import when location is known. warning otherwise.

Modified:
    sling/trunk/bundles/jcr/contentloader/pom.xml
    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/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/pom.xml?rev=1351670&r1=1351669&r2=1351670&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/pom.xml (original)
+++ sling/trunk/bundles/jcr/contentloader/pom.xml Tue Jun 19 12:25:37 2012
@@ -168,7 +168,7 @@
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-nop</artifactId>
+            <artifactId>slf4j-simple</artifactId>
             <version>1.5.2</version>
             <scope>test</scope>
         </dependency>

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=1351670&r1=1351669&r2=1351670&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
Tue Jun 19 12:25:37 2012
@@ -53,6 +53,8 @@ import org.apache.sling.jcr.contentloade
 import org.apache.sling.jcr.contentloader.internal.ContentReader;
 import org.apache.sling.jcr.contentloader.internal.ImportProvider;
 import org.kxml2.io.KXmlParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -103,6 +105,8 @@ public class XmlReader implements Conten
      */
 
     /** default log */
+    private static final Logger logger = LoggerFactory.getLogger(XmlReader.class);
+
     private static final String ELEM_NODE = "node";
 
     private static final String ELEM_PRIMARY_NODE_TYPE = "primaryNodeType";
@@ -242,23 +246,27 @@ public class XmlReader implements Conten
                     currentNode = NodeDescription.create(currentNode, creator);
                     currentNode = NodeDescription.SHARED;
                 } else if (ELEM_FILE_NAME.equals(currentElement) && ELEM_FILE_NAMESPACE.equals(this.xmlParser.getNamespace()))
{
-                    int attributeCount = this.xmlParser.getAttributeCount();
-                    if (attributeCount < 2 || attributeCount > 3) {
-                        throw new IOException("File element must have these attributes: url,
mimeType and lastModified: " + xmlLocation);
-                    }
-                    try {
-                        AttributeMap attributes = AttributeMap.getInstance();
-                        attributes.setValues(xmlParser);
-                        FileDescription.SHARED.setBaseLocation(xmlLocation);
-                        FileDescription.SHARED.setValues(attributes);
-                        attributes.clear();
-                    } catch (ParseException e) {
-                        IOException ioe = new IOException("Error parsing file description:
" + xmlLocation);
-                        ioe.initCause(e);
-                        throw ioe;
+                    if (xmlLocation != null) {
+                        int attributeCount = this.xmlParser.getAttributeCount();
+                        if (attributeCount < 2 || attributeCount > 3) {
+                            throw new IOException("File element must have these attributes:
url, mimeType and lastModified: " + xmlLocation);
+                        }
+                        try {
+                            AttributeMap attributes = AttributeMap.getInstance();
+                            attributes.setValues(xmlParser);
+                            FileDescription.SHARED.setBaseLocation(xmlLocation);
+                            FileDescription.SHARED.setValues(attributes);
+                            attributes.clear();
+                        } catch (ParseException e) {
+                            IOException ioe = new IOException("Error parsing file description:
" + xmlLocation);
+                            ioe.initCause(e);
+                            throw ioe;
+                        }
+                        FileDescription.SHARED.create(creator);
+                        FileDescription.SHARED.clear();
+                    } else {
+                        logger.warn("file element encountered when xml location isn't known.
skipping.");
                     }
-                    FileDescription.SHARED.create(creator);
-                    FileDescription.SHARED.clear();
                 }
 
             } else if (eventType == XmlPullParser.END_TAG) {

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=1351670&r1=1351669&r2=1351670&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
Tue Jun 19 12:25:37 2012
@@ -20,6 +20,7 @@ package org.apache.sling.jcr.contentload
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -70,6 +71,17 @@ public class XmlReaderTest extends TestC
         assertEquals("Could not read file", "This is a test file.", file.content);
 
     }
+    
+    public void testCreateFileWithNullLocation() throws Exception {
+        File input = new File("src/test/resources/reader/filesample.xml");
+        final FileInputStream ins = new FileInputStream(input);
+        try {
+            reader.parse(ins, creator);
+            assertEquals("Created files when we shouldn't have", 0, creator.filesCreated.size());
+        } finally {
+            ins.close();
+        }
+    }
 
     public void testUseOSLastModified() throws RepositoryException, IOException {
         File input = new File("src/test/resources/reader/datefallbacksample.xml");



Mime
View raw message