poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From talli...@apache.org
Subject svn commit: r1682473 [6/8] - in /poi/trunk/src/ooxml: java/org/apache/poi/util/ java/org/apache/poi/xwpf/ java/org/apache/poi/xwpf/extractor/ java/org/apache/poi/xwpf/model/ java/org/apache/poi/xwpf/usermodel/ testcases/org/apache/poi/xwpf/ testcases/o...
Date Fri, 29 May 2015 14:01:33 GMT
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java Fri May 29 14:01:31 2015
@@ -19,128 +19,141 @@ package org.apache.poi.xwpf.usermodel;
 
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
-
-/**
- * @author Philipp Epp
- *
- */
-public class XWPFStyle {
-	
-	 private CTStyle ctStyle;
-	 protected XWPFStyles styles;
-
-	 /**
-	  * constructor
-	  * @param style
-	  */
-	 public XWPFStyle(CTStyle style){
-		 this(style,null);
-	 }
-	 /**
-	  * constructor
-	  * @param style
-	  * @param styles
-	  */
-	 public XWPFStyle(CTStyle style, XWPFStyles styles){
-		 this.ctStyle  = style;
-		 this.styles = styles;
-	 }
-
-	 /**
-	  * get StyleID of the style
-	  * @return styleID		StyleID of the style
-	  */
-	 public String getStyleId(){
-		 return ctStyle.getStyleId();
-	 }
-	 
-	 /**
-	  * get Type of the Style
-	  * @return	ctType 
-	  */
-	 public STStyleType.Enum getType(){
-		 return ctStyle.getType();
-	 }
-	 
-	 /**
-	  * set style
-	  * @param style		
-	  */
-	 public void setStyle(CTStyle style){
-		 this.ctStyle = style;
-	 }
-	 /**
-	  * get ctStyle
-	  * @return	ctStyle
-	  */
-	 public CTStyle getCTStyle(){
-		 return this.ctStyle;
-	 }
-	 /**
-	  * set styleID
-	  * @param styleId
-	  */
-	 public void setStyleId(String styleId){
-		 ctStyle.setStyleId(styleId);
-	 }
-	 
-	 /**
-	  * set styleType
-	  * @param type
-	  */
-	 public void setType(STStyleType.Enum type){
-		 ctStyle.setType(type);
-	 }
-	 /**
-	  * get styles
-	  * @return styles		the styles to which this style belongs
-	  */
-	 public XWPFStyles getStyles(){
-		 return styles;
-	 }
-	 
-	 public String getBasisStyleID(){
-		 if(ctStyle.getBasedOn()!=null)
-			 return ctStyle.getBasedOn().getVal();
-		 else
-			 return null;
-	 }
-	 
-	 
-	 /**
-	  * get StyleID of the linked Style
-	  */
-	 public String getLinkStyleID(){
-		 if (ctStyle.getLink()!=null)
-			 return ctStyle.getLink().getVal();
-		 else
-			 return null;
-	 }
-	 
-	 /**
-	  * get StyleID of the next style
-	  */
-	 public String getNextStyleID(){
-		if(ctStyle.getNext()!=null)
-			return ctStyle.getNext().getVal();
-		else
-			return null;
-	 }
-	 
-	 public String getName() {
-	    if(ctStyle.isSetName()) 
-	       return ctStyle.getName().getVal();
-	    return null;
-	 }
-	 
-	 /**
-	  * compares the names of the Styles 
-	  * @param compStyle
-	  */
-	 public boolean hasSameName(XWPFStyle compStyle){
-		CTStyle ctCompStyle = compStyle.getCTStyle();
-		String name = ctCompStyle.getName().getVal();
-		return name.equals(ctStyle.getName().getVal());
-	 }
-	 
-}//end class
+
+/**
+ * @author Philipp Epp
+ */
+public class XWPFStyle {
+
+    protected XWPFStyles styles;
+    private CTStyle ctStyle;
+
+    /**
+     * constructor
+     *
+     * @param style
+     */
+    public XWPFStyle(CTStyle style) {
+        this(style, null);
+    }
+
+    /**
+     * constructor
+     *
+     * @param style
+     * @param styles
+     */
+    public XWPFStyle(CTStyle style, XWPFStyles styles) {
+        this.ctStyle = style;
+        this.styles = styles;
+    }
+
+    /**
+     * get StyleID of the style
+     *
+     * @return styleID        StyleID of the style
+     */
+    public String getStyleId() {
+        return ctStyle.getStyleId();
+    }
+
+    /**
+     * set styleID
+     *
+     * @param styleId
+     */
+    public void setStyleId(String styleId) {
+        ctStyle.setStyleId(styleId);
+    }
+
+    /**
+     * get Type of the Style
+     *
+     * @return ctType
+     */
+    public STStyleType.Enum getType() {
+        return ctStyle.getType();
+    }
+
+    /**
+     * set styleType
+     *
+     * @param type
+     */
+    public void setType(STStyleType.Enum type) {
+        ctStyle.setType(type);
+    }
+
+    /**
+     * set style
+     *
+     * @param style
+     */
+    public void setStyle(CTStyle style) {
+        this.ctStyle = style;
+    }
+
+    /**
+     * get ctStyle
+     *
+     * @return ctStyle
+     */
+    public CTStyle getCTStyle() {
+        return this.ctStyle;
+    }
+
+    /**
+     * get styles
+     *
+     * @return styles        the styles to which this style belongs
+     */
+    public XWPFStyles getStyles() {
+        return styles;
+    }
+
+    public String getBasisStyleID() {
+        if (ctStyle.getBasedOn() != null)
+            return ctStyle.getBasedOn().getVal();
+        else
+            return null;
+    }
+
+
+    /**
+     * get StyleID of the linked Style
+     */
+    public String getLinkStyleID() {
+        if (ctStyle.getLink() != null)
+            return ctStyle.getLink().getVal();
+        else
+            return null;
+    }
+
+    /**
+     * get StyleID of the next style
+     */
+    public String getNextStyleID() {
+        if (ctStyle.getNext() != null)
+            return ctStyle.getNext().getVal();
+        else
+            return null;
+    }
+
+    public String getName() {
+        if (ctStyle.isSetName())
+            return ctStyle.getName().getVal();
+        return null;
+    }
+
+    /**
+     * compares the names of the Styles
+     *
+     * @param compStyle
+     */
+    public boolean hasSameName(XWPFStyle compStyle) {
+        CTStyle ctCompStyle = compStyle.getCTStyle();
+        String name = ctCompStyle.getName().getVal();
+        return name.equals(ctStyle.getName().getVal());
+    }
+
+}//end class

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=1682473&r1=1682472&r2=1682473&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 Fri May 29 14:01:31 2015
@@ -31,42 +31,43 @@ import org.apache.poi.POIXMLDocumentPart
 import org.apache.poi.POIXMLException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocDefaults;
