You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/19 21:00:38 UTC

svn commit: r1691843 [3/30] - in /poi/branches/common_sl: ./ .settings/ legal/ osgi/ osgi/src/ src/examples/src/org/apache/poi/hpsf/examples/ src/examples/src/org/apache/poi/hssf/usermodel/examples/ src/examples/src/org/apache/poi/ss/examples/ src/exam...

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -19,10 +19,12 @@ package org.apache.poi.stress;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 
 import org.apache.poi.hdgf.HDGFDiagram;
+import org.apache.poi.hdgf.extractor.VisioTextExtractor;
 import org.apache.poi.hdgf.streams.Stream;
 import org.apache.poi.hdgf.streams.TrailerStream;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -48,11 +50,27 @@ public class HDGFFileHandler extends POI
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {
-		InputStream stream = new FileInputStream("test-data/diagram/44501.vsd");
+		File file = new File("test-data/diagram/44501.vsd");
+
+		InputStream stream = new FileInputStream(file);
 		try {
 			handleFile(stream);
 		} finally {
 			stream.close();
 		}
+		
+		handleExtracting(file);
+		
+		stream = new FileInputStream(file);
+		try {
+			VisioTextExtractor extractor = new VisioTextExtractor(stream);
+			try {
+				assertNotNull(extractor.getText());
+			} finally {
+				extractor.close();
+			}
+		} finally {
+			stream.close();
+		}
 	}
 }

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -26,7 +26,7 @@ import org.apache.poi.hmef.attribute.MAP
 import org.apache.poi.hmef.attribute.MAPIStringAttribute;
 import org.junit.Test;
 
