diff options
author | Nick Burch <nick@apache.org> | 2010-01-28 12:20:32 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-01-28 12:20:32 +0000 |
commit | 069207f64edf6486525e2bdbb815be81924d5a46 (patch) | |
tree | 0428a0c2add07d43360e2e061d5f7d3c1225dba7 /src/scratchpad | |
parent | 161a341e6c4ad5ea30288c598d5d5887ae4accf9 (diff) | |
download | poi-069207f64edf6486525e2bdbb815be81924d5a46.tar.gz poi-069207f64edf6486525e2bdbb815be81924d5a46.zip |
Fix generics warnings, and fix up tests to handle the extra bit of text being extracted now
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@904060 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java | 16 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java | 33 |
2 files changed, 34 insertions, 15 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java b/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java index c83257f5a3..74488f4bed 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java @@ -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 ); + } } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java index 30b8db4fbd..24b2a45b73 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java @@ -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); } } |