poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1691843 [16/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...
Date Sun, 19 Jul 2015 19:00:38 GMT
Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java Sun Jul 19 19:00:32 2015
@@ -28,30 +28,29 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
-/**
- * @author Yegor Kozlov
- */
-public final class XWPFFactory extends POIXMLFactory  {
-
-    private static final POILogger logger = POILogFactory.getLogger(XWPFFactory.class);
-
-    private XWPFFactory(){
-
-    }
-
-    private static final XWPFFactory inst = new XWPFFactory();
-
-    public static XWPFFactory getInstance(){
-        return inst;
-    }
-
-    @Override
-    public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackageRelationship rel, PackagePart part){
-        POIXMLRelation descriptor = XWPFRelation.getInstance(rel.getRelationshipType());
-        if(descriptor == null || descriptor.getRelationClass() == null){
-            logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
-            return new POIXMLDocumentPart(part, rel);
-        }
+/**
+ * @author Yegor Kozlov
+ */
+public final class XWPFFactory extends POIXMLFactory {
+
+    private static final POILogger logger = POILogFactory.getLogger(XWPFFactory.class);
+    private static final XWPFFactory inst = new XWPFFactory();
+
+    private XWPFFactory() {
+
+    }
+
+    public static XWPFFactory getInstance() {
+        return inst;
+    }
+
+    @Override
+    public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackageRelationship rel, PackagePart part) {
+        POIXMLRelation descriptor = XWPFRelation.getInstance(rel.getRelationshipType());
+        if (descriptor == null || descriptor.getRelationClass() == null) {
+            logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
+            return new POIXMLDocumentPart(part, rel);
+        }
 
         try {
             Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
@@ -59,23 +58,23 @@ public final class XWPFFactory extends P
                 Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(POIXMLDocumentPart.class, PackagePart.class, PackageRelationship.class);
                 return constructor.newInstance(parent, part, rel);
             } catch (NoSuchMethodException e) {
-                Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
-                return constructor.newInstance(part, rel);
-            }
-        } catch (Exception e){
-            throw new POIXMLException(e);
-        }
-    }
-
-    @Override
-    public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){
-        try {
-            Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
-            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
-            return constructor.newInstance();
-        } catch (Exception e){
-            throw new POIXMLException(e);
-        }
-    }
+                Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
+                return constructor.newInstance(part, rel);
+            }
+        } catch (Exception e) {
+            throw new POIXMLException(e);
+        }
+    }
+
+    @Override
+    public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor) {
+        try {
+            Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
+            return constructor.newInstance();
+        } catch (Exception e) {
+            throw new POIXMLException(e);
+        }
+    }
 
 }

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java Sun Jul 19 19:00:32 2015
@@ -53,16 +53,16 @@ public class XWPFFooter extends XWPFHead
         while (cursor.toNextSelection()) {
             XmlObject o = cursor.getObject();
             if (o instanceof CTP) {
-                XWPFParagraph p = new XWPFParagraph((CTP)o, this);
+                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                 paragraphs.add(p);
                 bodyElements.add(p);
             }
             if (o instanceof CTTbl) {
-                XWPFTable t = new XWPFTable((CTTbl)o, this);
+                XWPFTable t = new XWPFTable((CTTbl) o, this);
                 tables.add(t);
                 bodyElements.add(t);
             }
-            
+
         }
         cursor.dispose();
     }
@@ -78,7 +78,7 @@ public class XWPFFooter extends XWPFHead
     protected void commit() throws IOException {
         XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
         xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "ftr"));
-        Map<String,String> map = new HashMap<String, String>();
+        Map<String, String> map = new HashMap<String, String>();
         map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
         map.put("urn:schemas-microsoft-com:office:office", "o");
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
@@ -95,8 +95,8 @@ public class XWPFFooter extends XWPFHead
         out.close();
     }
 
-    @Override  
-    protected void onDocumentRead() throws IOException{
+    @Override
+    protected void onDocumentRead() throws IOException {
         super.onDocumentRead();
         FtrDocument ftrDocument = null;
         InputStream is;
@@ -111,19 +111,19 @@ public class XWPFFooter extends XWPFHead
             while (cursor.toNextSelection()) {
                 XmlObject o = cursor.getObject();
                 if (o instanceof CTP) {
-                    XWPFParagraph p = new XWPFParagraph((CTP)o, this);
+                    XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                     paragraphs.add(p);
                     bodyElements.add(p);
                 }
                 if (o instanceof CTTbl) {
-                    XWPFTable t = new XWPFTable((CTTbl)o, this);
+                    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 CTSdtBlock) {
+                    XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
+                    bodyElements.add(c);
+                }
             }
             cursor.dispose();
         } catch (Exception e) {
@@ -133,6 +133,7 @@ public class XWPFFooter extends XWPFHead
 
     /**
      * get the PartType of the body
+     *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
      */
     public BodyType getPartType() {

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java Sun Jul 19 19:00:32 2015
@@ -27,64 +27,64 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
-
-public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
-    private List<XWPFParagraph> paragraphs = new ArrayList<XWPFParagraph>();
-    private List<XWPFTable> tables= new ArrayList<XWPFTable>();
-    private List<XWPFPictureData> pictures = new ArrayList<XWPFPictureData>();
-    private List<IBodyElement> bodyElements = new ArrayList<IBodyElement>();
-
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
+
+public class XWPFFootnote implements Iterable<XWPFParagraph>, IBody {
+    private List<XWPFParagraph> paragraphs = new ArrayList<XWPFParagraph>();
+    private List<XWPFTable> tables = new ArrayList<XWPFTable>();
+    private List<XWPFPictureData> pictures = new ArrayList<XWPFPictureData>();
+    private List<IBodyElement> bodyElements = new ArrayList<IBodyElement>();
+
     private CTFtnEdn ctFtnEdn;
     private XWPFFootnotes footnotes;
-    private XWPFDocument document;
-
-    public XWPFFootnote(CTFtnEdn note, XWPFFootnotes xFootnotes) {
-       footnotes = xFootnotes;
-       ctFtnEdn = note;
-       document = xFootnotes.getXWPFDocument();
-       init();
-    }
-
-    public XWPFFootnote(XWPFDocument document, CTFtnEdn body) {
-       ctFtnEdn = body;
-       this.document = document;
-       init();
-    }
-    
-    private void init(){
-       XmlCursor cursor = ctFtnEdn.newCursor();
-       //copied from XWPFDocument...should centralize this code
-       //to avoid duplication
-       cursor.selectPath("./*");
-       while (cursor.toNextSelection()) {
-           XmlObject o = cursor.getObject();
-           if (o instanceof CTP) {
-               XWPFParagraph p = new XWPFParagraph((CTP) o, this);
-               bodyElements.add(p);
-               paragraphs.add(p);
-           } else if (o instanceof CTTbl) {
-               XWPFTable t = new XWPFTable((CTTbl) o, this);
-               bodyElements.add(t);
-               tables.add(t);
-           } else if (o instanceof CTSdtBlock){
-               XWPFSDT c = new XWPFSDT((CTSdtBlock)o, this);
-               bodyElements.add(c);
-           }
-
-       }
-       cursor.dispose();
-   }
-
-    public List<XWPFParagraph> getParagraphs() {
-        return paragraphs;
-    }
-
-    public Iterator<XWPFParagraph> iterator(){
-        return paragraphs.iterator();
-    }
-
+    private XWPFDocument document;
+
+    public XWPFFootnote(CTFtnEdn note, XWPFFootnotes xFootnotes) {
+        footnotes = xFootnotes;
+        ctFtnEdn = note;
+        document = xFootnotes.getXWPFDocument();
+        init();
+    }
+
+    public XWPFFootnote(XWPFDocument document, CTFtnEdn body) {
+        ctFtnEdn = body;
+        this.document = document;
+        init();
+    }
+
+    private void init() {
+        XmlCursor cursor = ctFtnEdn.newCursor();
+        //copied from XWPFDocument...should centralize this code
+        //to avoid duplication
+        cursor.selectPath("./*");
+        while (cursor.toNextSelection()) {
+            XmlObject o = cursor.getObject();
+            if (o instanceof CTP) {
+                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
+                bodyElements.add(p);
+                paragraphs.add(p);
+            } else if (o instanceof CTTbl) {
+                XWPFTable t = new XWPFTable((CTTbl) o, this);
+                bodyElements.add(t);
+                tables.add(t);
+            } else if (o instanceof CTSdtBlock) {
+                XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
+                bodyElements.add(c);
+            }
+
+        }
+        cursor.dispose();
+    }
+
+    public List<XWPFParagraph> getParagraphs() {
+        return paragraphs;
+    }
+
+    public Iterator<XWPFParagraph> iterator() {
+        return paragraphs.iterator();
+    }
+
     public List<XWPFTable> getTables() {
         return tables;
     }
@@ -95,226 +95,231 @@ public class XWPFFootnote implements Ite
 
     public List<IBodyElement> getBodyElements() {
         return bodyElements;
-    }
-
-    public CTFtnEdn getCTFtnEdn() {
-       return ctFtnEdn;
-    }
-
-    public void setCTFtnEdn(CTFtnEdn footnote) {
-       ctFtnEdn = footnote;
-    }
-
-    /**
+    }
+
+    public CTFtnEdn getCTFtnEdn() {
+        return ctFtnEdn;
+    }
+
+    public void setCTFtnEdn(CTFtnEdn footnote) {
+        ctFtnEdn = footnote;
+    }
+
+    /**
      * @param pos in table array
      * @return The table at position pos
-     * @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;
-    }
-
-    /**
-     * inserts an existing XWPFTable to the arrays bodyElements and tables
-     * @param pos
-     * @param table
-     * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table)
+     * @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;
+    }
+
+    /**
+     * inserts an existing XWPFTable to the arrays bodyElements and tables
+     *
+     * @param pos
+     * @param table
+     * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table)
      */
     @SuppressWarnings("deprecation")
     public void insertTable(int pos, XWPFTable table) {
-        bodyElements.add(pos, table);
-        int i = 0;
-        for (CTTbl tbl : ctFtnEdn.getTblArray()) {
-            if(tbl == table.getCTTbl()){
-                break;
-            }
-            i++;
+        bodyElements.add(pos, table);
+        int i = 0;
+        for (CTTbl tbl : ctFtnEdn.getTblArray()) {
+            if (tbl == table.getCTTbl()) {
+                break;
+            }
+            i++;
         }
         tables.add(i, table);
 
     }
 
-    /**
-     * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
-     * the method will return this table
-     * if there is no corresponding {@link XWPFTable} the method will return null 
-     * @param ctTable
-     * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable)
-     */
-    public XWPFTable getTable(CTTbl ctTable){
-        for (XWPFTable table : tables) {
-            if(table==null)
-                return null;
-            if(table.getCTTbl().equals(ctTable))
-                return table;
-        }
-        return null;
-    }
-
-    /**
-     * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer
-     * 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 header or footer
-     * 		   XWPFParagraph with the correspondig CTP p
-     * @see org.apache.poi.xwpf.usermodel.IBody#getParagraph(CTP p)
-     */
-    public XWPFParagraph getParagraph(CTP p){
-        for (XWPFParagraph paragraph : paragraphs) {
-            if(paragraph.getCTP().equals(p))
-                return paragraph;
-        }
-        return null;
-    }
-
-    /**
-     * Returns the paragraph that holds
-     *  the text of the header or footer.
-     * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos)
-     */
-    public XWPFParagraph getParagraphArray(int pos) {
+    /**
+     * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
+     * the method will return this table
+     * if there is no corresponding {@link XWPFTable} the method will return null
+     *
+     * @param ctTable
+     * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable)
+     */
+    public XWPFTable getTable(CTTbl ctTable) {
+        for (XWPFTable table : tables) {
+            if (table == null)
+                return null;
+            if (table.getCTTbl().equals(ctTable))
+                return table;
+        }
+        return null;
+    }
+
+    /**
+     * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer
+     * 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 header or footer
+     * XWPFParagraph with the correspondig CTP p
+     * @see org.apache.poi.xwpf.usermodel.IBody#getParagraph(CTP p)
+     */
+    public XWPFParagraph getParagraph(CTP p) {
+        for (XWPFParagraph paragraph : paragraphs) {
+            if (paragraph.getCTP().equals(p))
+                return paragraph;
+        }
+        return null;
+    }
+
+    /**
+     * Returns the paragraph that holds
+     * the text of the header or footer.
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos)
+     */
+    public XWPFParagraph getParagraphArray(int pos) {
 
         return paragraphs.get(pos);
     }
-
-    /**
-     * get the TableCell which belongs to the TableCell
-     * @param cell
-     * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell)
-     */
+
+    /**
+     * get the TableCell which belongs to the TableCell
+     *
+     * @param cell
+     * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell)
+     */
     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(row == null){
-            return null;
-        }
-        return tableRow.getTableCell(cell);
-    }
-
-    /**
-     * verifies that cursor is on the right position
-     * @param cursor
-     */
-    private boolean isCursorInFtn(XmlCursor cursor) {
-        XmlCursor verify = cursor.newCursor();
-        verify.toParent();
-        if(verify.getObject() == this.ctFtnEdn){
-            return true;
-        }
-        return false;
-    }
-
-    public POIXMLDocumentPart getOwner(){
-        return footnotes;
-    }
-
-    /**
-     * 
-     * @param cursor
-     * @return the inserted table
-     * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor)
-     */
-    public XWPFTable insertNewTbl(XmlCursor cursor) {
-        if(isCursorInFtn(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);
+        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 (row == null) {
+            return null;
+        }
+        return tableRow.getTableCell(cell);
+    }
+
+    /**
+     * verifies that cursor is on the right position
+     *
+     * @param cursor
+     */
+    private boolean isCursorInFtn(XmlCursor cursor) {
+        XmlCursor verify = cursor.newCursor();
+        verify.toParent();
+        if (verify.getObject() == this.ctFtnEdn) {
+            return true;
+        }
+        return false;
+    }
+
+    public POIXMLDocumentPart getOwner() {
+        return footnotes;
+    }
+
+    /**
+     * @param cursor
+     * @return the inserted table
+     * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor)
+     */
+    public XWPFTable insertNewTbl(XmlCursor cursor) {
+        if (isCursorInFtn(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;
     }
-
-    /**
-     * add a new paragraph at position of the cursor
-     * @param cursor
-     * @return the inserted paragraph
-     * @see org.apache.poi.xwpf.usermodel.IBody#insertNewParagraph(XmlCursor cursor)
-     */
-    public XWPFParagraph insertNewParagraph(XmlCursor cursor){
-        if(isCursorInFtn(cursor)){
-            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);
+
+    /**
+     * add a new paragraph at position of the cursor
+     *
+     * @param cursor
+     * @return the inserted paragraph
+     * @see org.apache.poi.xwpf.usermodel.IBody#insertNewParagraph(XmlCursor cursor)
+     */
+    public XWPFParagraph insertNewParagraph(XmlCursor cursor) {
+        if (isCursorInFtn(cursor)) {
+            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;
         }
         return null;
     }
-
-    /**
-     * add a new table to the end of the footnote
-     * @param table
-     * @return the added XWPFTable
-     */
+
+    /**
+     * add a new table to the end of the footnote
+     *
+     * @param table
+     * @return the added XWPFTable
+     */
     public XWPFTable addNewTbl(CTTbl table) {
         CTTbl newTable = ctFtnEdn.addNewTbl();
         newTable.set(table);
@@ -322,12 +327,13 @@ public class XWPFFootnote implements Ite
         tables.add(xTable);
         return xTable;
     }
-
-    /**
-     * add a new paragraph to the end of the footnote
-     * @param paragraph
-     * @return the added XWPFParagraph
-     */
+
+    /**
+     * add a new paragraph to the end of the footnote
+     *
+     * @param paragraph
+     * @return the added XWPFParagraph
+     */
     public XWPFParagraph addNewParagraph(CTP paragraph) {
         CTP newPara = ctFtnEdn.addNewP();
         newPara.set(paragraph);
@@ -336,26 +342,28 @@ public class XWPFFootnote implements Ite
         return xPara;
     }
 
-    /**
-     * @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument()
-     */
-    public  XWPFDocument getXWPFDocument() {
-        return document;
-    }
-
-    /**
-     * returns the Part, to which the body belongs, which you need for adding relationship to other parts
-     * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
-     */
-    public POIXMLDocumentPart getPart() {
+    /**
+     * @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument()
+     */
+    public XWPFDocument getXWPFDocument() {
+        return document;
+    }
+
+    /**
+     * returns the Part, to which the body belongs, which you need for adding relationship to other parts
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
+     */
+    public POIXMLDocumentPart getPart() {
         return footnotes;
     }
-
-    /**
-     * get the PartType of the body
-     * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
-     */
-    public BodyType getPartType() {
+
+    /**
+     * get the PartType of the body
+     *
+     * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
+     */
+    public BodyType getPartType() {
         return BodyType.FOOTNOTE;
     }
 }

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java Sun Jul 19 19:00:32 2015
@@ -31,32 +31,31 @@ 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.CTFtnEdn;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFootnotes;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
-
-/**
- * Looks after the collection of Footnotes for a document
- */
-public class XWPFFootnotes extends POIXMLDocumentPart {
-    private List<XWPFFootnote> listFootnote = new ArrayList<XWPFFootnote>();
-    private CTFootnotes ctFootnotes;
-
-    protected XWPFDocument document;
-
-    /**
-     * Construct XWPFFootnotes from a package part
-     *
-     * @param part the package part holding the data of the footnotes,
-     * @param rel  the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
-     */
-    public XWPFFootnotes(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{
-        super(part, rel);
-    }
-
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFootnotes;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
+
+/**
+ * Looks after the collection of Footnotes for a document
+ */
+public class XWPFFootnotes extends POIXMLDocumentPart {
+    protected XWPFDocument document;
+    private List<XWPFFootnote> listFootnote = new ArrayList<XWPFFootnote>();
+    private CTFootnotes ctFootnotes;
+
+    /**
+     * Construct XWPFFootnotes from a package part
+     *
+     * @param part the package part holding the data of the footnotes,
+     * @param rel  the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
+     */
+    public XWPFFootnotes(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException {
+        super(part, rel);
+    }
+
     /**
      * Construct XWPFFootnotes from scratch for a new document.
      */
@@ -65,33 +64,33 @@ public class XWPFFootnotes extends POIXM
 
     /**
      * Read document
-     */
-    @Override
-    @SuppressWarnings("deprecation")
-    protected void onDocumentRead () throws IOException {
-        FootnotesDocument notesDoc;
-        try {
-            InputStream is = getPackagePart().getInputStream();
+     */
+    @Override
+    @SuppressWarnings("deprecation")
+    protected void onDocumentRead() throws IOException {
+        FootnotesDocument notesDoc;
+        try {
+            InputStream is = getPackagePart().getInputStream();
             notesDoc = FootnotesDocument.Factory.parse(is);
             ctFootnotes = notesDoc.getFootnotes();
         } catch (XmlException e) {
             throw new POIXMLException();
-        }
-
-        // Find our footnotes
-        for(CTFtnEdn note : ctFootnotes.getFootnoteArray()) {
-            listFootnote.add(new XWPFFootnote(note, this));
-        }
-    }
+        }
+
+        // Find our footnotes
+        for (CTFtnEdn note : ctFootnotes.getFootnoteArray()) {
+            listFootnote.add(new XWPFFootnote(note, this));
+        }
+    }
 
     @Override
-    protected void commit() throws IOException {
-        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
-        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
-        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);
+    protected void commit() throws IOException {
+        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
+        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();
         ctFootnotes.save(out, xmlOptions);
@@ -100,59 +99,62 @@ public class XWPFFootnotes extends POIXM
 
     public List<XWPFFootnote> getFootnotesList() {
         return listFootnote;
-    }
-
-    public XWPFFootnote getFootnoteById(int id) {
-        for(XWPFFootnote note : listFootnote) {
-            if(note.getCTFtnEdn().getId().intValue() == id)
-                return note;
-        }
-        return null;
-    }
-
-    /**
-     * Sets the ctFootnotes
-     * @param footnotes
-     */
-    public void setFootnotes(CTFootnotes footnotes) {
+    }
+
+    public XWPFFootnote getFootnoteById(int id) {
+        for (XWPFFootnote note : listFootnote) {
+            if (note.getCTFtnEdn().getId().intValue() == id)
+                return note;
+        }
+        return null;
+    }
+
+    /**
+     * Sets the ctFootnotes
+     *
+     * @param footnotes
+     */
+    public void setFootnotes(CTFootnotes footnotes) {
         ctFootnotes = footnotes;
     }
-
-    /**
-     * add an XWPFFootnote to the document
-     * @param footnote
-     * @throws IOException		 
-     */
-    public void addFootnote(XWPFFootnote footnote){
-        listFootnote.add(footnote);
-        ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
-    }
-
-    /**
-     * add a footnote to the document
-     * @param note
-     * @throws IOException		 
-     */
-    public XWPFFootnote addFootnote(CTFtnEdn note){
-        CTFtnEdn newNote = ctFootnotes.addNewFootnote();
-        newNote.set(note);
-        XWPFFootnote xNote = new XWPFFootnote(newNote, this);
+
+    /**
+     * add an XWPFFootnote to the document
+     *
+     * @param footnote
+     * @throws IOException
+     */
+    public void addFootnote(XWPFFootnote footnote) {
+        listFootnote.add(footnote);
+        ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
+    }
+
+    /**
+     * add a footnote to the document
+     *
+     * @param note
+     * @throws IOException
+     */
+    public XWPFFootnote addFootnote(CTFtnEdn note) {
+        CTFtnEdn newNote = ctFootnotes.addNewFootnote();
+        newNote.set(note);
+        XWPFFootnote xNote = new XWPFFootnote(newNote, this);
         listFootnote.add(xNote);
-        return xNote;
-    }
-
-    public void setXWPFDocument(XWPFDocument doc) {
-        document = doc;
-    }
-
-    /**
-     * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
-     */
-    public XWPFDocument getXWPFDocument() {
-        if ( document != null) {
-            return document;
-        } else {
-            return (XWPFDocument)getParent();
-        }
-    }
-}
+        return xNote;
+    }
+
+    /**
+     * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
+     */
+    public XWPFDocument getXWPFDocument() {
+        if (document != null) {
+            return document;
+        } else {
+            return (XWPFDocument) getParent();
+        }
+    }
+
+    public void setXWPFDocument(XWPFDocument doc) {
+        document = doc;
+    }
+}

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java Sun Jul 19 19:00:32 2015
@@ -69,14 +69,14 @@ public class XWPFHeader extends XWPFHead
         cursor.dispose();
     }
 
-	/**
+    /**
      * save and commit footer
      */
     @Override
     protected void commit() throws IOException {
         XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
         xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "hdr"));
-        Map<String,String> map = new HashMap<String, String>();
+        Map<String, String> map = new HashMap<String, String>();
         map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
         map.put("urn:schemas-microsoft-com:office:office", "o");
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
@@ -95,11 +95,12 @@ public class XWPFHeader extends XWPFHead
 
     /**
      * reads the document
-     * @throws IOException 
+     *
+     * @throws IOException
      */
-    @Override  
+    @Override
     protected void onDocumentRead() throws IOException {
-        super.onDocumentRead();	          
+        super.onDocumentRead();
         HdrDocument hdrDocument = null;
         InputStream is;
         try {
@@ -113,17 +114,17 @@ public class XWPFHeader extends XWPFHead
             while (cursor.toNextSelection()) {
                 XmlObject o = cursor.getObject();
                 if (o instanceof CTP) {
-                    XWPFParagraph p = new XWPFParagraph((CTP)o, this);
+                    XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                     paragraphs.add(p);
                     bodyElements.add(p);
                 }
                 if (o instanceof CTTbl) {
-                    XWPFTable t = new XWPFTable((CTTbl)o, this);
+                    XWPFTable t = new XWPFTable((CTTbl) o, this);
                     tables.add(t);
                     bodyElements.add(t);
                 }
-                if (o instanceof CTSdtBlock){
-                    XWPFSDT c = new XWPFSDT((CTSdtBlock)o, this);
+                if (o instanceof CTSdtBlock) {
+                    XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
                     bodyElements.add(c);
                 }
             }
@@ -135,6 +136,7 @@ public class XWPFHeader extends XWPFHead
 
     /**
      * get the PartType of the body
+     *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
      */
     public BodyType getPartType() {

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java Sun Jul 19 19:00:32 2015
@@ -46,7 +46,7 @@ import org.openxmlformats.schemas.wordpr
  */
 public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBody {
     List<XWPFParagraph> paragraphs = new ArrayList<XWPFParagraph>(1);
-    List<XWPFTable> tables= new ArrayList<XWPFTable>(1);
+    List<XWPFTable> tables = new ArrayList<XWPFTable>(1);
     List<XWPFPictureData> pictures = new ArrayList<XWPFPictureData>();
     List<IBodyElement> bodyElements = new ArrayList<IBodyElement>(1);
 
@@ -54,7 +54,7 @@ public abstract class XWPFHeaderFooter e
     XWPFDocument document;
 
     XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr) {
-        if (doc==null) {
+        if (doc == null) {
             throw new NullPointerException();
         }
 
@@ -70,17 +70,17 @@ public abstract class XWPFHeaderFooter e
 
     public XWPFHeaderFooter(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel) throws IOException {
         super(parent, part, rel);
-        this.document = (XWPFDocument)getParent();
+        this.document = (XWPFDocument) getParent();
 
-        if (this.document==null) {
+        if (this.document == null) {
             throw new NullPointerException();
         }
     }
 
     @Override
     protected void onDocumentRead() throws IOException {
-        for (POIXMLDocumentPart poixmlDocumentPart : getRelations()){
-            if(poixmlDocumentPart instanceof XWPFPictureData){
+        for (POIXMLDocumentPart poixmlDocumentPart : getRelations()) {
+            if (poixmlDocumentPart instanceof XWPFPictureData) {
                 XWPFPictureData xwpfPicData = (XWPFPictureData) poixmlDocumentPart;
                 pictures.add(xwpfPicData);
                 document.registerPackagePictureData(xwpfPicData);
@@ -93,16 +93,16 @@ public abstract class XWPFHeaderFooter e
         return headerFooter;
     }
 
-    public List<IBodyElement> getBodyElements(){
+    public List<IBodyElement> getBodyElements() {
         return Collections.unmodifiableList(bodyElements);
     }
 
     /**
      * Returns the paragraph(s) that holds
-     *  the text of the header or footer.
+     * the text of the header or footer.
      * Normally there is only the one paragraph, but
-     *  there could be more in certain cases, or 
-     *  a table.
+     * there could be more in certain cases, or
+     * a table.
      */
     public List<XWPFParagraph> getParagraphs() {
         return Collections.unmodifiableList(paragraphs);
@@ -111,29 +111,28 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * Return the table(s) that holds the text
-     *  of the header or footer, for complex cases
-     *  where a paragraph isn't used.
+     * of the header or footer, for complex cases
+     * where a paragraph isn't used.
      * Normally there's just one paragraph, but some
-     *  complex headers/footers have a table or two
-     *  in addition. 
+     * complex headers/footers have a table or two
+     * in addition.
      */
-    public List<XWPFTable> getTables()throws ArrayIndexOutOfBoundsException {
+    public List<XWPFTable> getTables() throws ArrayIndexOutOfBoundsException {
         return Collections.unmodifiableList(tables);
     }
 
 
-
     /**
      * Returns the textual content of the header/footer,
-     *  by flattening out the text of its paragraph(s)
+     * by flattening out the text of its paragraph(s)
      */
     public String getText() {
         StringBuffer t = new StringBuffer();
-      //TODO: simplify this to get ibody elements in order
-        for(int i=0; i<paragraphs.size(); i++) {
-            if(! paragraphs.get(i).isEmpty()) {
+        //TODO: simplify this to get ibody elements in order
+        for (int i = 0; i < paragraphs.size(); i++) {
+            if (!paragraphs.get(i).isEmpty()) {
                 String text = paragraphs.get(i).getText();
-                if(text != null && text.length() > 0) {
+                if (text != null && text.length() > 0) {
                     t.append(text);
                     t.append('\n');
                 }
@@ -141,26 +140,26 @@ public abstract class XWPFHeaderFooter e
         }
 
         List<XWPFTable> tables = getTables();
-        for(int i=0; i<tables.size(); i++) {
+        for (int i = 0; i < tables.size(); i++) {
             String text = tables.get(i).getText();
-            if(text != null && text.length() > 0) {
+            if (text != null && text.length() > 0) {
                 t.append(text);
                 t.append('\n');
             }
         }
-        
-        for (IBodyElement bodyElement : getBodyElements()){
-           if (bodyElement instanceof XWPFSDT){
-               t.append(((XWPFSDT) bodyElement).getContent().getText()+'\n');
-           }
-       }
-        return t.toString(); 
+
+        for (IBodyElement bodyElement : getBodyElements()) {
+            if (bodyElement instanceof XWPFSDT) {
+                t.append(((XWPFSDT) bodyElement).getContent().getText() + '\n');
+            }
+        }
+        return t.toString();
     }
 
     /**
      * set a new headerFooter
      */
-    public void setHeaderFooter(CTHdrFtr headerFooter){
+    public void setHeaderFooter(CTHdrFtr headerFooter) {
         this.headerFooter = headerFooter;
         readHdrFtr();
     }
@@ -168,14 +167,15 @@ public abstract class XWPFHeaderFooter e
     /**
      * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
      * the method will return this table
-     * if there is no corresponding {@link XWPFTable} the method will return null 
+     * if there is no corresponding {@link XWPFTable} the method will return null
+     *
      * @param ctTable
      */
-    public XWPFTable getTable(CTTbl ctTable){
+    public XWPFTable getTable(CTTbl ctTable) {
         for (XWPFTable table : tables) {
-            if(table==null)
+            if (table == null)
                 return null;
-            if(table.getCTTbl().equals(ctTable))
+            if (table.getCTTbl().equals(ctTable))
                 return table;
         }
         return null;
@@ -184,14 +184,15 @@ public abstract class XWPFHeaderFooter e
     /**
      * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer
      * the method will return this paragraph
-     * if there is no corresponding {@link XWPFParagraph} the method will return null 
+     * 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 header or footer
-     * 		   XWPFParagraph with the correspondig CTP p
+     * XWPFParagraph with the correspondig CTP p
      */
-    public XWPFParagraph getParagraph(CTP p){
+    public XWPFParagraph getParagraph(CTP p) {
         for (XWPFParagraph paragraph : paragraphs) {
-            if(paragraph.getCTP().equals(p))
+            if (paragraph.getCTP().equals(p))
                 return paragraph;
         }
         return null;
@@ -200,7 +201,7 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * Returns the paragraph that holds
-     *  the text of the header or footer.
+     * the text of the header or footer.
      */
     public XWPFParagraph getParagraphArray(int pos) {
 
@@ -209,9 +210,10 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * get a List of all Paragraphs
-     * @return a list of {@link XWPFParagraph} 
+     *
+     * @return a list of {@link XWPFParagraph}
      */
-    public List<XWPFParagraph> getListParagraph(){
+    public List<XWPFParagraph> getListParagraph() {
         return paragraphs;
     }
 
@@ -221,9 +223,10 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * get all Pictures in this package
+     *
      * @return all Pictures in this package
      */
-    public List<XWPFPictureData> getAllPackagePictures(){
+    public List<XWPFPictureData> getAllPackagePictures() {
         return document.getAllPackagePictures();
 
     }
@@ -231,22 +234,19 @@ public abstract class XWPFHeaderFooter e
     /**
      * Adds a picture to the document.
      *
-     * @param pictureData       The picture data
-     * @param format            The format of the picture.
-     *
+     * @param pictureData The picture data
+     * @param format      The format of the picture.
      * @return the index to this picture (0 based), the added picture can be obtained from {@link #getAllPictures()} .
-     * @throws InvalidFormatException 
+     * @throws InvalidFormatException
      */
-    public String addPictureData(byte[] pictureData,int format) throws InvalidFormatException
-    {
+    public String addPictureData(byte[] pictureData, int format) throws InvalidFormatException {
         XWPFPictureData xwpfPicData = document.findPackagePictureData(pictureData, format);
         POIXMLRelation relDesc = XWPFPictureData.RELATIONS[format];
 
-        if (xwpfPicData == null)
-        {
+        if (xwpfPicData == null) {
             /* Part doesn't exist, create a new one */
             int idx = document.getNextPicNameNumber(format);
-            xwpfPicData = (XWPFPictureData) createRelationship(relDesc, XWPFFactory.getInstance(),idx);
+            xwpfPicData = (XWPFPictureData) createRelationship(relDesc, XWPFFactory.getInstance(), idx);
             /* write bytes to new part */
             PackagePart picDataPart = xwpfPicData.getPackagePart();
             OutputStream out = null;
@@ -266,9 +266,7 @@ public abstract class XWPFHeaderFooter e
             document.registerPackagePictureData(xwpfPicData);
             pictures.add(xwpfPicData);
             return getRelationId(xwpfPicData);
-        }
-        else if (!getRelations().contains(xwpfPicData))
-        {
+        } else if (!getRelations().contains(xwpfPicData)) {
             /*
              * Part already existed, but was not related so far. Create
              * relationship to the already existing part and update
@@ -279,14 +277,12 @@ public abstract class XWPFHeaderFooter e
             TargetMode targetMode = TargetMode.INTERNAL;
             PackagePartName partName = picDataPart.getPartName();
             String relation = relDesc.getRelation();
-            PackageRelationship relShip = getPackagePart().addRelationship(partName,targetMode,relation);
+            PackageRelationship relShip = getPackagePart().addRelationship(partName, targetMode, relation);
             String id = relShip.getId();
-            addRelation(id,xwpfPicData);
+            addRelation(id, xwpfPicData);
             pictures.add(xwpfPicData);
             return id;
-        }
-        else 
-        {
+        } else {
             /* Part already existed, get relation id and return it */
             return getRelationId(xwpfPicData);
         }
@@ -295,61 +291,61 @@ public abstract class XWPFHeaderFooter e
     /**
      * Adds a picture to the document.
      *
-     * @param is                The stream to read image from
-     * @param format            The format of the picture.
-     *
+     * @param is     The stream to read image from
+     * @param format The format of the picture.
      * @return the index to this picture (0 based), the added picture can be obtained from {@link #getAllPictures()} .
-     * @throws InvalidFormatException 
-     * @throws IOException 
+     * @throws InvalidFormatException
+     * @throws IOException
      */
-    public String addPictureData(InputStream is, int format) throws InvalidFormatException,IOException {
+    public String addPictureData(InputStream is, int format) throws InvalidFormatException, IOException {
         byte[] data = IOUtils.toByteArray(is);
-        return addPictureData(data,format);
+        return addPictureData(data, format);
     }
 
     /**
      * returns the PictureData by blipID
+     *
      * @param blipID
      * @return XWPFPictureData of a specificID
-     * @throws Exception 
+     * @throws Exception
      */
     public XWPFPictureData getPictureDataByID(String blipID) {
         POIXMLDocumentPart relatedPart = getRelationById(blipID);
         if (relatedPart != null && relatedPart instanceof XWPFPictureData) {
             return (XWPFPictureData) relatedPart;
         }
-        return null;   
+        return null;
     }
 
     /**
      * add a new paragraph at position of the cursor
+     *
      * @param cursor
      * @return the inserted paragraph
      */
-    public XWPFParagraph insertNewParagraph(XmlCursor cursor){
-        if(isCursorInHdrF(cursor)){
+    public XWPFParagraph insertNewParagraph(XmlCursor cursor) {
+        if (isCursorInHdrF(cursor)) {
             String uri = CTP.type.getName().getNamespaceURI();
             String localPart = "p";
-            cursor.beginElement(localPart,uri);
+            cursor.beginElement(localPart, uri);
             cursor.toParent();
-            CTP p = (CTP)cursor.getObject();
+            CTP p = (CTP) cursor.getObject();
             XWPFParagraph newP = new XWPFParagraph(p, this);
             XmlObject o = null;
-            while(!(o instanceof CTP)&&(cursor.toPrevSibling())){
+            while (!(o instanceof CTP) && (cursor.toPrevSibling())) {
                 o = cursor.getObject();
             }
-            if((!(o instanceof CTP)) || (CTP)o == p){
+            if ((!(o instanceof CTP)) || (CTP) o == p) {
                 paragraphs.add(0, newP);
+            } else {
+                int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1;
+                paragraphs.add(pos, newP);
             }
-            else{
-                int pos = paragraphs.indexOf(getParagraph((CTP)o))+1;
-                paragraphs.add(pos,newP);
-            }
-            int i=0;
+            int i = 0;
             cursor.toCursor(p.newCursor());
-            while(cursor.toPrevSibling()){
-                o =cursor.getObject();
-                if(o instanceof CTP || o instanceof CTTbl)
+            while (cursor.toPrevSibling()) {
+                o = cursor.getObject();
+                if (o instanceof CTP || o instanceof CTTbl)
                     i++;
             }
             bodyElements.add(i, newP);
@@ -362,35 +358,33 @@ public abstract class XWPFHeaderFooter e
 
 
     /**
-     * 
      * @param cursor
      * @return the inserted table
      */
     public XWPFTable insertNewTbl(XmlCursor cursor) {
-        if(isCursorInHdrF(cursor)){
+        if (isCursorInHdrF(cursor)) {
             String uri = CTTbl.type.getName().getNamespaceURI();
             String localPart = "tbl";
-            cursor.beginElement(localPart,uri);
+            cursor.beginElement(localPart, uri);
             cursor.toParent();
-            CTTbl t = (CTTbl)cursor.getObject();
+            CTTbl t = (CTTbl) cursor.getObject();
             XWPFTable newT = new XWPFTable(t, this);
             cursor.removeXmlContents();
             XmlObject o = null;
-            while(!(o instanceof CTTbl)&&(cursor.toPrevSibling())){
+            while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
                 o = cursor.getObject();
             }
-            if(!(o instanceof CTTbl)){
+            if (!(o instanceof CTTbl)) {
                 tables.add(0, newT);
+            } else {
+                int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
+                tables.add(pos, newT);
             }
-            else{
-                int pos = tables.indexOf(getTable((CTTbl)o))+1;
-                tables.add(pos,newT);
-            }
-            int i=0;
+            int i = 0;
             cursor = t.newCursor();
-            while(cursor.toPrevSibling()){
-                o =cursor.getObject();
-                if(o instanceof CTP || o instanceof CTTbl)
+            while (cursor.toPrevSibling()) {
+                o = cursor.getObject();
+                if (o instanceof CTP || o instanceof CTTbl)
                     i++;
             }
             bodyElements.add(i, newT);
@@ -403,29 +397,31 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * verifies that cursor is on the right position
+     *
      * @param cursor
      */
     private boolean isCursorInHdrF(XmlCursor cursor) {
         XmlCursor verify = cursor.newCursor();
         verify.toParent();
-        if(verify.getObject() == this.headerFooter){
+        if (verify.getObject() == this.headerFooter) {
             return true;
         }
         return false;
     }
 
 
-    public POIXMLDocumentPart getOwner(){
+    public POIXMLDocumentPart getOwner() {
         return this;
     }
 
     /**
      * Returns the table at position pos
+     *
      * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
      */
     public XWPFTable getTableArray(int pos) {
 
-        if(pos > 0 && pos < tables.size()){
+        if (pos > 0 && pos < tables.size()) {
             return tables.get(pos);
         }
         return null;
@@ -433,6 +429,7 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * inserts an existing XWPFTable to the arrays bodyElements and tables
+     *
      * @param pos
      * @param table
      */
@@ -441,7 +438,7 @@ public abstract class XWPFHeaderFooter e
         bodyElements.add(pos, table);
         int i = 0;
         for (CTTbl tbl : headerFooter.getTblArray()) {
-            if(tbl == table.getCTTbl()){
+            if (tbl == table.getCTTbl()) {
                 break;
             }
             i++;
@@ -450,10 +447,10 @@ public abstract class XWPFHeaderFooter e
 
     }
 
-    public void readHdrFtr(){
+    public void readHdrFtr() {
         bodyElements = new ArrayList<IBodyElement>();
         paragraphs = new ArrayList<XWPFParagraph>();
-        tables= new ArrayList<XWPFTable>();
+        tables = new ArrayList<XWPFTable>();
         // parse the document with cursor and add
         // the XmlObject to its lists
         XmlCursor cursor = headerFooter.newCursor();
@@ -461,12 +458,12 @@ public abstract class XWPFHeaderFooter e
         while (cursor.toNextSelection()) {
             XmlObject o = cursor.getObject();
             if (o instanceof CTP) {
-                XWPFParagraph p = new XWPFParagraph((CTP)o, this);
+                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                 paragraphs.add(p);
                 bodyElements.add(p);
             }
             if (o instanceof CTTbl) {
-                XWPFTable t = new XWPFTable((CTTbl)o, this);
+                XWPFTable t = new XWPFTable((CTTbl) o, this);
                 tables.add(t);
                 bodyElements.add(t);
             }
@@ -476,48 +473,50 @@ public abstract class XWPFHeaderFooter e
 
     /**
      * get the TableCell which belongs to the TableCell
+     *
      * @param cell
      */
     public XWPFTableCell getTableCell(CTTc cell) {
         XmlCursor cursor = cell.newCursor();
         cursor.toParent();
         XmlObject o = cursor.getObject();
-        if(!(o instanceof CTRow)){
+        if (!(o instanceof CTRow)) {
             return null;
         }
-        CTRow row = (CTRow)o;
+        CTRow row = (CTRow) o;
         cursor.toParent();
         o = cursor.getObject();
         cursor.dispose();
-        if(! (o instanceof CTTbl)){
+        if (!(o instanceof CTTbl)) {
             return null;
         }
         CTTbl tbl = (CTTbl) o;
         XWPFTable table = getTable(tbl);
-        if(table == null){
+        if (table == null) {
             return null;
         }
         XWPFTableRow tableRow = table.getRow(row);
-        if(row == null){
+        if (row == null) {
             return null;
         }
         return tableRow.getTableCell(cell);
     }
 
-    public void setXWPFDocument(XWPFDocument doc) {
-        document = doc;
-    }
-
     public XWPFDocument getXWPFDocument() {
-        if (document!=null) {
+        if (document != null) {
             return document;
         } else {
-            return (XWPFDocument)getParent();
+            return (XWPFDocument) getParent();
         }
     }
 
+    public void setXWPFDocument(XWPFDocument doc) {
+        document = doc;
+    }
+
     /**
      * returns the Part, to which the body belongs, which you need for adding relationship to other parts
+     *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
      */
     public POIXMLDocumentPart getPart() {

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlink.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlink.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlink.java Sun Jul 19 19:00:32 2015
@@ -18,26 +18,22 @@ package org.apache.poi.xwpf.usermodel;
 
 /**
  * Sketch of XWPF hyperlink class
- * 
-* @author Yury Batrakov (batrakov at gmail.com)
- * 
+ *
+ * @author Yury Batrakov (batrakov at gmail.com)
  */
-public class XWPFHyperlink
-{
+public class XWPFHyperlink {
     String id, url;
-    public XWPFHyperlink(String id, String url)
-    {
+
+    public XWPFHyperlink(String id, String url) {
         this.id = id;
         this.url = url;
     }
-    
-    public String getId()
-    {
+
+    public String getId() {
         return id;
     }
-    
-    public String getURL()
-    {
+
+    public String getURL() {
         return url;
     }
 }

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java Sun Jul 19 19:00:32 2015
@@ -20,45 +20,45 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
 
 /**
- * A run of text with a Hyperlink applied to it.
- * Any given Hyperlink may be made up of multiple of these.
- */
-public class XWPFHyperlinkRun extends XWPFRun
-{
-   private CTHyperlink hyperlink;
-   
-   public XWPFHyperlinkRun(CTHyperlink hyperlink, CTR run, IRunBody p) {
-      super(run, p);
-      this.hyperlink = hyperlink;
-   }
-   
-   public CTHyperlink getCTHyperlink() {
-      return hyperlink;
-   }
-   
-   public String getAnchor() {
-      return hyperlink.getAnchor();
-   }
-   
-   /**
-    * Returns the ID of the hyperlink, if one is set.
-    */
-   public String getHyperlinkId() {
-      return hyperlink.getId();
-   }
-   public void setHyperlinkId(String id) {
-      hyperlink.setId(id);
-   }
-   
-   /**
-    * If this Hyperlink is an external reference hyperlink,
-    *  return the object for it.
-    */
-   public XWPFHyperlink getHyperlink(XWPFDocument document) {
-      String id = getHyperlinkId();
-      if(id == null)
-         return null;
-      
-      return document.getHyperlinkByID(id);
-   }
-}
+ * A run of text with a Hyperlink applied to it.
+ * Any given Hyperlink may be made up of multiple of these.
+ */
+public class XWPFHyperlinkRun extends XWPFRun {
+    private CTHyperlink hyperlink;
+
+    public XWPFHyperlinkRun(CTHyperlink hyperlink, CTR run, IRunBody p) {
+        super(run, p);
+        this.hyperlink = hyperlink;
+    }
+
+    public CTHyperlink getCTHyperlink() {
+        return hyperlink;
+    }
+
+    public String getAnchor() {
+        return hyperlink.getAnchor();
+    }
+
+    /**
+     * Returns the ID of the hyperlink, if one is set.
+     */
+    public String getHyperlinkId() {
+        return hyperlink.getId();
+    }
+
+    public void setHyperlinkId(String id) {
+        hyperlink.setId(id);
+    }
+
+    /**
+     * If this Hyperlink is an external reference hyperlink,
+     * return the object for it.
+     */
+    public XWPFHyperlink getHyperlink(XWPFDocument document) {
+        String id = getHyperlinkId();
+        if (id == null)
+            return null;
+
+        return document.getHyperlinkByID(id);
+    }
+}

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFLatentStyles.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFLatentStyles.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFLatentStyles.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFLatentStyles.java Sun Jul 19 19:00:32 2015
@@ -17,34 +17,38 @@
 package org.apache.poi.xwpf.usermodel;
 
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException;
+
+public class XWPFLatentStyles {
+    protected XWPFStyles styles; //LatentStyle shall know styles
+    private CTLatentStyles latentStyles;
+
+    protected XWPFLatentStyles() {
+    }
+
+    protected XWPFLatentStyles(CTLatentStyles latentStyles) {
+        this(latentStyles, null);
+    }
+
+    protected XWPFLatentStyles(CTLatentStyles latentStyles, XWPFStyles styles) {
+        this.latentStyles = latentStyles;
+        this.styles = styles;
+    }
+
+    public int getNumberOfStyles() {
+        return latentStyles.sizeOfLsdExceptionArray();
+    }
 
-public class XWPFLatentStyles {
-	private CTLatentStyles latentStyles;
-	protected XWPFStyles styles; //LatentStyle shall know styles
-	
-	protected XWPFLatentStyles(){
-	}
-	
-	protected XWPFLatentStyles(CTLatentStyles latentStyles){
-		this(latentStyles,null);
-	}
-	
-	protected XWPFLatentStyles(CTLatentStyles latentStyles, XWPFStyles styles) {
-		this.latentStyles=latentStyles;
-		this.styles=styles;
-	}
-	
-	/**
-	 * checks wheter specific LatentStyleID is a latentStyle
-	*/
-    @SuppressWarnings("deprecation")
-	protected boolean isLatentStyle(String latentStyleID){	
-		for ( CTLsdException lsd: latentStyles.getLsdExceptionArray()) {
-			if(lsd.getName().equals(latentStyleID)) {
-				return true;
-			}
-		}
-		return false;		
-	}
-}
+    /**
+     * checks whether specific LatentStyleID is a latentStyle
+     */
+    @SuppressWarnings("deprecation")
+    protected boolean isLatentStyle(String latentStyleID) {
+        for (CTLsdException lsd : latentStyles.getLsdExceptionArray()) {
+            if (lsd.getName().equals(latentStyleID)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNum.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNum.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNum.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNum.java Sun Jul 19 19:00:32 2015
@@ -18,48 +18,47 @@ package org.apache.poi.xwpf.usermodel;
 
 
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
-
-/**
- * @author Philipp Epp
- *
- */
-public class XWPFNum {
-	private CTNum ctNum;
-	protected XWPFNumbering numbering;
-	
-	public XWPFNum(){
-		this.ctNum = null;
-		this.numbering = null;
-	}
-	
-	public XWPFNum(CTNum ctNum){
-		this.ctNum = ctNum;
-		this.numbering = null;
-	}
-	
-	public XWPFNum(XWPFNumbering numbering){
-		this.ctNum = null;
-		this.numbering = numbering;
-	}
-	
-	public XWPFNum(CTNum ctNum, XWPFNumbering numbering){
-		this.ctNum = ctNum;
-		this.numbering = numbering;
-	}
-	
-	public XWPFNumbering getNumbering(){
-		return numbering;
-	}
-	
-	public CTNum getCTNum(){
-		return ctNum;
-	}
-	
-	public void setNumbering(XWPFNumbering numbering){
-		this.numbering = numbering;
-	}
-	
-	public void setCTNum(CTNum ctNum){
-		this.ctNum = ctNum;
-	}
+
+/**
+ * @author Philipp Epp
+ */
+public class XWPFNum {
+    protected XWPFNumbering numbering;
+    private CTNum ctNum;
+
+    public XWPFNum() {
+        this.ctNum = null;
+        this.numbering = null;
+    }
+
+    public XWPFNum(CTNum ctNum) {
+        this.ctNum = ctNum;
+        this.numbering = null;
+    }
+
+    public XWPFNum(XWPFNumbering numbering) {
+        this.ctNum = null;
+        this.numbering = numbering;
+    }
+
+    public XWPFNum(CTNum ctNum, XWPFNumbering numbering) {
+        this.ctNum = ctNum;
+        this.numbering = numbering;
+    }
+
+    public XWPFNumbering getNumbering() {
+        return numbering;
+    }
+
+    public void setNumbering(XWPFNumbering numbering) {
+        this.numbering = numbering;
+    }
+
+    public CTNum getCTNum() {
+        return ctNum;
+    }
+
+    public void setCTNum(CTNum ctNum) {
+        this.ctNum = ctNum;
+    }
 }
\ No newline at end of file

Modified: poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java (original)
+++ poi/branches/common_sl/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java Sun Jul 19 19:00:32 2015
@@ -38,71 +38,69 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumbering;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
-
-/**
- * @author Philipp Epp
- *
- */
-public class XWPFNumbering extends POIXMLDocumentPart {
-    protected List<XWPFAbstractNum> abstractNums = new ArrayList<XWPFAbstractNum>();
-    protected List<XWPFNum> nums = new ArrayList<XWPFNum>();
-
-    private CTNumbering ctNumbering;
-	boolean isNew;
-	
-	/**
-	 *create a new styles object with an existing document 
-	 */
-	public XWPFNumbering(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{
-		super(part, rel);
-		isNew = true;
-	}
-
-	/**
-	 * create a new XWPFNumbering object for use in a new document
-	 */
-	public XWPFNumbering(){
-		abstractNums = new ArrayList<XWPFAbstractNum>();
-		nums = new ArrayList<XWPFNum>();
-		isNew = true;
-	}
-
-	/**
-	 * read numbering form an existing package
-	 */
-	@Override
-    @SuppressWarnings("deprecation")
-	protected void onDocumentRead() throws IOException{
-		NumberingDocument numberingDoc = null;
-		InputStream is;
-		is = getPackagePart().getInputStream();
-		try {
-			numberingDoc = NumberingDocument.Factory.parse(is);
-			ctNumbering = numberingDoc.getNumbering();
-	        //get any Nums
-	        for(CTNum ctNum : ctNumbering.getNumArray()) {
-	            nums.add(new XWPFNum(ctNum, this));
-	        }
-	        for(CTAbstractNum ctAbstractNum : ctNumbering.getAbstractNumArray()){
-	        	abstractNums.add(new XWPFAbstractNum(ctAbstractNum, this));
-	        }
-	        isNew = false;
-		} catch (XmlException e) {
-			throw new POIXMLException();
-		}
-	}
-	
-	/**
-	 * save and commit numbering
-	 */
-	@Override
-    protected void commit() throws IOException {
-        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
-        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "numbering"));
-        Map<String,String> map = new HashMap<String,String>();
-        map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
-        map.put("urn:schemas-microsoft-com:office:office", "o");
-        map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
+
+/**
+ * @author Philipp Epp
+ */
+public class XWPFNumbering extends POIXMLDocumentPart {
+    protected List<XWPFAbstractNum> abstractNums = new ArrayList<XWPFAbstractNum>();
+    protected List<XWPFNum> nums = new ArrayList<XWPFNum>();
+    boolean isNew;
+    private CTNumbering ctNumbering;
+
+    /**
+     * create a new styles object with an existing document
+     */
+    public XWPFNumbering(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException {
+        super(part, rel);
+        isNew = true;
+    }
+
+    /**
+     * create a new XWPFNumbering object for use in a new document
+     */
+    public XWPFNumbering() {
+        abstractNums = new ArrayList<XWPFAbstractNum>();
+        nums = new ArrayList<XWPFNum>();
+        isNew = true;
+    }
+
+    /**
+     * read numbering form an existing package
+     */
+    @Override
+    @SuppressWarnings("deprecation")
+    protected void onDocumentRead() throws IOException {
+        NumberingDocument numberingDoc = null;
+        InputStream is;
+        is = getPackagePart().getInputStream();
+        try {
+            numberingDoc = NumberingDocument.Factory.parse(is);
+            ctNumbering = numberingDoc.getNumbering();
+            //get any Nums
+            for (CTNum ctNum : ctNumbering.getNumArray()) {
+                nums.add(new XWPFNum(ctNum, this));
+            }
+            for (CTAbstractNum ctAbstractNum : ctNumbering.getAbstractNumArray()) {
+                abstractNums.add(new XWPFAbstractNum(ctAbstractNum, this));
+            }
+            isNew = false;
+        } catch (XmlException e) {
+            throw new POIXMLException();
+        }
+    }
+
+    /**
+     * save and commit numbering
+     */
+    @Override
+    protected void commit() throws IOException {
+        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "numbering"));
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
+        map.put("urn:schemas-microsoft-com:office:office", "o");
+        map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
         map.put("urn:schemas-microsoft-com:vml", "v");
         map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
@@ -114,169 +112,182 @@ public class XWPFNumbering extends POIXM
         OutputStream out = part.getOutputStream();
         ctNumbering.save(out, xmlOptions);
         out.close();
-    }
-
-
-	/**
-	 * Sets the ctNumbering
-	 * @param numbering
-	 */
-	public void setNumbering(CTNumbering numbering){
-		ctNumbering = numbering;
-	}
-	
-	
-	/**
-	 * Checks whether number with numID exists
-	 * @param numID
-	 * @return boolean		true if num exist, false if num not exist
-	 */
-	public boolean numExist(BigInteger numID){
-		for (XWPFNum num : nums) {
-			if (num.getCTNum().getNumId().equals(numID))
-				return true;
-		}
-		return false;
-	}
-	
-	/**
-	 * add a new number to the numbering document
-	 * @param num
-	 */
-	public BigInteger addNum(XWPFNum num){
-		ctNumbering.addNewNum();
-		int pos = ctNumbering.sizeOfNumArray() - 1;
-		ctNumbering.setNumArray(pos, num.getCTNum());
-		nums.add(num);
-		return num.getCTNum().getNumId();
-	}
-	
-	/**
-	 * Add a new num with an abstractNumID
-	 * @return return NumId of the added num 
-	 */
-	public BigInteger addNum(BigInteger abstractNumID){
-		CTNum ctNum = this.ctNumbering.addNewNum();
-		ctNum.addNewAbstractNumId();
-		ctNum.getAbstractNumId().setVal(abstractNumID);
-		ctNum.setNumId(BigInteger.valueOf(nums.size()+1));
-		XWPFNum num = new XWPFNum(ctNum, this);
-		nums.add(num);
-		return ctNum.getNumId();
-	}
-	
-	/**
-	 * Add a new num with an abstractNumID and a numID
-	 * @param abstractNumID
-	 * @param numID
-	 */
-	public void addNum(BigInteger abstractNumID, BigInteger numID){
-		CTNum ctNum = this.ctNumbering.addNewNum();
-		ctNum.addNewAbstractNumId();
-		ctNum.getAbstractNumId().setVal(abstractNumID);
-		ctNum.setNumId(numID);
-		XWPFNum num = new XWPFNum(ctNum, this);
-		nums.add(num);
-	}
-	
-	/**
-	 * get Num by NumID
-	 * @param numID
-	 * @return abstractNum with NumId if no Num exists with that NumID 
-	 * 			null will be returned
-	 */
-	public XWPFNum getNum(BigInteger numID){
-		for(XWPFNum num: nums){
-			if(num.getCTNum().getNumId().equals(numID))
-				return num;
-		}
-		return null;
-	}
-	/**
-	 * get AbstractNum by abstractNumID
-	 * @param abstractNumID
-	 * @return  abstractNum with abstractNumId if no abstractNum exists with that abstractNumID 
-	 * 			null will be returned
-	 */
-	public XWPFAbstractNum getAbstractNum(BigInteger abstractNumID){
-		for(XWPFAbstractNum abstractNum: abstractNums){
-			if(abstractNum.getAbstractNum().getAbstractNumId().equals(abstractNumID)){
-				return abstractNum;
-			}
-		}
-		return null;
-	}
-	/**
-	 * Compare AbstractNum with abstractNums of this numbering document.
-	 * If the content of abstractNum equals with an abstractNum of the List in numbering
-	 * the BigInteger Value of it will be returned.
-	 * If no equal abstractNum is existing null will be returned
-	 * 
-	 * @param abstractNum
-	 * @return 	BigInteger
-	 */
-	public BigInteger getIdOfAbstractNum(XWPFAbstractNum abstractNum){
-		CTAbstractNum copy = (CTAbstractNum) abstractNum.getCTAbstractNum().copy();
-		XWPFAbstractNum newAbstractNum = new XWPFAbstractNum(copy, this);
-		int i;
-		for (i = 0; i < abstractNums.size(); i++) {
-			newAbstractNum.getCTAbstractNum().setAbstractNumId(BigInteger.valueOf(i));
-			newAbstractNum.setNumbering(this);
-			if(newAbstractNum.getCTAbstractNum().valueEquals(abstractNums.get(i).getCTAbstractNum())){
-				return newAbstractNum.getCTAbstractNum().getAbstractNumId();
-			}
-		}
-		return null;
-	}
-
-
-	/**
-	 * add a new AbstractNum and return its AbstractNumID 
-	 * @param abstractNum
-	 */
-	public BigInteger addAbstractNum(XWPFAbstractNum abstractNum){
-		int pos = abstractNums.size();
-		if(abstractNum.getAbstractNum() != null){ // Use the current CTAbstractNum if it exists
-			ctNumbering.addNewAbstractNum().set(abstractNum.getAbstractNum());
-		} else {
-			ctNumbering.addNewAbstractNum();
-			abstractNum.getAbstractNum().setAbstractNumId(BigInteger.valueOf(pos));
-			ctNumbering.setAbstractNumArray(pos, abstractNum.getAbstractNum());
-		}
-		abstractNums.add(abstractNum);
-		return abstractNum.getCTAbstractNum().getAbstractNumId();
-	}
-	
-	/**
-	 * remove an existing abstractNum 
-	 * @param abstractNumID
-	 * @return true if abstractNum with abstractNumID exists in NumberingArray,
-	 * 		   false if abstractNum with abstractNumID not exists
-	 */
-	public boolean removeAbstractNum(BigInteger abstractNumID){
-		if(abstractNumID.byteValue()<abstractNums.size()){
-			ctNumbering.removeAbstractNum(abstractNumID.byteValue());
-			abstractNums.remove(abstractNumID.byteValue());
-			return true;
-		}
-		return false;
-	}
-	/**
-	 *return the abstractNumID
-	 *If the AbstractNumID not exists
-	 *return null
-	 * @param 		numID
-	 * @return 		abstractNumID
-	 */
-	public BigInteger getAbstractNumID(BigInteger numID){
-		XWPFNum num = getNum(numID);
-		if(num == null)
-			return null;
-		if (num.getCTNum() == null)
-			return null;
-		if (num.getCTNum().getAbstractNumId() == null)
-			return null;
-		return num.getCTNum().getAbstractNumId().getVal();
-	}
-}
-	
+    }
+
+
+    /**
+     * Sets the ctNumbering
+     *
+     * @param numbering
+     */
+    public void setNumbering(CTNumbering numbering) {
+        ctNumbering = numbering;
+    }
+
+
+    /**
+     * Checks whether number with numID exists
+     *
+     * @param numID
+     * @return boolean        true if num exist, false if num not exist
+     */
+    public boolean numExist(BigInteger numID) {
+        for (XWPFNum num : nums) {
+            if (num.getCTNum().getNumId().equals(numID))
+                return true;
+        }
+        return false;
+    }
+
+    /**
+     * add a new number to the numbering document
+     *
+     * @param num
+     */
+    public BigInteger addNum(XWPFNum num) {
+        ctNumbering.addNewNum();
+        int pos = ctNumbering.sizeOfNumArray() - 1;
+        ctNumbering.setNumArray(pos, num.getCTNum());
+        nums.add(num);
+        return num.getCTNum().getNumId();
+    }
+
+    /**
+     * Add a new num with an abstractNumID
+     *
+     * @return return NumId of the added num
+     */
+    public BigInteger addNum(BigInteger abstractNumID) {
+        CTNum ctNum = this.ctNumbering.addNewNum();
+        ctNum.addNewAbstractNumId();
+        ctNum.getAbstractNumId().setVal(abstractNumID);
+        ctNum.setNumId(BigInteger.valueOf(nums.size() + 1));
+        XWPFNum num = new XWPFNum(ctNum, this);
+        nums.add(num);
+        return ctNum.getNumId();
+    }
+
+    /**
+     * Add a new num with an abstractNumID and a numID
+     *
+     * @param abstractNumID
+     * @param numID
+     */
+    public void addNum(BigInteger abstractNumID, BigInteger numID) {
+        CTNum ctNum = this.ctNumbering.addNewNum();
+        ctNum.addNewAbstractNumId();
+        ctNum.getAbstractNumId().setVal(abstractNumID);
+        ctNum.setNumId(numID);
+        XWPFNum num = new XWPFNum(ctNum, this);
+        nums.add(num);
+    }
+
+    /**
+     * get Num by NumID
+     *
+     * @param numID
+     * @return abstractNum with NumId if no Num exists with that NumID
+     * null will be returned
+     */
+    public XWPFNum getNum(BigInteger numID) {
+        for (XWPFNum num : nums) {
+            if (num.getCTNum().getNumId().equals(numID))
+                return num;
+        }
+        return null;
+    }
+
+    /**
+     * get AbstractNum by abstractNumID
+     *
+     * @param abstractNumID
+     * @return abstractNum with abstractNumId if no abstractNum exists with that abstractNumID
+     * null will be returned
+     */
+    public XWPFAbstractNum getAbstractNum(BigInteger abstractNumID) {
+        for (XWPFAbstractNum abstractNum : abstractNums) {
+            if (abstractNum.getAbstractNum().getAbstractNumId().equals(abstractNumID)) {
+                return abstractNum;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Compare AbstractNum with abstractNums of this numbering document.
+     * If the content of abstractNum equals with an abstractNum of the List in numbering
+     * the BigInteger Value of it will be returned.
+     * If no equal abstractNum is existing null will be returned
+     *
+     * @param abstractNum
+     * @return BigInteger
+     */
+    public BigInteger getIdOfAbstractNum(XWPFAbstractNum abstractNum) {
+        CTAbstractNum copy = (CTAbstractNum) abstractNum.getCTAbstractNum().copy();
+        XWPFAbstractNum newAbstractNum = new XWPFAbstractNum(copy, this);
+        int i;
+        for (i = 0; i < abstractNums.size(); i++) {
+            newAbstractNum.getCTAbstractNum().setAbstractNumId(BigInteger.valueOf(i));
+            newAbstractNum.setNumbering(this);
+            if (newAbstractNum.getCTAbstractNum().valueEquals(abstractNums.get(i).getCTAbstractNum())) {
+                return newAbstractNum.getCTAbstractNum().getAbstractNumId();
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * add a new AbstractNum and return its AbstractNumID
+     *
+     * @param abstractNum
+     */
+    public BigInteger addAbstractNum(XWPFAbstractNum abstractNum) {
+        int pos = abstractNums.size();
+        if (abstractNum.getAbstractNum() != null) { // Use the current CTAbstractNum if it exists
+            ctNumbering.addNewAbstractNum().set(abstractNum.getAbstractNum());
+        } else {
+            ctNumbering.addNewAbstractNum();
+            abstractNum.getAbstractNum().setAbstractNumId(BigInteger.valueOf(pos));
+            ctNumbering.setAbstractNumArray(pos, abstractNum.getAbstractNum());
+        }
+        abstractNums.add(abstractNum);
+        return abstractNum.getCTAbstractNum().getAbstractNumId();
+    }
+
+    /**
+     * remove an existing abstractNum
+     *
+     * @param abstractNumID
+     * @return true if abstractNum with abstractNumID exists in NumberingArray,
+     * false if abstractNum with abstractNumID not exists
+     */
+    public boolean removeAbstractNum(BigInteger abstractNumID) {
+        if (abstractNumID.byteValue() < abstractNums.size()) {
+            ctNumbering.removeAbstractNum(abstractNumID.byteValue());
+            abstractNums.remove(abstractNumID.byteValue());
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * return the abstractNumID
+     * If the AbstractNumID not exists
+     * return null
+     *
+     * @param numID
+     * @return abstractNumID
+     */
+    public BigInteger getAbstractNumID(BigInteger numID) {
+        XWPFNum num = getNum(numID);
+        if (num == null)
+            return null;
+        if (num.getCTNum() == null)
+            return null;
+        if (num.getCTNum().getAbstractNumId() == null)
+            return null;
+        return num.getCTNum().getAbstractNumId().getVal();
+    }
+}
+



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


Mime
View raw message