aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java')
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java154
1 files changed, 65 insertions, 89 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
index 6ccbf46241..f18e0c7bd2 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
@@ -19,13 +19,13 @@ package org.apache.poi.xwpf.usermodel;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.xmlbeans.XmlCursor;
@@ -47,40 +47,31 @@ public class XWPFHeader extends XWPFHeaderFooter {
}
public XWPFHeader(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel) throws IOException {
- super(parent, part, rel);
- }
-
- public XWPFHeader(XWPFDocument doc, CTHdrFtr hdrFtr) throws IOException {
- super(doc, hdrFtr);
- paragraphs = new ArrayList<XWPFParagraph>();
- tables = new ArrayList<XWPFTable>();
- XmlCursor cursor = headerFooter.newCursor();
- cursor.selectPath("./*");
- while (cursor.toNextSelection()) {
- XmlObject o = cursor.getObject();
- if (o instanceof CTP) {
- XWPFParagraph p = new XWPFParagraph((CTP) o, this);
- paragraphs.add(p);
- }
- if (o instanceof CTTbl) {
- XWPFTable t = new XWPFTable((CTTbl) o, this);
- tables.add(t);
- }
- }
+ super(parent, part, rel);
+ }
+
+ public XWPFHeader(XWPFDocument doc, CTHdrFtr hdrFtr) {
+ super(doc, hdrFtr);
+ XmlCursor cursor = headerFooter.newCursor();
+ cursor.selectPath("./*");
+ while (cursor.toNextSelection()) {
+ XmlObject o = cursor.getObject();
+ if (o instanceof CTP) {
+ XWPFParagraph p = new XWPFParagraph((CTP) o, this);
+ paragraphs.add(p);
+ }
+ if (o instanceof CTTbl) {
+ XWPFTable t = new XWPFTable((CTTbl) o, this);
+ tables.add(t);
+ }
+ }
cursor.dispose();
- getAllPictures();
- }
+ }
/**
- public XWPFHeader(PackagePart part, PackageRelationship rel)
- throws IOException {
- super(part, rel);
- }
-
- /**
- * save and commit footer
- */
- @Override
+ * 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"));
@@ -101,62 +92,47 @@ public class XWPFHeader extends XWPFHeaderFooter {
out.close();
}
- /**
- * reads the document
- */
- @Override
- protected void onDocumentRead(){
- bodyElements = new ArrayList<IBodyElement>();
- paragraphs = new ArrayList<XWPFParagraph>();
- tables= new ArrayList<XWPFTable>();
- HdrDocument hdrDocument = null;
- InputStream is;
- try {
- is = getPackagePart().getInputStream();
- hdrDocument = HdrDocument.Factory.parse(is);
- headerFooter = hdrDocument.getHdr();
- // parse the document with cursor and add
- // the XmlObject to its lists
- XmlCursor cursor = headerFooter.newCursor();
- cursor.selectPath("./*");
- while (cursor.toNextSelection()) {
- XmlObject o = cursor.getObject();
- if (o instanceof CTP) {
- XWPFParagraph p = new XWPFParagraph((CTP)o, this);
- paragraphs.add(p);
- bodyElements.add(p);
- }
- if (o instanceof CTTbl) {
- XWPFTable t = new XWPFTable((CTTbl)o, this);
- tables.add(t);
- bodyElements.add(t);
- }
- }
- cursor.dispose();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (XmlException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- /**
- * 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 IBody getPart() {
- return this;
- }
-
- /**
- * get the PartType of the body
- * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
- */
- public BodyType getPartType() {
- return BodyType.HEADER;
- }
-
+ /**
+ * reads the document
+ * @throws IOException
+ */
+ @Override
+ protected void onDocumentRead() throws IOException {
+ super.onDocumentRead();
+ HdrDocument hdrDocument = null;
+ InputStream is;
+ try {
+ is = getPackagePart().getInputStream();
+ hdrDocument = HdrDocument.Factory.parse(is);
+ headerFooter = hdrDocument.getHdr();
+ // parse the document with cursor and add
+ // the XmlObject to its lists
+ XmlCursor cursor = headerFooter.newCursor();
+ cursor.selectPath("./*");
+ while (cursor.toNextSelection()) {
+ XmlObject o = cursor.getObject();
+ if (o instanceof CTP) {
+ XWPFParagraph p = new XWPFParagraph((CTP)o, this);
+ paragraphs.add(p);
+ bodyElements.add(p);
+ }
+ if (o instanceof CTTbl) {
+ XWPFTable t = new XWPFTable((CTTbl)o, this);
+ tables.add(t);
+ bodyElements.add(t);
+ }
+ }
+ cursor.dispose();
+ } catch (XmlException e) {
+ throw new POIXMLException(e);
+ }
+ }
+ /**
+ * get the PartType of the body
+ * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
+ */
+ public BodyType getPartType() {
+ return BodyType.HEADER;
+ }
}//end class