]> source.dussan.org Git - poi.git/commitdiff
Surface XSSF Header/Footer Attributes (60887)
authorMark Murphy <jmarkmurphy@apache.org>
Sat, 11 Nov 2017 14:18:24 +0000 (14:18 +0000)
committerMark Murphy <jmarkmurphy@apache.org>
Sat, 11 Nov 2017 14:18:24 +0000 (14:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814950 13f79535-47bb-0310-9956-ffa450edef68

19 files changed:
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvenFooter.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvenHeader.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddFooter.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooter.java [deleted file]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFHeaderFooter.java [new file with mode: 0644]

index 9dd28daf2240b2b3f04f85da615ad066ac2bda22..0b2dad42cd3932e3c1f80adecc11c7c49eaa274e 100644 (file)
@@ -36,7 +36,7 @@ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
      * @see XSSFSheet#getEvenFooter()
      * @param headerFooter
      */
-    public XSSFEvenFooter(CTHeaderFooter headerFooter) {
+    protected XSSFEvenFooter(CTHeaderFooter headerFooter) {
         super(headerFooter);
         headerFooter.setDifferentOddEven(true);
     }
@@ -57,6 +57,9 @@ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
     public void setText(String text) {
        if(text == null) {
                getHeaderFooter().unsetEvenFooter();
+               if (!getHeaderFooter().isSetEvenHeader()) {
+                   getHeaderFooter().unsetDifferentOddEven();
+               }
        } else {
                getHeaderFooter().setEvenFooter(text);
        }
index 1bf9555fc89c731a9f12ef8d84317d1758af6588..c6b7444dfa5ddd48dcd20e3e3b1f7684150554da 100644 (file)
@@ -23,45 +23,52 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
 
 /**
  * <p>
- * Even page header value. Corresponds to even printed pages.
- * Even page(s) in the sheet may not be printed, for example, if the print area is specified to be 
- * a range such that it falls outside an even page's scope.
- * If no even header is specified, then odd header value is assumed for even page headers.
- *</p>
+ * Even page header value. Corresponds to even printed pages. Even page(s) in
+ * the sheet may not be printed, for example, if the print area is specified to
+ * be a range such that it falls outside an even page's scope. If no even header
+ * is specified, then odd header value is assumed for even page headers.
+ * </p>
  *
  */
-public class XSSFEvenHeader extends XSSFHeaderFooter implements Header{
+public class XSSFEvenHeader extends XSSFHeaderFooter implements Header {
 
     /**
      * Create an instance of XSSFEvenHeader from the supplied XML bean
+     * 
      * @see XSSFSheet#getEvenHeader()
      * @param headerFooter
      */
-    public XSSFEvenHeader(CTHeaderFooter headerFooter) {
-       super(headerFooter);
-       headerFooter.setDifferentOddEven(true);
+    protected XSSFEvenHeader(CTHeaderFooter headerFooter) {
+        super(headerFooter);
+        headerFooter.setDifferentOddEven(true);
     }
 
     /**
      * Get the content text representing this header
+     * 
      * @return text
      */
     public String getText() {
-       return getHeaderFooter().getEvenHeader();
+        return getHeaderFooter().getEvenHeader();
     }
 
     /**
      * Set a text for the header. If null unset the value
-     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
-     * @param text - a string representing the header. 
+     * 
+     * @see XSSFHeaderFooter to see how to create a string with Header/Footer
+     *      Formatting Syntax
+     * @param text
+     *            - a string representing the header.
      */
     public void setText(String text) {
-       if(text == null) {
-           getHeaderFooter().unsetEvenHeader();
-       } else {
-           getHeaderFooter().setEvenHeader(text);
-       }
+        if (text == null) {
+            getHeaderFooter().unsetEvenHeader();
+            if (!getHeaderFooter().isSetEvenFooter()) {
+                getHeaderFooter().unsetDifferentOddEven();
+            }
+        } else {
+            getHeaderFooter().setEvenHeader(text);
+        }
     }
 
-    
 }
index b0f2cb5174c0435c36f87c3fc3ca0fbc3ce5d97f..711292397e3afde93d5f841b72d456f33146bfb1 100644 (file)
@@ -56,6 +56,9 @@ public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
     public void setText(String text) {
        if(text == null) {
                getHeaderFooter().unsetFirstFooter();
+               if (!getHeaderFooter().isSetFirstHeader()) {
+                   getHeaderFooter().unsetDifferentFirst();
+               }
        } else {
                getHeaderFooter().setFirstFooter(text);
        }
index 9ffd45781431d76f43ad9041cde48cff67370eee..9c5d6e8055b0b6acd22a4a265cada69660189980 100644 (file)
@@ -56,6 +56,9 @@ public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
     public void setText(String text) {
        if(text == null) {
                getHeaderFooter().unsetFirstHeader();
+               if (!getHeaderFooter().isSetFirstFooter()) {
+                   getHeaderFooter().unsetDifferentFirst();
+               }
        } else {
                getHeaderFooter().setFirstHeader(text);
        }
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java
new file mode 100644 (file)
index 0000000..eab6f12
--- /dev/null
@@ -0,0 +1,138 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
+
+/**
+ */
+public class XSSFHeaderFooterProperties {
+       private CTHeaderFooter headerFooter;
+
+       /**
+        * Create an instance of XSSFAbstractHeaderFooter from the supplied XML bean
+        *
+        * @param headerFooter
+        */
+       public XSSFHeaderFooterProperties(CTHeaderFooter headerFooter) {
+        this.headerFooter = headerFooter;
+       }
+
+       /**
+        * Returns the underlying CTHeaderFooter xml bean
+        *
+        * @return the underlying CTHeaderFooter xml bean
+        */
+    @Internal
+       public CTHeaderFooter getHeaderFooter() {
+               return this.headerFooter;
+       }
+
+    /**
+        * returns alignWithMargins attribute
+        */
+       public boolean getAlignWithMargins() {
+         return getHeaderFooter().isSetAlignWithMargins() ? getHeaderFooter().getAlignWithMargins() : false;
+       }
+       
+       /**
+        * returns differentFirst attribute
+        */
+       public boolean getDifferentFirst() {
+           return getHeaderFooter().isSetDifferentFirst() ? getHeaderFooter().getDifferentFirst() : false;
+       }
+       
+       /**
+        * returns differentOddEven attribute
+        */
+       public boolean getDifferentOddEven() {
+           return getHeaderFooter().isSetDifferentOddEven() ? getHeaderFooter().getDifferentOddEven() : false;
+       }
+       
+       /**
+        * returns scaleWithDoc attribute
+        */
+       public boolean getScaleWithDoc() {
+           return getHeaderFooter().isSetScaleWithDoc() ? getHeaderFooter().getScaleWithDoc() : false;
+       }
+       
+       /**
+        * set alignWithMargins attribute
+        */
+       public void setAlignWithMargins(boolean flag) {
+           getHeaderFooter().setAlignWithMargins(flag);
+       }
+          
+    /**
+     * set differentFirst attribute
+     */
+       public void setDifferentFirst(boolean flag) {
+        getHeaderFooter().setDifferentFirst(flag);
+    }
+    
+    /**
+     * set differentOddEven attribute
+     */
+       public void setDifferentOddEven(boolean flag) {
+        getHeaderFooter().setDifferentOddEven(flag);
+    }
+    
+    /**
+     * set scaleWithDoc attribute
+     */
+       public void setScaleWithDoc(boolean flag) {
+        getHeaderFooter().setScaleWithDoc(flag);
+    }
+    
+    /**
+     * remove alignWithMargins attribute
+     */
+       public void removeAlignWithMargins() {
+        if (getHeaderFooter().isSetAlignWithMargins()) {
+            getHeaderFooter().unsetAlignWithMargins();
+        }
+    }
+       
+    /**
+     * remove differentFirst attribute
+     */
+       public void removeDifferentFirst() {
+        if (getHeaderFooter().isSetDifferentFirst()) {
+            getHeaderFooter().unsetDifferentFirst();
+        }
+    }
+    
+    /**
+     * remove differentOddEven attribute
+     */
+       public void removeDifferentOddEven() {
+        if (getHeaderFooter().isSetDifferentOddEven()) {
+            getHeaderFooter().unsetDifferentOddEven();
+        }
+    }
+    
+    /**
+     * remove scaleWithDoc attribute
+     */
+       public void removeScaleWithDoc() {
+        if (getHeaderFooter().isSetScaleWithDoc()) {
+            getHeaderFooter().unsetScaleWithDoc();
+        }
+    }
+}
index ca3950f819ada800e1ab6e7b9b9cfb837fd7a66e..6d422dd6881289f95e8cac1cd701dab2eaab75e0 100644 (file)
@@ -34,7 +34,7 @@ public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{
      * @see XSSFSheet#getOddFooter()
      * @param headerFooter
      */
-    public XSSFOddFooter(CTHeaderFooter headerFooter) {
+    protected XSSFOddFooter(CTHeaderFooter headerFooter) {
         super(headerFooter);
     }
     
index cef6ae3fbebcce31957af80bea719ba3500264ab..a604f18449f00289d1c2b03944d86da31b0d2671 100644 (file)
@@ -4514,5 +4514,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         }
     }
 
-
+    public XSSFHeaderFooterProperties getHeaderFooterProperties() {
+        return new XSSFHeaderFooterProperties(getSheetTypeHeaderFooter());
+    }
 }
index b9d0841d3fb6310836284cc74eb8754f0eea4328..a21a4254bf45be647bfcada65883fc8852d90bb4 100644 (file)
@@ -125,14 +125,14 @@ public abstract class XSSFHeaderFooter implements HeaderFooter {
        private CTHeaderFooter headerFooter;
 
        private boolean stripFields;
-
+       
        /**
-        * Create an instance of XSSFHeaderFooter from the supplied XML bean
+        * Create an instance of XSSFAbstractHeaderFooter from the supplied XML bean
         *
         * @param headerFooter
         */
        public XSSFHeaderFooter(CTHeaderFooter headerFooter) {
-               this.headerFooter = headerFooter;
+        this.headerFooter = headerFooter;
                this.helper = new HeaderFooterHelper();
        }
 
index 6ecad0a74f0b3aa272e96584064453c9a6bdd9eb..7ee7546b3d1c4b61a3cfa8e1b3b5b6946af09ec4 100644 (file)
@@ -42,7 +42,7 @@ import org.junit.runners.Suite;
     TestXSSFDrawing.class,
     TestXSSFFont.class,
     TestXSSFFormulaEvaluation.class,
-    TestXSSFHeaderFooter.class,
+    //TestXSSFHeaderFooter.class, //converted to junit4
     TestXSSFHyperlink.class,
     TestXSSFName.class,
     TestXSSFPicture.class,
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java
new file mode 100644 (file)
index 0000000..62e8552
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFEvenFooter {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testSetGetText() {
+        XSSFEvenFooter footer = (XSSFEvenFooter) sheet.getEvenFooter();
+        assertNotNull(footer);
+        assertNull(footer.getText());
+        footer.setText("this is a test");
+        assertEquals("this is a test", footer.getText());
+    }
+}
\ No newline at end of file
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java
new file mode 100644 (file)
index 0000000..e3b12bf
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFEvenHeader {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testSetGetText() {
+        XSSFEvenHeader header = (XSSFEvenHeader) sheet.getEvenHeader();
+        assertNotNull(header);
+        assertNull(header.getText());
+        header.setText("this is a test");
+        assertEquals("this is a test", header.getText());
+    }
+}
\ No newline at end of file
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java
new file mode 100644 (file)
index 0000000..e06faec
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFFirstFooter {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testSetGetText() {
+        XSSFFirstFooter footer = (XSSFFirstFooter) sheet.getFirstFooter();
+        assertNotNull(footer);
+        assertNull(footer.getText());
+        footer.setText("this is a test");
+        assertEquals("this is a test", footer.getText());
+    }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java
new file mode 100644 (file)
index 0000000..ab9e575
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFFirstHeader {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testSetGetText() {
+        XSSFFirstHeader header = (XSSFFirstHeader) sheet.getFirstHeader();
+        assertNotNull(header);
+        assertNull(header.getText());
+        header.setText("this is a test");
+        assertEquals("this is a test", header.getText());
+    }
+}
\ No newline at end of file
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooter.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooter.java
deleted file mode 100644 (file)
index 7c50d6a..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.xssf.usermodel;
-
-import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
-
-import junit.framework.TestCase;
-
-/**
- * Tests for {@link XSSFHeaderFooter}
- */
-public class TestXSSFHeaderFooter extends TestCase {
-       public void testStripFields() {
-               String simple = "I am a test header";
-               String withPage = "I am a&P test header";
-               String withLots = "I&A am&N a&P test&T header&U";
-               String withFont = "I&22 am a&\"Arial,bold\" test header";
-               String withOtherAnds = "I am a&P test header&&";
-               String withOtherAnds2 = "I am a&P test header&a&b";
-               
-               assertEquals(simple, XSSFOddHeader.stripFields(simple));
-               assertEquals(simple, XSSFOddHeader.stripFields(withPage));
-               assertEquals(simple, XSSFOddHeader.stripFields(withLots));
-               assertEquals(simple, XSSFOddHeader.stripFields(withFont));
-               assertEquals(simple + "&&", XSSFOddHeader.stripFields(withOtherAnds));
-               assertEquals(simple + "&a&b", XSSFOddHeader.stripFields(withOtherAnds2));
-               
-               // Now test the default strip flag
-               XSSFEvenHeader head = new XSSFEvenHeader(CTHeaderFooter.Factory.newInstance());
-               head.setCenter("Center");
-               head.setLeft("In the left");
-       
-               assertEquals("In the left", head.getLeft());
-               assertEquals("Center", head.getCenter());
-               assertEquals("", head.getRight());
-               
-               head.setLeft("Top &P&F&D Left");
-               assertEquals("Top &P&F&D Left", head.getLeft());
-               assertFalse(head.areFieldsStripped());
-               
-               head.setAreFieldsStripped(true);
-               assertEquals("Top  Left", head.getLeft());
-               assertTrue(head.areFieldsStripped());
-               
-               // Now even more complex
-               head.setCenter("HEADER TEXT &P&N&D&T&Z&F&F&A&V");
-               assertEquals("HEADER TEXT &V", head.getCenter());
-       }
-
-       public void testGetSetCenterLeftRight() {
-               
-               XSSFOddFooter footer = new XSSFOddFooter(CTHeaderFooter.Factory.newInstance());
-               assertEquals("", footer.getCenter());
-               footer.setCenter("My first center section");
-               assertEquals("My first center section", footer.getCenter());
-               footer.setCenter("No, let's update the center section");
-               assertEquals("No, let's update the center section", footer.getCenter());
-               footer.setLeft("And add a left one");
-               footer.setRight("Finally the right section is added");
-               assertEquals("And add a left one", footer.getLeft());
-               assertEquals("Finally the right section is added", footer.getRight());
-               
-               // Test changing the three sections value
-               footer.setCenter("Second center version");
-               footer.setLeft("Second left version");
-               footer.setRight("Second right version");
-               assertEquals("Second center version", footer.getCenter());
-               assertEquals("Second left version", footer.getLeft());
-               assertEquals("Second right version", footer.getRight());
-               
-       }
-       
-       // TODO Rest of tests
-}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java
new file mode 100644 (file)
index 0000000..92e7f7f
--- /dev/null
@@ -0,0 +1,109 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFHeaderFooterProperties {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    private XSSFHeaderFooterProperties hfProp;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+        hfProp = sheet.getHeaderFooterProperties();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testGetAlignWithMargins() {
+        assertFalse(hfProp.getAlignWithMargins());
+        hfProp.setAlignWithMargins(true);
+        assertTrue(hfProp.getAlignWithMargins());
+    }
+
+    @Test
+    public void testGetDifferentFirst() {
+        assertFalse(hfProp.getDifferentFirst());
+        hfProp.setDifferentFirst(true);
+        assertTrue(hfProp.getDifferentFirst());
+        hfProp.setDifferentFirst(false);
+        assertFalse(hfProp.getDifferentFirst());
+    }
+
+    @Test
+    public void testGetDifferentOddEven() {
+        assertFalse(hfProp.getDifferentOddEven());
+        hfProp.setDifferentOddEven(true);
+        assertTrue(hfProp.getDifferentOddEven());
+        hfProp.setDifferentOddEven(false);
+        assertFalse(hfProp.getDifferentOddEven());
+    }
+
+    @Test
+    public void testGetScaleWithDoc() {
+        assertFalse(hfProp.getScaleWithDoc());
+        hfProp.setScaleWithDoc(true);
+        assertTrue(hfProp.getScaleWithDoc());
+    }
+
+    @Test
+    public void testRemoveAlignWithMargins() {
+        hfProp.setAlignWithMargins(true);
+        assertTrue(hfProp.getHeaderFooter().isSetAlignWithMargins());
+        hfProp.removeAlignWithMargins();
+        assertFalse(hfProp.getHeaderFooter().isSetAlignWithMargins());
+    }
+
+    @Test
+    public void testRemoveDifferentFirst() {
+        hfProp.setDifferentFirst(true);
+        assertTrue(hfProp.getHeaderFooter().isSetDifferentFirst());
+        hfProp.removeDifferentFirst();
+        assertFalse(hfProp.getHeaderFooter().isSetDifferentFirst());
+    }
+
+    @Test
+    public void testRemoveDifferentOddEven() {
+        hfProp.setDifferentOddEven(true);
+        assertTrue(hfProp.getHeaderFooter().isSetDifferentOddEven());
+        hfProp.removeDifferentOddEven();
+        assertFalse(hfProp.getHeaderFooter().isSetDifferentOddEven());
+    }
+
+    @Test
+    public void testRemoveScaleWithDoc() {
+        hfProp.setScaleWithDoc(true);
+        assertTrue(hfProp.getHeaderFooter().isSetScaleWithDoc());
+        hfProp.removeScaleWithDoc();
+        assertFalse(hfProp.getHeaderFooter().isSetScaleWithDoc());
+    }
+
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java
new file mode 100644 (file)
index 0000000..0a20a20
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFOddFooter {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testSetGetText() {
+        XSSFOddFooter footer = (XSSFOddFooter) sheet.getOddFooter();
+        assertNotNull(footer);
+        assertNull(footer.getText());
+        footer.setText("this is a test");
+        assertEquals("this is a test", footer.getText());
+    }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java
new file mode 100644 (file)
index 0000000..4f53c2f
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXSSFOddHeader {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testSetGetText() {
+        XSSFOddHeader header = (XSSFOddHeader) sheet.getOddHeader();
+        assertNotNull(header);
+        assertNull(header.getText());
+        header.setText("this is a test");
+        assertEquals("this is a test", header.getText());
+    }
+}
\ No newline at end of file
index 5a40456299c1c76722e43a30985e5f0e00e5bba4..09adc3561c59b36d999d510264be22850f717577 100644 (file)
@@ -1990,4 +1990,15 @@ public final class TestXSSFSheet extends BaseTestXSheet {
         
         assertEquals("There should not be any comments left!",  0, sheet.getCellComments().size());
     }
+    
+    @Test
+    public void testGetHeaderFooterProperties() throws IOException {
+         XSSFWorkbook wb = new XSSFWorkbook();
+         XSSFSheet sh = wb.createSheet();
+         
+         XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
+         assertNotNull(hfProp);
+         
+         wb.close();
+    }
 }
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFHeaderFooter.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFHeaderFooter.java
new file mode 100644 (file)
index 0000000..5a78f2b
--- /dev/null
@@ -0,0 +1,317 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel.extensions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.poi.xssf.usermodel.XSSFOddHeader;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
+
+public class TestXSSFHeaderFooter {
+    
+    private XSSFWorkbook wb;
+    private XSSFSheet sheet;
+    private XSSFHeaderFooter hO;
+    private XSSFHeaderFooter hE;
+    private XSSFHeaderFooter hF;
+    private XSSFHeaderFooter fO;
+    private XSSFHeaderFooter fE;
+    private XSSFHeaderFooter fF;
+    
+    @Before
+    public void before() {
+        wb = new XSSFWorkbook();
+        sheet = wb.createSheet();
+        hO = (XSSFHeaderFooter) sheet.getOddHeader();
+        hE = (XSSFHeaderFooter) sheet.getEvenHeader();
+        hF = (XSSFHeaderFooter) sheet.getFirstHeader();
+        fO = (XSSFHeaderFooter) sheet.getOddFooter();
+        fE = (XSSFHeaderFooter) sheet.getEvenFooter();
+        fF = (XSSFHeaderFooter) sheet.getFirstFooter();
+    }
+    
+    @After
+    public void after() throws Exception {
+        wb.close();
+    }
+
+    @Test
+    public void testGetHeaderFooter() {
+        CTHeaderFooter ctHf; 
+        ctHf = hO.getHeaderFooter();
+        assertNotNull(ctHf);
+        ctHf = hE.getHeaderFooter();
+        assertNotNull(ctHf);
+        ctHf = hF.getHeaderFooter();
+        assertNotNull(ctHf);
+        ctHf = fO.getHeaderFooter();
+        assertNotNull(ctHf);
+        ctHf = fE.getHeaderFooter();
+        assertNotNull(ctHf);
+        ctHf = fF.getHeaderFooter();
+        assertNotNull(ctHf);
+    }
+
+    @Test
+    public void testGetValue() {
+        assertEquals("", hO.getValue());
+        assertEquals("", hE.getValue());
+        assertEquals("", hF.getValue());
+        assertEquals("", fO.getValue());
+        assertEquals("", fE.getValue());
+        assertEquals("", fF.getValue());
+        hO.setLeft("Left value");
+        hO.setCenter("Center value");
+        hO.setRight("Right value");
+        hE.setLeft("LeftEvalue");
+        hE.setCenter("CenterEvalue");
+        hE.setRight("RightEvalue");
+        hF.setLeft("LeftFvalue");
+        hF.setCenter("CenterFvalue");
+        hF.setRight("RightFvalue");
+        assertEquals("&CCenter value&LLeft value&RRight value", hO.getValue());
+        assertEquals("&CCenterEvalue&LLeftEvalue&RRightEvalue", hE.getValue());
+        assertEquals("&CCenterFvalue&LLeftFvalue&RRightFvalue", hF.getValue());
+        fO.setLeft("Left value1");
+        fO.setCenter("Center value1");
+        fO.setRight("Right value1");
+        fE.setLeft("LeftEvalue1");
+        fE.setCenter("CenterEvalue1");
+        fE.setRight("RightEvalue1");
+        fF.setLeft("LeftFvalue1");
+        fF.setCenter("CenterFvalue1");
+        fF.setRight("RightFvalue1");
+        assertEquals("&CCenter value1&LLeft value1&RRight value1", fO.getValue());
+        assertEquals("&CCenterEvalue1&LLeftEvalue1&RRightEvalue1", fE.getValue());
+        assertEquals("&CCenterFvalue1&LLeftFvalue1&RRightFvalue1", fF.getValue());
+    }
+
+    @Ignore("Test not yet created")
+    public void testAreFieldsStripped() {
+        fail("Not yet implemented");
+    }
+
+    @Ignore("Test not yet created")
+    public void testSetAreFieldsStripped() {
+        fail("Not yet implemented");
+    }
+
+    @Test
+    public void testStripFields() {
+        String simple = "I am a test header";
+        String withPage = "I am a&P test header";
+        String withLots = "I&A am&N a&P test&T header&U";
+        String withFont = "I&22 am a&\"Arial,bold\" test header";
+        String withOtherAnds = "I am a&P test header&&";
+        String withOtherAnds2 = "I am a&P test header&a&b";
+        
+        assertEquals(simple, XSSFOddHeader.stripFields(simple));
+        assertEquals(simple, XSSFOddHeader.stripFields(withPage));
+        assertEquals(simple, XSSFOddHeader.stripFields(withLots));
+        assertEquals(simple, XSSFOddHeader.stripFields(withFont));
+        assertEquals(simple + "&&", XSSFOddHeader.stripFields(withOtherAnds));
+        assertEquals(simple + "&a&b", XSSFOddHeader.stripFields(withOtherAnds2));
+        
+        // Now test the default strip flag
+        hE.setCenter("Center");
+        hE.setLeft("In the left");
+    
+        assertEquals("In the left", hE.getLeft());
+        assertEquals("Center", hE.getCenter());
+        assertEquals("", hE.getRight());
+        
+        hE.setLeft("Top &P&F&D Left");
+        assertEquals("Top &P&F&D Left", hE.getLeft());
+        assertFalse(hE.areFieldsStripped());
+        
+        hE.setAreFieldsStripped(true);
+        assertEquals("Top  Left", hE.getLeft());
+        assertTrue(hE.areFieldsStripped());
+        
+        // Now even more complex
+        hE.setCenter("HEADER TEXT &P&N&D&T&Z&F&F&A&V");
+        assertEquals("HEADER TEXT &V", hE.getCenter());
+    }
+
+    @Test
+    public void testGetCenter() {
+        assertEquals("", hO.getCenter());
+        assertEquals("", hE.getCenter());
+        assertEquals("", hF.getCenter());
+        assertEquals("", fO.getCenter());
+        assertEquals("", fE.getCenter());
+        assertEquals("", fF.getCenter());
+        hO.setCenter("Center value");
+        hE.setCenter("CenterEvalue");
+        hF.setCenter("CenterFvalue");
+        assertEquals("Center value", hO.getCenter());
+        assertEquals("CenterEvalue", hE.getCenter());
+        assertEquals("CenterFvalue", hF.getCenter());
+        fO.setCenter("Center value1");
+        fE.setCenter("CenterEvalue1");
+        fF.setCenter("CenterFvalue1");
+        assertEquals("Center value1", fO.getCenter());
+        assertEquals("CenterEvalue1", fE.getCenter());
+        assertEquals("CenterFvalue1", fF.getCenter());
+    }
+
+    @Test
+    public void testGetLeft() {
+        assertEquals("", hO.getLeft());
+        assertEquals("", hE.getLeft());
+        assertEquals("", hF.getLeft());
+        assertEquals("", fO.getLeft());
+        assertEquals("", fE.getLeft());
+        assertEquals("", fF.getLeft());
+        hO.setLeft("Left value");
+        hE.setLeft("LeftEvalue");
+        hF.setLeft("LeftFvalue");
+        assertEquals("Left value", hO.getLeft());
+        assertEquals("LeftEvalue", hE.getLeft());
+        assertEquals("LeftFvalue", hF.getLeft());
+        fO.setLeft("Left value1");
+        fE.setLeft("LeftEvalue1");
+        fF.setLeft("LeftFvalue1");
+        assertEquals("Left value1", fO.getLeft());
+        assertEquals("LeftEvalue1", fE.getLeft());
+        assertEquals("LeftFvalue1", fF.getLeft());
+    }
+
+    @Test
+    public void testGetRight() {
+        assertEquals("", hO.getValue());
+        assertEquals("", hE.getValue());
+        assertEquals("", hF.getValue());
+        assertEquals("", fO.getValue());
+        assertEquals("", fE.getValue());
+        assertEquals("", fF.getValue());
+        hO.setRight("Right value");
+        hE.setRight("RightEvalue");
+        hF.setRight("RightFvalue");
+        assertEquals("Right value", hO.getRight());
+        assertEquals("RightEvalue", hE.getRight());
+        assertEquals("RightFvalue", hF.getRight());
+        fO.setRight("Right value1");
+        fE.setRight("RightEvalue1");
+        fF.setRight("RightFvalue1");
+        assertEquals("Right value1", fO.getRight());
+        assertEquals("RightEvalue1", fE.getRight());
+        assertEquals("RightFvalue1", fF.getRight());
+    }
+
+    @Test
+    public void testSetCenter() {
+        assertEquals("", hO.getValue());
+        assertEquals("", hE.getValue());
+        assertEquals("", hF.getValue());
+        assertEquals("", fO.getValue());
+        assertEquals("", fE.getValue());
+        assertEquals("", fF.getValue());
+        hO.setCenter("Center value");
+        hE.setCenter("CenterEvalue");
+        hF.setCenter("CenterFvalue");
+        assertEquals("&CCenter value", hO.getValue());
+        assertEquals("&CCenterEvalue", hE.getValue());
+        assertEquals("&CCenterFvalue", hF.getValue());
+        fO.setCenter("Center value1");
+        fE.setCenter("CenterEvalue1");
+        fF.setCenter("CenterFvalue1");
+        assertEquals("&CCenter value1", fO.getValue());
+        assertEquals("&CCenterEvalue1", fE.getValue());
+        assertEquals("&CCenterFvalue1", fF.getValue());
+    }
+
+    @Test
+    public void testSetLeft() {
+        assertEquals("", hO.getValue());
+        assertEquals("", hE.getValue());
+        assertEquals("", hF.getValue());
+        assertEquals("", fO.getValue());
+        assertEquals("", fE.getValue());
+        assertEquals("", fF.getValue());
+        hO.setLeft("Left value");
+        hE.setLeft("LeftEvalue");
+        hF.setLeft("LeftFvalue");
+        assertEquals("&LLeft value", hO.getValue());
+        assertEquals("&LLeftEvalue", hE.getValue());
+        assertEquals("&LLeftFvalue", hF.getValue());
+        fO.setLeft("Left value1");
+        fE.setLeft("LeftEvalue1");
+        fF.setLeft("LeftFvalue1");
+        assertEquals("&LLeft value1", fO.getValue());
+        assertEquals("&LLeftEvalue1", fE.getValue());
+        assertEquals("&LLeftFvalue1", fF.getValue());
+    }
+
+    @Test
+    public void testSetRight() {
+        assertEquals("", hO.getValue());
+        assertEquals("", hE.getValue());
+        assertEquals("", hF.getValue());
+        assertEquals("", fO.getValue());
+        assertEquals("", fE.getValue());
+        assertEquals("", fF.getValue());
+        hO.setRight("Right value");
+        hE.setRight("RightEvalue");
+        hF.setRight("RightFvalue");
+        assertEquals("&RRight value", hO.getValue());
+        assertEquals("&RRightEvalue", hE.getValue());
+        assertEquals("&RRightFvalue", hF.getValue());
+        fO.setRight("Right value1");
+        fE.setRight("RightEvalue1");
+        fF.setRight("RightFvalue1");
+        assertEquals("&RRight value1", fO.getValue());
+        assertEquals("&RRightEvalue1", fE.getValue());
+        assertEquals("&RRightFvalue1", fF.getValue());
+    }
+    
+
+    @Test
+    public void testGetSetCenterLeftRight() {
+        
+        assertEquals("", fO.getCenter());
+        fO.setCenter("My first center section");
+        assertEquals("My first center section", fO.getCenter());
+        fO.setCenter("No, let's update the center section");
+        assertEquals("No, let's update the center section", fO.getCenter());
+        fO.setLeft("And add a left one");
+        fO.setRight("Finally the right section is added");
+        assertEquals("And add a left one", fO.getLeft());
+        assertEquals("Finally the right section is added", fO.getRight());
+        
+        // Test changing the three sections value
+        fO.setCenter("Second center version");
+        fO.setLeft("Second left version");
+        fO.setRight("Second right version");
+        assertEquals("Second center version", fO.getCenter());
+        assertEquals("Second left version", fO.getLeft());
+        assertEquals("Second right version", fO.getRight());
+        
+    }    
+}