Fix generics warnings, and make the NPOIFS and deprecated constructor parts of Publisher clearer and consistent with other parts
Also fix a test filename git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1085443 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
78bcc564f4
commit
535e69dea4
@ -20,7 +20,6 @@ package org.apache.poi;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,6 +34,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
|
|||||||
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
||||||
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
||||||
import org.apache.poi.poifs.filesystem.Entry;
|
import org.apache.poi.poifs.filesystem.Entry;
|
||||||
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
@ -64,12 +64,18 @@ public abstract class POIDocument {
|
|||||||
protected POIDocument(DirectoryNode dir) {
|
protected POIDocument(DirectoryNode dir) {
|
||||||
this.directory = dir;
|
this.directory = dir;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @deprecated use {@link POIDocument#POIDocument(DirectoryNode)} instead
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
|
protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
|
||||||
this.directory = dir;
|
this.directory = dir;
|
||||||
}
|
}
|
||||||
protected POIDocument(POIFSFileSystem fs) {
|
protected POIDocument(POIFSFileSystem fs) {
|
||||||
this(fs.getRoot());
|
this(fs.getRoot());
|
||||||
|
}
|
||||||
|
protected POIDocument(NPOIFSFileSystem fs) {
|
||||||
|
this(fs.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,7 +186,7 @@ public abstract class POIDocument {
|
|||||||
* @param outFS the POIFSFileSystem to write the properties into
|
* @param outFS the POIFSFileSystem to write the properties into
|
||||||
* @param writtenEntries a list of POIFS entries to add the property names too
|
* @param writtenEntries a list of POIFS entries to add the property names too
|
||||||
*/
|
*/
|
||||||
protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException {
|
protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
|
||||||
SummaryInformation si = getSummaryInformation();
|
SummaryInformation si = getSummaryInformation();
|
||||||
if(si != null) {
|
if(si != null) {
|
||||||
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, outFS);
|
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, outFS);
|
||||||
@ -231,35 +237,21 @@ public abstract class POIDocument {
|
|||||||
* @param excepts is a list of Strings specifying what nodes NOT to copy
|
* @param excepts is a list of Strings specifying what nodes NOT to copy
|
||||||
*/
|
*/
|
||||||
protected void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
|
protected void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
|
||||||
List excepts) throws IOException {
|
List<String> excepts) throws IOException {
|
||||||
//System.err.println("CopyNodes called");
|
//System.err.println("CopyNodes called");
|
||||||
|
|
||||||
DirectoryEntry root = source.getRoot();
|
DirectoryEntry root = source.getRoot();
|
||||||
DirectoryEntry newRoot = target.getRoot();
|
DirectoryEntry newRoot = target.getRoot();
|
||||||
|
|
||||||
Iterator entries = root.getEntries();
|
Iterator<Entry> entries = root.getEntries();
|
||||||
|
|
||||||
while (entries.hasNext()) {
|
while (entries.hasNext()) {
|
||||||
Entry entry = (Entry)entries.next();
|
Entry entry = entries.next();
|
||||||
if (!isInList(entry.getName(), excepts)) {
|
if (!excepts.contains(entry.getName())) {
|
||||||
copyNodeRecursively(entry,newRoot);
|
copyNodeRecursively(entry,newRoot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if the String is in the list, used when copying
|
|
||||||
* nodes between one POIFS and another
|
|
||||||
*/
|
|
||||||
private boolean isInList(String entry, List list) {
|
|
||||||
for (int k = 0; k < list.size(); k++) {
|
|
||||||
if (list.get(k).equals(entry)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies an Entry into a target POIFS directory, recursively
|
* Copies an Entry into a target POIFS directory, recursively
|
||||||
*/
|
*/
|
||||||
@ -270,10 +262,10 @@ public abstract class POIDocument {
|
|||||||
DirectoryEntry newTarget = null;
|
DirectoryEntry newTarget = null;
|
||||||
if (entry.isDirectoryEntry()) {
|
if (entry.isDirectoryEntry()) {
|
||||||
newTarget = target.createDirectory(entry.getName());
|
newTarget = target.createDirectory(entry.getName());
|
||||||
Iterator entries = ((DirectoryEntry)entry).getEntries();
|
Iterator<Entry> entries = ((DirectoryEntry)entry).getEntries();
|
||||||
|
|
||||||
while (entries.hasNext()) {
|
while (entries.hasNext()) {
|
||||||
copyNodeRecursively((Entry)entries.next(),newTarget);
|
copyNodeRecursively(entries.next(),newTarget);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DocumentEntry dentry = (DocumentEntry)entry;
|
DocumentEntry dentry = (DocumentEntry)entry;
|
||||||
|
@ -1193,7 +1193,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
|
|
||||||
// For tracking what we've written out, used if we're
|
// For tracking what we've written out, used if we're
|
||||||
// going to be preserving nodes
|
// going to be preserving nodes
|
||||||
List excepts = new ArrayList(1);
|
List<String> excepts = new ArrayList<String>(1);
|
||||||
|
|
||||||
// Write out the Workbook stream
|
// Write out the Workbook stream
|
||||||
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
|
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
|
||||||
|
@ -27,6 +27,7 @@ import org.apache.poi.hpbf.model.EscherStm;
|
|||||||
import org.apache.poi.hpbf.model.MainContents;
|
import org.apache.poi.hpbf.model.MainContents;
|
||||||
import org.apache.poi.hpbf.model.QuillContents;
|
import org.apache.poi.hpbf.model.QuillContents;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,27 +45,39 @@ public final class HPBFDocument extends POIDocument {
|
|||||||
* Opens a new publisher document
|
* Opens a new publisher document
|
||||||
*/
|
*/
|
||||||
public HPBFDocument(POIFSFileSystem fs) throws IOException {
|
public HPBFDocument(POIFSFileSystem fs) throws IOException {
|
||||||
this(fs.getRoot(), fs);
|
this(fs.getRoot());
|
||||||
|
}
|
||||||
|
public HPBFDocument(NPOIFSFileSystem fs) throws IOException {
|
||||||
|
this(fs.getRoot());
|
||||||
}
|
}
|
||||||
public HPBFDocument(InputStream inp) throws IOException {
|
public HPBFDocument(InputStream inp) throws IOException {
|
||||||
this(new POIFSFileSystem(inp));
|
this(new POIFSFileSystem(inp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens an embeded publisher document,
|
* Opens an embedded publisher document,
|
||||||
|
* at the given directory.
|
||||||
|
* @deprecated Use {@link #HPBFDocument(DirectoryNode)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
||||||
|
this(dir);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Opens an embedded publisher document,
|
||||||
* at the given directory.
|
* at the given directory.
|
||||||
*/
|
*/
|
||||||
public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
public HPBFDocument(DirectoryNode dir) throws IOException {
|
||||||
super(dir, fs);
|
super(dir);
|
||||||
|
|
||||||
// Go looking for our interesting child
|
// Go looking for our interesting child
|
||||||
// streams
|
// streams
|
||||||
mainContents = new MainContents(dir);
|
mainContents = new MainContents(dir);
|
||||||
quillContents = new QuillContents(dir);
|
quillContents = new QuillContents(dir);
|
||||||
|
|
||||||
// Now the Escher bits
|
// Now the Escher bits
|
||||||
escherStm = new EscherStm(dir);
|
escherStm = new EscherStm(dir);
|
||||||
escherDelayStm = new EscherDelayStm(dir);
|
escherDelayStm = new EscherDelayStm(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainContents getMainContents() {
|
public MainContents getMainContents() {
|
||||||
|
@ -33,22 +33,26 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|||||||
* Extract text from HPBF Publisher files
|
* Extract text from HPBF Publisher files
|
||||||
*/
|
*/
|
||||||
public final class PublisherTextExtractor extends POIOLE2TextExtractor {
|
public final class PublisherTextExtractor extends POIOLE2TextExtractor {
|
||||||
private HPBFDocument doc;
|
private HPBFDocument doc;
|
||||||
private boolean hyperlinksByDefault = false;
|
private boolean hyperlinksByDefault = false;
|
||||||
|
|
||||||
public PublisherTextExtractor(HPBFDocument doc) {
|
public PublisherTextExtractor(HPBFDocument doc) {
|
||||||
super(doc);
|
super(doc);
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
}
|
}
|
||||||
|
public PublisherTextExtractor(DirectoryNode dir) throws IOException {
|
||||||
|
this(new HPBFDocument(dir));
|
||||||
|
}
|
||||||
|
public PublisherTextExtractor(POIFSFileSystem fs) throws IOException {
|
||||||
|
this(new HPBFDocument(fs));
|
||||||
|
}
|
||||||
|
public PublisherTextExtractor(InputStream is) throws IOException {
|
||||||
|
this(new POIFSFileSystem(is));
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
public PublisherTextExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
public PublisherTextExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
||||||
this(new HPBFDocument(dir, fs));
|
this(new HPBFDocument(dir, fs));
|
||||||
}
|
}
|
||||||
public PublisherTextExtractor(POIFSFileSystem fs) throws IOException {
|
|
||||||
this(new HPBFDocument(fs));
|
|
||||||
}
|
|
||||||
public PublisherTextExtractor(InputStream is) throws IOException {
|
|
||||||
this(new POIFSFileSystem(is));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should a call to getText() return hyperlinks inline
|
* Should a call to getText() return hyperlinks inline
|
||||||
|
@ -18,14 +18,13 @@
|
|||||||
package org.apache.poi.hpbf.extractor;
|
package org.apache.poi.hpbf.extractor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
|
|
||||||
import org.apache.poi.hpbf.HPBFDocument;
|
|
||||||
import org.apache.poi.POIDataSamples;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public final class TextPublisherTextExtractor extends TestCase {
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.hpbf.HPBFDocument;
|
||||||
|
|
||||||
|
public final class TestPublisherTextExtractor extends TestCase {
|
||||||
private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
|
private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
|
||||||
|
|
||||||
public void testBasics() throws Exception {
|
public void testBasics() throws Exception {
|
Loading…
Reference in New Issue
Block a user