poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1678197 - /poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
Date Thu, 07 May 2015 13:34:04 GMT
Author: nick
Date: Thu May  7 13:34:03 2015
New Revision: 1678197

URL: http://svn.apache.org/r1678197
Log:
Refactor common default styles code to use the new helpers

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1678197&r1=1678196&r2=1678197&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Thu May  7 13:34:03
2015
@@ -231,11 +231,7 @@ public class XWPFStyles extends POIXMLDo
         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 POIXMLDo
         } 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);
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message