-public class HMEFFileHandler implements FileHandler {
+public class HMEFFileHandler extends AbstractFileHandler {
 
 	@Override
     public void handleFile(InputStream stream) throws Exception {

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -18,10 +18,12 @@ package org.apache.poi.stress;
 
 import static org.junit.Assert.assertNotNull;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 
 import org.apache.poi.hpbf.HPBFDocument;
+import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.junit.Test;
 
@@ -39,11 +41,28 @@ public class HPBFFileHandler extends POI
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {
-		InputStream stream = new FileInputStream("test-data/publisher/SampleBrochure.pub");
+		File file = new File("test-data/publisher/SampleBrochure.pub");
+
+		InputStream stream = new FileInputStream(file);
 		try {
 			handleFile(stream);
 		} finally {
 			stream.close();
 		}
+		
+		handleExtracting(file);
+		
+		stream = new FileInputStream(file);
+		try {
+			PublisherTextExtractor extractor = new PublisherTextExtractor(stream);
+			try {
+				assertNotNull(extractor.getText());
+			} finally {
+				extractor.close();
+			}
+		} finally {
+			stream.close();
+		}
 	}
+	
 }

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -18,6 +18,7 @@ package org.apache.poi.stress;
 
 import static org.junit.Assert.assertNotNull;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 
@@ -25,7 +26,7 @@ import org.apache.poi.hpsf.HPSFPropertie
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.junit.Test;
 
-public class HPSFFileHandler implements FileHandler {
+public class HPSFFileHandler extends AbstractFileHandler {
 	@Override
     public void handleFile(InputStream stream) throws Exception {
 		HPSFPropertiesOnlyDocument hpsf = new HPSFPropertiesOnlyDocument(new POIFSFileSystem(stream));
@@ -43,4 +44,10 @@ public class HPSFFileHandler implements
 			stream.close();
 		}
 	}
+
+    // a test-case to test this locally without executing the full TestAllFiles
+    @Test
+    public void testExtractor() throws Exception {
+        handleExtracting(new File("test-data/hpsf/TestBug44375.xls"));
+    }
 }

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -22,6 +22,8 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 
 import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.datatypes.AttachmentChunks;
+import org.apache.poi.hsmf.datatypes.DirectoryChunk;
 import org.junit.Test;
 
 public class HSMFFileHandler extends POIFSFileHandler {
@@ -32,6 +34,19 @@ public class HSMFFileHandler extends POI
 		assertNotNull(mapi.getDisplayBCC());
 		assertNotNull(mapi.getMessageDate());
 
+		AttachmentChunks[] attachments = mapi.getAttachmentFiles();
+
+		for(AttachmentChunks attachment : attachments) {
+
+		   DirectoryChunk chunkDirectory = attachment.attachmentDirectory;
+		   if(chunkDirectory != null) {
+			   MAPIMessage attachmentMSG = chunkDirectory.getAsEmbededMessage();
+			   assertNotNull(attachmentMSG);
+			   String body = attachmentMSG.getTextBody();
+			   assertNotNull(body);
+		   }
+		}
+
 		/* => Writing isn't yet supported...
 		// write out the file
 		File file = TempFile.createTempFile("StressTest", ".msg");

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 
@@ -49,4 +50,10 @@ public class HSSFFileHandler extends Spr
 			stream.close();
 		}
 	}
+
+	// a test-case to test this locally without executing the full TestAllFiles
+    @Test
+    public void testExtractor() throws Exception {
+        handleExtracting(new File("test-data/spreadsheet/BOOK_in_capitals.xls"));
+    }
 }
\ No newline at end of file

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -18,12 +18,21 @@ package org.apache.poi.stress;
 
 import static org.junit.Assert.assertNotNull;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 
+import org.apache.poi.hdf.extractor.WordDocument;
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.extractor.WordExtractor;
 import org.junit.Test;
 
+@SuppressWarnings("deprecation")
 public class HWPFFileHandler extends POIFSFileHandler {
 	@Override
 	public void handleFile(InputStream stream) throws Exception {
@@ -33,16 +42,57 @@ public class HWPFFileHandler extends POI
 		assertNotNull(doc.getEndnotes());
 		
 		handlePOIDocument(doc);
+		
+		// fails for many documents, but is deprecated anyway... 
+		// handleWordDocument(doc);
+	}
+
+	protected void handleWordDocument(HWPFDocument doc) throws IOException {
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+		doc.write(outStream);
+
+		WordDocument wordDoc = new WordDocument(new ByteArrayInputStream(outStream.toByteArray()));
+        
+        StringWriter docTextWriter = new StringWriter();
+        PrintWriter out = new PrintWriter(docTextWriter);
+        try {
+        	wordDoc.writeAllText(out);
+        } finally {
+        	out.close();
+        }
+        docTextWriter.close();
 	}
 
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {
-		InputStream stream = new FileInputStream("test-data/document/HeaderFooterUnicode.doc");
+		File file = new File("test-data/document/52117.doc");
+
+		InputStream stream = new FileInputStream(file);
 		try {
 			handleFile(stream);
 		} finally {
 			stream.close();
 		}
+		
+		handleExtracting(file);
+		
+		stream = new FileInputStream(file);
+		try {
+			WordExtractor extractor = new WordExtractor(stream);
+			try {
+				assertNotNull(extractor.getText());
+			} finally {
+				extractor.close();
+			}
+		} finally {
+			stream.close();
+		}
+	}
+
+	@Test
+	public void testExtractingOld() throws Exception {
+		File file = new File("test-data/document/52117.doc");
+		handleExtracting(file);
 	}
-}
\ No newline at end of file
+}

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java Sun Jul 19 19:00:32 2015
@@ -25,7 +25,7 @@ import java.io.InputStream;
 import org.apache.poi.POIDocument;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
-public class POIFSFileHandler implements FileHandler {
+public class POIFSFileHandler extends AbstractFileHandler {
 
 	@Override
     public void handleFile(InputStream stream) throws Exception {

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java Sun Jul 19 19:00:32 2015
@@ -20,9 +20,17 @@ import static org.junit.Assert.assertNot
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.List;
 
 import org.apache.poi.POIXMLDocument;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.poifs.crypt.Decryptor;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.Ignore;
+import org.junit.Test;
 
 public final class POIXMLDocumentHandler {
 	protected void handlePOIXMLDocument(POIXMLDocument doc) throws Exception {
@@ -36,11 +44,33 @@ public final class POIXMLDocumentHandler
     protected static boolean isEncrypted(InputStream stream) throws IOException {
         if (POIFSFileSystem.hasPOIFSHeader(stream)) {
             POIFSFileSystem poifs = new POIFSFileSystem(stream);
-            if (poifs.getRoot().hasEntry("EncryptedPackage")) {
+            if (poifs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
                 return true;
             }
             throw new IOException("wrong file format or file extension for OO XML file");
         }
         return false;
     }
+	
+	// a test-case to test this locally without executing the full TestAllFiles
+    @Ignore("POIXMLDocument cannot handle this Visio file currently...")
+	@Test
+	public void test() throws Exception {
+		OPCPackage pkg = OPCPackage.open("test-data/diagram/test.vsdx", PackageAccess.READ);
+		try {
+			handlePOIXMLDocument(new TestPOIXMLDocument(pkg));
+		} finally {
+			pkg.close();
+		}
+	}
+	
+	private final static class TestPOIXMLDocument extends POIXMLDocument {
+		public TestPOIXMLDocument(OPCPackage pkg) {
+			super(pkg);
+		}
+
+		public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+			return null;
+		}
+	}
 }

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java Sun Jul 19 19:00:32 2015
@@ -30,7 +30,7 @@ import org.apache.poi.ss.usermodel.Sheet
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 
-public abstract class SpreadsheetHandler implements FileHandler {
+public abstract class SpreadsheetHandler extends AbstractFileHandler {
 	public void handleWorkbook(Workbook wb, String extension) throws IOException {
 		// try to access some of the content
 		readContent(wb);

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -18,35 +18,97 @@ package org.apache.poi.stress;
 
 import static org.junit.Assert.assertNotNull;
 
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.sl.draw.DrawFactory;
+import org.apache.poi.sl.draw.Drawable;
 import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFNotes;
+import org.apache.poi.xslf.usermodel.XSLFShape;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
+import org.apache.poi.xslf.usermodel.XSLFTextShape;
 import org.junit.Test;
 
-public class XSLFFileHandler implements FileHandler {
+public class XSLFFileHandler extends AbstractFileHandler {
 	@Override
     public void handleFile(InputStream stream) throws Exception {
-        // ignore password protected files
-        if (POIXMLDocumentHandler.isEncrypted(stream)) return;
-
         XSLFSlideShow slide = new XSLFSlideShow(OPCPackage.open(stream));
 		assertNotNull(slide.getPresentation());
 		assertNotNull(slide.getSlideMasterReferences());
 		assertNotNull(slide.getSlideReferences());
 		
 		new POIXMLDocumentHandler().handlePOIXMLDocument(slide);
+
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		try {
+		    slide.write(out);
+		} finally {
+		    out.close();
+		}
+		
+        createBitmaps(out);		
 	}
 
+    private void createBitmaps(ByteArrayOutputStream out) throws IOException {
+        XMLSlideShow ppt = new XMLSlideShow(new ByteArrayInputStream(out.toByteArray()));
+        Dimension pgsize = ppt.getPageSize();
+        for (XSLFSlide xmlSlide : ppt.getSlides()) {
+//            System.out.println("slide-" + (i + 1));
+//            System.out.println("" + xmlSlide[i].getTitle());
+
+            BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
+            Graphics2D graphics = img.createGraphics();
+
+            // draw stuff
+            xmlSlide.draw(graphics);
+
+            // Also try to read notes
+            XSLFNotes notes = xmlSlide.getNotes();
+            if(notes != null) {
+                for (XSLFShape note : notes) {
+                    DrawFactory df = DrawFactory.getInstance(graphics);
+                    Drawable d = df.getDrawable(note);
+                    d.draw(graphics);
+                    
+                    if (note instanceof XSLFTextShape) {
+                        XSLFTextShape txShape = (XSLFTextShape) note;
+                        for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
+                            xslfParagraph.getText();
+                        }
+                    }
+                }
+            }
+        }
+        
+        ppt.close();
+    }
+
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {
-		InputStream stream = new FileInputStream("test-data/slideshow/testPPT.pptx");
+		InputStream stream = new FileInputStream("test-data/slideshow/SampleShow.pptx");
 		try {
 			handleFile(stream);
 		} finally {
 			stream.close();
 		}
 	}
+
+
+    // a test-case to test this locally without executing the full TestAllFiles
+    @Test
+    public void testExtractor() throws Exception {
+        handleExtracting(new File("test-data/slideshow/testPPT.thmx"));
+    }
 }
\ No newline at end of file

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -17,6 +17,7 @@
 package org.apache.poi.stress;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 
@@ -71,4 +72,10 @@ public class XSSFFileHandler extends Spr
 			stream.close();
 		}
 	}
+
+    // a test-case to test this locally without executing the full TestAllFiles
+    @Test
+    public void testExtractor() throws Exception {
+        handleExtracting(new File("test-data/spreadsheet/56278.xlsx"));
+    }
 }
\ No newline at end of file

Modified: poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java (original)
+++ poi/branches/common_sl/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java Sun Jul 19 19:00:32 2015
@@ -16,13 +16,15 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.io.PushbackInputStream;
 
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.junit.Test;
 
-public class XWPFFileHandler implements FileHandler {
+public class XWPFFileHandler extends AbstractFileHandler {
 	@Override
     public void handleFile(InputStream stream) throws Exception {
         // ignore password protected files
@@ -36,12 +38,16 @@ public class XWPFFileHandler implements
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {
-		InputStream stream = new FileInputStream("test-data/document/footnotes.docx");
+		File file = new File("test-data/document/51921-Word-Crash067.docx");
+
+		InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
 		try {
 			handleFile(stream);
 		} finally {
 			stream.close();
 		}
+		
+		handleExtracting(file);
 	}
 	
 }
\ No newline at end of file

Modified: poi/branches/common_sl/src/java/org/apache/poi/EncryptedDocumentException.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/EncryptedDocumentException.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/EncryptedDocumentException.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/EncryptedDocumentException.java Sun Jul 19 19:00:32 2015
@@ -16,9 +16,10 @@
 ==================================================================== */
 package org.apache.poi;
 
-@SuppressWarnings("serial")
 public class EncryptedDocumentException extends IllegalStateException
 {
+    private static final long serialVersionUID = 7276950444540469193L;
+    
 	public EncryptedDocumentException(String s) {
 		super(s);
 	}

Modified: poi/branches/common_sl/src/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/POIDocument.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/POIDocument.java Sun Jul 19 19:00:32 2015
@@ -30,14 +30,11 @@ import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.poifs.crypt.EncryptionInfo;
-import org.apache.poi.poifs.filesystem.DirectoryEntry;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.Entry;
-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;
-import org.apache.poi.util.Internal;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
@@ -45,8 +42,6 @@ import org.apache.poi.util.POILogger;
  * This holds the common functionality for all POI
  *  Document classes.
  * Currently, this relates to Document Information Properties 
- * 
- * @author Nick Burch
  */
 public abstract class POIDocument {
     /** Holds metadata on our document */
@@ -72,20 +67,23 @@ public abstract class POIDocument {
     }
 
     /**
-     * @deprecated use {@link POIDocument#POIDocument(DirectoryNode)} instead 
+     * Constructs from an old-style OPOIFS
      */
-    @Deprecated
-    protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
-       this.directory = dir;
-    }
-
-    protected POIDocument(POIFSFileSystem fs) {
+    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
@@ -179,12 +177,13 @@ public abstract class POIDocument {
     protected PropertySet getPropertySet(String setName, EncryptionInfo encryptionInfo) {
         DirectoryNode dirNode = directory;
         
+        NPOIFSFileSystem encPoifs = null;
         if (encryptionInfo != null) {
             try {
                 InputStream is = encryptionInfo.getDecryptor().getDataStream(directory);
-                POIFSFileSystem poifs = new POIFSFileSystem(is);
+                encPoifs = new NPOIFSFileSystem(is);
                 is.close();
-                dirNode = poifs.getRoot();
+                dirNode = encPoifs.getRoot();
             } catch (Exception e) {
                 logger.log(POILogger.ERROR, "Error getting encrypted property set with name " + setName, e);
                 return null;
@@ -208,6 +207,11 @@ public abstract class POIDocument {
         try {
             // Create the Property Set
             PropertySet set = PropertySetFactory.create(dis);
+            // Tidy up if needed
+            if (encPoifs != null) {
+                encPoifs.close();
+            }
+            // Return the properties
             return set;
         } catch(IOException ie) {
             // Must be corrupt or something like that
@@ -218,26 +222,39 @@ public abstract class POIDocument {
         }
         return null;
     }
+    
+    /**
+     * Writes out the updated standard Document Information Properties (HPSF)
+     *  into the currently open NPOIFSFileSystem
+     * TODO Implement in-place update
+     * 
+     * @throws IOException if an error when writing to the open
+     *      {@link NPOIFSFileSystem} occurs
+     * TODO throws exception if open from stream not file
+     */
+    protected void writeProperties() throws IOException {
+        throw new IllegalStateException("In-place write is not yet supported");
+    }
 
     /**
-     * Writes out the standard Documment Information Properties (HPSF)
+     * Writes out the standard Document Information Properties (HPSF)
      * @param outFS the POIFSFileSystem to write the properties into
      * 
      * @throws IOException if an error when writing to the 
-     *      {@link POIFSFileSystem} occurs
+     *      {@link NPOIFSFileSystem} occurs
      */
-    protected void writeProperties(POIFSFileSystem outFS) throws IOException {
+    protected void writeProperties(NPOIFSFileSystem outFS) throws IOException {
         writeProperties(outFS, null);
     }
     /**
-     * Writes out the standard Documment Information Properties (HPSF)
-     * @param outFS the POIFSFileSystem to write the properties into
+     * Writes out the standard Document Information Properties (HPSF)
+     * @param outFS the NPOIFSFileSystem to write the properties into
      * @param writtenEntries a list of POIFS entries to add the property names too
      * 
      * @throws IOException if an error when writing to the 
-     *      {@link POIFSFileSystem} occurs
+     *      {@link NPOIFSFileSystem} occurs
      */
-    protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
+    protected void writeProperties(NPOIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
         SummaryInformation si = getSummaryInformation();
         if (si != null) {
             writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, outFS);
@@ -258,12 +275,12 @@ public abstract class POIDocument {
      * Writes out a given ProperySet
      * @param name the (POIFS Level) name of the property to write
      * @param set the PropertySet to write out 
-     * @param outFS the POIFSFileSystem to write the property into
+     * @param outFS the NPOIFSFileSystem to write the property into
      * 
      * @throws IOException if an error when writing to the 
-     *      {@link POIFSFileSystem} occurs
+     *      {@link NPOIFSFileSystem} occurs
      */
-    protected void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException {
+    protected void writePropertySet(String name, PropertySet set, NPOIFSFileSystem outFS) throws IOException {
         try {
             MutablePropertySet mSet = new MutablePropertySet(set);
             ByteArrayOutputStream bOut = new ByteArrayOutputStream();
@@ -288,55 +305,4 @@ public abstract class POIDocument {
      * @throws IOException thrown on errors writing to the stream
      */
     public abstract void write(OutputStream out) throws IOException;
-
-    /**
-     * Copies nodes from one POIFS to the other minus the excepts
-     * @param source is the source POIFS to copy from
-     * @param target is the target POIFS to copy to
-     * @param excepts is a list of Strings specifying what nodes NOT to copy
-     * 
-     * @throws IOException thrown on errors writing to the target file system.
-     * 
-     * @deprecated Use {@link EntryUtils#copyNodes(DirectoryEntry, DirectoryEntry, List)} instead
-     */
-    @Deprecated
-    protected void copyNodes( POIFSFileSystem source, POIFSFileSystem target,
-            List<String> excepts ) throws IOException {
-        EntryUtils.copyNodes( source, target, excepts );
-    }
-
-   /**
-    * Copies nodes from one POIFS to the other minus the excepts
-    * @param sourceRoot is the source POIFS to copy from
-    * @param targetRoot is the target POIFS to copy to
-    * @param excepts is a list of Strings specifying what nodes NOT to copy
-     * 
-     * @throws IOException thrown on errors writing to the target directory node.
-     * 
-    * @deprecated Use {@link EntryUtils#copyNodes(DirectoryEntry, DirectoryEntry, List)} instead
-    */
-    @Deprecated
-    protected void copyNodes( DirectoryNode sourceRoot,
-            DirectoryNode targetRoot, List<String> excepts ) throws IOException
-    {
-        EntryUtils.copyNodes( sourceRoot, targetRoot, excepts );
-    }
-
-    /**
-     * Copies an Entry into a target POIFS directory, recursively
-     * 
-     * @param entry the entry to copy from
-     * @param target the entry to write to
-     * 
-     * @throws IOException thrown on errors writing to the target directory entry.
-     * 
-     * @deprecated Use {@link EntryUtils#copyNodeRecursively(Entry, DirectoryEntry)} instead
-     */
-    @Internal
-    @Deprecated
-    protected void copyNodeRecursively( Entry entry, DirectoryEntry target )
-            throws IOException
-    {
-        EntryUtils.copyNodeRecursively( entry, target );
-    }
 }

Modified: poi/branches/common_sl/src/java/org/apache/poi/POIOLE2TextExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/POIOLE2TextExtractor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/POIOLE2TextExtractor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/POIOLE2TextExtractor.java Sun Jul 19 19:00:32 2015
@@ -20,7 +20,6 @@ import org.apache.poi.hpsf.DocumentSumma
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
 import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
 /**
  * Common Parent for OLE2 based Text Extractors
@@ -34,16 +33,28 @@ import org.apache.poi.poifs.filesystem.P
  * @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 
@@ -81,17 +92,4 @@ public abstract class POIOLE2TextExtract
     {
         return document.directory;
     }
-
-    /**
-     * Return the underlying POIFS FileSystem of this document.
-     * 
-     * @return the POIFSFileSystem that is associated with the POIDocument of this extractor. 
-     *
-     * @deprecated Use {@link #getRoot()} instead
-     */
-    @Deprecated
-    public POIFSFileSystem getFileSystem()
-    {
-        return document.directory.getFileSystem();
-    }
 }

Modified: poi/branches/common_sl/src/java/org/apache/poi/POITextExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/POITextExtractor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/POITextExtractor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/POITextExtractor.java Sun Jul 19 19:00:32 2015
@@ -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

Modified: poi/branches/common_sl/src/java/org/apache/poi/ddf/EscherPropertyFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/ddf/EscherPropertyFactory.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/ddf/EscherPropertyFactory.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/ddf/EscherPropertyFactory.java Sun Jul 19 19:00:32 2015
@@ -82,6 +82,13 @@ public final class EscherPropertyFactory
                     pos += ((EscherArrayProperty)p).setArrayData(data, pos);
                 } else {
                     byte[] complexData = ((EscherComplexProperty)p).getComplexData();
+
+                    int leftover = data.length-pos;
+                    if(leftover < complexData.length){
+                        throw new IllegalStateException("Could not read complex escher property, lenght was " + complexData.length + ", but had only " +
+                                leftover + " bytes left");
+                    }
+
                     System.arraycopy(data, pos, complexData, 0, complexData.length);
                     pos += complexData.length;
                 }

Modified: poi/branches/common_sl/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java Sun Jul 19 19:00:32 2015
@@ -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
     public HPSFPropertiesOnlyDocument(NPOIFSFileSystem fs) {
         super(fs.getRoot());
     }
+    public HPSFPropertiesOnlyDocument(OPOIFSFileSystem fs) {
+        super(fs);
+    }
     public HPSFPropertiesOnlyDocument(POIFSFileSystem fs) {
         super(fs);
     }
@@ -44,7 +48,7 @@ public class HPSFPropertiesOnlyDocument
      * Write out, with any properties changes, but nothing else
      */
     public void write(OutputStream out) throws IOException {
-        POIFSFileSystem fs = new POIFSFileSystem();
+        NPOIFSFileSystem fs = new NPOIFSFileSystem();
 
         // For tracking what we've written out, so far
         List<String> excepts = new ArrayList<String>(1);

Modified: poi/branches/common_sl/src/java/org/apache/poi/hpsf/Section.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hpsf/Section.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hpsf/Section.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hpsf/Section.java Sun Jul 19 19:00:32 2015
@@ -285,7 +285,7 @@ public class Section
         /*
          * Extract the dictionary (if available).
          */
-        dictionary = (Map) getProperty(0);
+        dictionary = (Map<Long,String>) getProperty(0);
     }
 
 

Modified: poi/branches/common_sl/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Sun Jul 19 19:00:32 2015
@@ -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.P
  *  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) {
@@ -57,6 +58,10 @@ public class HPSFPropertiesExtractor ext
     }
 
     public String getDocumentSummaryInformationText() {
+        if(document == null) {  // event based extractor does not have a document
+            return "";
+        }
+
         DocumentSummaryInformation dsi = document.getDocumentSummaryInformation();
         StringBuffer text = new StringBuffer();
 
@@ -78,6 +83,10 @@ public class HPSFPropertiesExtractor ext
         return text.toString();
     }
     public String getSummaryInformationText() {
+        if(document == null) {  // event based extractor does not have a document
+            return "";
+        }
+
         SummaryInformation si = document.getSummaryInformation();
 
         // Just normal properties

Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java Sun Jul 19 19:00:32 2015
@@ -34,7 +34,7 @@ import org.apache.poi.hssf.record.Drawin
 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);

Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffViewer.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffViewer.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffViewer.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/dev/BiffViewer.java Sun Jul 19 19:00:32 2015
@@ -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,330 +82,330 @@ import org.apache.poi.hssf.record.pivott
 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;
 
 /**
  *  Utillity for reading in BIFF8 records and displaying data from them.
- *
- *@author     Andrew C. Oliver (acoliver at apache dot org)
- *@author     Glen Stampoultzis (glens at apache.org)
- *@see        #main
+ * @see        #main
  */
 public final class BiffViewer {
-	static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
+    static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
 
     private BiffViewer() {
-		// no instances of this class
-	}
-
-	/**
-	 *  Create an array of records from an input stream
-	 *
-	 *@param  is the InputStream from which the records will be obtained
-	 *@return an array of Records created from the InputStream
-	 *@exception  RecordFormatException  on error processing the InputStream
-	 */
-	public static Record[] createRecords(InputStream is, PrintStream ps, BiffRecordListener recListener, boolean dumpInterpretedRecords)
-			throws RecordFormatException {
-		List<Record> temp = new ArrayList<Record>();
-
-		RecordInputStream recStream = new RecordInputStream(is);
-		while (true) {
-			boolean hasNext;
-			try {
-				hasNext = recStream.hasNextRecord();
-			} catch (LeftoverDataException e) {
-				e.printStackTrace();
-				System.err.println("Discarding " + recStream.remaining() + " bytes and continuing");
-				recStream.readRemainder();
-				hasNext = recStream.hasNextRecord();
-			}
-			if (!hasNext) {
-				break;
-			}
-			recStream.nextRecord();
-			if (recStream.getSid() == 0) {
-				continue;
-			}
-			Record record;
-			if (dumpInterpretedRecords) {
-				record = createRecord (recStream);
-				if (record.getSid() == ContinueRecord.sid) {
-					continue;
-				}
-				temp.add(record);
-
-				if (dumpInterpretedRecords) {
-					for (String header : recListener.getRecentHeaders()) {
-						ps.println(header);
-					}
-					ps.print(record.toString());
-				}
-			} else {
-				recStream.readRemainder();
-			}
-			ps.println();
-		}
-		Record[] result = new Record[temp.size()];
-		temp.toArray(result);
-		return result;
-	}
-
-
-	/**
-	 *  Essentially a duplicate of RecordFactory. Kept separate as not to screw
-	 *  up non-debug operations.
-	 *
-	 */
-	private static Record createRecord(RecordInputStream in) {
-		switch (in.getSid()) {
-			case AreaFormatRecord.sid:     return new AreaFormatRecord(in);
-			case AreaRecord.sid:           return new AreaRecord(in);
-			case ArrayRecord.sid:          return new ArrayRecord(in);
-			case AxisLineFormatRecord.sid: return new AxisLineFormatRecord(in);
-			case AxisOptionsRecord.sid:    return new AxisOptionsRecord(in);
-			case AxisParentRecord.sid:     return new AxisParentRecord(in);
-			case AxisRecord.sid:           return new AxisRecord(in);
-			case AxisUsedRecord.sid:       return new AxisUsedRecord(in);
-			case AutoFilterInfoRecord.sid: return new AutoFilterInfoRecord(in);
-			case BOFRecord.sid:            return new BOFRecord(in);
-			case BackupRecord.sid:         return new BackupRecord(in);
-			case BarRecord.sid:            return new BarRecord(in);
-			case BeginRecord.sid:          return new BeginRecord(in);
-			case BlankRecord.sid:          return new BlankRecord(in);
-			case BookBoolRecord.sid:       return new BookBoolRecord(in);
-			case BoolErrRecord.sid:        return new BoolErrRecord(in);
-			case BottomMarginRecord.sid:   return new BottomMarginRecord(in);
-			case BoundSheetRecord.sid:     return new BoundSheetRecord(in);
-			case CFHeaderRecord.sid:       return new CFHeaderRecord(in);
-			case CFRuleRecord.sid:         return new CFRuleRecord(in);
-			case CalcCountRecord.sid:      return new CalcCountRecord(in);
-			case CalcModeRecord.sid:       return new CalcModeRecord(in);
-			case CategorySeriesAxisRecord.sid: return new CategorySeriesAxisRecord(in);
-			case ChartFormatRecord.sid:    return new ChartFormatRecord(in);
-			case ChartRecord.sid:          return new ChartRecord(in);
-			case CodepageRecord.sid:       return new CodepageRecord(in);
-			case ColumnInfoRecord.sid:     return new ColumnInfoRecord(in);
-			case ContinueRecord.sid:       return new ContinueRecord(in);
-			case CountryRecord.sid:        return new CountryRecord(in);
-			case DBCellRecord.sid:         return new DBCellRecord(in);
-			case DSFRecord.sid:            return new DSFRecord(in);
-			case DatRecord.sid:            return new DatRecord(in);
-			case DataFormatRecord.sid:     return new DataFormatRecord(in);
-			case DateWindow1904Record.sid: return new DateWindow1904Record(in);
-			case DConRefRecord.sid: return new DConRefRecord(in);
-			case DefaultColWidthRecord.sid:return new DefaultColWidthRecord(in);
-			case DefaultDataLabelTextPropertiesRecord.sid: return new DefaultDataLabelTextPropertiesRecord(in);
-			case DefaultRowHeightRecord.sid: return new DefaultRowHeightRecord(in);
-			case DeltaRecord.sid:          return new DeltaRecord(in);
-			case DimensionsRecord.sid:     return new DimensionsRecord(in);
-			case DrawingGroupRecord.sid:   return new DrawingGroupRecord(in);
-			case DrawingRecordForBiffViewer.sid: return new DrawingRecordForBiffViewer(in);
-			case DrawingSelectionRecord.sid: return new DrawingSelectionRecord(in);
-			case DVRecord.sid:             return new DVRecord(in);
-			case DVALRecord.sid:           return new DVALRecord(in);
-			case EOFRecord.sid:            return new EOFRecord(in);
-			case EndRecord.sid:            return new EndRecord(in);
-			case ExtSSTRecord.sid:         return new ExtSSTRecord(in);
-			case ExtendedFormatRecord.sid: return new ExtendedFormatRecord(in);
-			case ExternSheetRecord.sid:    return new ExternSheetRecord(in);
-			case ExternalNameRecord.sid:   return new ExternalNameRecord(in);
-			case FeatRecord.sid:           return new FeatRecord(in);
-			case FeatHdrRecord.sid:        return new FeatHdrRecord(in);
-			case FilePassRecord.sid:       return new FilePassRecord(in);
-			case FileSharingRecord.sid:    return new FileSharingRecord(in);
-			case FnGroupCountRecord.sid:   return new FnGroupCountRecord(in);
-			case FontBasisRecord.sid:      return new FontBasisRecord(in);
-			case FontIndexRecord.sid:      return new FontIndexRecord(in);
-			case FontRecord.sid:           return new FontRecord(in);
-			case FooterRecord.sid:         return new FooterRecord(in);
-			case FormatRecord.sid:         return new FormatRecord(in);
-			case FormulaRecord.sid:        return new FormulaRecord(in);
-			case FrameRecord.sid:          return new FrameRecord(in);
-			case GridsetRecord.sid:        return new GridsetRecord(in);
-			case GutsRecord.sid:           return new GutsRecord(in);
-			case HCenterRecord.sid:        return new HCenterRecord(in);
-			case HeaderRecord.sid:         return new HeaderRecord(in);
-			case HideObjRecord.sid:        return new HideObjRecord(in);
-			case HorizontalPageBreakRecord.sid: return new HorizontalPageBreakRecord(in);
-			case HyperlinkRecord.sid:      return new HyperlinkRecord(in);
-			case IndexRecord.sid:          return new IndexRecord(in);
-			case InterfaceEndRecord.sid:   return InterfaceEndRecord.create(in);
-			case InterfaceHdrRecord.sid:   return new InterfaceHdrRecord(in);
-			case IterationRecord.sid:      return new IterationRecord(in);
-			case LabelRecord.sid:          return new LabelRecord(in);
-			case LabelSSTRecord.sid:       return new LabelSSTRecord(in);
-			case LeftMarginRecord.sid:     return new LeftMarginRecord(in);
-			case LegendRecord.sid:         return new LegendRecord(in);
-			case LineFormatRecord.sid:     return new LineFormatRecord(in);
-			case LinkedDataRecord.sid:     return new LinkedDataRecord(in);
-			case MMSRecord.sid:            return new MMSRecord(in);
-			case MergeCellsRecord.sid:     return new MergeCellsRecord(in);
-			case MulBlankRecord.sid:       return new MulBlankRecord(in);
-			case MulRKRecord.sid:          return new MulRKRecord(in);
-			case NameRecord.sid:           return new NameRecord(in);
-			case NameCommentRecord.sid:    return new NameCommentRecord(in);
-			case NoteRecord.sid:           return new NoteRecord(in);
-			case NumberRecord.sid:         return new NumberRecord(in);
-			case ObjRecord.sid:            return new ObjRecord(in);
-			case ObjectLinkRecord.sid:     return new ObjectLinkRecord(in);
-			case PaletteRecord.sid:        return new PaletteRecord(in);
-			case PaneRecord.sid:           return new PaneRecord(in);
-			case PasswordRecord.sid:       return new PasswordRecord(in);
-			case PasswordRev4Record.sid:   return new PasswordRev4Record(in);
-			case PlotAreaRecord.sid:       return new PlotAreaRecord(in);
-			case PlotGrowthRecord.sid:     return new PlotGrowthRecord(in);
-			case PrecisionRecord.sid:      return new PrecisionRecord(in);
-			case PrintGridlinesRecord.sid: return new PrintGridlinesRecord(in);
-			case PrintHeadersRecord.sid:   return new PrintHeadersRecord(in);
-			case PrintSetupRecord.sid:     return new PrintSetupRecord(in);
-			case ProtectRecord.sid:        return new ProtectRecord(in);
-			case ProtectionRev4Record.sid: return new ProtectionRev4Record(in);
-			case RKRecord.sid:             return new RKRecord(in);
-			case RecalcIdRecord.sid:       return new RecalcIdRecord(in);
-			case RefModeRecord.sid:        return new RefModeRecord(in);
-			case RefreshAllRecord.sid:     return new RefreshAllRecord(in);
-			case RightMarginRecord.sid:    return new RightMarginRecord(in);
-			case RowRecord.sid:            return new RowRecord(in);
-			case SCLRecord.sid:            return new SCLRecord(in);
-			case SSTRecord.sid:            return new SSTRecord(in);
-			case SaveRecalcRecord.sid:     return new SaveRecalcRecord(in);
-			case SelectionRecord.sid:      return new SelectionRecord(in);
-			case SeriesIndexRecord.sid:    return new SeriesIndexRecord(in);
-			case SeriesListRecord.sid:     return new SeriesListRecord(in);
-			case SeriesRecord.sid:         return new SeriesRecord(in);
-			case SeriesTextRecord.sid:     return new SeriesTextRecord(in);
-			case SeriesToChartGroupRecord.sid: return new SeriesToChartGroupRecord(in);
-			case SharedFormulaRecord.sid:  return new SharedFormulaRecord(in);
-			case SheetPropertiesRecord.sid:return new SheetPropertiesRecord(in);
-			case StringRecord.sid:         return new StringRecord(in);
-			case StyleRecord.sid:          return new StyleRecord(in);
-			case SupBookRecord.sid:        return new SupBookRecord(in);
-			case TabIdRecord.sid:          return new TabIdRecord(in);
-			case TableStylesRecord.sid:    return new TableStylesRecord(in);
-			case TableRecord.sid:          return new TableRecord(in);
-			case TextObjectRecord.sid:     return new TextObjectRecord(in);
-			case TextRecord.sid:           return new TextRecord(in);
-			case TickRecord.sid:           return new TickRecord(in);
-			case TopMarginRecord.sid:      return new TopMarginRecord(in);
-            case UncalcedRecord.sid:       return new UncalcedRecord(in);
-			case UnitsRecord.sid:          return new UnitsRecord(in);
-			case UseSelFSRecord.sid:       return new UseSelFSRecord(in);
-			case VCenterRecord.sid:        return new VCenterRecord(in);
-			case ValueRangeRecord.sid:     return new ValueRangeRecord(in);
-			case VerticalPageBreakRecord.sid: return new VerticalPageBreakRecord(in);
-			case WSBoolRecord.sid:         return new WSBoolRecord(in);
-			case WindowOneRecord.sid:      return new WindowOneRecord(in);
-			case WindowProtectRecord.sid:  return new WindowProtectRecord(in);
-			case WindowTwoRecord.sid:      return new WindowTwoRecord(in);
-			case WriteAccessRecord.sid:    return new WriteAccessRecord(in);
-			case WriteProtectRecord.sid:   return new WriteProtectRecord(in);
-
-			// chart
-			case CatLabRecord.sid:         return new CatLabRecord(in);
-			case ChartEndBlockRecord.sid:  return new ChartEndBlockRecord(in);
-			case ChartEndObjectRecord.sid: return new ChartEndObjectRecord(in);
-			case ChartFRTInfoRecord.sid:   return new ChartFRTInfoRecord(in);
-			case ChartStartBlockRecord.sid: return new ChartStartBlockRecord(in);
-			case ChartStartObjectRecord.sid: return new ChartStartObjectRecord(in);
-
-			// pivot table
-			case StreamIDRecord.sid:        return new StreamIDRecord(in);
-			case ViewSourceRecord.sid:      return new ViewSourceRecord(in);
-			case PageItemRecord.sid:        return new PageItemRecord(in);
-			case ViewDefinitionRecord.sid:  return new ViewDefinitionRecord(in);
-			case ViewFieldsRecord.sid:      return new ViewFieldsRecord(in);
-			case DataItemRecord.sid:        return new DataItemRecord(in);
-			case ExtendedPivotTableViewFieldsRecord.sid: return new ExtendedPivotTableViewFieldsRecord(in);
-		}
-		return new UnknownRecord(in);
-	}
-
-	private static final class CommandArgs {
-
-		private final boolean _biffhex;
-		private final boolean _noint;
-		private final boolean _out;
-		private final boolean _rawhex;
-		private final boolean _noHeader;
-		private final File _file;
-
-		private CommandArgs(boolean biffhex, boolean noint, boolean out, boolean rawhex, boolean noHeader, File file) {
-			_biffhex = biffhex;
-			_noint = noint;
-			_out = out;
-			_rawhex = rawhex;
-			_file = file;
-			_noHeader = noHeader;
-		}
+        // no instances of this class
+    }
 
-		public static CommandArgs parse(String[] args) throws CommandParseException {
-			int nArgs = args.length;
-			boolean biffhex = false;
-			boolean noint = false;
-			boolean out = false;
-			boolean rawhex = false;
-			boolean noheader = false;
-			File file = null;
-			for (int i=0; i<nArgs; i++) {
-				String arg = args[i];
-				if (arg.startsWith("--")) {
-					if ("--biffhex".equals(arg)) {
-						biffhex = true;
-					} else if ("--noint".equals(arg)) {
-						noint = true;
-					} else if ("--out".equals(arg)) {
-						out = true;
-					} else if ("--escher".equals(arg)) {
-						System.setProperty("poi.deserialize.escher", "true");
-					} else if ("--rawhex".equals(arg)) {
-						rawhex = true;
-					} else if ("--noheader".equals(arg)) {
-						noheader = true;
-					} else {
-						throw new CommandParseException("Unexpected option '" + arg + "'");
-					}
-					continue;
-				}
-				file = new File(arg);
-				if (!file.exists()) {
-					throw new CommandParseException("Specified file '" + arg + "' does not exist");
-				}
-				if (i+1<nArgs) {
-					throw new CommandParseException("File name must be the last arg");
-				}
-			}
-			if (file == null) {
-				throw new CommandParseException("Biff viewer needs a filename");
-			}
-			return new CommandArgs(biffhex, noint, out, rawhex, noheader, file);
-		}
-		public boolean shouldDumpBiffHex() {
-			return _biffhex;
-		}
-		public boolean shouldDumpRecordInterpretations() {
-			return !_noint;
-		}
-		public boolean shouldOutputToFile() {
-			return _out;
-		}
-		public boolean shouldOutputRawHexOnly() {
-			return _rawhex;
-		}
-		public boolean suppressHeader() {
-			return _noHeader;
-		}
-		public File getFile() {
-			return _file;
-		}
-	}
-	private static final class CommandParseException extends Exception {
-		public CommandParseException(String msg) {
-			super(msg);
-		}
-	}
+    /**
+     *  Create an array of records from an input stream
+     *
+     *@param  is the InputStream from which the records will be obtained
+     *@return an array of Records created from the InputStream
+     *@exception  RecordFormatException  on error processing the InputStream
+     */
+    public static Record[] createRecords(InputStream is, PrintStream ps, BiffRecordListener recListener, boolean dumpInterpretedRecords)
+            throws RecordFormatException {
+        List<Record> temp = new ArrayList<Record>();
+
+        RecordInputStream recStream = new RecordInputStream(is);
+        while (true) {
+            boolean hasNext;
+            try {
+                hasNext = recStream.hasNextRecord();
+            } catch (LeftoverDataException e) {
+                e.printStackTrace();
+                System.err.println("Discarding " + recStream.remaining() + " bytes and continuing");
+                recStream.readRemainder();
+                hasNext = recStream.hasNextRecord();
+            }
+            if (!hasNext) {
+                break;
+            }
+            recStream.nextRecord();
+            if (recStream.getSid() == 0) {
+                continue;
+            }
+            Record record;
+            if (dumpInterpretedRecords) {
+                record = createRecord (recStream);
+                if (record.getSid() == ContinueRecord.sid) {
+                    continue;
+                }
+                temp.add(record);
+
+                if (dumpInterpretedRecords) {
+                    for (String header : recListener.getRecentHeaders()) {
+                        ps.println(header);
+                    }
+                    ps.print(record.toString());
+                }
+            } else {
+                recStream.readRemainder();
+            }
+            ps.println();
+        }
+        Record[] result = new Record[temp.size()];
+        temp.toArray(result);
+        return result;
+    }
+
+
+    /**
+     *  Essentially a duplicate of RecordFactory. Kept separate as not to screw
+     *  up non-debug operations.
+     *
+     */
+    private static Record createRecord(RecordInputStream in) {
+        switch (in.getSid()) {
+            case AreaFormatRecord.sid:        return new AreaFormatRecord(in);
+            case AreaRecord.sid:              return new AreaRecord(in);
+            case ArrayRecord.sid:             return new ArrayRecord(in);
+            case AxisLineFormatRecord.sid:    return new AxisLineFormatRecord(in);
+            case AxisOptionsRecord.sid:       return new AxisOptionsRecord(in);
+            case AxisParentRecord.sid:        return new AxisParentRecord(in);
+            case AxisRecord.sid:              return new AxisRecord(in);
+            case AxisUsedRecord.sid:          return new AxisUsedRecord(in);
+            case AutoFilterInfoRecord.sid:    return new AutoFilterInfoRecord(in);
+            case BOFRecord.sid:               return new BOFRecord(in);
+            case BackupRecord.sid:            return new BackupRecord(in);
+            case BarRecord.sid:               return new BarRecord(in);
+            case BeginRecord.sid:             return new BeginRecord(in);
+            case BlankRecord.sid:             return new BlankRecord(in);
+            case BookBoolRecord.sid:          return new BookBoolRecord(in);
+            case BoolErrRecord.sid:           return new BoolErrRecord(in);
+            case BottomMarginRecord.sid:      return new BottomMarginRecord(in);
+            case BoundSheetRecord.sid:        return new BoundSheetRecord(in);
+            case CFHeaderRecord.sid:          return new CFHeaderRecord(in);
+            case CFHeader12Record.sid:        return new CFHeader12Record(in);
+            case CFRuleRecord.sid:            return new CFRuleRecord(in);
+            case CFRule12Record.sid:          return new CFRule12Record(in);
+            // TODO Add CF Ex, and remove from UnknownRecord 
+            case CalcCountRecord.sid:         return new CalcCountRecord(in);
+            case CalcModeRecord.sid:          return new CalcModeRecord(in);
+            case CategorySeriesAxisRecord.sid:return new CategorySeriesAxisRecord(in);
+            case ChartFormatRecord.sid:       return new ChartFormatRecord(in);
+            case ChartRecord.sid:             return new ChartRecord(in);
+            case CodepageRecord.sid:          return new CodepageRecord(in);
+            case ColumnInfoRecord.sid:        return new ColumnInfoRecord(in);
+            case ContinueRecord.sid:          return new ContinueRecord(in);
+            case CountryRecord.sid:           return new CountryRecord(in);
+            case DBCellRecord.sid:            return new DBCellRecord(in);
+            case DSFRecord.sid:               return new DSFRecord(in);
+            case DatRecord.sid:               return new DatRecord(in);
+            case DataFormatRecord.sid:        return new DataFormatRecord(in);
+            case DateWindow1904Record.sid:    return new DateWindow1904Record(in);
+            case DConRefRecord.sid:           return new DConRefRecord(in);
+            case DefaultColWidthRecord.sid:   return new DefaultColWidthRecord(in);
+            case DefaultDataLabelTextPropertiesRecord.sid: return new DefaultDataLabelTextPropertiesRecord(in);
+            case DefaultRowHeightRecord.sid:  return new DefaultRowHeightRecord(in);
+            case DeltaRecord.sid:             return new DeltaRecord(in);
+            case DimensionsRecord.sid:        return new DimensionsRecord(in);
+            case DrawingGroupRecord.sid:      return new DrawingGroupRecord(in);
+            case DrawingRecordForBiffViewer.sid: return new DrawingRecordForBiffViewer(in);
+            case DrawingSelectionRecord.sid:  return new DrawingSelectionRecord(in);
+            case DVRecord.sid:                return new DVRecord(in);
+            case DVALRecord.sid:              return new DVALRecord(in);
+            case EOFRecord.sid:               return new EOFRecord(in);
+            case EndRecord.sid:               return new EndRecord(in);
+            case ExtSSTRecord.sid:            return new ExtSSTRecord(in);
+            case ExtendedFormatRecord.sid:    return new ExtendedFormatRecord(in);
+            case ExternSheetRecord.sid:       return new ExternSheetRecord(in);
+            case ExternalNameRecord.sid:      return new ExternalNameRecord(in);
+            case FeatRecord.sid:              return new FeatRecord(in);
+            case FeatHdrRecord.sid:           return new FeatHdrRecord(in);
+            case FilePassRecord.sid:          return new FilePassRecord(in);
+            case FileSharingRecord.sid:       return new FileSharingRecord(in);
+            case FnGroupCountRecord.sid:      return new FnGroupCountRecord(in);
+            case FontBasisRecord.sid:         return new FontBasisRecord(in);
+            case FontIndexRecord.sid:         return new FontIndexRecord(in);
+            case FontRecord.sid:              return new FontRecord(in);
+            case FooterRecord.sid:            return new FooterRecord(in);
+            case FormatRecord.sid:            return new FormatRecord(in);
+            case FormulaRecord.sid:           return new FormulaRecord(in);
+            case FrameRecord.sid:             return new FrameRecord(in);
+            case GridsetRecord.sid:           return new GridsetRecord(in);
+            case GutsRecord.sid:              return new GutsRecord(in);
+            case HCenterRecord.sid:           return new HCenterRecord(in);
+            case HeaderRecord.sid:            return new HeaderRecord(in);
+            case HideObjRecord.sid:           return new HideObjRecord(in);
+            case HorizontalPageBreakRecord.sid: return new HorizontalPageBreakRecord(in);
+            case HyperlinkRecord.sid:         return new HyperlinkRecord(in);
+            case IndexRecord.sid:             return new IndexRecord(in);
+            case InterfaceEndRecord.sid:      return InterfaceEndRecord.create(in);
+            case InterfaceHdrRecord.sid:      return new InterfaceHdrRecord(in);
+            case IterationRecord.sid:         return new IterationRecord(in);
+            case LabelRecord.sid:             return new LabelRecord(in);
+            case LabelSSTRecord.sid:          return new LabelSSTRecord(in);
+            case LeftMarginRecord.sid:        return new LeftMarginRecord(in);
+            case LegendRecord.sid:            return new LegendRecord(in);
+            case LineFormatRecord.sid:        return new LineFormatRecord(in);
+            case LinkedDataRecord.sid:        return new LinkedDataRecord(in);
+            case MMSRecord.sid:               return new MMSRecord(in);
+            case MergeCellsRecord.sid:        return new MergeCellsRecord(in);
+            case MulBlankRecord.sid:          return new MulBlankRecord(in);
+            case MulRKRecord.sid:             return new MulRKRecord(in);
+            case NameRecord.sid:              return new NameRecord(in);
+            case NameCommentRecord.sid:       return new NameCommentRecord(in);
+            case NoteRecord.sid:              return new NoteRecord(in);
+            case NumberRecord.sid:            return new NumberRecord(in);
+            case ObjRecord.sid:               return new ObjRecord(in);
+            case ObjectLinkRecord.sid:        return new ObjectLinkRecord(in);
+            case PaletteRecord.sid:           return new PaletteRecord(in);
+            case PaneRecord.sid:              return new PaneRecord(in);
+            case PasswordRecord.sid:          return new PasswordRecord(in);
+            case PasswordRev4Record.sid:      return new PasswordRev4Record(in);
+            case PlotAreaRecord.sid:          return new PlotAreaRecord(in);
+            case PlotGrowthRecord.sid:        return new PlotGrowthRecord(in);
+            case PrecisionRecord.sid:         return new PrecisionRecord(in);
+            case PrintGridlinesRecord.sid:    return new PrintGridlinesRecord(in);
+            case PrintHeadersRecord.sid:      return new PrintHeadersRecord(in);
+            case PrintSetupRecord.sid:        return new PrintSetupRecord(in);
+            case ProtectRecord.sid:           return new ProtectRecord(in);
+            case ProtectionRev4Record.sid:    return new ProtectionRev4Record(in);
+            case RKRecord.sid:                return new RKRecord(in);
+            case RecalcIdRecord.sid:          return new RecalcIdRecord(in);
+            case RefModeRecord.sid:           return new RefModeRecord(in);
+            case RefreshAllRecord.sid:        return new RefreshAllRecord(in);
+            case RightMarginRecord.sid:       return new RightMarginRecord(in);
+            case RowRecord.sid:               return new RowRecord(in);
+            case SCLRecord.sid:               return new SCLRecord(in);
+            case SSTRecord.sid:               return new SSTRecord(in);
+            case SaveRecalcRecord.sid:        return new SaveRecalcRecord(in);
+            case SelectionRecord.sid:         return new SelectionRecord(in);
+            case SeriesIndexRecord.sid:       return new SeriesIndexRecord(in);
+            case SeriesListRecord.sid:        return new SeriesListRecord(in);
+            case SeriesRecord.sid:            return new SeriesRecord(in);
+            case SeriesTextRecord.sid:        return new SeriesTextRecord(in);
+            case SeriesToChartGroupRecord.sid:return new SeriesToChartGroupRecord(in);
+            case SharedFormulaRecord.sid:     return new SharedFormulaRecord(in);
+            case SheetPropertiesRecord.sid:   return new SheetPropertiesRecord(in);
+            case StringRecord.sid:            return new StringRecord(in);
+            case StyleRecord.sid:             return new StyleRecord(in);
+            case SupBookRecord.sid:           return new SupBookRecord(in);
+            case TabIdRecord.sid:             return new TabIdRecord(in);
+            case TableStylesRecord.sid:       return new TableStylesRecord(in);
+            case TableRecord.sid:             return new TableRecord(in);
+            case TextObjectRecord.sid:        return new TextObjectRecord(in);
+            case TextRecord.sid:              return new TextRecord(in);
+            case TickRecord.sid:              return new TickRecord(in);
+            case TopMarginRecord.sid:         return new TopMarginRecord(in);
+            case UncalcedRecord.sid:          return new UncalcedRecord(in);
+            case UnitsRecord.sid:             return new UnitsRecord(in);
+            case UseSelFSRecord.sid:          return new UseSelFSRecord(in);
+            case VCenterRecord.sid:           return new VCenterRecord(in);
+            case ValueRangeRecord.sid:        return new ValueRangeRecord(in);
+            case VerticalPageBreakRecord.sid: return new VerticalPageBreakRecord(in);
+            case WSBoolRecord.sid:            return new WSBoolRecord(in);
+            case WindowOneRecord.sid:         return new WindowOneRecord(in);
+            case WindowProtectRecord.sid:     return new WindowProtectRecord(in);
+            case WindowTwoRecord.sid:         return new WindowTwoRecord(in);
+            case WriteAccessRecord.sid:       return new WriteAccessRecord(in);
+            case WriteProtectRecord.sid:      return new WriteProtectRecord(in);
+
+            // chart
+            case CatLabRecord.sid:            return new CatLabRecord(in);
+            case ChartEndBlockRecord.sid:     return new ChartEndBlockRecord(in);
+            case ChartEndObjectRecord.sid:    return new ChartEndObjectRecord(in);
+            case ChartFRTInfoRecord.sid:      return new ChartFRTInfoRecord(in);
+            case ChartStartBlockRecord.sid:   return new ChartStartBlockRecord(in);
+            case ChartStartObjectRecord.sid:  return new ChartStartObjectRecord(in);
+
+            // pivot table
+            case StreamIDRecord.sid:           return new StreamIDRecord(in);
+            case ViewSourceRecord.sid:         return new ViewSourceRecord(in);
+            case PageItemRecord.sid:           return new PageItemRecord(in);
+            case ViewDefinitionRecord.sid:     return new ViewDefinitionRecord(in);
+            case ViewFieldsRecord.sid:         return new ViewFieldsRecord(in);
+            case DataItemRecord.sid:           return new DataItemRecord(in);
+            case ExtendedPivotTableViewFieldsRecord.sid: return new ExtendedPivotTableViewFieldsRecord(in);
+        }
+        return new UnknownRecord(in);
+    }
+
+    private static final class CommandArgs {
+
+        private final boolean _biffhex;
+        private final boolean _noint;
+        private final boolean _out;
+        private final boolean _rawhex;
+        private final boolean _noHeader;
+        private final File _file;
+
+        private CommandArgs(boolean biffhex, boolean noint, boolean out, boolean rawhex, boolean noHeader, File file) {
+            _biffhex = biffhex;
+            _noint = noint;
+            _out = out;
+            _rawhex = rawhex;
+            _file = file;
+            _noHeader = noHeader;
+        }
+
+        public static CommandArgs parse(String[] args) throws CommandParseException {
+            int nArgs = args.length;
+            boolean biffhex = false;
+            boolean noint = false;
+            boolean out = false;
+            boolean rawhex = false;
+            boolean noheader = false;
+            File file = null;
+            for (int i=0; i<nArgs; i++) {
+                String arg = args[i];
+                if (arg.startsWith("--")) {
+                    if ("--biffhex".equals(arg)) {
+                        biffhex = true;
+                    } else if ("--noint".equals(arg)) {
+                        noint = true;
+                    } else if ("--out".equals(arg)) {
+                        out = true;
+                    } else if ("--escher".equals(arg)) {
+                        System.setProperty("poi.deserialize.escher", "true");
+                    } else if ("--rawhex".equals(arg)) {
+                        rawhex = true;
+                    } else if ("--noheader".equals(arg)) {
+                        noheader = true;
+                    } else {
+                        throw new CommandParseException("Unexpected option '" + arg + "'");
+                    }
+                    continue;
+                }
+                file = new File(arg);
+                if (!file.exists()) {
+                    throw new CommandParseException("Specified file '" + arg + "' does not exist");
+                }
+                if (i+1<nArgs) {
+                    throw new CommandParseException("File name must be the last arg");
+                }
+            }
+            if (file == null) {
+                throw new CommandParseException("Biff viewer needs a filename");
+            }
+            return new CommandArgs(biffhex, noint, out, rawhex, noheader, file);
+        }
+        public boolean shouldDumpBiffHex() {
+            return _biffhex;
+        }
+        public boolean shouldDumpRecordInterpretations() {
+            return !_noint;
+        }
+        public boolean shouldOutputToFile() {
+            return _out;
+        }
+        public boolean shouldOutputRawHexOnly() {
+            return _rawhex;
+        }
+        public boolean suppressHeader() {
+            return _noHeader;
+        }
+        public File getFile() {
+            return _file;
+        }
+    }
+    private static final class CommandParseException extends Exception {
+        public CommandParseException(String msg) {
+            super(msg);
+        }
+    }
 
 	/**
 	 * Method main with 1 argument just run straight biffview against given
@@ -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);
 	}

Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java Sun Jul 19 19:00:32 2015
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.eventusermod
 
 import java.io.InputStream;
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.poi.hssf.eventusermodel.HSSFUserException;
 import org.apache.poi.hssf.record.*;
@@ -56,11 +57,24 @@ public class HSSFEventFactory {
     * @param req an Instance of HSSFRequest which has your registered listeners
     * @param dir  a DirectoryNode containing your workbook
     */
-   public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException {
-      InputStream in = dir.createDocumentInputStream("Workbook");
+    public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException {
+        // some old documents have "WORKBOOK" or "BOOK"
+        final String name;
+        Set<String> entryNames = dir.getEntryNames();
+        if (entryNames.contains("Workbook")) {
+            name = "Workbook";
+        } else if (entryNames.contains("WORKBOOK")) {
+            name = "WORKBOOK";
+        } else if (entryNames.contains("BOOK")) {
+            name = "BOOK";
+        } else {
+            name = "Workbook";
+        }
 
-      processEvents(req, in);
-   }
+        InputStream in = dir.createDocumentInputStream(name);
+
+        processEvents(req, in);
+    }
 
    /**
     * Processes a file into essentially record events.

Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java Sun Jul 19 19:00:32 2015
@@ -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 ex
 
     public EventBasedExcelExtractor( DirectoryNode dir )
     {
-        super( null );
+        super( (POIDocument)null );
         _dir = dir;
     }
 
@@ -84,16 +85,6 @@ public class EventBasedExcelExtractor ex
    }
 
    /**
-    * Return the underlying POIFS FileSystem of
-    *  this document.
-    *
-    * @deprecated Use {@link #getRoot()} instead
-    */
-   public POIFSFileSystem getFileSystem() {
-      return _dir.getFileSystem();
-   }
-
-   /**
     * Would return the document information metadata for the document,
     *  if we supported it
     */

Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/model/InternalWorkbook.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/model/InternalWorkbook.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/model/InternalWorkbook.java Sun Jul 19 19:00:32 2015
@@ -774,11 +774,12 @@ public final class InternalWorkbook {
             }
         }
         
-        // also tell the LinkTable about the removed sheet
-        // +1 because we already removed it from the count of sheets!
-        for(int i = sheetIndex+1;i < getNumSheets()+1;i++) {
-            // also update the link-table as otherwise references might point at invalid sheets
-            linkTable.removeSheet(i);
+        if (linkTable != null) {
+            // also tell the LinkTable about the removed sheet
+            // +1 because we already removed it from the count of sheets!
+            for(int i = sheetIndex+1;i < getNumSheets()+1;i++) {
+                linkTable.removeSheet(i);
+            }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org