import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
+import org.apache.poi.xwpf.usermodel.XWPFFooter;
+import org.apache.poi.xwpf.usermodel.XWPFHeader;
import org.apache.poi.xwpf.usermodel.XWPFHyperlink;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFComment;
*/
public class XWPFDocument extends POIXMLDocument {
public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
- public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
public static final String HEADER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";
+ public static final String HEADER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
+ public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
+ public static final String FOOTER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
public static final String STYLES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
public static final String STYLES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
public static final String HYPERLINK_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
protected List<XWPFHyperlink> hyperlinks;
protected List<XWPFParagraph> paragraphs;
protected List<XWPFTable> tables;
+ /** Should only ever be zero or one of these, we think */
+ protected XWPFHeader header;
+ /** Should only ever be zero or one of these, we think */
+ protected XWPFFooter footer;
public XWPFDocument(Package container) throws OpenXML4JException, IOException, XmlException {
super(container);
for(PackageRelationship rel : getCorePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
embedds.add(getTargetPart(rel));
}
+
+ // Fetch the header, if there's one
+ PackageRelationshipCollection headerRel = getCorePart().getRelationshipsByType(HEADER_RELATION_TYPE);
+ if(headerRel != null && headerRel.size() > 0) {
+ PackagePart headerPart = getTargetPart(headerRel.getRelationship(0));
+ header = new XWPFHeader(
+ HdrDocument.Factory.parse(headerPart.getInputStream()).getHdr()
+ );
+ }
+
+ // Fetch the footer, if there's one
+ PackageRelationshipCollection footerRel = getCorePart().getRelationshipsByType(FOOTER_RELATION_TYPE);
+ if(footerRel != null && footerRel.size() > 0) {
+ PackagePart footerPart = getTargetPart(footerRel.getRelationship(0));
+ footer = new XWPFFooter(
+ FtrDocument.Factory.parse(footerPart.getInputStream()).getFtr()
+ );
+ }
}
/**
return tables.iterator();
}
- public XWPFHyperlink getHyperlinkByID(String id)
- {
+ public XWPFHyperlink getHyperlinkByID(String id) {
Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
while(iter.hasNext())
{
return null;
}
+ public XWPFHyperlink[] getHyperlinks() {
+ return hyperlinks.toArray(
+ new XWPFHyperlink[hyperlinks.size()]
+ );
+ }
- public XWPFComment getCommentByID(String id)
- {
+ public XWPFComment getCommentByID(String id) {
Iterator<XWPFComment> iter = comments.iterator();
while(iter.hasNext())
{
return null;
}
+ public XWPFComment[] getComments() {
+ return comments.toArray(
+ new XWPFComment[comments.size()]
+ );
+ }
+
+ public XWPFHeader getDocumentHeader() {
+ return header;
+ }
+ public XWPFFooter getDocumentFooter() {
+ return footer;
+ }
/**
* Returns the low level body of the document
public XWPFDocument _getXWPFXML() {
return xwpfXML;
}
+
+ public XWPFHyperlink getHyperlinkByID(String id) {
+ return xwpfXML.getHyperlinkByID(id);
+ }
+ public XWPFHyperlink[] getHyperlinks() {
+ return xwpfXML.getHyperlinks();
+ }
+
+ public XWPFComment getCommentByID(String id) {
+ return xwpfXML.getCommentByID(id);
+ }
+ public XWPFComment[] getComments() {
+ return xwpfXML.getComments();
+ }
+
+ public XWPFHeader getHeader() {
+ return xwpfXML.getDocumentHeader();
+ }
+ public XWPFFooter getFooter() {
+ return xwpfXML.getDocumentFooter();
+ }
}
--- /dev/null
+/* ====================================================================
+ 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.xwpf.usermodel;
+
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
+
+/**
+ * Sketch of XWPF footer class
+ */
+public class XWPFFooter extends XWPFHeaderFooter {
+ public XWPFFooter() {
+ super();
+ }
+ public XWPFFooter(CTHdrFtr hdrFtr) {
+ super(hdrFtr);
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ 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.xwpf.usermodel;
+
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
+
+/**
+ * Sketch of XWPF header class
+ */
+public class XWPFHeader extends XWPFHeaderFooter {
+ public XWPFHeader() {
+ super();
+ }
+ public XWPFHeader(CTHdrFtr hdrFtr) {
+ super(hdrFtr);
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ 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.xwpf.usermodel;
+
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
+
+/**
+ * Parent of XWPF headers and footers
+ */
+public abstract class XWPFHeaderFooter {
+ protected CTHdrFtr headerFooter;
+
+ protected XWPFHeaderFooter(CTHdrFtr hdrFtr) {
+ headerFooter = hdrFtr;
+ }
+ protected XWPFHeaderFooter() {
+ headerFooter = CTHdrFtr.Factory.newInstance();
+ }
+}
assertTrue(text.length() > 0);
char euro = '\u20ac';
- System.err.println("'"+text.substring(text.length() - 20) + "'");
+// System.err.println("'"+text.substring(text.length() - 20) + "'");
// Check contents
assertTrue(text.startsWith(