git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678801 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_13_BETA1
@@ -33,6 +33,7 @@ import org.apache.poi.poifs.crypt.EncryptionInfo; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.DocumentInputStream; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.util.POILogFactory; | |||
import org.apache.poi.util.POILogger; | |||
@@ -65,13 +66,24 @@ public abstract class POIDocument { | |||
this.directory = dir; | |||
} | |||
protected POIDocument(POIFSFileSystem fs) { | |||
/** | |||
* Constructs from an old-style OPOIFS | |||
*/ | |||
protected POIDocument(OPOIFSFileSystem fs) { | |||
this(fs.getRoot()); | |||
} | |||
/** | |||
* Constructs from an old-style OPOIFS | |||
*/ | |||
protected POIDocument(NPOIFSFileSystem fs) { | |||
this(fs.getRoot()); | |||
} | |||
/** | |||
* Constructs from the default POIFS | |||
*/ | |||
protected POIDocument(POIFSFileSystem fs) { | |||
this(fs.getRoot()); | |||
} | |||
/** | |||
* Fetch the Document Summary Information of the document |
@@ -24,6 +24,7 @@ import java.util.List; | |||
import org.apache.poi.POIDocument; | |||
import org.apache.poi.poifs.filesystem.EntryUtils; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
/** | |||
@@ -36,6 +37,9 @@ public class HPSFPropertiesOnlyDocument extends POIDocument { | |||
public HPSFPropertiesOnlyDocument(NPOIFSFileSystem fs) { | |||
super(fs.getRoot()); | |||
} | |||
public HPSFPropertiesOnlyDocument(OPOIFSFileSystem fs) { | |||
super(fs); | |||
} | |||
public HPSFPropertiesOnlyDocument(POIFSFileSystem fs) { | |||
super(fs); | |||
} |
@@ -34,7 +34,7 @@ import org.apache.poi.hssf.record.DrawingGroupRecord; | |||
import org.apache.poi.hssf.record.EscherAggregate; | |||
import org.apache.poi.hssf.usermodel.HSSFPatriarch; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
/** | |||
* Utility for representing drawings contained in a binary Excel file as a XML tree | |||
@@ -138,7 +138,7 @@ public class BiffDrawingToXml { | |||
} | |||
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException { | |||
POIFSFileSystem fs = new POIFSFileSystem(xlsWorkbook); | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook); | |||
HSSFWorkbook workbook = new HSSFWorkbook(fs); | |||
InternalWorkbook internalWorkbook = getInternalWorkbook(workbook); | |||
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid); |
@@ -17,13 +17,63 @@ | |||
package org.apache.poi.hssf.dev; | |||
import java.io.*; | |||
import java.io.DataInputStream; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import java.io.OutputStreamWriter; | |||
import java.io.PrintStream; | |||
import java.io.Writer; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.apache.poi.hssf.record.*; | |||
import org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException; | |||
import org.apache.poi.hssf.record.chart.*; | |||
import org.apache.poi.hssf.record.chart.AreaFormatRecord; | |||
import org.apache.poi.hssf.record.chart.AreaRecord; | |||
import org.apache.poi.hssf.record.chart.AxisLineFormatRecord; | |||
import org.apache.poi.hssf.record.chart.AxisOptionsRecord; | |||
import org.apache.poi.hssf.record.chart.AxisParentRecord; | |||
import org.apache.poi.hssf.record.chart.AxisRecord; | |||
import org.apache.poi.hssf.record.chart.AxisUsedRecord; | |||
import org.apache.poi.hssf.record.chart.BarRecord; | |||
import org.apache.poi.hssf.record.chart.BeginRecord; | |||
import org.apache.poi.hssf.record.chart.CatLabRecord; | |||
import org.apache.poi.hssf.record.chart.CategorySeriesAxisRecord; | |||
import org.apache.poi.hssf.record.chart.ChartEndBlockRecord; | |||
import org.apache.poi.hssf.record.chart.ChartEndObjectRecord; | |||
import org.apache.poi.hssf.record.chart.ChartFRTInfoRecord; | |||
import org.apache.poi.hssf.record.chart.ChartFormatRecord; | |||
import org.apache.poi.hssf.record.chart.ChartRecord; | |||
import org.apache.poi.hssf.record.chart.ChartStartBlockRecord; | |||
import org.apache.poi.hssf.record.chart.ChartStartObjectRecord; | |||
import org.apache.poi.hssf.record.chart.DatRecord; | |||
import org.apache.poi.hssf.record.chart.DataFormatRecord; | |||
import org.apache.poi.hssf.record.chart.DefaultDataLabelTextPropertiesRecord; | |||
import org.apache.poi.hssf.record.chart.EndRecord; | |||
import org.apache.poi.hssf.record.chart.FontBasisRecord; | |||
import org.apache.poi.hssf.record.chart.FontIndexRecord; | |||
import org.apache.poi.hssf.record.chart.FrameRecord; | |||
import org.apache.poi.hssf.record.chart.LegendRecord; | |||
import org.apache.poi.hssf.record.chart.LineFormatRecord; | |||
import org.apache.poi.hssf.record.chart.LinkedDataRecord; | |||
import org.apache.poi.hssf.record.chart.ObjectLinkRecord; | |||
import org.apache.poi.hssf.record.chart.PlotAreaRecord; | |||
import org.apache.poi.hssf.record.chart.PlotGrowthRecord; | |||
import org.apache.poi.hssf.record.chart.SeriesIndexRecord; | |||
import org.apache.poi.hssf.record.chart.SeriesListRecord; | |||
import org.apache.poi.hssf.record.chart.SeriesRecord; | |||
import org.apache.poi.hssf.record.chart.SeriesTextRecord; | |||
import org.apache.poi.hssf.record.chart.SeriesToChartGroupRecord; | |||
import org.apache.poi.hssf.record.chart.SheetPropertiesRecord; | |||
import org.apache.poi.hssf.record.chart.TextRecord; | |||
import org.apache.poi.hssf.record.chart.TickRecord; | |||
import org.apache.poi.hssf.record.chart.UnitsRecord; | |||
import org.apache.poi.hssf.record.chart.ValueRangeRecord; | |||
import org.apache.poi.hssf.record.pivottable.DataItemRecord; | |||
import org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord; | |||
import org.apache.poi.hssf.record.pivottable.PageItemRecord; | |||
@@ -32,7 +82,7 @@ import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord; | |||
import org.apache.poi.hssf.record.pivottable.ViewFieldsRecord; | |||
import org.apache.poi.hssf.record.pivottable.ViewSourceRecord; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.HexDump; | |||
import org.apache.poi.util.LittleEndian; | |||
@@ -420,7 +470,7 @@ public final class BiffViewer { | |||
protected static InputStream getPOIFSInputStream(File file) | |||
throws IOException, FileNotFoundException { | |||
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file)); | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem(new FileInputStream(file)); | |||
String workbookName = HSSFWorkbook.getWorkbookDirEntryName(fs.getRoot()); | |||
return fs.createDocumentInputStream(workbookName); | |||
} |
@@ -45,7 +45,6 @@ import org.apache.poi.hssf.record.ObjRecord; | |||
import org.apache.poi.hssf.util.CellReference; | |||
import org.apache.poi.poifs.filesystem.DirectoryEntry; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.ss.usermodel.Chart; | |||
import org.apache.poi.ss.usermodel.ClientAnchor; | |||
import org.apache.poi.ss.usermodel.Drawing; |
@@ -206,6 +206,19 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss | |||
public HSSFWorkbook(POIFSFileSystem fs) throws IOException { | |||
this(fs,true); | |||
} | |||
/** | |||
* Given a POI POIFSFileSystem object, read in its Workbook along | |||
* with all related nodes, and populate the high and low level models. | |||
* <p>This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with | |||
* preserve nodes set to true. | |||
* | |||
* @see #HSSFWorkbook(POIFSFileSystem, boolean) | |||
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem | |||
* @exception IOException if the stream cannot be read | |||
*/ | |||
public HSSFWorkbook(NPOIFSFileSystem fs) throws IOException { | |||
this(fs.getRoot(),true); | |||
} | |||
/** | |||
* Given a POI POIFSFileSystem object, read in its Workbook and populate | |||
@@ -379,7 +392,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss | |||
public HSSFWorkbook(InputStream s, boolean preserveNodes) | |||
throws IOException | |||
{ | |||
this(new POIFSFileSystem(s), preserveNodes); | |||
this(new NPOIFSFileSystem(s).getRoot(), preserveNodes); | |||
} | |||
/** | |||
@@ -1844,7 +1857,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss | |||
throws IOException { | |||
// check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data | |||
if (directory == null) { | |||
directory = new POIFSFileSystem().getRoot(); | |||
directory = new NPOIFSFileSystem().getRoot(); | |||
preserveNodes = true; | |||
} | |||
@@ -25,6 +25,7 @@ import javax.crypto.SecretKey; | |||
import org.apache.poi.EncryptedDocumentException; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
public abstract class Decryptor { | |||
@@ -84,7 +85,9 @@ public abstract class Decryptor { | |||
public InputStream getDataStream(NPOIFSFileSystem fs) throws IOException, GeneralSecurityException { | |||
return getDataStream(fs.getRoot()); | |||
} | |||
public InputStream getDataStream(OPOIFSFileSystem fs) throws IOException, GeneralSecurityException { | |||
return getDataStream(fs.getRoot()); | |||
} | |||
public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { | |||
return getDataStream(fs.getRoot()); | |||
} |
@@ -26,6 +26,7 @@ import java.io.IOException; | |||
import org.apache.poi.EncryptedDocumentException; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.util.BitField; | |||
import org.apache.poi.util.BitFieldFactory; | |||
@@ -74,6 +75,12 @@ public class EncryptionInfo { | |||
public EncryptionInfo(POIFSFileSystem fs) throws IOException { | |||
this(fs.getRoot()); | |||
} | |||
/** | |||
* Opens for decryption | |||
*/ | |||
public EncryptionInfo(OPOIFSFileSystem fs) throws IOException { | |||
this(fs.getRoot()); | |||
} | |||
/** | |||
* Opens for decryption | |||
*/ |
@@ -24,6 +24,7 @@ import javax.crypto.SecretKey; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
public abstract class Encryptor { | |||
@@ -51,7 +52,9 @@ public abstract class Encryptor { | |||
public OutputStream getDataStream(NPOIFSFileSystem fs) throws IOException, GeneralSecurityException { | |||
return getDataStream(fs.getRoot()); | |||
} | |||
public OutputStream getDataStream(OPOIFSFileSystem fs) throws IOException, GeneralSecurityException { | |||
return getDataStream(fs.getRoot()); | |||
} | |||
public OutputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { | |||
return getDataStream(fs.getRoot()); | |||
} |
@@ -40,7 +40,7 @@ import org.apache.poi.poifs.crypt.HashAlgorithm; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.DocumentInputStream; | |||
import org.apache.poi.poifs.filesystem.DocumentNode; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.BitField; | |||
import org.apache.poi.util.BitFieldFactory; | |||
import org.apache.poi.util.BoundedInputStream; | |||
@@ -200,7 +200,7 @@ public class CryptoAPIDecryptor extends Decryptor { | |||
@SuppressWarnings("unused") | |||
public InputStream getDataStream(DirectoryNode dir) | |||
throws IOException, GeneralSecurityException { | |||
POIFSFileSystem fsOut = new POIFSFileSystem(); | |||
NPOIFSFileSystem fsOut = new NPOIFSFileSystem(); | |||
DocumentNode es = (DocumentNode) dir.getEntry("EncryptedSummary"); | |||
DocumentInputStream dis = dir.createDocumentInputStream(es); | |||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |||
@@ -240,6 +240,7 @@ public class CryptoAPIDecryptor extends Decryptor { | |||
sbis = null; | |||
bos.reset(); | |||
fsOut.writeFilesystem(bos); | |||
fsOut.close(); | |||
_length = bos.size(); | |||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); | |||
return bis; |
@@ -26,10 +26,7 @@ import java.io.OutputStream; | |||
import java.util.Iterator; | |||
/** | |||
* | |||
* Dump internal structure of a OLE2 file into file system | |||
* | |||
* @author Yegor Kozlov | |||
*/ | |||
public class POIFSDump { | |||
@@ -37,7 +34,7 @@ public class POIFSDump { | |||
for (int i = 0; i < args.length; i++) { | |||
System.out.println("Dumping " + args[i]); | |||
FileInputStream is = new FileInputStream(args[i]); | |||
POIFSFileSystem fs = new POIFSFileSystem(is); | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem(is); | |||
is.close(); | |||
DirectoryEntry root = fs.getRoot(); |
@@ -19,12 +19,12 @@ | |||
package org.apache.poi.poifs.dev; | |||
import java.io.FileInputStream; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
/** | |||
* A simple viewer for POIFS files | |||
@@ -76,10 +76,10 @@ public class POIFSViewer | |||
try | |||
{ | |||
POIFSViewable fs = | |||
new POIFSFileSystem(new FileInputStream(filename)); | |||
List<String> strings = POIFSViewEngine.inspectViewable(fs, true, | |||
new NPOIFSFileSystem(new File(filename)); | |||
List<String> strings = POIFSViewEngine.inspectViewable(fs, true, | |||
0, " "); | |||
Iterator<String> iter = strings.iterator(); | |||
Iterator<String> iter = strings.iterator(); | |||
while (iter.hasNext()) | |||
{ |
@@ -58,7 +58,7 @@ public class DocumentInputStream extends InputStream implements LittleEndianInpu | |||
if(documentNode.getDocument() != null) { | |||
delegate = new ODocumentInputStream(document); | |||
} else if(parentNode.getFileSystem() != null) { | |||
} else if(parentNode.getOFileSystem() != null) { | |||
delegate = new ODocumentInputStream(document); | |||
} else if(parentNode.getNFileSystem() != null) { | |||
delegate = new NDocumentInputStream(document); |
@@ -376,6 +376,15 @@ public class NPOIFSFileSystem extends BlockStore | |||
return (signature.get() == HeaderBlockConstants._signature); | |||
} | |||
/** | |||
* Checks if the supplied first 8 bytes of a stream / file | |||
* has a POIFS (OLE2) header. | |||
*/ | |||
public static boolean hasPOIFSHeader(byte[] header8Bytes) { | |||
LongField signature = new LongField(HeaderBlockConstants._signature_offset, header8Bytes); | |||
return (signature.get() == HeaderBlockConstants._signature); | |||
} | |||
/** | |||
* Read and process the PropertiesTable and the | |||
* FAT / XFAT blocks, so that we're ready to |
@@ -21,7 +21,6 @@ import java.io.IOException; | |||
import java.io.OutputStream; | |||
import org.apache.poi.poifs.common.POIFSBigBlockSize; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.storage.BlockWritable; | |||
import org.apache.poi.poifs.storage.HeaderBlock; | |||
import org.apache.poi.poifs.storage.PropertyBlock; |
@@ -20,8 +20,6 @@ package org.apache.poi.util; | |||
import java.io.FilterInputStream; | |||
import java.io.InputStream; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
/** | |||
* A wrapper around an {@link InputStream}, which | |||
* ignores close requests made to it. |
@@ -18,12 +18,12 @@ | |||
package org.apache.poi.util; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.poi.hssf.usermodel.HSSFSheet; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import java.io.FileInputStream; | |||
import java.io.IOException; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
/** | |||
* Dump out the aggregated escher records | |||
@@ -32,8 +32,8 @@ public class DrawingDump | |||
{ | |||
public static void main( String[] args ) throws IOException | |||
{ | |||
POIFSFileSystem fs = | |||
new POIFSFileSystem(new FileInputStream(args[0])); | |||
NPOIFSFileSystem fs = | |||
new NPOIFSFileSystem(new File(args[0])); | |||
HSSFWorkbook wb = new HSSFWorkbook(fs); | |||
try { | |||
System.out.println( "Drawing group:" ); |
@@ -18,7 +18,6 @@ package org.apache.poi.extractor; | |||
import java.io.ByteArrayInputStream; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileNotFoundException; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
@@ -51,6 +50,10 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; | |||
import org.apache.poi.poifs.filesystem.DirectoryEntry; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.Entry; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NotOLE2FileException; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.xslf.XSLFSlideShow; | |||
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; | |||
@@ -128,16 +131,14 @@ public class ExtractorFactory { | |||
public static POITextExtractor createExtractor(File f) throws IOException, InvalidFormatException, OpenXML4JException, XmlException { | |||
InputStream inp = null; | |||
try { | |||
inp = new PushbackInputStream( | |||
new FileInputStream(f), 8); | |||
if(POIFSFileSystem.hasPOIFSHeader(inp)) { | |||
return createExtractor(new POIFSFileSystem(inp)); | |||
} | |||
if(POIXMLDocument.hasOOXMLHeader(inp)) { | |||
try { | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem(f); | |||
return createExtractor(fs); | |||
} catch (OfficeXmlFileException e) { | |||
return createExtractor(OPCPackage.open(f.toString(), PackageAccess.READ)); | |||
} catch (NotOLE2FileException ne) { | |||
throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file"); | |||
} | |||
throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file"); | |||
} finally { | |||
if(inp != null) inp.close(); | |||
} | |||
@@ -150,8 +151,8 @@ public class ExtractorFactory { | |||
inp = new PushbackInputStream(inp, 8); | |||
} | |||
if(POIFSFileSystem.hasPOIFSHeader(inp)) { | |||
return createExtractor(new POIFSFileSystem(inp)); | |||
if(NPOIFSFileSystem.hasPOIFSHeader(inp)) { | |||
return createExtractor(new NPOIFSFileSystem(inp)); | |||
} | |||
if(POIXMLDocument.hasOOXMLHeader(inp)) { | |||
return createExtractor(OPCPackage.open(inp)); | |||
@@ -226,16 +227,14 @@ public class ExtractorFactory { | |||
// Only ever an OLE2 one from the root of the FS | |||
return (POIOLE2TextExtractor)createExtractor(fs.getRoot()); | |||
} | |||
/** | |||
* @deprecated Use {@link #createExtractor(DirectoryNode)} instead | |||
*/ | |||
@Deprecated | |||
public static POITextExtractor createExtractor(DirectoryNode poifsDir, POIFSFileSystem fs) | |||
throws IOException, InvalidFormatException, OpenXML4JException, XmlException | |||
{ | |||
return createExtractor(poifsDir); | |||
} | |||
public static POIOLE2TextExtractor createExtractor(NPOIFSFileSystem fs) throws IOException, InvalidFormatException, OpenXML4JException, XmlException { | |||
// Only ever an OLE2 one from the root of the FS | |||
return (POIOLE2TextExtractor)createExtractor(fs.getRoot()); | |||
} | |||
public static POIOLE2TextExtractor createExtractor(OPOIFSFileSystem fs) throws IOException, InvalidFormatException, OpenXML4JException, XmlException { | |||
// Only ever an OLE2 one from the root of the FS | |||
return (POIOLE2TextExtractor)createExtractor(fs.getRoot()); | |||
} | |||
public static POITextExtractor createExtractor(DirectoryNode poifsDir) throws IOException, | |||
InvalidFormatException, OpenXML4JException, XmlException |
@@ -167,7 +167,7 @@ public class WorkbookFactory { | |||
byte[] header8 = IOUtils.peekFirst8Bytes(inp); | |||
// Try to create | |||
if (POIFSFileSystem.hasPOIFSHeader(header8)) { | |||
if (NPOIFSFileSystem.hasPOIFSHeader(header8)) { | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem(inp); | |||
return create(fs, password); | |||
} |
@@ -17,7 +17,7 @@ | |||
package org.apache.poi.hdgf.dev; | |||
import java.io.FileInputStream; | |||
import java.io.File; | |||
import org.apache.poi.hdgf.HDGFDiagram; | |||
import org.apache.poi.hdgf.chunks.Chunk; | |||
@@ -26,7 +26,7 @@ import org.apache.poi.hdgf.pointers.Pointer; | |||
import org.apache.poi.hdgf.streams.ChunkStream; | |||
import org.apache.poi.hdgf.streams.PointerContainingStream; | |||
import org.apache.poi.hdgf.streams.Stream; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
/** | |||
* Developer helper class to dump out the pointer+stream structure | |||
@@ -41,7 +41,7 @@ public final class VSDDumper { | |||
} | |||
HDGFDiagram hdgf = new HDGFDiagram( | |||
new POIFSFileSystem(new FileInputStream(args[0])) | |||
new NPOIFSFileSystem(new File(args[0])) | |||
); | |||
System.out.println("Opened " + args[0]); |
@@ -62,7 +62,7 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor { | |||
this(new HDGFDiagram(dir, fs)); | |||
} | |||
public VisioTextExtractor(InputStream inp) throws IOException { | |||
this(new POIFSFileSystem(inp)); | |||
this(new NPOIFSFileSystem(inp)); | |||
} | |||
/** |
@@ -51,18 +51,9 @@ public final class HPBFDocument extends POIDocument { | |||
this(fs.getRoot()); | |||
} | |||
public HPBFDocument(InputStream inp) throws IOException { | |||
this(new POIFSFileSystem(inp)); | |||
this(new NPOIFSFileSystem(inp)); | |||
} | |||
/** | |||
* 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. |
@@ -25,7 +25,7 @@ import org.apache.poi.ddf.DefaultEscherRecordFactory; | |||
import org.apache.poi.ddf.EscherRecord; | |||
import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.DocumentEntry; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.LittleEndian; | |||
import org.apache.poi.util.StringUtil; | |||
@@ -35,12 +35,12 @@ import org.apache.poi.util.StringUtil; | |||
* constructed. | |||
*/ | |||
public final class HPBFDumper { | |||
private POIFSFileSystem fs; | |||
public HPBFDumper(POIFSFileSystem fs) { | |||
private NPOIFSFileSystem fs; | |||
public HPBFDumper(NPOIFSFileSystem fs) { | |||
this.fs = fs; | |||
} | |||
public HPBFDumper(InputStream inp) throws IOException { | |||
this(new POIFSFileSystem(inp)); | |||
this(new NPOIFSFileSystem(inp)); | |||
} | |||
private static byte[] getData(DirectoryNode dir, String name) throws IOException { |
@@ -24,7 +24,7 @@ import java.io.InputStream; | |||
import org.apache.poi.hpbf.HPBFDocument; | |||
import org.apache.poi.hpbf.model.QuillContents; | |||
import org.apache.poi.hpbf.model.qcbits.QCBit; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.HexDump; | |||
/** | |||
@@ -40,11 +40,11 @@ public final class PLCDumper { | |||
doc = hpbfDoc; | |||
qc = doc.getQuillContents(); | |||
} | |||
public PLCDumper(POIFSFileSystem fs) throws IOException { | |||
public PLCDumper(NPOIFSFileSystem fs) throws IOException { | |||
this(new HPBFDocument(fs)); | |||
} | |||
public PLCDumper(InputStream inp) throws IOException { | |||
this(new POIFSFileSystem(inp)); | |||
this(new NPOIFSFileSystem(inp)); | |||
} | |||
public static void main(String[] args) throws Exception { |
@@ -53,10 +53,6 @@ public final class PublisherTextExtractor extends POIOLE2TextExtractor { | |||
public PublisherTextExtractor(InputStream is) throws IOException { | |||
this(new POIFSFileSystem(is)); | |||
} | |||
@Deprecated | |||
public PublisherTextExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException { | |||
this(new HPBFDocument(dir, fs)); | |||
} | |||
/** | |||
* Should a call to getText() return hyperlinks inline |
@@ -123,7 +123,7 @@ public final class HSLFSlideShow extends POIDocument { | |||
*/ | |||
public HSLFSlideShow(InputStream inputStream) throws IOException { | |||
//do Ole stuff | |||
this(new POIFSFileSystem(inputStream)); | |||
this(new NPOIFSFileSystem(inputStream)); | |||
} | |||
/** | |||
@@ -150,22 +150,6 @@ public final class HSLFSlideShow extends POIDocument { | |||
this(filesystem.getRoot()); | |||
} | |||
/** | |||
* Constructs a Powerpoint document from a specific point in a | |||
* POIFS Filesystem. Parses the document and places all the | |||
* important stuff into data structures. | |||
* | |||
* @deprecated Use {@link #HSLFSlideShow(DirectoryNode)} instead | |||
* @param dir the POIFS directory to read from | |||
* @param filesystem the POIFS FileSystem to read from | |||
* @throws IOException if there is a problem while parsing the document. | |||
*/ | |||
@Deprecated | |||
public HSLFSlideShow(DirectoryNode dir, POIFSFileSystem filesystem) throws IOException | |||
{ | |||
this(dir); | |||
} | |||
/** | |||
* Constructs a Powerpoint document from a specific point in a | |||
* POIFS Filesystem. Parses the document and places all the |
@@ -18,7 +18,6 @@ | |||
package org.apache.poi.hslf.dev; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileWriter; | |||
import java.io.IOException; | |||
@@ -28,7 +27,7 @@ import java.io.Writer; | |||
import org.apache.poi.hslf.record.RecordTypes; | |||
import org.apache.poi.poifs.filesystem.DocumentEntry; | |||
import org.apache.poi.poifs.filesystem.DocumentInputStream; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.LittleEndian; | |||
/** | |||
@@ -50,9 +49,7 @@ public final class PPTXMLDump { | |||
protected boolean hexHeader = true; | |||
public PPTXMLDump(File ppt) throws IOException { | |||
FileInputStream fis = new FileInputStream(ppt); | |||
POIFSFileSystem fs = new POIFSFileSystem(fis); | |||
fis.close(); | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem(ppt); | |||
//read the document entry from OLE file system | |||
DocumentEntry entry = (DocumentEntry)fs.getRoot().getEntry(PPDOC_ENTRY); |
@@ -17,14 +17,17 @@ | |||
package org.apache.poi.hslf.dev; | |||
import java.io.*; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.DocumentEntry; | |||
import org.apache.poi.ddf.*; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import org.apache.poi.ddf.DefaultEscherRecordFactory; | |||
import org.apache.poi.ddf.EscherContainerRecord; | |||
import org.apache.poi.ddf.EscherRecord; | |||
import org.apache.poi.ddf.EscherTextboxRecord; | |||
import org.apache.poi.hslf.record.RecordTypes; | |||
import org.apache.poi.poifs.filesystem.DocumentEntry; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.LittleEndian; | |||
/** | |||
@@ -38,12 +41,9 @@ import org.apache.poi.util.LittleEndian; | |||
* To peek inside PPDrawings, which hold Escher drawings, we use the | |||
* DDF package from POI (but we can fake it by using the Escher listings | |||
* from hslf.record.RecordTypes also) | |||
* | |||
* @author Nick Burch | |||
*/ | |||
public final class SlideShowDumper { | |||
private InputStream istream; | |||
private POIFSFileSystem filesystem; | |||
private NPOIFSFileSystem filesystem; | |||
private byte[] _docstream; | |||
@@ -92,7 +92,7 @@ public final class SlideShowDumper { | |||
*/ | |||
public SlideShowDumper(String fileName) throws IOException | |||
{ | |||
this(new FileInputStream(fileName)); | |||
this(new NPOIFSFileSystem(new File(fileName))); | |||
} | |||
/** | |||
@@ -105,8 +105,7 @@ public final class SlideShowDumper { | |||
public SlideShowDumper(InputStream inputStream) throws IOException | |||
{ | |||
//do Ole stuff | |||
this(new POIFSFileSystem(inputStream)); | |||
istream = inputStream; | |||
this(new NPOIFSFileSystem(inputStream)); | |||
} | |||
/** | |||
@@ -116,7 +115,7 @@ public final class SlideShowDumper { | |||
* @param filesystem the POIFS FileSystem to read from | |||
* @throws IOException if there is a problem while parsing the document. | |||
*/ | |||
public SlideShowDumper(POIFSFileSystem filesystem) throws IOException | |||
public SlideShowDumper(NPOIFSFileSystem filesystem) throws IOException | |||
{ | |||
this.filesystem = filesystem; | |||
@@ -153,10 +152,7 @@ public final class SlideShowDumper { | |||
*/ | |||
public void close() throws IOException | |||
{ | |||
if(istream != null) { | |||
istream.close(); | |||
} | |||
filesystem = null; | |||
filesystem.close(); | |||
} | |||
@@ -17,6 +17,7 @@ | |||
package org.apache.poi.hslf.extractor; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
@@ -83,7 +84,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor { | |||
* @param fileName The name of the file to extract from | |||
*/ | |||
public PowerPointExtractor(String fileName) throws IOException { | |||
this(new FileInputStream(fileName)); | |||
this(new NPOIFSFileSystem(new File(fileName))); | |||
} | |||
/** | |||
@@ -92,7 +93,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor { | |||
* @param iStream The input stream containing the PowerPoint document | |||
*/ | |||
public PowerPointExtractor(InputStream iStream) throws IOException { | |||
this(new POIFSFileSystem(iStream)); | |||
this(new NPOIFSFileSystem(iStream)); | |||
} | |||
/** | |||
@@ -123,14 +124,6 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor { | |||
this(new HSLFSlideShow(dir)); | |||
} | |||
/** | |||
* @deprecated Use {@link #PowerPointExtractor(DirectoryNode)} instead | |||
*/ | |||
@Deprecated | |||
public PowerPointExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException { | |||
this(new HSLFSlideShow(dir, fs)); | |||
} | |||
/** | |||
* Creates a PowerPointExtractor, from a HSLFSlideShow | |||
* |
@@ -17,7 +17,7 @@ | |||
package org.apache.poi.hslf.extractor; | |||
import java.io.FileInputStream; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.ArrayList; | |||
@@ -32,7 +32,7 @@ import org.apache.poi.hslf.record.TextBytesAtom; | |||
import org.apache.poi.hslf.record.TextCharsAtom; | |||
import org.apache.poi.hslf.record.TextHeaderAtom; | |||
import org.apache.poi.poifs.filesystem.DocumentEntry; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.util.LittleEndian; | |||
/** | |||
@@ -52,11 +52,9 @@ import org.apache.poi.util.LittleEndian; | |||
* Almost everyone will want to use @see PowerPointExtractor instead. There | |||
* are only a very small number of cases (eg some performance sensitive | |||
* lucene indexers) that would ever want to use this! | |||
* | |||
* @author Nick Burch | |||
*/ | |||
public final class QuickButCruddyTextExtractor { | |||
private POIFSFileSystem fs; | |||
private NPOIFSFileSystem fs; | |||
private InputStream is; | |||
private byte[] pptContents; | |||
@@ -84,7 +82,7 @@ public final class QuickButCruddyTextExtractor { | |||
* @param fileName | |||
*/ | |||
public QuickButCruddyTextExtractor(String fileName) throws IOException { | |||
this(new FileInputStream(fileName)); | |||
this(new NPOIFSFileSystem(new File(fileName))); | |||
} | |||
/** | |||
@@ -92,7 +90,7 @@ public final class QuickButCruddyTextExtractor { | |||
* @param iStream | |||
*/ | |||
public QuickButCruddyTextExtractor(InputStream iStream) throws IOException { | |||
this(new POIFSFileSystem(iStream)); | |||
this(new NPOIFSFileSystem(iStream)); | |||
is = iStream; | |||
} | |||
@@ -100,7 +98,7 @@ public final class QuickButCruddyTextExtractor { | |||
* Creates an extractor from a POIFS Filesystem | |||
* @param poifs | |||
*/ | |||
public QuickButCruddyTextExtractor(POIFSFileSystem poifs) throws IOException { | |||
public QuickButCruddyTextExtractor(NPOIFSFileSystem poifs) throws IOException { | |||
fs = poifs; | |||
// Find the PowerPoint bit, and get out the bytes |
@@ -27,7 +27,7 @@ import junit.framework.TestCase; | |||
import org.apache.poi.hssf.HSSFTestDataSamples; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
/** | |||
* Tests that POIDocument correctly loads and saves the common | |||
@@ -97,7 +97,7 @@ public final class TestPOIDocumentMain extends TestCase { | |||
// Create a new version | |||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); | |||
POIFSFileSystem inFS = new POIFSFileSystem(bais); | |||
OPOIFSFileSystem inFS = new OPOIFSFileSystem(bais); | |||
// Check they're still there | |||
doc.directory = inFS.getRoot(); |
@@ -31,7 +31,7 @@ import org.apache.poi.hpsf.PropertySetFactory; | |||
import org.apache.poi.hpsf.SummaryInformation; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
import org.apache.poi.poifs.filesystem.DocumentInputStream; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
/** | |||
* Tests various bugs have been fixed | |||
@@ -109,8 +109,8 @@ public final class TestHPSFBugs extends TestCase { | |||
*/ | |||
public void test54233() throws Exception { | |||
DocumentInputStream dis; | |||
POIFSFileSystem fs = | |||
new POIFSFileSystem(_samples.openResourceAsStream("TestNon4ByteBoundary.doc")); | |||
NPOIFSFileSystem fs = | |||
new NPOIFSFileSystem(_samples.openResourceAsStream("TestNon4ByteBoundary.doc")); | |||
dis = fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME); | |||
SummaryInformation si = (SummaryInformation)PropertySetFactory.create(dis); | |||
@@ -130,7 +130,7 @@ public final class TestHPSFBugs extends TestCase { | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
doc.write(baos); | |||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); | |||
doc = new HPSFPropertiesOnlyDocument(new POIFSFileSystem(bais)); | |||
doc = new HPSFPropertiesOnlyDocument(new NPOIFSFileSystem(bais)); | |||
// Check properties are still there | |||
assertEquals("Microsoft Word 10.0", si.getApplicationName()); | |||
@@ -144,8 +144,8 @@ public final class TestHPSFBugs extends TestCase { | |||
*/ | |||
public void test56138() throws Exception { | |||
DocumentInputStream dis; | |||
POIFSFileSystem fs = | |||
new POIFSFileSystem(_samples.openResourceAsStream("TestZeroLengthCodePage.mpp")); | |||
NPOIFSFileSystem fs = | |||
new NPOIFSFileSystem(_samples.openResourceAsStream("TestZeroLengthCodePage.mpp")); | |||
dis = fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME); | |||
SummaryInformation si = (SummaryInformation)PropertySetFactory.create(dis); |
@@ -17,6 +17,8 @@ | |||
package org.apache.poi.hssf; | |||
import java.io.InputStream; | |||
import org.apache.poi.POIDataSamples; | |||
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
@@ -38,6 +40,9 @@ public final class HSSFITestDataProvider implements ITestDataProvider { | |||
public HSSFWorkbook openSampleWorkbook(String sampleFileName) { | |||
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName); | |||
} | |||
public InputStream openWorkbookStream(String sampleFileName) { | |||
return HSSFTestDataSamples.openSampleFileStream(sampleFileName); | |||
} | |||
public HSSFWorkbook writeOutAndReadBack(Workbook original) { | |||
if(!(original instanceof HSSFWorkbook)) { |
@@ -58,6 +58,7 @@ import org.apache.poi.hssf.record.aggregates.RecordAggregate; | |||
import org.apache.poi.hssf.record.common.UnicodeString; | |||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; | |||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.ss.formula.ptg.Area3DPtg; | |||
import org.apache.poi.ss.formula.ptg.DeletedArea3DPtg; | |||
@@ -1566,15 +1567,30 @@ public final class TestBugs extends BaseTestBugzillaIssues { | |||
* (is an excel 95 file though) | |||
*/ | |||
@Test | |||
public void bug46904() { | |||
public void bug46904() throws Exception { | |||
try { | |||
openSample("46904.xls"); | |||
OPOIFSFileSystem fs = new OPOIFSFileSystem( | |||
HSSFITestDataProvider.instance.openWorkbookStream("46904.xls")); | |||
new HSSFWorkbook(fs.getRoot(), false); | |||
fail(); | |||
} catch(OldExcelFormatException e) { | |||
assertTrue(e.getMessage().startsWith( | |||
"The supplied spreadsheet seems to be Excel" | |||
)); | |||
} | |||
// TODO Fix this to work with NPOIFS as well | |||
/* | |||
try { | |||
NPOIFSFileSystem fs = new NPOIFSFileSystem( | |||
HSSFITestDataProvider.instance.openWorkbookStream("46904.xls")); | |||
new HSSFWorkbook(fs.getRoot(), false); | |||
fail(); | |||
} catch(OldExcelFormatException e) { | |||
assertTrue(e.getMessage().startsWith( | |||
"The supplied spreadsheet seems to be Excel" | |||
)); | |||
} | |||
*/ | |||
} | |||
/** |