diff options
author | Nick Burch <nick@apache.org> | 2015-05-07 13:34:03 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-05-07 13:34:03 +0000 |
commit | f94b28ab52fbf582dfef820fefc6b1d98987374c (patch) | |
tree | c7b8b4f319de2ded480458f5ffa47579523e3709 /src/ooxml | |
parent | d38594d5526ede5b687e0dd5f54a1448997feea7 (diff) | |
download | poi-f94b28ab52fbf582dfef820fefc6b1d98987374c.tar.gz poi-f94b28ab52fbf582dfef820fefc6b1d98987374c.zip |
Refactor common default styles code to use the new helpers
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678197 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java | 69 |
1 files changed, 17 insertions, 52 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java index cebc63cadb..8647cc9f7e 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java @@ -231,11 +231,7 @@ public class XWPFStyles extends POIXMLDocumentPart{ return usedStyleList; } - /** - * Sets the default spelling language on ctStyles DocDefaults parameter - * @param strSpellingLanguage - */ - public void setSpellingLanguage(String strSpellingLanguage) { + protected CTLanguage getCTLanguage() { ensureDocDefaults(); CTLanguage lang = null; @@ -244,69 +240,38 @@ public class XWPFStyles extends POIXMLDocumentPart{ } else { lang = defaultRunStyle.getRPr().addNewLang(); } - + + return lang; + } + + /** + * Sets the default spelling language on ctStyles DocDefaults parameter + * @param strSpellingLanguage + */ + public void setSpellingLanguage(String strSpellingLanguage) { + CTLanguage lang = getCTLanguage(); lang.setVal(strSpellingLanguage); lang.setBidi(strSpellingLanguage); } - // TODO Refactor the others like this - /** * Sets the default East Asia spelling language on ctStyles DocDefaults parameter * @param strEastAsia */ public void setEastAsia(String strEastAsia) { - CTDocDefaults docDefaults = null; - CTRPr runProps = null; - CTLanguage lang = null; - - // Just making sure we use the members that have already been defined - if(ctStyles.isSetDocDefaults()) { - docDefaults = ctStyles.getDocDefaults(); - if(docDefaults.isSetRPrDefault()) { - CTRPrDefault RPrDefault = docDefaults.getRPrDefault(); - if(RPrDefault.isSetRPr()) { - runProps = RPrDefault.getRPr(); - if(runProps.isSetLang()) - lang = runProps.getLang(); - } - } - } - - if(docDefaults == null) - docDefaults = ctStyles.addNewDocDefaults(); - if(runProps == null) - runProps = docDefaults.addNewRPrDefault().addNewRPr(); - if(lang == null) - lang = runProps.addNewLang(); - + CTLanguage lang = getCTLanguage(); lang.setEastAsia(strEastAsia); } /** * Sets the default font on ctStyles DocDefaults parameter - * @param fonts + * TODO Replace this with specific setters for each type, possibly + * on XWPFDefaultRunStyle */ public void setDefaultFonts(CTFonts fonts) { - CTDocDefaults docDefaults = null; - CTRPr runProps = null; - - // Just making sure we use the members that have already been defined - if(ctStyles.isSetDocDefaults()) { - docDefaults = ctStyles.getDocDefaults(); - if(docDefaults.isSetRPrDefault()) { - CTRPrDefault RPrDefault = docDefaults.getRPrDefault(); - if(RPrDefault.isSetRPr()) { - runProps = RPrDefault.getRPr(); - } - } - } - - if(docDefaults == null) - docDefaults = ctStyles.addNewDocDefaults(); - if(runProps == null) - runProps = docDefaults.addNewRPrDefault().addNewRPr(); - + ensureDocDefaults(); + + CTRPr runProps = defaultRunStyle.getRPr(); runProps.setRFonts(fonts); } |