Author: nick
Date: Fri Oct 22 17:23:39 2010
New Revision: 1026412

URL: http://svn.apache.org/viewvc?rev=1026412&view=rev
Log:
Fix bug #50118

Added:
    poi/trunk/test-data/poifs/Notes.ole2   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
    
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
    
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1026412&r1=1026411&r2=1026412&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Oct 22 17:23:39 
2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
+           <action dev="poi-developers" type="fix">50118 - OLE2 does allow a 
directory with an empty name, so support this in POIFS</action>
            <action dev="poi-developers" type="fix">50119 - avoid NPE when 
XSSFReader comes across chart sheets</action>
         </release>
         <release version="3.7" date="2010-10-25">

Modified: 
poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java?rev=1026412&r1=1026411&r2=1026412&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java 
Fri Oct 22 17:23:39 2010
@@ -21,6 +21,9 @@ package org.apache.poi.poifs.filesystem;
 
 import java.io.File;
 
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
 /**
  * Class POIFSDocumentPath
  *
@@ -30,6 +33,8 @@ import java.io.File;
 
 public class POIFSDocumentPath
 {
+    private static final POILogger log = 
POILogFactory.getLogger(POIFSDocumentPath.class);
+          
     private String[] components;
     private int      hashcode = 0;
 
@@ -125,12 +130,17 @@ public class POIFSDocumentPath
         {
             for (int j = 0; j < components.length; j++)
             {
-                if ((components[ j ] == null)
-                        || (components[ j ].length() == 0))
+                if (components[ j ] == null)
                 {
                     throw new IllegalArgumentException(
-                        "components cannot contain null or empty strings");
+                        "components cannot contain null");
+                }
+                if (components[ j ].length() == 0)
+                {
+                    log.log(POILogger.WARN, "Directory under " + path + " has 
an empty name, " +
+                            "not all OLE2 readers will handle this file 
correctly!");
                 }
+                
                 this.components[ j + path.components.length ] =
                     components[ j ];
             }

Modified: 
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java?rev=1026412&r1=1026411&r2=1026412&view=diff
==============================================================================
--- 
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
 (original)
+++ 
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
 Fri Oct 22 17:23:39 2010
@@ -165,24 +165,40 @@ public final class TestPOIFSDocumentPath
                 }
             }
 
-            // test weird variants
+            // Test weird variants
+            
+            // This one is allowed, even if it's really odd
             assertEquals(n, new POIFSDocumentPath(base, null).length());
+            new POIFSDocumentPath(base, new String[]
+            {
+                 "fu", ""
+            });
+            
+            // This one is allowed too
+            new POIFSDocumentPath(base, new String[]
+            {
+                 "", "fu"
+            });
+            
+            // This one shouldn't be allowed
             try
             {
                 new POIFSDocumentPath(base, new String[]
                 {
-                    "fu", ""
+                    "fu", null
                 });
                 fail("should have caught IllegalArgumentException");
             }
             catch (IllegalArgumentException ignored)
             {
             }
+            
+            // Ditto
             try
             {
                 new POIFSDocumentPath(base, new String[]
                 {
-                    "fu", null
+                    null, "fu"
                 });
                 fail("should have caught IllegalArgumentException");
             }

Modified: 
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=1026412&r1=1026411&r2=1026412&view=diff
==============================================================================
--- 
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
 (original)
+++ 
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
 Fri Oct 22 17:23:39 2010
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Iterator;
 
 import junit.framework.TestCase;
 
@@ -226,6 +227,43 @@ public final class TestPOIFSFileSystem e
              }
           }
        }
+       
+       /**
+        * Test that we can open files that come via Lotus notes.
+        * These have a top level directory without a name....
+        */
+       public void testNotesOLE2Files() throws Exception {
+      POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
+      
+      // Open the file up
+      POIFSFileSystem fs = new POIFSFileSystem(
+          _samples.openResourceAsStream("Notes.ole2")
+      );
+      
+      // Check the contents
+      assertEquals(1, fs.getRoot().getEntryCount());
+      
+      Entry entry = fs.getRoot().getEntries().next();
+      assertTrue(entry.isDirectoryEntry());
+      assertTrue(entry instanceof DirectoryEntry);
+      
+      // The directory lacks a name!
+      DirectoryEntry dir = (DirectoryEntry)entry;
+      assertEquals("", dir.getName());
+      
+      // Has two children
+      assertEquals(2, dir.getEntryCount());
+      
+      // Check them
+      Iterator<Entry> it = dir.getEntries();
+      entry = it.next();
+      assertEquals(true, entry.isDocumentEntry());
+      assertEquals("\u0001Ole10Native", entry.getName());
+      
+      entry = it.next();
+      assertEquals(true, entry.isDocumentEntry());
+      assertEquals("\u0001CompObj", entry.getName());
+       }
 
        private static InputStream openSampleStream(String sampleFileName) {
                return HSSFTestDataSamples.openSampleFileStream(sampleFileName);

Added: poi/trunk/test-data/poifs/Notes.ole2
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/poifs/Notes.ole2?rev=1026412&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/poifs/Notes.ole2
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to