-/**
- * Holds details of built-in, default and user styles, which
- *  apply to tables / paragraphs / lists etc.
- * Text within one of those with custom stylings has the style
- *  information stored in the {@link XWPFRun}
- */
-public class XWPFStyles extends POIXMLDocumentPart{
-    private CTStyles ctStyles;
-    private List<XWPFStyle> listStyle = new ArrayList<XWPFStyle>();
-    
-    private XWPFLatentStyles latentStyles;
-    private XWPFDefaultRunStyle defaultRunStyle;
-    private XWPFDefaultParagraphStyle defaultParaStyle;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocDefaults;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
+
+/**
+ * Holds details of built-in, default and user styles, which
+ * apply to tables / paragraphs / lists etc.
+ * Text within one of those with custom stylings has the style
+ * information stored in the {@link XWPFRun}
+ */
+public class XWPFStyles extends POIXMLDocumentPart {
+    private CTStyles ctStyles;
+    private List<XWPFStyle> listStyle = new ArrayList<XWPFStyle>();
+
+    private XWPFLatentStyles latentStyles;
+    private XWPFDefaultRunStyle defaultRunStyle;
+    private XWPFDefaultParagraphStyle defaultParaStyle;
 
     /**
      * Construct XWPFStyles from a package part
      *
-     * @param part the package part holding the data of the styles,
-     * @param rel  the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
-     */
-    public XWPFStyles(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{
-        super(part, rel);
-    }
-
+     * @param part the package part holding the data of the styles,
+     * @param rel  the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
+     */
+    public XWPFStyles(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException {
+        super(part, rel);
+    }
+
     /**
      * Construct XWPFStyles from scratch for a new document.
      */
@@ -74,13 +75,13 @@ public class XWPFStyles extends POIXMLDo
     }
 
     /**
-     * Read document
-     */
-    @Override
-    protected void onDocumentRead() throws IOException{
-        StylesDocument stylesDoc;
-        try {
-            InputStream is = getPackagePart().getInputStream();
+     * Read document
+     */
+    @Override
+    protected void onDocumentRead() throws IOException {
+        StylesDocument stylesDoc;
+        try {
+            InputStream is = getPackagePart().getInputStream();
             stylesDoc = StylesDocument.Factory.parse(is);
             setStyles(stylesDoc.getStyles());
             latentStyles = new XWPFLatentStyles(ctStyles.getLatentStyles(), this);
@@ -94,52 +95,53 @@ public class XWPFStyles extends POIXMLDo
         if (ctStyles == null) {
             throw new IllegalStateException("Unable to write out styles that were never read in!");
         }
-
-        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
-        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles"));
-        Map<String,String> map = new HashMap<String,String>();
-        map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
-        map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
-        xmlOptions.setSaveSuggestedPrefixes(map);
+
+        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles"));
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
+        map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
+        xmlOptions.setSaveSuggestedPrefixes(map);
         PackagePart part = getPackagePart();
         OutputStream out = part.getOutputStream();
         ctStyles.save(out, xmlOptions);
         out.close();
-    }
-
-    protected void ensureDocDefaults() {
-        if (! ctStyles.isSetDocDefaults()) {
-            ctStyles.addNewDocDefaults();
-        }
-        
-        CTDocDefaults docDefaults = ctStyles.getDocDefaults();
-        if (! docDefaults.isSetPPrDefault())
-            docDefaults.addNewPPrDefault();
-        if (! docDefaults.isSetRPrDefault())
-            docDefaults.addNewRPrDefault();
-        
-        CTPPrDefault pprd = docDefaults.getPPrDefault();
-        CTRPrDefault rprd = docDefaults.getRPrDefault();
-        if (!pprd.isSetPPr()) pprd.addNewPPr();
-        if (!rprd.isSetRPr()) rprd.addNewRPr();
-        
-        defaultRunStyle = new XWPFDefaultRunStyle(rprd.getRPr());
-        defaultParaStyle = new XWPFDefaultParagraphStyle(pprd.getPPr());
-    }
-
-    /**
-     * Sets the ctStyles
-     * @param styles
-     */
-    @SuppressWarnings("deprecation")
+    }
+
+    protected void ensureDocDefaults() {
+        if (!ctStyles.isSetDocDefaults()) {
+            ctStyles.addNewDocDefaults();
+        }
+
+        CTDocDefaults docDefaults = ctStyles.getDocDefaults();
+        if (!docDefaults.isSetPPrDefault())
+            docDefaults.addNewPPrDefault();
+        if (!docDefaults.isSetRPrDefault())
+            docDefaults.addNewRPrDefault();
+
+        CTPPrDefault pprd = docDefaults.getPPrDefault();
+        CTRPrDefault rprd = docDefaults.getRPrDefault();
+        if (!pprd.isSetPPr()) pprd.addNewPPr();
+        if (!rprd.isSetRPr()) rprd.addNewRPr();
+
+        defaultRunStyle = new XWPFDefaultRunStyle(rprd.getRPr());
+        defaultParaStyle = new XWPFDefaultParagraphStyle(pprd.getPPr());
+    }
+
+    /**
+     * Sets the ctStyles
+     *
+     * @param styles
+     */
+    @SuppressWarnings("deprecation")
     public void setStyles(CTStyles styles) {
-        ctStyles = styles;
-
-        // Build up all the style objects
-        for(CTStyle style : ctStyles.getStyleArray()) {
-            listStyle.add(new XWPFStyle(style, this));
-        }
-        if (ctStyles.isSetDocDefaults()) {
+        ctStyles = styles;
+
+        // Build up all the style objects
+        for (CTStyle style : ctStyles.getStyleArray()) {
+            listStyle.add(new XWPFStyle(style, this));
+        }
+        if (ctStyles.isSetDocDefaults()) {
             CTDocDefaults docDefaults = ctStyles.getDocDefaults();
             if (docDefaults.isSetRPrDefault() && docDefaults.getRPrDefault().isSetRPr()) {
                 defaultRunStyle = new XWPFDefaultRunStyle(
@@ -151,142 +153,152 @@ public class XWPFStyles extends POIXMLDo
             }
         }
     }
-
-    /**
-     * checks whether style with styleID exist
-     * @param styleID		styleID of the Style in the style-Document
-     * @return				true if style exist, false if style not exist
-     */
-    public boolean styleExist(String styleID){
-        for (XWPFStyle style : listStyle) {
-            if (style.getStyleId().equals(styleID))
-                return true;
-        }
-        return false;
-    }
-    /**
-     * add a style to the document
-     * @param style				
-     * @throws IOException		 
-     */
-    public void addStyle(XWPFStyle style){
-        listStyle.add(style);
-        ctStyles.addNewStyle();
-        int pos = ctStyles.sizeOfStyleArray() - 1;
-        ctStyles.setStyleArray(pos, style.getCTStyle());
-    }
-    /**
-     * Get style by a styleID 
-     * @param styleID	styleID of the searched style
-     * @return style
-     */
-    public XWPFStyle getStyle(String styleID){
-        for (XWPFStyle style : listStyle) {
-            if(style.getStyleId().equals(styleID))
-                return style;		
-        }
-        return null;
-    }
-    public int getNumberOfStyles() {
-        return listStyle.size();
-    }
-
-    /**
-     * get the styles which are related to the parameter style and their relatives
-     * this method can be used to copy all styles from one document to another document 
-     * @param style
-     * @return a list of all styles which were used by this method 
-     */
-    public List<XWPFStyle> getUsedStyleList(XWPFStyle style){
-        List<XWPFStyle> usedStyleList = new ArrayList<XWPFStyle>();
-        usedStyleList.add(style);
-        return getUsedStyleList(style, usedStyleList);
-    }
-
-    /** 
-     * get the styles which are related to parameter style
-     * @param style
-     * @return all Styles of the parameterList
-     */
-    private List<XWPFStyle> getUsedStyleList(XWPFStyle style, List<XWPFStyle> usedStyleList){
-        String basisStyleID  = style.getBasisStyleID();
-        XWPFStyle basisStyle = getStyle(basisStyleID);
-        if((basisStyle!=null)&&(!usedStyleList.contains(basisStyle))){
-            usedStyleList.add(basisStyle);
-            getUsedStyleList(basisStyle, usedStyleList);
-        }		
-        String linkStyleID = style.getLinkStyleID();
-        XWPFStyle linkStyle = getStyle(linkStyleID);
-        if((linkStyle!=null)&&(!usedStyleList.contains(linkStyle))){
-            usedStyleList.add(linkStyle);
-            getUsedStyleList(linkStyle, usedStyleList);
-        }
-
-        String nextStyleID = style.getNextStyleID();
-        XWPFStyle nextStyle = getStyle(nextStyleID);
-        if((nextStyle!=null)&&(!usedStyleList.contains(nextStyle))){
-            usedStyleList.add(linkStyle);
-            getUsedStyleList(linkStyle, usedStyleList);
-        }		
-        return usedStyleList;
-    }
-
-    protected CTLanguage getCTLanguage() {
-        ensureDocDefaults();
-        
-        CTLanguage lang = null;
-        if (defaultRunStyle.getRPr().isSetLang()) {
-            lang = defaultRunStyle.getRPr().getLang();
-        } else {
-            lang = defaultRunStyle.getRPr().addNewLang();
-        }
-        
-        return lang;
-    }
-    
-    /**
-     * Sets the default spelling language on ctStyles DocDefaults parameter
-     * @param strSpellingLanguage
-     */
-    public void setSpellingLanguage(String strSpellingLanguage) {
+
+    /**
+     * checks whether style with styleID exist
+     *
+     * @param styleID styleID of the Style in the style-Document
+     * @return true if style exist, false if style not exist
+     */
+    public boolean styleExist(String styleID) {
+        for (XWPFStyle style : listStyle) {
+            if (style.getStyleId().equals(styleID))
+                return true;
+        }
+        return false;
+    }
+
+    /**
+     * add a style to the document
+     *
+     * @param style
+     * @throws IOException
+     */
+    public void addStyle(XWPFStyle style) {
+        listStyle.add(style);
+        ctStyles.addNewStyle();
+        int pos = ctStyles.sizeOfStyleArray() - 1;
+        ctStyles.setStyleArray(pos, style.getCTStyle());
+    }
+
+    /**
+     * Get style by a styleID
+     *
+     * @param styleID styleID of the searched style
+     * @return style
+     */
+    public XWPFStyle getStyle(String styleID) {
+        for (XWPFStyle style : listStyle) {
+            if (style.getStyleId().equals(styleID))
+                return style;
+        }
+        return null;
+    }
+
+    public int getNumberOfStyles() {
+        return listStyle.size();
+    }
+
+    /**
+     * get the styles which are related to the parameter style and their relatives
+     * this method can be used to copy all styles from one document to another document
+     *
+     * @param style
+     * @return a list of all styles which were used by this method
+     */
+    public List<XWPFStyle> getUsedStyleList(XWPFStyle style) {
+        List<XWPFStyle> usedStyleList = new ArrayList<XWPFStyle>();
+        usedStyleList.add(style);
+        return getUsedStyleList(style, usedStyleList);
+    }
+
+    /**
+     * get the styles which are related to parameter style
+     *
+     * @param style
+     * @return all Styles of the parameterList
+     */
+    private List<XWPFStyle> getUsedStyleList(XWPFStyle style, List<XWPFStyle> usedStyleList) {
+        String basisStyleID = style.getBasisStyleID();
+        XWPFStyle basisStyle = getStyle(basisStyleID);
+        if ((basisStyle != null) && (!usedStyleList.contains(basisStyle))) {
+            usedStyleList.add(basisStyle);
+            getUsedStyleList(basisStyle, usedStyleList);
+        }
+        String linkStyleID = style.getLinkStyleID();
+        XWPFStyle linkStyle = getStyle(linkStyleID);
+        if ((linkStyle != null) && (!usedStyleList.contains(linkStyle))) {
+            usedStyleList.add(linkStyle);
+            getUsedStyleList(linkStyle, usedStyleList);
+        }
+
+        String nextStyleID = style.getNextStyleID();
+        XWPFStyle nextStyle = getStyle(nextStyleID);
+        if ((nextStyle != null) && (!usedStyleList.contains(nextStyle))) {
+            usedStyleList.add(linkStyle);
+            getUsedStyleList(linkStyle, usedStyleList);
+        }
+        return usedStyleList;
+    }
+
+    protected CTLanguage getCTLanguage() {
+        ensureDocDefaults();
+
+        CTLanguage lang = null;
+        if (defaultRunStyle.getRPr().isSetLang()) {
+            lang = defaultRunStyle.getRPr().getLang();
+        } 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);
-    }
-    
-    /**
-     * Sets the default East Asia spelling language on ctStyles DocDefaults parameter
-     * @param strEastAsia
-     */
-    public void setEastAsia(String strEastAsia) {
+        lang.setVal(strSpellingLanguage);
+        lang.setBidi(strSpellingLanguage);
+    }
+
+    /**
+     * Sets the default East Asia spelling language on ctStyles DocDefaults parameter
+     *
+     * @param strEastAsia
+     */
+    public void setEastAsia(String strEastAsia) {
         CTLanguage lang = getCTLanguage();
         lang.setEastAsia(strEastAsia);
     }
 
-    /**
-     * Sets the default font on ctStyles DocDefaults parameter
-     * TODO Replace this with specific setters for each type, possibly
-     *  on XWPFDefaultRunStyle
-     */
-    public void setDefaultFonts(CTFonts fonts) {
-        ensureDocDefaults();
-        
-        CTRPr runProps = defaultRunStyle.getRPr();
-        runProps.setRFonts(fonts);
-    }
-
-    /**
-     * get the style with the same name
-     * if this style is not existing, return null
-     */
-    public XWPFStyle getStyleWithSameName(XWPFStyle style){
-        for (XWPFStyle ownStyle : listStyle) {
-            if(ownStyle.hasSameName(style)){
-                return ownStyle;
-            }	
-        }
-        return null;
-    }
+    /**
+     * Sets the default font on ctStyles DocDefaults parameter
+     * TODO Replace this with specific setters for each type, possibly
+     * on XWPFDefaultRunStyle
+     */
+    public void setDefaultFonts(CTFonts fonts) {
+        ensureDocDefaults();
+
+        CTRPr runProps = defaultRunStyle.getRPr();
+        runProps.setRFonts(fonts);
+    }
+
+    /**
+     * get the style with the same name
+     * if this style is not existing, return null
+     */
+    public XWPFStyle getStyleWithSameName(XWPFStyle style) {
+        for (XWPFStyle ownStyle : listStyle) {
+            if (ownStyle.hasSameName(style)) {
+                return ownStyle;
+            }
+        }
+        return null;
+    }
 
     /**
      * Get the default style which applies text runs in the document

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java Fri May 29 14:01:31 2015
@@ -44,19 +44,10 @@ import org.openxmlformats.schemas.wordpr
  * of paragraphs (and other block-level content) arranged in rows and columns.</p>
  */
 public class XWPFTable implements IBodyElement, ISDTContents {
-    protected StringBuffer text = new StringBuffer();
-    private CTTbl ctTbl;
-    protected List<XWPFTableRow> tableRows;
-    protected List<String> styleIDs;
-
-    // Create a map from this XWPF-level enum to the STBorder.Enum values
-    public static enum XWPFBorderType { NIL, NONE, SINGLE, THICK, DOUBLE, DOTTED, DASHED, DOT_DASH };
     private static EnumMap<XWPFBorderType, STBorder.Enum> xwpfBorderTypeMap;
     // Create a map from the STBorder.Enum values to the XWPF-level enums
     private static HashMap<Integer, XWPFBorderType> stBorderTypeMap;
 
-    protected IBody part;
-
     static {
         // populate enum maps
         xwpfBorderTypeMap = new EnumMap<XWPFBorderType, STBorder.Enum>(XWPFBorderType.class);
@@ -77,9 +68,17 @@ public class XWPFTable implements IBodyE
         stBorderTypeMap.put(STBorder.INT_DOUBLE, XWPFBorderType.DOUBLE);
         stBorderTypeMap.put(STBorder.INT_DOTTED, XWPFBorderType.DOTTED);
         stBorderTypeMap.put(STBorder.INT_DASHED, XWPFBorderType.DASHED);
-        stBorderTypeMap.put(STBorder.INT_DOT_DASH, XWPFBorderType.DOT_DASH); 
+        stBorderTypeMap.put(STBorder.INT_DOT_DASH, XWPFBorderType.DOT_DASH);
     }
-    
+
+    protected StringBuffer text = new StringBuffer();
+    protected List<XWPFTableRow> tableRows;
+
+    ;
+    protected List<String> styleIDs;
+    protected IBody part;
+    private CTTbl ctTbl;
+
     public XWPFTable(CTTbl table, IBody part, int row, int col) {
         this(table, part);
 
@@ -94,7 +93,7 @@ public class XWPFTable implements IBodyE
     }
 
     @SuppressWarnings("deprecation")
-    public XWPFTable(CTTbl table, IBody part){
+    public XWPFTable(CTTbl table, IBody part) {
         this.part = part;
         this.ctTbl = table;
 
@@ -163,9 +162,9 @@ public class XWPFTable implements IBodyE
      * Convenience method to extract text in cells.  This
      * does not extract text recursively in cells, and it does not
      * currently include text in SDT (form) components.
-     * <p>
+     * <p/>
      * To get all text within a table, see XWPFWordExtractor's appendTableText
-     * as an example. 
+     * as an example.
      *
      * @return text
      */
@@ -216,22 +215,21 @@ public class XWPFTable implements IBodyE
         return null;
     }
 
-
     /**
-     * @param width
+     * @return width value
      */
-    public void setWidth(int width) {
+    public int getWidth() {
         CTTblPr tblPr = getTrPr();
-        CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW();
-        tblWidth.setW(new BigInteger("" + width));
+        return tblPr.isSetTblW() ? tblPr.getTblW().getW().intValue() : -1;
     }
 
     /**
-     * @return width value
+     * @param width
      */
-    public int getWidth() {
+    public void setWidth(int width) {
         CTTblPr tblPr = getTrPr();
-        return tblPr.isSetTblW() ? tblPr.getTblW().getW().intValue() : -1;
+        CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW();
+        tblWidth.setW(new BigInteger("" + width));
     }
 
     /**
@@ -253,12 +251,13 @@ public class XWPFTable implements IBodyE
             }
         }
     }
-    
+
     /**
      * get the StyleID of the table
-     * @return	style-ID of the table
+     *
+     * @return style-ID of the table
      */
-    public String getStyleID(){
+    public String getStyleID() {
         String styleId = null;
         CTTblPr tblPr = ctTbl.getTblPr();
         if (tblPr != null) {
@@ -273,6 +272,7 @@ public class XWPFTable implements IBodyE
     /**
      * Set the table style. If the style is not defined in the document, MS Word
      * will set the table style to "Normal".
+     *
      * @param styleName - the style name to apply to this table
      */
     public void setStyleID(String styleName) {
@@ -523,24 +523,25 @@ public class XWPFTable implements IBodyE
 
     /**
      * add a new Row to the table
-     * 
-     * @param row	the row which should be added
+     *
+     * @param row the row which should be added
      */
-    public void addRow(XWPFTableRow row){
+    public void addRow(XWPFTableRow row) {
         ctTbl.addNewTr();
-        ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
+        ctTbl.setTrArray(getNumberOfRows() - 1, row.getCtRow());
         tableRows.add(row);
     }
 
     /**
      * add a new Row to the table
      * at position pos
-     * @param row	the row which should be added
+     *
+     * @param row the row which should be added
      */
-    public boolean addRow(XWPFTableRow row, int pos){
-        if(pos >= 0 && pos <= tableRows.size()){
+    public boolean addRow(XWPFTableRow row, int pos) {
+        if (pos >= 0 && pos <= tableRows.size()) {
             ctTbl.insertNewTr(pos);
-            ctTbl.setTrArray(pos,row.getCtRow());
+            ctTbl.setTrArray(pos, row.getCtRow());
             tableRows.add(pos, row);
             return true;
         }
@@ -548,12 +549,13 @@ public class XWPFTable implements IBodyE
     }
 
     /**
-     * inserts a new tablerow 
+     * inserts a new tablerow
+     *
      * @param pos
-     * @return  the inserted row
+     * @return the inserted row
      */
-    public XWPFTableRow insertNewTableRow(int pos){
-        if(pos >= 0 && pos <= tableRows.size()){
+    public XWPFTableRow insertNewTableRow(int pos) {
+        if (pos >= 0 && pos <= tableRows.size()) {
             CTRow row = ctTbl.insertNewTr(pos);
             XWPFTableRow tableRow = new XWPFTableRow(row, this);
             tableRows.add(pos, tableRow);
@@ -562,10 +564,10 @@ public class XWPFTable implements IBodyE
         return null;
     }
 
-
     /**
      * Remove a row at position pos from the table
-     * @param pos	position the Row in the Table
+     *
+     * @param pos position the Row in the Table
      */
     public boolean removeRow(int pos) throws IndexOutOfBoundsException {
         if (pos >= 0 && pos < tableRows.size()) {
@@ -582,9 +584,9 @@ public class XWPFTable implements IBodyE
         return tableRows;
     }
 
-
     /**
      * returns the type of the BodyElement Table
+     *
      * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
      */
     public BodyElementType getElementType() {
@@ -597,10 +599,11 @@ public class XWPFTable implements IBodyE
 
     /**
      * returns the part of the bodyElement
+     *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
      */
     public POIXMLDocumentPart getPart() {
-        if(part != null){
+        if (part != null) {
             return part.getPart();
         }
         return null;
@@ -608,6 +611,7 @@ public class XWPFTable implements IBodyE
 
     /**
      * returns the partType of the bodyPart which owns the bodyElement
+     *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
      */
     public BodyType getPartType() {
@@ -619,9 +623,14 @@ public class XWPFTable implements IBodyE
      * if this row is not existing in the table null will be returned
      */
     public XWPFTableRow getRow(CTRow row) {
-        for(int i=0; i<getRows().size(); i++){
-            if(getRows().get(i).getCtRow()== row) return getRow(i); 
+        for (int i = 0; i < getRows().size(); i++) {
+            if (getRows().get(i).getCtRow() == row) return getRow(i);
         }
         return null;
     }
+
+    // Create a map from this XWPF-level enum to the STBorder.Enum values
+    public static enum XWPFBorderType {
+        NIL, NONE, SINGLE, THICK, DOUBLE, DOTTED, DASHED, DOT_DASH
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java Fri May 29 14:01:31 2015
@@ -37,23 +37,15 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
-
-/**
- * Represents a Cell within a {@link XWPFTable}. The
- *  Cell is the thing that holds the actual content (paragraphs etc)
- */
-public class XWPFTableCell implements IBody, ICell {
-    private final CTTc ctTc;
-    protected List<XWPFParagraph> paragraphs = null;
-    protected List<XWPFTable> tables = null;
-    protected List<IBodyElement> bodyElements = null;
-    protected IBody part;
-    private XWPFTableRow tableRow = null;
-    // Create a map from this XWPF-level enum to the STVerticalJc.Enum values
-    public static enum XWPFVertAlign { TOP, CENTER, BOTH, BOTTOM };
-    private static EnumMap<XWPFVertAlign, STVerticalJc.Enum> alignMap;
-    // Create a map from the STVerticalJc.Enum values to the XWPF-level enums
-    private static HashMap<Integer, XWPFVertAlign> stVertAlignTypeMap;
+
+/**
+ * Represents a Cell within a {@link XWPFTable}. The
+ * Cell is the thing that holds the actual content (paragraphs etc)
+ */
+public class XWPFTableCell implements IBody, ICell {
+    private static EnumMap<XWPFVertAlign, STVerticalJc.Enum> alignMap;
+    // Create a map from the STVerticalJc.Enum values to the XWPF-level enums
+    private static HashMap<Integer, XWPFVertAlign> stVertAlignTypeMap;
 
     static {
         // populate enum maps
@@ -68,337 +60,343 @@ public class XWPFTableCell implements IB
         stVertAlignTypeMap.put(STVerticalJc.INT_CENTER, XWPFVertAlign.CENTER);
         stVertAlignTypeMap.put(STVerticalJc.INT_BOTH, XWPFVertAlign.BOTH);
         stVertAlignTypeMap.put(STVerticalJc.INT_BOTTOM, XWPFVertAlign.BOTTOM);
-
-    }
-
-    /**
-     * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
-     */
+
+    }
+
+    private final CTTc ctTc;
+    protected List<XWPFParagraph> paragraphs = null;
+    protected List<XWPFTable> tables = null;
+    protected List<IBodyElement> bodyElements = null;
+
+    ;
+    protected IBody part;
+    private XWPFTableRow tableRow = null;
+
+    /**
+     * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
+     */
     public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) {
         this.ctTc = cell;
-        this.part = part;
-        this.tableRow = tableRow;
-        // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
-        if(cell.sizeOfPArray()<1)
-            cell.addNewP();
-        bodyElements = new ArrayList<IBodyElement>();
-        paragraphs = new ArrayList<XWPFParagraph>();
+        this.part = part;
+        this.tableRow = tableRow;
+        // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
+        if (cell.sizeOfPArray() < 1)
+            cell.addNewP();
+        bodyElements = new ArrayList<IBodyElement>();
+        paragraphs = new ArrayList<XWPFParagraph>();
         tables = new ArrayList<XWPFTable>();
 
         XmlCursor cursor = ctTc.newCursor();
         cursor.selectPath("./*");
-        while (cursor.toNextSelection()) {
-            XmlObject o = cursor.getObject();
-            if (o instanceof CTP) {
-                XWPFParagraph p = new XWPFParagraph((CTP)o, this);
-                paragraphs.add(p);
-                bodyElements.add(p);
-            }
-            if (o instanceof CTTbl) {
-                XWPFTable t = new XWPFTable((CTTbl)o, this);
-                tables.add(t);
-                bodyElements.add(t);
-            }
-            if (o instanceof CTSdtBlock){
-               XWPFSDT c = new XWPFSDT((CTSdtBlock)o, this);
-               bodyElements.add(c);
-            }
-            if (o instanceof CTSdtRun){
-               XWPFSDT c = new XWPFSDT((CTSdtRun)o, this);
-               System.out.println(c.getContent().getText());
-               bodyElements.add(c);
-            }
-        }
-        cursor.dispose();
-    }
-
-
-    @Internal
-    public CTTc getCTTc() {
-        return ctTc;
-    }
-
-    /**
-     * returns an Iterator with paragraphs and tables
-     * @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements()
-     */
-    public List<IBodyElement> getBodyElements(){
-      return Collections.unmodifiableList(bodyElements);
-    }
-    
-    public void setParagraph(XWPFParagraph p) {
-        if (ctTc.sizeOfPArray() == 0) {
-            ctTc.addNewP();
+        while (cursor.toNextSelection()) {
+            XmlObject o = cursor.getObject();
+            if (o instanceof CTP) {
+                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
+                paragraphs.add(p);
+                bodyElements.add(p);
+            }
+            if (o instanceof CTTbl) {
+                XWPFTable t = new XWPFTable((CTTbl) o, this);
+                tables.add(t);
+                bodyElements.add(t);
+            }
+            if (o instanceof CTSdtBlock) {
+                XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
+                bodyElements.add(c);
+            }
+            if (o instanceof CTSdtRun) {
+                XWPFSDT c = new XWPFSDT((CTSdtRun) o, this);
+                System.out.println(c.getContent().getText());
+                bodyElements.add(c);
+            }
+        }
+        cursor.dispose();
+    }
+
+    @Internal
+    public CTTc getCTTc() {
+        return ctTc;
+    }
+
+    /**
+     * returns an Iterator with paragraphs and tables
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements()
+     */
+    public List<IBodyElement> getBodyElements() {
+        return Collections.unmodifiableList(bodyElements);
+    }
+
+    public void setParagraph(XWPFParagraph p) {
+        if (ctTc.sizeOfPArray() == 0) {
+            ctTc.addNewP();
         }
         ctTc.setPArray(0, p.getCTP());
     }
 
-    /**
-     * returns a list of paragraphs
-     */
-    public List<XWPFParagraph> getParagraphs(){
-    		return paragraphs;
-    }
-    
-    /**
-     * Add a Paragraph to this Table Cell
-     * @return The paragraph which was added
-     */
-    public XWPFParagraph addParagraph() {
-       XWPFParagraph p = new XWPFParagraph(ctTc.addNewP(), this);
-       addParagraph(p);
-       return p;
-    }
-    
-    /**
-     * add a Paragraph to this TableCell
-     * @param p the paragaph which has to be added
-     */
-    public void addParagraph(XWPFParagraph p){
-    	paragraphs.add(p);
-    }
-    
-    /**
-     * removes a paragraph of this tablecell
-     * @param pos
-     */
-    public void removeParagraph(int pos){
-    	paragraphs.remove(pos);
-    	ctTc.removeP(pos);
-    }
-    
-	/**
-	 * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this table
-	 * the method will return this paragraph
-	 * if there is no corresponding {@link XWPFParagraph} the method will return null 
-	 * @param p is instance of CTP and is searching for an XWPFParagraph
-	 * @return null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this table
-	 * 		   XWPFParagraph with the correspondig CTP p
-	 */
-    public XWPFParagraph getParagraph(CTP p){
-	for (XWPFParagraph paragraph : paragraphs) {
-	    if(p.equals(paragraph.getCTP())){
-		return paragraph;
-	    }
-	}
-	return null;
-    }	
-    
-    public void setText(String text) {
-        CTP ctP = (ctTc.sizeOfPArray() == 0) ? ctTc.addNewP() : ctTc.getPArray(0);
-        XWPFParagraph par = new XWPFParagraph(ctP, this);
-        par.createRun().setText(text);
-    }
-    
-    public XWPFTableRow getTableRow(){
-    	return tableRow;
-    }
-    
-    /**
-     * Set cell color. This sets some associated values; for finer control
-     * you may want to access these elements individually.
-     * @param rgbStr - the desired cell color, in the hex form "RRGGBB".
-     */
-    public void setColor(String rgbStr) {
-        CTTcPr tcpr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr();
-        CTShd ctshd = tcpr.isSetShd() ? tcpr.getShd() : tcpr.addNewShd();
-        ctshd.setColor("auto");
-        ctshd.setVal(STShd.CLEAR);
-        ctshd.setFill(rgbStr);
-    }
-
-    /**
-     * Get cell color. Note that this method only returns the "fill" value.
-     * @return RGB string of cell color
-     */
-    public String getColor() {
-	String color = null;
-	CTTcPr tcpr = ctTc.getTcPr();
-	if (tcpr != null) {
-	    CTShd ctshd = tcpr.getShd();
-	    if (ctshd != null) {
-		color = ctshd.xgetFill().getStringValue();
-	    }
-	}
-	return color;
-    }
-
-    /**
-     * Set the vertical alignment of the cell.
-     * @param vAlign - the desired alignment enum value
-     */
-    public void setVerticalAlignment(XWPFVertAlign vAlign) {
-        CTTcPr tcpr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr();
-    	CTVerticalJc va = tcpr.addNewVAlign();
-    	va.setVal(alignMap.get(vAlign));
-    }
-
-    /**
-     * Get the vertical alignment of the cell.
-     * @return the cell alignment enum value
-     */
-    public XWPFVertAlign getVerticalAlignment() {
-	XWPFVertAlign vAlign = null;
-	CTTcPr tcpr = ctTc.getTcPr();
-	if (ctTc != null) {
-	    CTVerticalJc va = tcpr.getVAlign();
-	    vAlign = stVertAlignTypeMap.get(va.getVal().intValue());
-	}
-	return vAlign;
-    }
-
-    /**
-     * add a new paragraph at position of the cursor
-     * @param cursor
-     * @return the inserted paragraph
-     */
-    public XWPFParagraph insertNewParagraph(XmlCursor cursor){
-	if(!isCursorInTableCell(cursor)) {
-	    return null;
-	}
-
-	String uri = CTP.type.getName().getNamespaceURI();
-	String localPart = "p";
-	cursor.beginElement(localPart,uri);
-	cursor.toParent();
-	CTP p = (CTP)cursor.getObject();
-	XWPFParagraph newP = new XWPFParagraph(p, this);
-	XmlObject o = null;
-	while(!(o instanceof CTP)&&(cursor.toPrevSibling())){
-	    o = cursor.getObject();
-	}
-	if((!(o instanceof CTP)) || (CTP)o == p){
-	    paragraphs.add(0, newP);
-	}
-	else{
-	    int pos = paragraphs.indexOf(getParagraph((CTP)o))+1;
-	    paragraphs.add(pos,newP);
-	}
-	int i=0;
-	cursor.toCursor(p.newCursor());
-	while(cursor.toPrevSibling()){
-	    o =cursor.getObject();
-	    if(o instanceof CTP || o instanceof CTTbl)
-		i++;
-	}
-	bodyElements.add(i, newP);
-	cursor.toCursor(p.newCursor());
-	cursor.toEndToken();
-	return newP;
-    }
-
-    public XWPFTable insertNewTbl(XmlCursor cursor) {
-	if(isCursorInTableCell(cursor)){
-	    String uri = CTTbl.type.getName().getNamespaceURI();
-	    String localPart = "tbl";
-	    cursor.beginElement(localPart,uri);
-	    cursor.toParent();
-	    CTTbl t = (CTTbl)cursor.getObject();
-	    XWPFTable newT = new XWPFTable(t, this);
-	    cursor.removeXmlContents();
-	    XmlObject o = null;
-	    while(!(o instanceof CTTbl)&&(cursor.toPrevSibling())){
-		o = cursor.getObject();
-	    }
-	    if(!(o instanceof CTTbl)){
-		tables.add(0, newT);
-	    }
-	    else{
-		int pos = tables.indexOf(getTable((CTTbl)o))+1;
-		tables.add(pos,newT);
-	    }
-	    int i=0;
-	    cursor = t.newCursor();
-	    while(cursor.toPrevSibling()){
-		o =cursor.getObject();
-		if(o instanceof CTP || o instanceof CTTbl)
-		    i++;
-	    }
-	    bodyElements.add(i, newT);
-	    cursor = t.newCursor();
-	    cursor.toEndToken();
-	    return newT;
-	}
-	return null;
-    }
-
-    /**
-     * verifies that cursor is on the right position
-     */
-    private boolean isCursorInTableCell(XmlCursor cursor) {
-	XmlCursor verify = cursor.newCursor();
-	verify.toParent();
-	if(verify.getObject() == this.ctTc){
-	    return true;
-	}
-	return false;
-    }
-
-
-
-    /**
-     * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
-     */
-    public XWPFParagraph getParagraphArray(int pos) {
-	if(pos > 0 && pos < paragraphs.size()){
-	    return paragraphs.get(pos);
-	}
-	return null;
-    }
-
-    /**
-     * get the to which the TableCell belongs
-     * 
-     * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
-     */
-    public POIXMLDocumentPart getPart() {
-        return tableRow.getTable().getPart();
-    }
-
-    /** 
-     * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
-     */
-    public BodyType getPartType() {
-	return BodyType.TABLECELL;
-    }
-
-
-    /**
-     * get a table by its CTTbl-Object
-     * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)
-     */
-    public XWPFTable getTable(CTTbl ctTable) {
-	for(int i=0; i<tables.size(); i++){
-	    if(getTables().get(i).getCTTbl() == ctTable) return getTables().get(i); 
-	}
-	return null;
-    }
-
-
-    /** 
-     * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
-     */
-    public XWPFTable getTableArray(int pos) {
-	if(pos > 0 && pos < tables.size()){
-	    return tables.get(pos);
-	}
-	return null;
-    }
-
-
-    /** 
-     * @see org.apache.poi.xwpf.usermodel.IBody#getTables()
-     */
-    public List<XWPFTable> getTables() {
-	return Collections.unmodifiableList(tables);
-    }
-
-
-    /**
-     * inserts an existing XWPFTable to the arrays bodyElements and tables
-     * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable)
-     */
-    @SuppressWarnings("deprecation")
+    /**
+     * returns a list of paragraphs
+     */
+    public List<XWPFParagraph> getParagraphs() {
+        return paragraphs;
+    }
+
+    /**
+     * Add a Paragraph to this Table Cell
+     *
+     * @return The paragraph which was added
+     */
+    public XWPFParagraph addParagraph() {
+        XWPFParagraph p = new XWPFParagraph(ctTc.addNewP(), this);
+        addParagraph(p);
+        return p;
+    }
+
+    /**
+     * add a Paragraph to this TableCell
+     *
+     * @param p the paragaph which has to be added
+     */
+    public void addParagraph(XWPFParagraph p) {
+        paragraphs.add(p);
+    }
+
+    /**
+     * removes a paragraph of this tablecell
+     *
+     * @param pos
+     */
+    public void removeParagraph(int pos) {
+        paragraphs.remove(pos);
+        ctTc.removeP(pos);
+    }
+
+    /**
+     * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this table
+     * the method will return this paragraph
+     * if there is no corresponding {@link XWPFParagraph} the method will return null
+     *
+     * @param p is instance of CTP and is searching for an XWPFParagraph
+     * @return null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this table
+     * XWPFParagraph with the correspondig CTP p
+     */
+    public XWPFParagraph getParagraph(CTP p) {
+        for (XWPFParagraph paragraph : paragraphs) {
+            if (p.equals(paragraph.getCTP())) {
+                return paragraph;
+            }
+        }
+        return null;
+    }
+
+    public XWPFTableRow getTableRow() {
+        return tableRow;
+    }
+
+    /**
+     * Get cell color. Note that this method only returns the "fill" value.
+     *
+     * @return RGB string of cell color
+     */
+    public String getColor() {
+        String color = null;
+        CTTcPr tcpr = ctTc.getTcPr();
+        if (tcpr != null) {
+            CTShd ctshd = tcpr.getShd();
+            if (ctshd != null) {
+                color = ctshd.xgetFill().getStringValue();
+            }
+        }
+        return color;
+    }
+
+    /**
+     * Set cell color. This sets some associated values; for finer control
+     * you may want to access these elements individually.
+     *
+     * @param rgbStr - the desired cell color, in the hex form "RRGGBB".
+     */
+    public void setColor(String rgbStr) {
+        CTTcPr tcpr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr();
+        CTShd ctshd = tcpr.isSetShd() ? tcpr.getShd() : tcpr.addNewShd();
+        ctshd.setColor("auto");
+        ctshd.setVal(STShd.CLEAR);
+        ctshd.setFill(rgbStr);
+    }
+
+    /**
+     * Get the vertical alignment of the cell.
+     *
+     * @return the cell alignment enum value
+     */
+    public XWPFVertAlign getVerticalAlignment() {
+        XWPFVertAlign vAlign = null;
+        CTTcPr tcpr = ctTc.getTcPr();
+        if (ctTc != null) {
+            CTVerticalJc va = tcpr.getVAlign();
+            vAlign = stVertAlignTypeMap.get(va.getVal().intValue());
+        }
+        return vAlign;
+    }
+
+    /**
+     * Set the vertical alignment of the cell.
+     *
+     * @param vAlign - the desired alignment enum value
+     */
+    public void setVerticalAlignment(XWPFVertAlign vAlign) {
+        CTTcPr tcpr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr();
+        CTVerticalJc va = tcpr.addNewVAlign();
+        va.setVal(alignMap.get(vAlign));
+    }
+
+    /**
+     * add a new paragraph at position of the cursor
+     *
+     * @param cursor
+     * @return the inserted paragraph
+     */
+    public XWPFParagraph insertNewParagraph(XmlCursor cursor) {
+        if (!isCursorInTableCell(cursor)) {
+            return null;
+        }
+
+        String uri = CTP.type.getName().getNamespaceURI();
+        String localPart = "p";
+        cursor.beginElement(localPart, uri);
+        cursor.toParent();
+        CTP p = (CTP) cursor.getObject();
+        XWPFParagraph newP = new XWPFParagraph(p, this);
+        XmlObject o = null;
+        while (!(o instanceof CTP) && (cursor.toPrevSibling())) {
+            o = cursor.getObject();
+        }
+        if ((!(o instanceof CTP)) || (CTP) o == p) {
+            paragraphs.add(0, newP);
+        } else {
+            int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1;
+            paragraphs.add(pos, newP);
+        }
+        int i = 0;
+        cursor.toCursor(p.newCursor());
+        while (cursor.toPrevSibling()) {
+            o = cursor.getObject();
+            if (o instanceof CTP || o instanceof CTTbl)
+                i++;
+        }
+        bodyElements.add(i, newP);
+        cursor.toCursor(p.newCursor());
+        cursor.toEndToken();
+        return newP;
+    }
+
+    public XWPFTable insertNewTbl(XmlCursor cursor) {
+        if (isCursorInTableCell(cursor)) {
+            String uri = CTTbl.type.getName().getNamespaceURI();
+            String localPart = "tbl";
+            cursor.beginElement(localPart, uri);
+            cursor.toParent();
+            CTTbl t = (CTTbl) cursor.getObject();
+            XWPFTable newT = new XWPFTable(t, this);
+            cursor.removeXmlContents();
+            XmlObject o = null;
+            while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
+                o = cursor.getObject();
+            }
+            if (!(o instanceof CTTbl)) {
+                tables.add(0, newT);
+            } else {
+                int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
+                tables.add(pos, newT);
+            }
+            int i = 0;
+            cursor = t.newCursor();
+            while (cursor.toPrevSibling()) {
+                o = cursor.getObject();
+                if (o instanceof CTP || o instanceof CTTbl)
+                    i++;
+            }
+            bodyElements.add(i, newT);
+            cursor = t.newCursor();
+            cursor.toEndToken();
+            return newT;
+        }
+        return null;
+    }
+
+    /**
+     * verifies that cursor is on the right position
+     */
+    private boolean isCursorInTableCell(XmlCursor cursor) {
+        XmlCursor verify = cursor.newCursor();
+        verify.toParent();
+        if (verify.getObject() == this.ctTc) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
+     */
+    public XWPFParagraph getParagraphArray(int pos) {
+        if (pos > 0 && pos < paragraphs.size()) {
+            return paragraphs.get(pos);
+        }
+        return null;
+    }
+
+    /**
+     * get the to which the TableCell belongs
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
+     */
+    public POIXMLDocumentPart getPart() {
+        return tableRow.getTable().getPart();
+    }
+
+    /**
+     * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
+     */
+    public BodyType getPartType() {
+        return BodyType.TABLECELL;
+    }
+
+    /**
+     * get a table by its CTTbl-Object
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)
+     */
+    public XWPFTable getTable(CTTbl ctTable) {
+        for (int i = 0; i < tables.size(); i++) {
+            if (getTables().get(i).getCTTbl() == ctTable) return getTables().get(i);
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
+     */
+    public XWPFTable getTableArray(int pos) {
+        if (pos > 0 && pos < tables.size()) {
+            return tables.get(pos);
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.poi.xwpf.usermodel.IBody#getTables()
+     */
+    public List<XWPFTable> getTables() {
+        return Collections.unmodifiableList(tables);
+    }
+
+    /**
+     * inserts an existing XWPFTable to the arrays bodyElements and tables
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable)
+     */
+    @SuppressWarnings("deprecation")
     public void insertTable(int pos, XWPFTable table) {
         bodyElements.add(pos, table);
         int i = 0;
@@ -408,90 +406,101 @@ public class XWPFTableCell implements IB
             }
             i++;
         }
-        tables.add(i, table);
-    }
-
-    public String getText(){
-	StringBuffer text = new StringBuffer();
-	for (XWPFParagraph p : paragraphs) {
-	    text.append(p.getText());
-	}
-	return text.toString();
-    }
-
-    /**
-     * extracts all text recursively through embedded tables and embedded SDTs
-     */
-    public String getTextRecursively(){
-
-        StringBuffer text = new StringBuffer();
-        for (int i = 0; i < bodyElements.size(); i++){
-            boolean isLast = (i== bodyElements.size()-1)? true : false;
-            appendBodyElementText(text, bodyElements.get(i), isLast);
-        }
-
-        return text.toString();
-    }
-
-    private void appendBodyElementText(StringBuffer text, IBodyElement e, boolean isLast){
-        if (e instanceof XWPFParagraph){
-            text.append(((XWPFParagraph)e).getText());
-            if (isLast == false){
-                text.append('\t');
-            }
-        } else if (e instanceof XWPFTable){
-            XWPFTable eTable = (XWPFTable)e;
-            for (XWPFTableRow row : eTable.getRows()){
-                for (XWPFTableCell cell : row.getTableCells()){
-                    List<IBodyElement> localBodyElements = cell.getBodyElements();
-                    for (int i = 0; i < localBodyElements.size(); i++){
-                        boolean localIsLast = (i== localBodyElements.size()-1)? true : false;
-                        appendBodyElementText(text, localBodyElements.get(i), localIsLast);
-                    }
-                }
-            }
-
-            if (isLast == false){
-                text.append('\n');
-            }
-        } else if (e instanceof XWPFSDT){
-            text.append(((XWPFSDT)e).getContent().getText());
-            if (isLast == false){
-                text.append('\t');
-            }
-        }
-    }
-
-    /**
-     * get the TableCell which belongs to the TableCell
-     */
-    public XWPFTableCell getTableCell(CTTc cell) {
-	XmlCursor cursor = cell.newCursor();
-	cursor.toParent();
-	XmlObject o = cursor.getObject();
-	if(!(o instanceof CTRow)){
-	    return null;
-	}
-	CTRow row = (CTRow)o;
-	cursor.toParent();
-	o = cursor.getObject();
-	cursor.dispose();
-	if(! (o instanceof CTTbl)){
-	    return null;
-	}
-	CTTbl tbl = (CTTbl) o;
-	XWPFTable table = getTable(tbl);
-	if(table == null){
-	    return null;
-	}
-	XWPFTableRow tableRow = table.getRow(row);
-	if (tableRow == null) {
-	    return null;
-	}
-	return tableRow.getTableCell(cell);
-    }
-
-    public XWPFDocument getXWPFDocument() {
-	return part.getXWPFDocument();
-    }
-}
+        tables.add(i, table);
+    }
+
+    public String getText() {
+        StringBuffer text = new StringBuffer();
+        for (XWPFParagraph p : paragraphs) {
+            text.append(p.getText());
+        }
+        return text.toString();
+    }
+
+    public void setText(String text) {
+        CTP ctP = (ctTc.sizeOfPArray() == 0) ? ctTc.addNewP() : ctTc.getPArray(0);
+        XWPFParagraph par = new XWPFParagraph(ctP, this);
+        par.createRun().setText(text);
+    }
+
+    /**
+     * extracts all text recursively through embedded tables and embedded SDTs
+     */
+    public String getTextRecursively() {
+
+        StringBuffer text = new StringBuffer();
+        for (int i = 0; i < bodyElements.size(); i++) {
+            boolean isLast = (i == bodyElements.size() - 1) ? true : false;
+            appendBodyElementText(text, bodyElements.get(i), isLast);
+        }
+
+        return text.toString();
+    }
+
+    private void appendBodyElementText(StringBuffer text, IBodyElement e, boolean isLast) {
+        if (e instanceof XWPFParagraph) {
+            text.append(((XWPFParagraph) e).getText());
+            if (isLast == false) {
+                text.append('\t');
+            }
+        } else if (e instanceof XWPFTable) {
+            XWPFTable eTable = (XWPFTable) e;
+            for (XWPFTableRow row : eTable.getRows()) {
+                for (XWPFTableCell cell : row.getTableCells()) {
+                    List<IBodyElement> localBodyElements = cell.getBodyElements();
+                    for (int i = 0; i < localBodyElements.size(); i++) {
+                        boolean localIsLast = (i == localBodyElements.size() - 1) ? true : false;
+                        appendBodyElementText(text, localBodyElements.get(i), localIsLast);
+                    }
+                }
+            }
+
+            if (isLast == false) {
+                text.append('\n');
+            }
+        } else if (e instanceof XWPFSDT) {
+            text.append(((XWPFSDT) e).getContent().getText());
+            if (isLast == false) {
+                text.append('\t');
+            }
+        }
+    }
+
+    /**
+     * get the TableCell which belongs to the TableCell
+     */
+    public XWPFTableCell getTableCell(CTTc cell) {
+        XmlCursor cursor = cell.newCursor();
+        cursor.toParent();
+        XmlObject o = cursor.getObject();
+        if (!(o instanceof CTRow)) {
+            return null;
+        }
+        CTRow row = (CTRow) o;
+        cursor.toParent();
+        o = cursor.getObject();
+        cursor.dispose();
+        if (!(o instanceof CTTbl)) {
+            return null;
+        }
+        CTTbl tbl = (CTTbl) o;
+        XWPFTable table = getTable(tbl);
+        if (table == null) {
+            return null;
+        }
+        XWPFTableRow tableRow = table.getRow(row);
+        if (tableRow == null) {
+            return null;
+        }
+        return tableRow.getTableCell(cell);
+    }
+
+    public XWPFDocument getXWPFDocument() {
+        return part.getXWPFDocument();
+    }
+
+    // Create a map from this XWPF-level enum to the STVerticalJc.Enum values
+    public static enum XWPFVertAlign {
+        TOP, CENTER, BOTH, BOTTOM
+    }
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java Fri May 29 14:01:31 2015
@@ -31,14 +31,14 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
 
-
-/**
- * A row within an {@link XWPFTable}. Rows mostly just have
- *  sizings and stylings, the interesting content lives inside
- *  the child {@link XWPFTableCell}s
- */
-public class XWPFTableRow {
-    private CTRow ctRow;
+
+/**
+ * A row within an {@link XWPFTable}. Rows mostly just have
+ * sizings and stylings, the interesting content lives inside
+ * the child {@link XWPFTableCell}s
+ */
+public class XWPFTableRow {
+    private CTRow ctRow;
     private XWPFTable table;
     private List<XWPFTableCell> tableCells;
 
@@ -52,187 +52,195 @@ public class XWPFTableRow {
     public CTRow getCtRow() {
         return ctRow;
     }
-
-    /**
-     * create a new XWPFTableCell and add it to the tableCell-list of this tableRow
-     * @return the newly created XWPFTableCell
-     */
-    public XWPFTableCell createCell() {
-	XWPFTableCell tableCell = new XWPFTableCell(ctRow.addNewTc(), this, table.getBody());
-	tableCells.add(tableCell);
-	return tableCell;
-    }
-
-    public XWPFTableCell getCell(int pos) {
-	if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
-	    return getTableCells().get(pos);
-	}
-	return null;
-    }
-
-    public void removeCell(int pos) {
-	if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
-	    tableCells.remove(pos);
-	}    	
-    }
-    /**
-     * adds a new TableCell at the end of this tableRow
-     */
-    public XWPFTableCell addNewTableCell(){
-	CTTc cell = ctRow.addNewTc();
-	XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.getBody());
-	tableCells.add(tableCell);
-	return tableCell;
-    }
-
-    /**
+
+    /**
+     * create a new XWPFTableCell and add it to the tableCell-list of this tableRow
+     *
+     * @return the newly created XWPFTableCell
+     */
+    public XWPFTableCell createCell() {
+        XWPFTableCell tableCell = new XWPFTableCell(ctRow.addNewTc(), this, table.getBody());
+        tableCells.add(tableCell);
+        return tableCell;
+    }
+
+    public XWPFTableCell getCell(int pos) {
+        if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
+            return getTableCells().get(pos);
+        }
+        return null;
+    }
+
+    public void removeCell(int pos) {
+        if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
+            tableCells.remove(pos);
+        }
+    }
+
+    /**
+     * adds a new TableCell at the end of this tableRow
+     */
+    public XWPFTableCell addNewTableCell() {
+        CTTc cell = ctRow.addNewTc();
+        XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.getBody());
+        tableCells.add(tableCell);
+        return tableCell;
+    }
+
+    /**
      * This element specifies the height of the current table row within the
      * current table. This height shall be used to determine the resulting
      * height of the table row, which may be absolute or relative (depending on
      * its attribute values). If omitted, then the table row shall automatically
-     * resize its height to the height required by its contents (the equivalent
-     * of an hRule value of auto).
-     *
-     * @param height
-     */
-    public void setHeight(int height) {
-	CTTrPr properties = getTrPr();
-	CTHeight h = properties.sizeOfTrHeightArray() == 0 ? properties.addNewTrHeight() : properties.getTrHeightArray(0);
-	h.setVal(new BigInteger("" + height));
-    }
-
-    /**
+     * resize its height to the height required by its contents (the equivalent
+     * of an hRule value of auto).
+     *
+     * @return height
+     */
+    public int getHeight() {
+        CTTrPr properties = getTrPr();
+        return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
+    }
+
+    /**
      * This element specifies the height of the current table row within the
      * current table. This height shall be used to determine the resulting
      * height of the table row, which may be absolute or relative (depending on
      * its attribute values). If omitted, then the table row shall automatically
-     * resize its height to the height required by its contents (the equivalent
-     * of an hRule value of auto).
-     *
-     * @return height
-     */
-    public int getHeight() {
-	CTTrPr properties = getTrPr();
-	return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
-    }
-
-    private CTTrPr getTrPr() {
-	return (ctRow.isSetTrPr()) ? ctRow.getTrPr() : ctRow.addNewTrPr();
-    }
-
-    public XWPFTable getTable(){
-	return table;
-    }
-
-    /**
-     * create and return a list of all XWPFTableCell
-     * who belongs to this row
-     * @return a list of {@link XWPFTableCell} 
-     */
-    public List<ICell> getTableICells(){
-    
-        List<ICell> cells = new ArrayList<ICell>();
-        //Can't use ctRow.getTcList because that only gets table cells
-        //Can't use ctRow.getSdtList because that only gets sdts that are at cell level
+     * resize its height to the height required by its contents (the equivalent
+     * of an hRule value of auto).
+     *
+     * @param height
+     */
+    public void setHeight(int height) {
+        CTTrPr properties = getTrPr();
+        CTHeight h = properties.sizeOfTrHeightArray() == 0 ? properties.addNewTrHeight() : properties.getTrHeightArray(0);
+        h.setVal(new BigInteger("" + height));
+    }
+
+    private CTTrPr getTrPr() {
+        return (ctRow.isSetTrPr()) ? ctRow.getTrPr() : ctRow.addNewTrPr();
+    }
+
+    public XWPFTable getTable() {
+        return table;
+    }
+
+    /**
+     * create and return a list of all XWPFTableCell
+     * who belongs to this row
+     *
+     * @return a list of {@link XWPFTableCell}
+     */
+    public List<ICell> getTableICells() {
+
+        List<ICell> cells = new ArrayList<ICell>();
+        //Can't use ctRow.getTcList because that only gets table cells
+        //Can't use ctRow.getSdtList because that only gets sdts that are at cell level
         XmlCursor cursor = ctRow.newCursor();
-        cursor.selectPath("./*");
-        while (cursor.toNextSelection()) {
-            XmlObject o = cursor.getObject();
-            if (o instanceof CTTc){
-                cells.add(new XWPFTableCell((CTTc)o, this, table.getBody()));
-            } else if (o instanceof CTSdtCell) {
-                cells.add(new XWPFSDTCell((CTSdtCell)o, this, table.getBody()));
-            }
-        }
-        return cells;
-    }
-
-    /**
-     * create and return a list of all XWPFTableCell
-     * who belongs to this row
-     * @return a list of {@link XWPFTableCell} 
-     */
-    @SuppressWarnings("deprecation")
-    public List<XWPFTableCell> getTableCells(){
-	if(tableCells == null){
-	    List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
-	    for (CTTc tableCell : ctRow.getTcArray()) {
-		cells.add(new XWPFTableCell(tableCell, this, table.getBody()));
-	    }
-       //TODO: it is possible to have an SDT that contains a cell in within a row
-       //need to modify this code so that it pulls out SDT wrappers around cells, too.
-
-	    this.tableCells = cells;
-	}
-	return tableCells;
-    }
-
-    /**
+        cursor.selectPath("./*");
+        while (cursor.toNextSelection()) {
+            XmlObject o = cursor.getObject();
+            if (o instanceof CTTc) {
+                cells.add(new XWPFTableCell((CTTc) o, this, table.getBody()));
+            } else if (o instanceof CTSdtCell) {
+                cells.add(new XWPFSDTCell((CTSdtCell) o, this, table.getBody()));
+            }
+        }
+        return cells;
+    }
+
+    /**
+     * create and return a list of all XWPFTableCell
+     * who belongs to this row
+     *
+     * @return a list of {@link XWPFTableCell}
+     */
+    @SuppressWarnings("deprecation")
+    public List<XWPFTableCell> getTableCells() {
+        if (tableCells == null) {
+            List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
+            for (CTTc tableCell : ctRow.getTcArray()) {
+                cells.add(new XWPFTableCell(tableCell, this, table.getBody()));
+            }
+            //TODO: it is possible to have an SDT that contains a cell in within a row
+            //need to modify this code so that it pulls out SDT wrappers around cells, too.
+
+            this.tableCells = cells;
+        }
+        return tableCells;
+    }
+
+    /**
      * returns the XWPFTableCell which belongs to the CTTC cell
-     * if there is no XWPFTableCell which belongs to the parameter CTTc cell null will be returned
-     */
-    public XWPFTableCell getTableCell(CTTc cell) {
-	for(int i=0; i<tableCells.size(); i++){
-	    if (tableCells.get(i).getCTTc() == cell)
-		return tableCells.get(i); 
-	}
-	return null;
-    }
-
-    /**
-     * This attribute controls whether to allow table rows to split across pages.
-     * The logic for this attribute is a little unusual: a true value means
-     * DON'T allow rows to split, false means allow rows to split.
-     * @param split - if true, don't allow rows to be split. If false, allow
-     *        rows to be split.
-     */
-    public void setCantSplitRow(boolean split) {
-	CTTrPr trpr = getTrPr();
-	CTOnOff onoff = trpr.addNewCantSplit();
-	onoff.setVal(split ? STOnOff.ON : STOnOff.OFF);
-    }
-
-    /**
-     * Return true if the "can't split row" value is true. The logic for this
-     * attribute is a little unusual: a TRUE value means DON'T allow rows to
-     * split, FALSE means allow rows to split.
-     * @return true if rows can't be split, false otherwise.
-     */
-    public boolean isCantSplitRow() {
-	boolean isCant = false;
-	CTTrPr trpr = getTrPr();
-	if (trpr.sizeOfCantSplitArray() > 0) {
-	    CTOnOff onoff = trpr.getCantSplitArray(0);
-	    isCant = onoff.getVal().equals(STOnOff.ON);
-	}
-	return isCant;
-    }
-
-    /**
-     * This attribute controls whether to repeat a table's header row at the top
-     * of a table split across pages.
-     * @param repeat - if TRUE, repeat header row at the top of each page of table;
-     *                 if FALSE, don't repeat header row.
-     */
-    public void setRepeatHeader(boolean repeat) {
-	CTTrPr trpr = getTrPr();
-	CTOnOff onoff = trpr.addNewTblHeader();
-	onoff.setVal(repeat ? STOnOff.ON : STOnOff.OFF);
-    }
-
-    /**
-     * Return true if a table's header row should be repeated at the top of a
-     * table split across pages.
-     * @return true if table's header row should be repeated at the top of each
-     *         page of table, false otherwise.
-     */
-    public boolean isRepeatHeader() {
-	boolean repeat = false;
-	CTTrPr trpr = getTrPr();
-	if (trpr.sizeOfTblHeaderArray() > 0) {
-	    CTOnOff rpt = trpr.getTblHeaderArray(0);
-	    repeat = rpt.getVal().equals(STOnOff.ON);
-	}
-	return repeat;
-    }
-}
+     * if there is no XWPFTableCell which belongs to the parameter CTTc cell null will be returned
+     */
+    public XWPFTableCell getTableCell(CTTc cell) {
+        for (int i = 0; i < tableCells.size(); i++) {
+            if (tableCells.get(i).getCTTc() == cell)
+                return tableCells.get(i);
+        }
+        return null;
+    }
+
+    /**
+     * Return true if the "can't split row" value is true. The logic for this
+     * attribute is a little unusual: a TRUE value means DON'T allow rows to
+     * split, FALSE means allow rows to split.
+     *
+     * @return true if rows can't be split, false otherwise.
+     */
+    public boolean isCantSplitRow() {
+        boolean isCant = false;
+        CTTrPr trpr = getTrPr();
+        if (trpr.sizeOfCantSplitArray() > 0) {
+            CTOnOff onoff = trpr.getCantSplitArray(0);
+            isCant = onoff.getVal().equals(STOnOff.ON);
+        }
+        return isCant;
+    }
+
+    /**
+     * This attribute controls whether to allow table rows to split across pages.
+     * The logic for this attribute is a little unusual: a true value means
+     * DON'T allow rows to split, false means allow rows to split.
+     *
+     * @param split - if true, don't allow rows to be split. If false, allow
+     *              rows to be split.
+     */
+    public void setCantSplitRow(boolean split) {
+        CTTrPr trpr = getTrPr();
+        CTOnOff onoff = trpr.addNewCantSplit();
+        onoff.setVal(split ? STOnOff.ON : STOnOff.OFF);
+    }
+
+    /**
+     * Return true if a table's header row should be repeated at the top of a
+     * table split across pages.
+     *
+     * @return true if table's header row should be repeated at the top of each
+     * page of table, false otherwise.
+     */
+    public boolean isRepeatHeader() {
+        boolean repeat = false;
+        CTTrPr trpr = getTrPr();
+        if (trpr.sizeOfTblHeaderArray() > 0) {
+            CTOnOff rpt = trpr.getTblHeaderArray(0);
+            repeat = rpt.getVal().equals(STOnOff.ON);
+        }
+        return repeat;
+    }
+
+    /**
+     * This attribute controls whether to repeat a table's header row at the top
+     * of a table split across pages.
+     *
+     * @param repeat - if TRUE, repeat header row at the top of each page of table;
+     *               if FALSE, don't repeat header row.
+     */
+    public void setRepeatHeader(boolean repeat) {
+        CTTrPr trpr = getTrPr();
+        CTOnOff onoff = trpr.addNewTblHeader();
+        onoff.setVal(repeat ? STOnOff.ON : STOnOff.OFF);
+    }
+}

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java Fri May 29 14:01:31 2015
@@ -33,24 +33,24 @@ import org.junit.runners.Suite;
 
 /**
  * Collects all tests for <tt>org.apache.poi.xwpf</tt> and sub-packages.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-    TestXWPFBugs.class,
-    org.apache.poi.xwpf.usermodel.TestXWPFBugs.class,
-    TestXWPFDocument.class,
-    TestXWPFWordExtractor.class,
-    TestXWPFHeaderFooterPolicy.class,
-    TestXWPFHeader.class,
-    TestXWPFHeadings.class,
-    TestXWPFParagraph.class,
-    TestXWPFRun.class,
-    TestXWPFTable.class,
-    TestXWPFStyles.class,
-    TestXWPFPictureData.class,
-    TestXWPFNumbering.class,
-    TestAllExtendedProperties.class,
-    TestPackageCorePropertiesGetKeywords.class
-})
-public final class AllXWPFTests {
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+        TestXWPFBugs.class,
+        org.apache.poi.xwpf.usermodel.TestXWPFBugs.class,
+        TestXWPFDocument.class,
+        TestXWPFWordExtractor.class,
+        TestXWPFHeaderFooterPolicy.class,
+        TestXWPFHeader.class,
+        TestXWPFHeadings.class,
+        TestXWPFParagraph.class,
+        TestXWPFRun.class,
+        TestXWPFTable.class,
+        TestXWPFStyles.class,
+        TestXWPFPictureData.class,
+        TestXWPFNumbering.class,
+        TestAllExtendedProperties.class,
+        TestPackageCorePropertiesGetKeywords.class
+})
+public final class AllXWPFTests {
 }
\ No newline at end of file

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java Fri May 29 14:01:31 2015
@@ -17,13 +17,12 @@
 
 package org.apache.poi.xwpf;
 
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.POIXMLProperties.CoreProperties;
-import org.apache.poi.openxml4j.opc.PackageProperties;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import org.apache.poi.POIXMLProperties.CoreProperties;
+import org.apache.poi.openxml4j.opc.PackageProperties;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTDigSigBlob;
 import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties;
 import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTVectorLpstr;
@@ -31,77 +30,76 @@ import org.openxmlformats.schemas.office
 
 /**
  * Tests if the {@link CoreProperties#getKeywords()} method. This test has been
- * submitted because even though the
- * {@link PackageProperties#getKeywordsProperty()} had been present before, the
- * {@link CoreProperties#getKeywords()} had been missing.
- * 
- * The author of this has added {@link CoreProperties#getKeywords()} and
- * {@link CoreProperties#setKeywords(String)} and this test is supposed to test
- * them.
- * 
- * @author Antoni Mylka
- * 
- */
-public final class TestAllExtendedProperties extends TestCase {
-	public void testGetAllExtendedProperties() throws IOException {
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestPoiXMLDocumentCorePropertiesGetKeywords.docx");
-		CTProperties ctProps = doc.getProperties().getExtendedProperties().getUnderlyingProperties();
-		assertEquals("Microsoft Office Word",ctProps.getApplication());
-		assertEquals("14.0000",ctProps.getAppVersion());
-		assertEquals(57,ctProps.getCharacters());
-		assertEquals(66,ctProps.getCharactersWithSpaces());
-		assertEquals("",ctProps.getCompany());
-		assertNull(ctProps.getDigSig());
-		assertEquals(0,ctProps.getDocSecurity());
-		assertNotNull(ctProps.getDomNode());
-		
-		CTVectorVariant vec = ctProps.getHeadingPairs();
-		assertEquals(2,vec.getVector().sizeOfVariantArray());
-		assertEquals("Title",vec.getVector().getVariantArray(0).getLpstr());
-		assertEquals(1,vec.getVector().getVariantArray(1).getI4());
-		
-		assertFalse(ctProps.isSetHiddenSlides());
-		assertEquals(0,ctProps.getHiddenSlides());
-		assertFalse(ctProps.isSetHLinks());
-		assertNull(ctProps.getHLinks());
-		assertNull(ctProps.getHyperlinkBase());
-		assertTrue(ctProps.isSetHyperlinksChanged());
-		assertFalse(ctProps.getHyperlinksChanged());
-		assertEquals(1,ctProps.getLines());
-		assertTrue(ctProps.isSetLinksUpToDate());
-		assertFalse(ctProps.getLinksUpToDate());
-		assertNull(ctProps.getManager());
-		assertFalse(ctProps.isSetMMClips());
-		assertEquals(0,ctProps.getMMClips());
-		assertFalse(ctProps.isSetNotes());
-		assertEquals(0,ctProps.getNotes());
-		assertEquals(1,ctProps.getPages());
-		assertEquals(1,ctProps.getParagraphs());
-		assertNull(ctProps.getPresentationFormat());
-		assertTrue(ctProps.isSetScaleCrop());
-		assertFalse(ctProps.getScaleCrop());
-		assertTrue(ctProps.isSetSharedDoc());
-		assertFalse(ctProps.getSharedDoc());
-		assertFalse(ctProps.isSetSlides());
-		assertEquals(0,ctProps.getSlides());
-		assertEquals("Normal.dotm",ctProps.getTemplate());
-		
-		CTVectorLpstr vec2 = ctProps.getTitlesOfParts();
-		assertEquals(1,vec2.getVector().sizeOfLpstrArray());
-		assertEquals("Example Word 2010 Document",vec2.getVector().getLpstrArray(0));
-		
-		assertEquals(3,ctProps.getTotalTime());
-		assertEquals(10,ctProps.getWords());
-		
-		// Check the digital signature part
-		// Won't be there in this file, but we
-		//  need to do this check so that the
-		//  appropriate parts end up in the
-		//  smaller ooxml schemas file
-		CTDigSigBlob blob = ctProps.getDigSig();
-		assertNull(blob);
-		
-		blob = CTDigSigBlob.Factory.newInstance();
-		blob.setBlob(new byte [] {2,6,7,2,3,4,5,1,2,3});
-	}
-}
+ * submitted because even though the
+ * {@link PackageProperties#getKeywordsProperty()} had been present before, the
+ * {@link CoreProperties#getKeywords()} had been missing.
+ * <p/>
+ * The author of this has added {@link CoreProperties#getKeywords()} and
+ * {@link CoreProperties#setKeywords(String)} and this test is supposed to test
+ * them.
+ *
+ * @author Antoni Mylka
+ */
+public final class TestAllExtendedProperties extends TestCase {
+    public void testGetAllExtendedProperties() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestPoiXMLDocumentCorePropertiesGetKeywords.docx");
+        CTProperties ctProps = doc.getProperties().getExtendedProperties().getUnderlyingProperties();
+        assertEquals("Microsoft Office Word", ctProps.getApplication());
+        assertEquals("14.0000", ctProps.getAppVersion());
+        assertEquals(57, ctProps.getCharacters());
+        assertEquals(66, ctProps.getCharactersWithSpaces());
+        assertEquals("", ctProps.getCompany());
+        assertNull(ctProps.getDigSig());
+        assertEquals(0, ctProps.getDocSecurity());
+        assertNotNull(ctProps.getDomNode());
+
+        CTVectorVariant vec = ctProps.getHeadingPairs();
+        assertEquals(2, vec.getVector().sizeOfVariantArray());
+        assertEquals("Title", vec.getVector().getVariantArray(0).getLpstr());
+        assertEquals(1, vec.getVector().getVariantArray(1).getI4());
+
+        assertFalse(ctProps.isSetHiddenSlides());
+        assertEquals(0, ctProps.getHiddenSlides());
+        assertFalse(ctProps.isSetHLinks());
+        assertNull(ctProps.getHLinks());
+        assertNull(ctProps.getHyperlinkBase());
+        assertTrue(ctProps.isSetHyperlinksChanged());
+        assertFalse(ctProps.getHyperlinksChanged());
+        assertEquals(1, ctProps.getLines());
+        assertTrue(ctProps.isSetLinksUpToDate());
+        assertFalse(ctProps.getLinksUpToDate());
+        assertNull(ctProps.getManager());
+        assertFalse(ctProps.isSetMMClips());
+        assertEquals(0, ctProps.getMMClips());
+        assertFalse(ctProps.isSetNotes());
+        assertEquals(0, ctProps.getNotes());
+        assertEquals(1, ctProps.getPages());
+        assertEquals(1, ctProps.getParagraphs());
+        assertNull(ctProps.getPresentationFormat());
+        assertTrue(ctProps.isSetScaleCrop());
+        assertFalse(ctProps.getScaleCrop());
+        assertTrue(ctProps.isSetSharedDoc());
+        assertFalse(ctProps.getSharedDoc());
+        assertFalse(ctProps.isSetSlides());
+        assertEquals(0, ctProps.getSlides());
+        assertEquals("Normal.dotm", ctProps.getTemplate());
+
+        CTVectorLpstr vec2 = ctProps.getTitlesOfParts();
+        assertEquals(1, vec2.getVector().sizeOfLpstrArray());
+        assertEquals("Example Word 2010 Document", vec2.getVector().getLpstrArray(0));
+
+        assertEquals(3, ctProps.getTotalTime());
+        assertEquals(10, ctProps.getWords());
+
+        // Check the digital signature part
+        // Won't be there in this file, but we
+        //  need to do this check so that the
+        //  appropriate parts end up in the
+        //  smaller ooxml schemas file
+        CTDigSigBlob blob = ctProps.getDigSig();
+        assertNull(blob);
+
+        blob = CTDigSigBlob.Factory.newInstance();
+        blob.setBlob(new byte[]{2, 6, 7, 2, 3, 4, 5, 1, 2, 3});
+    }
+}

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java?rev=1682473&r1=1682472&r2=1682473&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java Fri May 29 14:01:31 2015
@@ -17,36 +17,34 @@
 
 package org.apache.poi.xwpf;
 
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.POIXMLProperties.CoreProperties;
-import org.apache.poi.openxml4j.opc.PackageProperties;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import org.apache.poi.POIXMLProperties.CoreProperties;
+import org.apache.poi.openxml4j.opc.PackageProperties;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 /**
  * Tests if the {@link CoreProperties#getKeywords()} method. This test has been
- * submitted because even though the
- * {@link PackageProperties#getKeywordsProperty()} had been present before, the
- * {@link CoreProperties#getKeywords()} had been missing.
- * 
- * The author of this has added {@link CoreProperties#getKeywords()} and
- * {@link CoreProperties#setKeywords(String)} and this test is supposed to test
- * them.
- * 
- * @author Antoni Mylka
- * 
- */
-public final class TestPackageCorePropertiesGetKeywords extends TestCase {
-	public void testGetSetKeywords() throws IOException {
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestPoiXMLDocumentCorePropertiesGetKeywords.docx");
-		String keywords = doc.getProperties().getCoreProperties().getKeywords();
-		assertEquals("extractor, test, rdf", keywords);
-		
-		doc.getProperties().getCoreProperties().setKeywords("test, keywords");
-		doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
-		keywords = doc.getProperties().getCoreProperties().getKeywords();
-		assertEquals("test, keywords",keywords);
-	}
-}
+ * submitted because even though the
+ * {@link PackageProperties#getKeywordsProperty()} had been present before, the
+ * {@link CoreProperties#getKeywords()} had been missing.
+ * <p/>
+ * The author of this has added {@link CoreProperties#getKeywords()} and
+ * {@link CoreProperties#setKeywords(String)} and this test is supposed to test
+ * them.
+ *
+ * @author Antoni Mylka
+ */
+public final class TestPackageCorePropertiesGetKeywords extends TestCase {
+    public void testGetSetKeywords() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestPoiXMLDocumentCorePropertiesGetKeywords.docx");
+        String keywords = doc.getProperties().getCoreProperties().getKeywords();
+        assertEquals("extractor, test, rdf", keywords);
+
+        doc.getProperties().getCoreProperties().setKeywords("test, keywords");
+        doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
+        keywords = doc.getProperties().getCoreProperties().getKeywords();
+        assertEquals("test, keywords", keywords);
+    }
+}



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


Mime
View raw message