From ec521065e2af78f002dfd75051471f3f967945c8 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 6 Jan 2009 19:09:02 +0000 Subject: [PATCH] Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@732063 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../poi/POIXMLPropertiesTextExtractor.java | 2 +- .../org/apache/poi/POIXMLTextExtractor.java | 4 ++-- .../poi/TestXMLPropertiesTextExtractor.java | 24 +++++++++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 63002aae8..410abba48 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor 46472 - Avoid NPE in HPSFPropertiesExtractor when no properties exist 46479 - fixed bugs related to cached formula values and HSSFFormulaEvaluator.evaluateInCell() 45031 - added implementation for CHOOSE() function diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 8878fce6f..e9e6761cb 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor 46472 - Avoid NPE in HPSFPropertiesExtractor when no properties exist 46479 - fixed bugs related to cached formula values and HSSFFormulaEvaluator.evaluateInCell() 45031 - added implementation for CHOOSE() function diff --git a/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java index 455b8ab1b..320c6e143 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java +++ b/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java @@ -136,7 +136,7 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor { } } - public POITextExtractor getMetadataTextExtractor() { + public POIXMLPropertiesTextExtractor getMetadataTextExtractor() { throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!"); } } diff --git a/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java index 7c04aa079..c6a99436b 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java +++ b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java @@ -66,7 +66,7 @@ public abstract class POIXMLTextExtractor extends POITextExtractor { * Returns an OOXML properties text extractor for the * document properties metadata, such as title and author. */ - public POITextExtractor getMetadataTextExtractor() { - throw new RuntimeException("Not yet supported for OOXML!"); + public POIXMLPropertiesTextExtractor getMetadataTextExtractor() { + return new POIXMLPropertiesTextExtractor(document); } } diff --git a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java index a8cf7ea99..8ff64a850 100644 --- a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java @@ -18,9 +18,12 @@ package org.apache.poi; import java.io.File; +import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openxml4j.opc.Package; +import sun.awt.X11.XModifierKeymap; + import junit.framework.TestCase; public class TestXMLPropertiesTextExtractor extends TestCase { @@ -30,6 +33,27 @@ public class TestXMLPropertiesTextExtractor extends TestCase { dirname = System.getProperty("OOXML.testdata.path"); assertTrue( (new File(dirname)).exists() ); } + + public void testGetFromMainExtractor() throws Exception { + org.openxml4j.opc.Package pkg = Package.open( + (new File(dirname, "ExcelWithAttachments.xlsx")).toString() + ); + XSSFWorkbook wb = new XSSFWorkbook(pkg); + + XSSFExcelExtractor ext = new XSSFExcelExtractor(wb); + POIXMLPropertiesTextExtractor textExt = ext.getMetadataTextExtractor(); + + // Check basics + assertNotNull(textExt); + assertTrue(textExt.getText().length() > 0); + + // Check some of the content + String text = textExt.getText(); + String cText = textExt.getCorePropertiesText(); + + assertTrue(text.contains("LastModifiedBy = Yury Batrakov")); + assertTrue(cText.contains("LastModifiedBy = Yury Batrakov")); + } public void testCore() throws Exception { org.openxml4j.opc.Package pkg = Package.open(