[bug-63013] add XWPFRun setLang method

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849152 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2018-12-18 08:12:42 +00:00
parent 9f3c99c25c
commit 1a25ff4dce
2 changed files with 29 additions and 2 deletions

View File

@ -242,6 +242,18 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
return (String) lang;
}
/**
* Set the language tag associated with this run.
*
* @param lang the language tag associated with this run
* @since 4.1.0
*/
public void setLang(String lang) {
CTRPr pr = getRunProperties(true);
CTLanguage ctLang = pr.isSetLang() ? pr.getLang() : pr.addNewLang();
ctLang.setVal(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
@ -1545,7 +1557,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
* @param create If true, create the properties, if false, do not.
* @return The run properties or null if there are no properties and create is false.
*/
private CTRPr getRunProperties(boolean create) {
protected CTRPr getRunProperties(boolean create) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : null;
if (create && pr == null) {
pr = run.addNewRPr();

View File

@ -448,6 +448,21 @@ public class TestXWPFRun {
XWPFRun run = p.createRun();
assertNull(run.getLang());
run.setLang("en-CA");
assertEquals("en-CA", run.getLang());
run.setLang("fr-CA");
assertEquals("fr-CA", run.getLang());
run.setLang(null);
assertNull(run.getLang());
}
@Test
public void testSetGetLang2() {
XWPFRun run = p.createRun();
assertNull(run.getLang());
run.getCTR().addNewRPr().addNewLang().setVal("en-CA");
assertEquals("en-CA", run.getLang());