incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1302220 - in /incubator/odf/trunk/simple/src: main/java/org/odftoolkit/simple/common/ test/java/org/odftoolkit/simple/common/ test/java/org/odftoolkit/simple/common/navigation/ test/java/org/odftoolkit/simple/table/
Date Sun, 18 Mar 2012 20:37:07 GMT
Author: olira
Date: Sun Mar 18 20:37:06 2012
New Revision: 1302220

URL: http://svn.apache.org/viewvc?rev=1302220&view=rev
Log:
issue ODFTOOLKIT-311: TextExtractor uses wrong new line character 
https://issues.apache.org/jira/browse/ODFTOOLKIT-311

Modified:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/common/TextExtractor.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/GetTextTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/navigation/CellSelectionTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellRangeTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/common/TextExtractor.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/common/TextExtractor.java?rev=1302220&r1=1302219&r2=1302220&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/common/TextExtractor.java
(original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/common/TextExtractor.java
Sun Mar 18 20:37:06 2012
@@ -53,11 +53,11 @@ import org.w3c.dom.Node;
  */
 public class TextExtractor extends DefaultElementVisitor {
 
-	protected static final char NewLineChar = '\r';
+	protected static final char NewLineChar = '\n';
 	protected static final char TabChar = '\t';
 	protected final ExtractorStringBuilder mTextBuilder;
 	OdfElement mElement;
-
+	
 	/**
 	 * This class is used to provide the string builder functions to extractor.
 	 * It will automatically process the last NewLineChar.

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/GetTextTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/GetTextTest.java?rev=1302220&r1=1302219&r2=1302220&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/GetTextTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/GetTextTest.java
Sun Mar 18 20:37:06 2012
@@ -76,7 +76,7 @@ public class GetTextTest {
 
 			int count = 0;
 			for (int i = 0; i < text.length(); i++)
-				if (text.charAt(i) == '\r')
+				if (text.charAt(i) == '\n')
 					count++;
 			Assert.assertEquals(2, count);
 
@@ -84,7 +84,7 @@ public class GetTextTest {
 			text = extractor.getText();
 			count = 0;
 			for (int i = 0; i < text.length(); i++)
-				if (text.charAt(i) == '\r')
+				if (text.charAt(i) == '\n')
 					count++;
 			Assert.assertEquals(0, count);
 		} catch (Exception e) {

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/navigation/CellSelectionTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/navigation/CellSelectionTest.java?rev=1302220&r1=1302219&r2=1302220&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/navigation/CellSelectionTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/common/navigation/CellSelectionTest.java
Sun Mar 18 20:37:06 2012
@@ -15,7 +15,7 @@ software distributed under the License i
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-*/
+ */
 
 package org.odftoolkit.simple.common.navigation;
 
@@ -35,11 +35,11 @@ import org.odftoolkit.simple.utils.Resou
  * Test the method of class org.odftoolkit.simple.common.navigation.CellSelection
  */
 public class CellSelectionTest {
-	
-	public static final String TEST_FILE = "TestCellSelection.ods";
+
+	public static final String TEST_FILE         = "TestCellSelection.ods";
 	public static final String SAVE_FILE_REPLACE = "CellSelectionResultReplace.ods";
-	SpreadsheetDocument doc;
-	
+	SpreadsheetDocument        doc;
+
 	@Before
 	public void setUp() {
 		try {
@@ -49,25 +49,26 @@ public class CellSelectionTest {
 			Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
 		}
 	}
-	
+
 	/**
-	 * Test replaceWith method of org.odftoolkit.simple.common.navigation.TextSelection
-	 * replace all the 'SIMPLE' with 'Odf Toolkit'
+	 * Test replaceWith method of org.odftoolkit.simple.common.navigation.TextSelection replace
all the 'SIMPLE' with 'Odf
+	 * Toolkit'
 	 */
 	@Test
 	public void testAdvancedReplacewith() {
-		Map<String, String> valueProperties = new HashMap<String,String>();
+		Map<String, String> valueProperties = new HashMap<String, String>();
 		valueProperties.put("Amount", "3,000,000");
 		valueProperties.put("Task", "Develop");
 		valueProperties.put("Date", "11/09/2010");
 		valueProperties.put("Time", "14:30");
 		valueProperties.put("Status", "true");
-		Map<String, String> typeProperties = new HashMap<String,String>();
+		Map<String, String> typeProperties = new HashMap<String, String>();
 		typeProperties.put("Amount", "float");
 		typeProperties.put("Task", "string");
 		typeProperties.put("Date", "date");
 		typeProperties.put("Time", "time");
 		typeProperties.put("Status", "boolean");
+		
 		// simple text replace
 		for (String key : valueProperties.keySet()) {
 			String value = valueProperties.get(key);
@@ -84,4 +85,38 @@ public class CellSelectionTest {
 			}
 		}
 	}
+
+	/**
+	 * this method tests a simple replace with. Especially Line breaks
+	 */
+	@Test
+	public void testReplaceWith() {
+		Map<String, String> valueProperties = new HashMap<String, String>();
+		valueProperties.put("Amount", "3,000,000");
+		valueProperties.put("Task", "Develop\nWith a second line");
+		valueProperties.put("Date", "11/09/2010");
+		valueProperties.put("Time", "14:30");
+		valueProperties.put("Status", "true");
+
+		// simple text replace
+		for (String key : valueProperties.keySet()) {
+			String value = valueProperties.get(key);
+			TextNavigation navigate = new TextNavigation(key, doc);
+			while (navigate.hasNext()) {
+				CellSelection selection = (CellSelection) navigate.nextSelection();
+				try {
+					// use a simple replace to replace the values
+					selection.replaceWith(value);
+
+					// get the cell's string value (which is different from the textvalue)
+					String newValue = selection.getCell().getStringValue();
+
+					// make sure that the cell's value is the same as the intended value
+					Assert.assertEquals(valueProperties.get(key), newValue);
+				} catch (InvalidNavigationException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+	}
 }

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellRangeTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellRangeTest.java?rev=1302220&r1=1302219&r2=1302220&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellRangeTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellRangeTest.java
Sun Mar 18 20:37:06 2012
@@ -64,7 +64,7 @@ public class TableCellRangeTest {
 		cellRange.merge();
 		Cell cell = cellRange.getCellByPosition(0, 0);
 		saveodt("MergeTwoCell");
-		Assert.assertEquals(cell.getDisplayText(), "cell1\rcell2");
+		Assert.assertEquals(cell.getDisplayText(), "cell1\ncell2");
 		try {
 			TextDocument saveddoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
 					.getTestResourceAsStream(odtfilename + "MergeTwoCell.odt"));

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java?rev=1302220&r1=1302219&r2=1302220&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
Sun Mar 18 20:37:06 2012
@@ -285,7 +285,7 @@ public class TableCellTest {
 		Table table1 = odtdoc.getTableByName("Table1");
 		Cell fcell2 = table1.getCellByPosition(0, 1);
 		text = fcell2.getDisplayText();
-		Assert.assertEquals("Aa\rbb\rcc\rdd\ree", text);
+		Assert.assertEquals("Aa\nbb\ncc\ndd\nee", text);
 	}
 
 	@Test



Mime
View raw message