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
This commit is contained in:
Nick Burch 2013-06-26 00:10:43 +00:00
parent 40d49a54d2
commit 90b74675d5
2 changed files with 29 additions and 20 deletions

View File

@ -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!");
}
}

View File

@ -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(