poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r904060 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java
Date Thu, 28 Jan 2010 12:20:33 GMT
Author: nick
Date: Thu Jan 28 12:20:32 2010
New Revision: 904060

URL: http://svn.apache.org/viewvc?rev=904060&view=rev
Log:
Fix generics warnings, and fix up tests to handle the extra bit of text being extracted now

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

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java?rev=904060&r1=904059&r2=904060&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java Thu
Jan 28 12:20:32 2010
@@ -61,13 +61,13 @@
 	 *  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 @@
 						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 );
+					   }
 					}
 				}
 			}

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java?rev=904060&r1=904059&r2=904060&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java
Thu Jan 28 12:20:32 2010
@@ -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 @@
     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 @@
 		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 @@
 		);
 		assertNotNull(extractor);
 		assertNotNull(extractor.getAllText());
-		assertEquals(3, extractor.getAllText().length);
+		assertEquals(defTextChunks, extractor.getAllText().length);
 
 		extractor = new VisioTextExtractor(
 			new HDGFDiagram(
@@ -64,7 +65,7 @@
 		);
 		assertNotNull(extractor);
 		assertNotNull(extractor.getAllText());
-		assertEquals(3, extractor.getAllText().length);
+		assertEquals(defTextChunks, extractor.getAllText().length);
 	}
 
 	public void testExtraction() throws Exception {
@@ -74,19 +75,25 @@
 		// 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 @@
 		// 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);
 	}
 }



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


Mime
View raw message