You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/10/28 11:31:34 UTC
svn commit: r830492 - in /poi/trunk/src:
documentation/content/xdocs/status.xml
ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
Author: yegor
Date: Wed Oct 28 10:31:34 2009
New Revision: 830492
URL: http://svn.apache.org/viewvc?rev=830492&view=rev
Log:
preserve leading and trailing white spaces in XSSFRichTextString, see Bugzilla 48070
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.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=830492&r1=830491&r2=830492&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Oct 28 10:31:34 2009
@@ -33,6 +33,7 @@
<changes>
<release version="3.6-beta1" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">48070 - preserve leading and trailing white spaces in XSSFRichTextString</action>
<action dev="POI-DEVELOPERS" type="add">48044 - added implementation for CountBlank function</action>
<action dev="POI-DEVELOPERS" type="fix">48036 - added IntersectionEval to allow evaluation of the intersection formula operator</action>
<action dev="POI-DEVELOPERS" type="fix">47999 - avoid un-needed call to the JVM Garbage Collector when working on OOXML OPC Packages</action>
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=830492&r1=830491&r2=830492&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Wed Oct 28 10:31:34 2009
@@ -20,8 +20,11 @@
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.xssf.model.StylesTable;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlCursor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+import javax.xml.namespace.QName;
import java.util.ArrayList;
@@ -70,15 +73,16 @@
private StylesTable styles;
/**
- * Create a rich text string and initialize it with empty string
+ * Create a rich text string
*/
public XSSFRichTextString(String str) {
st = CTRst.Factory.newInstance();
st.setT(str);
+ preserveSpaces(st.xgetT());
}
/**
- * Create empty rich text string
+ * Create empty rich text string and initialize it with empty string
*/
public XSSFRichTextString() {
st = CTRst.Factory.newInstance();
@@ -342,6 +346,7 @@
public void setString(String s){
clearFormatting();
st.setT(s);
+ preserveSpaces(st.xgetT());
}
/**
@@ -461,4 +466,19 @@
return ctFont;
}
+
+ /**
+ * Add the xml:spaces="preserve" attribute if the string has leading or trailing white spaces
+ *
+ * @param xs the string to check
+ */
+ protected static void preserveSpaces(STXstring xs) {
+ String text = xs.getStringValue();
+ if (text != null && (text.startsWith(" ") || text.endsWith(" "))) {
+ XmlCursor c = xs.newCursor();
+ c.toNextToken();
+ c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
+ c.dispose();
+ }
+ }
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java?rev=830492&r1=830491&r2=830492&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java Wed Oct 28 10:31:34 2009
@@ -20,6 +20,7 @@
import junit.framework.TestCase;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring;
/**
* Tests functionality of the XSSFRichTextRun object
@@ -115,4 +116,18 @@
assertEquals(font2.getBold(), font2$.getBold());
assertEquals(font2.getFontName(), font2$.getFontName());
}
+
+ /**
+ * make sure we insert xml:space="preserve" attribute
+ * if a string has leading or trailing white spaces
+ */
+ public void testPreserveSpaces() {
+ XSSFRichTextString rt = new XSSFRichTextString("Apache");
+ CTRst ct = rt.getCTRst();
+ STXstring xs = ct.xgetT();
+ assertEquals("<xml-fragment>Apache</xml-fragment>", xs.xmlText());
+ rt.setString(" Apache");
+ assertEquals("<xml-fragment xml:space=\"preserve\"> Apache</xml-fragment>", xs.xmlText());
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org