You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/19 21:00:38 UTC

svn commit: r1691843 [19/30] - in /poi/branches/common_sl: ./ .settings/ legal/ osgi/ osgi/src/ src/examples/src/org/apache/poi/hpsf/examples/ src/examples/src/org/apache/poi/hssf/usermodel/examples/ src/examples/src/org/apache/poi/ss/examples/ src/exa...

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java Sun Jul 19 19:00:32 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/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Sun Jul 19 19:00:32 2015
@@ -31,281 +31,295 @@ 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.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;
-/**
- * @author Philipp Epp
- *
- */
-public class XWPFStyles extends POIXMLDocumentPart{
-    
-    private List<XWPFStyle> listStyle = new ArrayList<XWPFStyle>();
-    private CTStyles ctStyles;
-    XWPFLatentStyles latentStyles;
+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);
-	}
-
-	/**
-	 * Construct XWPFStyles from scratch for a new document.
-	 */
-	public XWPFStyles() {
-	}
-
-   /**
-    * 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);
-      } catch (XmlException e) {
-         throw new POIXMLException("Unable to read styles", e);
-      }
-      
-      
-   }
-	
-   @Override
-   protected void commit() throws IOException {
-      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);
-      PackagePart part = getPackagePart();
-      OutputStream out = part.getOutputStream();
-      ctStyles.save(out, xmlOptions);
-      out.close();
-   }
-	
+     * @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);
+    }
+
     /**
-     * Sets the ctStyles
-     * @param styles
+     * Construct XWPFStyles from scratch for a new document.
      */
-    @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));
-       }
+    public XWPFStyles() {
     }
-	
-	 /**
-	  * 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;
-	}
-
-	/**
-	 * 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;
-	}
-	
-	/**
-	 * Sets the default spelling language on ctStyles DocDefaults parameter
-	 * @param strSpellingLanguage
-	 */
-	public void setSpellingLanguage(String strSpellingLanguage) {
-		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();
-
-		lang.setVal(strSpellingLanguage);
-		lang.setBidi(strSpellingLanguage);
-	}
-
-	/**
-	 * 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();
-				}
-			}
-		}
+    /**
+     * 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);
+        } catch (XmlException e) {
+            throw new POIXMLException("Unable to read styles", e);
+        }
+    }
 
-		if(docDefaults == null)
-			docDefaults = ctStyles.addNewDocDefaults();
-		if(runProps == null)
-			runProps = docDefaults.addNewRPrDefault().addNewRPr();
-		if(lang == null)
-			lang = runProps.addNewLang();
+    @Override
+    protected void commit() throws IOException {
+        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);
+        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")
+    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()) {
+            CTDocDefaults docDefaults = ctStyles.getDocDefaults();
+            if (docDefaults.isSetRPrDefault() && docDefaults.getRPrDefault().isSetRPr()) {
+                defaultRunStyle = new XWPFDefaultRunStyle(
+                        docDefaults.getRPrDefault().getRPr());
+            }
+            if (docDefaults.isSetPPrDefault() && docDefaults.getPPrDefault().isSetPPr()) {
+                defaultParaStyle = new XWPFDefaultParagraphStyle(
+                        docDefaults.getPPrDefault().getPPr());
+            }
+        }
+    }
+
+    /**
+     * 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) {
+        CTLanguage lang = getCTLanguage();
+        lang.setEastAsia(strEastAsia);
+    }
 
-		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);
+    }
 
-	/**
-	 * Sets the default font on ctStyles DocDefaults parameter
-	 * @param fonts
-	 */
-	public void setDefaultFonts(CTFonts fonts) {
-		CTDocDefaults docDefaults = null;
-		CTRPr runProps = null;
+    /**
+     * 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;
+    }
 
-		// 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();
-				}
-			}
-		}
+    /**
+     * Get the default style which applies text runs in the document
+     */
+    public XWPFDefaultRunStyle getDefaultRunStyle() {
+        ensureDocDefaults();
+        return defaultRunStyle;
+    }
 
-		if(docDefaults == null)
-			docDefaults = ctStyles.addNewDocDefaults();
-		if(runProps == null)
-			runProps = docDefaults.addNewRPrDefault().addNewRPr();
+    /**
+     * Get the default paragraph style which applies to the document
+     */
+    public XWPFDefaultParagraphStyle getDefaultParagraphStyle() {
+        ensureDocDefaults();
+        return defaultParaStyle;
+    }
 
-		runProps.setRFonts(fonts);
-	}
-	
-	
-	/**
-	 * get latentstyles
-	 */
-	public XWPFLatentStyles getLatentStyles() {
-		return latentStyles;
-	}
-	
-	/**
-	 * 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;
-		
-	}
-}//end class
+    /**
+     * Get the definition of all the Latent Styles
+     */
+    public XWPFLatentStyles getLatentStyles() {
+        return latentStyles;
+    }
+}

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java Sun Jul 19 19:00:32 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/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java Sun Jul 19 19:00:32 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/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java Sun Jul 19 19:00:32 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/branches/common_sl/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java Sun Jul 19 19:00:32 2015
@@ -155,13 +155,16 @@ public final class TestPOIXMLDocument ex
     public void testRelationOrder() throws Exception {
         OPCPackage pkg = PackageHelper.open(POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx"));
         OPCParser doc = new OPCParser(pkg);
-        doc.parse(new TestFactory());
-
-        for(POIXMLDocumentPart rel : doc.getRelations()){
-            //TODO finish me
-            assertNotNull(rel);
+        try {
+            doc.parse(new TestFactory());
+    
+            for(POIXMLDocumentPart rel : doc.getRelations()){
+                //TODO finish me
+                assertNotNull(rel);
+            }
+        } finally {
+        	doc.close();
         }
-
     }
 
     public void testCommitNullPart() throws IOException, InvalidFormatException {



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