]> source.dussan.org Git - poi.git/commitdiff
Support stripping XSSF header and footer fields (eg page number) out of header and...
authorNick Burch <nick@apache.org>
Thu, 14 Aug 2008 22:09:47 +0000 (22:09 +0000)
committerNick Burch <nick@apache.org>
Thu, 14 Aug 2008 22:09:47 +0000 (22:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@686059 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Footer.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Header.java
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooter.java

index 09fcd8574be6e5ec8cb0be54fb26775384acb7a9..c069267b7e390dc458dc0f643519d3768a456ca4 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5.1-beta2" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Support stripping XSSF header and footer fields (eg page number) out of header and footer text if required</action>
            <action dev="POI-DEVELOPERS" type="add">Add POIXMLPropertiesTextExtractor, which provides to the OOXML file formats a similar function to HPSF's HPSFPropertiesExtractor</action>
            <action dev="POI-DEVELOPERS" type="add">45539 - Improve XWPFWordExtractor to extract headers and footers</action>
            <action dev="POI-DEVELOPERS" type="fix">Improve how XWPF handles paragraph text</action>
index 282ee631e45c347527e9da3fcc29c75cd8209faa..b9b02cc64de1db78752129139a515b9b78885e27 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5.1-beta2" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Support stripping XSSF header and footer fields (eg page number) out of header and footer text if required</action>
            <action dev="POI-DEVELOPERS" type="add">Add POIXMLPropertiesTextExtractor, which provides to the OOXML file formats a similar function to HPSF's HPSFPropertiesExtractor</action>
            <action dev="POI-DEVELOPERS" type="add">45539 - Improve XWPFWordExtractor to extract headers and footers</action>
            <action dev="POI-DEVELOPERS" type="fix">Improve how XWPF handles paragraph text</action>
index 499cda7920aadb7b9dbe7b9639f40989cc3f7da3..2f0aa8a07db6d4df05e40587d3f96264cf480c17 100644 (file)
@@ -265,7 +265,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
        
        /**
         * Are fields currently being stripped from
-        *  the text that this {@link HeaderStories} returns?
+        *  the text that this {@link HeaderFooter} returns?
         *  Default is false, but can be changed
         */
        public boolean areFieldsStripped() {
index de592a1462abdc47913d03ac085170e0dae428f3..4a1bbfbb068774d311c05279a26c2d78f40350d8 100644 (file)
 
 package org.apache.poi.ss.usermodel;
 
+/**
+ * Common definition of a HSSF or XSSF page footer.
+ * For a list of all the different fields that can be
+ *  placed into a footer, such as page number,
+ *  bold, underline etc, see 
+ *  {@link org.apache.poi.hssf.usermodel.HeaderFooter}.
+ */
 public interface Footer extends HeaderFooter {
     /**
      * Get the left side of the footer.
index 9e864b5739e201a93f11e154e4cf5b90197998ce..e06345c9f55925642aec8aceaa4193173a5553e4 100644 (file)
 
 package org.apache.poi.ss.usermodel;
 
+/**
+ * Common definition of a HSSF or XSSF page header.
+ * For a list of all the different fields that can be
+ *  placed into a header, such as page number,
+ *  bold, underline etc, see 
+ *  {@link org.apache.poi.hssf.usermodel.HeaderFooter}.
+ */
 public interface Header extends HeaderFooter {
     /**
      * Get the left side of the header.
index 8c79761e950019cb68335171b52ba2efed7b7924..5a9e4cda0de2b8dda2fba2dc3d8d49f7567cb41c 100644 (file)
@@ -21,10 +21,20 @@ import org.apache.poi.ss.usermodel.HeaderFooter;
 import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
 
+/**
+ * Parent class of all XSSF headers and footers.
+ * 
+ * For a list of all the different fields that can be
+ *  placed into a header or footer, such as page number,
+ *  bold, underline etc, see 
+ *  {@link org.apache.poi.hssf.usermodel.HeaderFooter}.
+ */
 public abstract class XSSFHeaderFooter implements HeaderFooter {
     private HeaderFooterHelper helper;
     private CTHeaderFooter headerFooter;
 
+       private boolean stripFields = false;
+       
     public XSSFHeaderFooter(CTHeaderFooter headerFooter) {
        this.headerFooter = headerFooter;
        this.helper = new HeaderFooterHelper();
@@ -41,20 +51,53 @@ public abstract class XSSFHeaderFooter implements HeaderFooter {
         return value;
     }
     
+    
+       /**
+        * Are fields currently being stripped from
+        *  the text that this {@link XSSFHeaderFooter} returns?
+        *  Default is false, but can be changed
+        */
+       public boolean areFieldsStripped() {
+               return stripFields;
+       }
+       /**
+        * Should fields (eg macros) be stripped from
+        *  the text that this class returns?
+        * Default is not to strip.
+        * @param stripFields
+        */
+       public void setAreFieldsStripped(boolean stripFields) {
+               this.stripFields = stripFields;
+       }
+       
+       public static String stripFields(String text) {
+               return org.apache.poi.hssf.usermodel.HeaderFooter.stripFields(text);
+       }
+
+    
     public abstract String getText();
     
     protected abstract void setText(String text);
 
     public String getCenter() {
-        return helper.getCenterSection(getText());
+       String text = helper.getCenterSection(getText()); 
+       if(stripFields)
+               return stripFields(text);
+        return text;
     }
 
     public String getLeft() {
-        return helper.getLeftSection(getText());
+        String text = helper.getLeftSection(getText());
+       if(stripFields)
+               return stripFields(text);
+        return text;
     }
 
     public String getRight() {
-        return helper.getRightSection(getText());
+        String text = helper.getRightSection(getText());
+       if(stripFields)
+               return stripFields(text);
+        return text;
     }
 
     public void setCenter(String newCenter) {
@@ -68,5 +111,4 @@ public abstract class XSSFHeaderFooter implements HeaderFooter {
     public void setRight(String newRight) {
         setText(helper.setRightSection(getText(), newRight));
     }
-
 }
index 52df16ab38ec70c35966a36a73b3af25322f7ca9..97e0218c11604dce990c9c5bef862881adda296d 100644 (file)
 
 package org.apache.poi.xssf.usermodel;
 
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
+
 import junit.framework.TestCase;
 
 public class TestXSSFHeaderFooter extends TestCase {
-       // So eclipse doesn't moan
-       public void testTODO() {
+       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&G");
+       assertEquals("HEADER TEXT &G", head.getCenter());
        }
+       
+       // TODO Rest of tests
 }