mirror of https://github.com/apache/poi.git
Support stripping XSSF header and footer fields (eg page number) out of header and footer text if required
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@686059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
65144ee101
commit
3a7210c20d
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
|
||||
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.
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
|
||||
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.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,47 @@
|
|||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue