]> source.dussan.org Git - poi.git/commitdiff
[github-86] expose language for Text Runs. Thanks to Geoff Baskwill. This closes #86
authorPJ Fanning <fanningpj@apache.org>
Thu, 4 Jan 2018 23:32:14 +0000 (23:32 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 4 Jan 2018 23:32:14 +0000 (23:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1820242 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java

index b00ffd731f106300347e7f027eee350da1d7904c..fdfe2cc6fa667db18653a7cc44692ce6da6e052c 100644 (file)
@@ -248,6 +248,17 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
         );
     }
 
+    /**
+     * Get the language tag associated with this run, if any.
+     *
+     * @return the language tag associated with this run, if any
+     */
+    public String getLang() {
+        CTRPr pr = run.getRPr();
+        Object lang = pr == null || !pr.isSetLang() ? null : pr.getLang().getVal();
+        return (String)lang;
+    }
+
     /**
      * Whether the bold property shall be applied to all non-complex script
      * characters in the contents of this run when displayed in a document
index a603ab276cb4a3ebbe45dee556e588f808bc0d9f..459271ec27490f8a2b960a6b049b64c2e83c3480 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.poi.xwpf.usermodel;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -37,11 +38,14 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
 import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLang;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLang;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
@@ -452,6 +456,21 @@ public class TestXWPFRun {
         assertEquals(1, count);
         sampleDoc.close();
     }
+    
+    @Test
+    public void testSetGetLang() throws IOException {
+        XWPFRun run = p.createRun();
+        assertNull(run.getLang());
+
+        run.getCTR().addNewRPr().addNewLang().setVal("en-CA");
+        assertEquals("en-CA", run.getLang());
+
+        run.getCTR().getRPr().getLang().setVal("fr-CA");
+        assertEquals("fr-CA", run.getLang());
+
+        run.getCTR().getRPr().getLang().setVal(null);
+        assertNull(run.getLang());
+    }
 
     @Test
     public void testSetGetHighlight() throws IOException {