You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/08/09 13:27:30 UTC
svn commit: r684229 - in /poi/branches/ooxml: ./
src/ooxml/java/org/apache/poi/xwpf/
src/ooxml/java/org/apache/poi/xwpf/usermodel/
src/ooxml/testcases/org/apache/poi/xwpf/extractor/
Author: nick
Date: Sat Aug 9 04:27:29 2008
New Revision: 684229
URL: http://svn.apache.org/viewvc?rev=684229&view=rev
Log:
Start on xwpf header/footer support
Added:
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java (with props)
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java (with props)
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (with props)
Modified:
poi/branches/ooxml/ (props changed)
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
Propchange: poi/branches/ooxml/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat Aug 9 04:27:29 2008
@@ -1 +1 @@
-/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-684213
+/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-684223
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java?rev=684229&r1=684228&r2=684229&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java Sat Aug 9 04:27:29 2008
@@ -35,10 +35,14 @@
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;
@@ -57,8 +61,10 @@
*/
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";
@@ -69,6 +75,10 @@
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);
@@ -122,6 +132,24 @@
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()
+ );
+ }
}
/**
@@ -141,8 +169,7 @@
return tables.iterator();
}
- public XWPFHyperlink getHyperlinkByID(String id)
- {
+ public XWPFHyperlink getHyperlinkByID(String id) {
Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
while(iter.hasNext())
{
@@ -153,9 +180,13 @@
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())
{
@@ -166,6 +197,18 @@
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
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java?rev=684229&r1=684228&r2=684229&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java Sat Aug 9 04:27:29 2008
@@ -31,4 +31,25 @@
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();
+ }
}
Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java?rev=684229&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java Sat Aug 9 04:27:29 2008
@@ -0,0 +1,32 @@
+/* ====================================================================
+ 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);
+ }
+
+}
Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java?rev=684229&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java Sat Aug 9 04:27:29 2008
@@ -0,0 +1,32 @@
+/* ====================================================================
+ 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);
+ }
+
+}
Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java?rev=684229&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java Sat Aug 9 04:27:29 2008
@@ -0,0 +1,33 @@
+/* ====================================================================
+ 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();
+ }
+}
Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=684229&r1=684228&r2=684229&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java Sat Aug 9 04:27:29 2008
@@ -111,7 +111,7 @@
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(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org