]> source.dussan.org Git - poi.git/commitdiff
Fix generics warnings, and fix up tests to handle the extra bit of text being extract...
authorNick Burch <nick@apache.org>
Thu, 28 Jan 2010 12:20:32 +0000 (12:20 +0000)
committerNick Burch <nick@apache.org>
Thu, 28 Jan 2010 12:20:32 +0000 (12:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@904060 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java

index c83257f5a32a280983498d9a7ab57a29b19aa8e4..74488f4bed657aadee818f9a667fa3e4d406aa1d 100644 (file)
@@ -61,13 +61,13 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
         *  contents.
         */
        public String[] getAllText() {
-               ArrayList text = new ArrayList();
+               ArrayList<String> text = new ArrayList<String>();
                for(int i=0; i<hdgf.getTopLevelStreams().length; i++) {
                        findText(hdgf.getTopLevelStreams()[i], text);
                }
-               return (String[])text.toArray( new String[text.size()] );
+               return text.toArray( new String[text.size()] );
        }
-       private void findText(Stream stream, ArrayList text) {
+       private void findText(Stream stream, ArrayList<String> text) {
                if(stream instanceof PointerContainingStream) {
                        PointerContainingStream ps = (PointerContainingStream)stream;
                        for(int i=0; i<ps.getPointedToStreams().length; i++) {
@@ -82,10 +82,18 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
                                                chunk.getName() != null &&
                                                chunk.getName().equals("Text") &&
                                                chunk.getCommands().length > 0) {
+                                  
                                        // First command
                                        Command cmd = chunk.getCommands()[0];
                                        if(cmd != null && cmd.getValue() != null) {
-                                               text.add( cmd.getValue().toString() );
+                                          // Capture the text, as long as it isn't
+                                          //  simply an empty string
+                                          String str = cmd.getValue().toString();
+                                          if(str.equals("") || str.equals("\n")) {
+                                             // Ignore empty strings
+                                          } else {
+                                             text.add( str );
+                                          }
                                        }
                                }
                        }
index 30b8db4fbdb07e03ed8b5bbed635109c81c5dfe9..24b2a45b737b9c794cb90969d775243db4aec174 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.poi.hdgf.extractor;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.PrintStream;
 
 import junit.framework.TestCase;
@@ -31,8 +30,10 @@ public final class TestVisioExtractor extends TestCase {
     private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance();
 
        private String defFilename;
+       private int defTextChunks;
        protected void setUp() {
                defFilename = "Test_Visio-Some_Random_Text.vsd";
+               defTextChunks = 5;
        }
 
        /**
@@ -44,7 +45,7 @@ public final class TestVisioExtractor extends TestCase {
                extractor = new VisioTextExtractor(_dgTests.openResourceAsStream(defFilename));
                assertNotNull(extractor);
                assertNotNull(extractor.getAllText());
-               assertEquals(3, extractor.getAllText().length);
+               assertEquals(defTextChunks, extractor.getAllText().length);
 
                extractor = new VisioTextExtractor(
                                new POIFSFileSystem(
@@ -53,7 +54,7 @@ public final class TestVisioExtractor extends TestCase {
                );
                assertNotNull(extractor);
                assertNotNull(extractor.getAllText());
-               assertEquals(3, extractor.getAllText().length);
+               assertEquals(defTextChunks, extractor.getAllText().length);
 
                extractor = new VisioTextExtractor(
                        new HDGFDiagram(
@@ -64,7 +65,7 @@ public final class TestVisioExtractor extends TestCase {
                );
                assertNotNull(extractor);
                assertNotNull(extractor.getAllText());
-               assertEquals(3, extractor.getAllText().length);
+               assertEquals(defTextChunks, extractor.getAllText().length);
        }
 
        public void testExtraction() throws Exception {
@@ -74,19 +75,25 @@ public final class TestVisioExtractor extends TestCase {
                // Check the array fetch
                String[] text = extractor.getAllText();
                assertNotNull(text);
-               assertEquals(3, text.length);
+               assertEquals(defTextChunks, text.length);
 
-               assertEquals("Test View\n", text[0]);
-               assertEquals("I am a test view\n", text[1]);
-               assertEquals("Some random text, on a page\n", text[2]);
+      assertEquals("text\n", text[0]);
+      assertEquals("View\n", text[1]);
+               assertEquals("Test View\n", text[2]);
+               assertEquals("I am a test view\n", text[3]);
+               assertEquals("Some random text, on a page\n", text[4]);
 
                // And the all-in fetch
                String textS = extractor.getText();
-               assertEquals("Test View\nI am a test view\nSome random text, on a page\n", textS);
+               assertEquals("text\nView\nTest View\nI am a test view\nSome random text, on a page\n", textS);
        }
 
        public void testProblemFiles() throws Exception {
-               String[] files = {"44594.vsd", "44594-2.vsd", "ShortChunk1.vsd", "ShortChunk2.vsd", "ShortChunk3.vsd"};
+               String[] files = {
+                     "44594.vsd", "44594-2.vsd", 
+                     "ShortChunk1.vsd", "ShortChunk2.vsd", "ShortChunk3.vsd",
+                     "NegativeChunkLength.vsd", "NegativeChunkLength2.vsd"
+               };
         for(String file : files){
             VisioTextExtractor ex = new VisioTextExtractor(_dgTests.openResourceAsStream(file));
             ex.getText();
@@ -108,6 +115,10 @@ public final class TestVisioExtractor extends TestCase {
                // Check
                capture.flush();
                String text = baos.toString();
-               assertEquals("Test View\nI am a test view\nSome random text, on a page\n", text);
+               assertEquals(
+                     "text\nView\n" +
+                     "Test View\nI am a test view\n" +
+                     "Some random text, on a page\n", 
+                     text);
        }
 }