Hi,

I have worked locally on changes to fix the class hierarchy of
POITextExtractor and it's child-classes. Currently the base class
holds a POIDocument, but only a few of the derived classes actually
use it, so it makes sense to keep the POIDocument only for those
classes where we are going to make use of it.

I would like to fix this by moving the POIDocument member to the point
in the class-hierarchy where it is actually used, POIOLE2TextExtractor
to not pollute the classes under POIXMLTextExtractor with this.

Please see the attached patch and let me know if you think we cannot
do this change because of backwards compatibility (there could be a
problem if someone is deriving a custom POITextExtractor and thus
would need to adjust the super() in order to compile again). I propose
to note this as "incompatible change" in the release notes of the next
version.

Any reason we should not do this change?

Thanks... Dominik.
From 70e26bb4d011c46edef643caba20e0f4607076b1 Mon Sep 17 00:00:00 2001
From: Dominik Stadler <[email protected]>
Date: Sun, 1 Mar 2015 17:17:23 +0100
Subject: [PATCH] Move location where document is held and adjust constructors
 and class-hierarchy accordingly

---
 src/java/org/apache/poi/POIOLE2TextExtractor.java      | 14 +++++++++++++-
 src/java/org/apache/poi/POITextExtractor.java          | 18 ------------------
 .../poi/hpsf/extractor/HPSFPropertiesExtractor.java    |  5 +++--
 .../poi/hssf/extractor/EventBasedExcelExtractor.java   |  3 ++-
 src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java |  2 --
 5 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/java/org/apache/poi/POIOLE2TextExtractor.java b/src/java/org/apache/poi/POIOLE2TextExtractor.java
index 7679136..5dd1d75 100644
--- a/src/java/org/apache/poi/POIOLE2TextExtractor.java
+++ b/src/java/org/apache/poi/POIOLE2TextExtractor.java
@@ -33,16 +33,28 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry;
  * @see org.apache.poi.hwpf.extractor.WordExtractor
  */
 public abstract class POIOLE2TextExtractor extends POITextExtractor {
+	/** The POIDocument that's open */
+	protected POIDocument document;
+
 	/**
 	 * Creates a new text extractor for the given document
 	 * 
 	 * @param document The POIDocument to use in this extractor.
 	 */
 	public POIOLE2TextExtractor(POIDocument document) {
-		super(document);
+		this.document = document;
 	}
 
 	/**
+	 * Creates a new text extractor, using the same
+	 *  document as another text extractor. Normally
+	 *  only used by properties extractors.
+	 */
+	protected POIOLE2TextExtractor(POIOLE2TextExtractor otherExtractor) {
+		this.document = otherExtractor.document;
+	}
+	
+	/**
 	 * Returns the document information metadata for the document
 	 * 
      * @return The Document Summary Information or null 
diff --git a/src/java/org/apache/poi/POITextExtractor.java b/src/java/org/apache/poi/POITextExtractor.java
index e18078b..6514ad5 100644
--- a/src/java/org/apache/poi/POITextExtractor.java
+++ b/src/java/org/apache/poi/POITextExtractor.java
@@ -31,24 +31,6 @@ import java.io.IOException;
  * @see org.apache.poi.hwpf.extractor.WordExtractor
  */
 public abstract class POITextExtractor implements Closeable {
-	/** The POIDocument that's open */
-	protected POIDocument document;
-
-	/**
-	 * Creates a new text extractor for the given document
-	 */
-	public POITextExtractor(POIDocument document) {
-		this.document = document;
-	}
-	/**
-	 * Creates a new text extractor, using the same
-	 *  document as another text extractor. Normally
-	 *  only used by properties extractors.
-	 */
-	protected POITextExtractor(POITextExtractor otherExtractor) {
-		this.document = otherExtractor.document;
-	}
-	
 	/**
 	 * Retrieves all the text from the document.
 	 * How cells, paragraphs etc are separated in the text
diff --git a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
index 1a0db03..b7967f3 100644
--- a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
+++ b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.Iterator;
 
 import org.apache.poi.POIDocument;
+import org.apache.poi.POIOLE2TextExtractor;
 import org.apache.poi.POITextExtractor;
 import org.apache.poi.hpsf.CustomProperties;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
@@ -39,10 +40,10 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  *  build in and custom, returning them in
  *  textual form.
  */
-public class HPSFPropertiesExtractor extends POITextExtractor {
+public class HPSFPropertiesExtractor extends POIOLE2TextExtractor {
     private Closeable toClose;
 
-    public HPSFPropertiesExtractor(POITextExtractor mainExtractor) {
+    public HPSFPropertiesExtractor(POIOLE2TextExtractor mainExtractor) {
         super(mainExtractor);
     }
     public HPSFPropertiesExtractor(POIDocument doc) {
diff --git a/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
index 889de20..debeee9 100644
--- a/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
+++ b/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.poi.POIDocument;
 import org.apache.poi.POIOLE2TextExtractor;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.SummaryInformation;
@@ -75,7 +76,7 @@ public class EventBasedExcelExtractor extends POIOLE2TextExtractor implements or
 
     public EventBasedExcelExtractor( DirectoryNode dir )
     {
-        super( null );
+        super( (POIDocument)null );
         _dir = dir;
     }
 
diff --git a/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java
index 3a600f4..705bf42 100644
--- a/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java
+++ b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java
@@ -32,8 +32,6 @@ public abstract class POIXMLTextExtractor extends POITextExtractor {
 	 * Creates a new text extractor for the given document
 	 */
 	public POIXMLTextExtractor(POIXMLDocument document) {
-		super((POIDocument)null);
-
 		_document = document;
 	}
 
-- 
2.1.4

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to