From 90b74675d59b2ff0dc0b21ed217a15dba62133b5 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 26 Jun 2013 00:10:43 +0000 Subject: [PATCH] Pull the Properties-Only document type out to a superclass, so other places (eg unit tests) can use it git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1496680 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hpsf/HPSFPropertiesOnlyDocument.java | 26 +++++++++++++++++++ .../extractor/HPSFPropertiesExtractor.java | 23 +++------------- 2 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java diff --git a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java new file mode 100644 index 000000000..196cabbbb --- /dev/null +++ b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java @@ -0,0 +1,26 @@ +package org.apache.poi.hpsf; + +import java.io.OutputStream; + +import org.apache.poi.POIDocument; +import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + +/** + * A version of {@link POIDocument} which allows access to the + * HPSF Properties, but no other document contents. + * Normally used when you want to read or alter the Document Properties, + * without affecting the rest of the file + */ +public class HPSFPropertiesOnlyDocument extends POIDocument { + public HPSFPropertiesOnlyDocument(NPOIFSFileSystem fs) { + super(fs.getRoot()); + } + public HPSFPropertiesOnlyDocument(POIFSFileSystem fs) { + super(fs); + } + + public void write(OutputStream out) { + throw new IllegalStateException("Unable to write, only for properties!"); + } +} \ No newline at end of file diff --git a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java index 64e0dafcb..7907408c0 100644 --- a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java +++ b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java @@ -19,13 +19,13 @@ package org.apache.poi.hpsf.extractor; import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.util.Iterator; import org.apache.poi.POIDocument; import org.apache.poi.POITextExtractor; import org.apache.poi.hpsf.CustomProperties; import org.apache.poi.hpsf.DocumentSummaryInformation; +import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument; import org.apache.poi.hpsf.Property; import org.apache.poi.hpsf.SpecialPropertySet; import org.apache.poi.hpsf.SummaryInformation; @@ -47,10 +47,10 @@ public class HPSFPropertiesExtractor extends POITextExtractor { super(doc); } public HPSFPropertiesExtractor(POIFSFileSystem fs) { - super(new PropertiesOnlyDocument(fs)); + super(new HPSFPropertiesOnlyDocument(fs)); } public HPSFPropertiesExtractor(NPOIFSFileSystem fs) { - super(new PropertiesOnlyDocument(fs)); + super(new HPSFPropertiesOnlyDocument(fs)); } public String getDocumentSummaryInformationText() { @@ -143,23 +143,6 @@ public class HPSFPropertiesExtractor extends POITextExtractor { throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!"); } - /** - * So we can get at the properties of any - * random OLE2 document. - */ - private static final class PropertiesOnlyDocument extends POIDocument { - public PropertiesOnlyDocument(NPOIFSFileSystem fs) { - super(fs.getRoot()); - } - public PropertiesOnlyDocument(POIFSFileSystem fs) { - super(fs); - } - - public void write(OutputStream out) { - throw new IllegalStateException("Unable to write, only for properties!"); - } - } - public static void main(String[] args) throws IOException { for (String file : args) { HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(