poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r795329 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/xwpf/usermodel/ ooxml/testcases/org/apache/poi/xwpf/extractor/ scratchpad/testcases/org/apache/poi/hwpf/data/
Date Sat, 18 Jul 2009 09:28:53 GMT
Author: yegor
Date: Sat Jul 18 09:28:38 2009
New Revision: 795329

URL: http://svn.apache.org/viewvc?rev=795329&view=rev
Log:
Support for extraction of endnotes from docx files

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=795329&r1=795328&r2=795329&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sat Jul 18 09:28:38 2009
@@ -33,8 +33,9 @@
 
     <changes>
         <release version="3.5-beta7" date="2009-??-??">
-           <action dev="POI-DEVELOPERS" type="fix">45556 - Fixed ExtractorFactory to
support .xltx and .dotx files</action>
+           <action dev="POI-DEVELOPERS" type="fix">47517 - Fixed ExtractorFactory to
support .xltx and .dotx files</action>
            <action dev="POI-DEVELOPERS" type="add">45556 - Support for extraction of
footnotes from docx files</action>
+           <action dev="POI-DEVELOPERS" type="add">45555 - Support for extraction of
endnotes from docx files</action>
            <action dev="POI-DEVELOPERS" type="add">47520 - Initial support for custom
XML mappings in XSSF</action>
            <action dev="POI-DEVELOPERS" type="fix">47460 - Fixed NPE when retrieving
core properties from a newly created workbook</action>
            <action dev="POI-DEVELOPERS" type="fix">47498 - Fixed HyperlinkRecord to
properly handle URL monikers</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=795329&r1=795328&r2=795329&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Sat Jul 18 09:28:38
2009
@@ -53,6 +53,7 @@
     protected List<XWPFParagraph> paragraphs;
     protected List<XWPFTable> tables;
     protected Map<Integer, XWPFFootnote> footnotes;
+    protected Map<Integer, XWPFFootnote> endnotes;
 
     /** Handles the joy of different headers/footers for different pages */
     private XWPFHeaderFooterPolicy headerFooterPolicy;
@@ -81,6 +82,7 @@
         paragraphs = new ArrayList<XWPFParagraph>();
         tables= new ArrayList<XWPFTable>();
         footnotes = new HashMap<Integer, XWPFFootnote>();
+        endnotes = new HashMap<Integer, XWPFFootnote>();
 
         try {
             DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
@@ -143,6 +145,12 @@
                 for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteArray())
{
                     footnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
                 }
+            } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
+                EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
+
+                for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray())
{
+                    endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
+                }
             }
         }
     }
@@ -218,6 +226,10 @@
         return footnotes.get(id);
     }
 
+    public XWPFFootnote getEndnoteByID(int id) {
+        return endnotes.get(id);
+    }
+
     public Collection<XWPFFootnote> getFootnotes() {
         return footnotes == null ? new ArrayList<XWPFFootnote>() : footnotes.values();
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java?rev=795329&r1=795328&r2=795329&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java Sat Jul 18 09:28:38
2009
@@ -93,7 +93,10 @@
                     if (o instanceof CTFtnEdnRef) {
                         CTFtnEdnRef ftn = (CTFtnEdnRef) o;
                         footnoteText.append("[").append(ftn.getId()).append(": ");
-                        XWPFFootnote footnote = document.getFootnoteByID(ftn.getId().intValue());
+                        XWPFFootnote footnote = 
+                                ftn.getDomNode().getLocalName().equals("footnoteReference")
?
+                                        document.getFootnoteByID(ftn.getId().intValue())
:
+                                        document.getEndnoteByID(ftn.getId().intValue());
 
                         boolean first = true;
                         for (XWPFParagraph p : footnote.getParagraphs()) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java?rev=795329&r1=795328&r2=795329&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java Sat Jul 18 09:28:38
2009
@@ -112,6 +112,12 @@
             null,
             null
     );
+    public static final XWPFRelation ENDNOTE = new XWPFRelation(
+            null,
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes",
+            null,
+            null
+    );
 
 
     private XWPFRelation(String type, String rel, String defaultName, Class<? extends
POIXMLDocumentPart> cls) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=795329&r1=795328&r2=795329&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
Sat Jul 18 09:28:38 2009
@@ -185,7 +185,15 @@
         assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
     }
 
-    //TODO use the same logic as in HSSFTestDataSamples
+    public void testEndnotes() throws Exception {
+        XWPFDocument doc = open("endnotes.docx");
+        XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
+
+        assertTrue(extractor.getText().contains("XXX"));
+    }
+
+
+    //TODO use the same logic for opening test files as in HSSFTestDataSamples
     private XWPFDocument open(String sampleFileName) throws IOException {
         File file = new File(
                 System.getProperty("HWPF.testdata.path"), sampleFileName);

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx?rev=795329&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message