You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2019/02/23 07:52:24 UTC
svn commit: r1854192 [2/2] - in /poi/trunk/src:
ooxml/testcases/org/apache/poi/ ooxml/testcases/org/apache/poi/openxml4j/opc/
ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/
ooxml/testcases/org/apache/poi/ss/format/ ooxml/testcases/org/apache/...
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1854192&r1=1854191&r2=1854192&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Sat Feb 23 07:52:24 2019
@@ -17,8 +17,10 @@
package org.apache.poi.xwpf.usermodel;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -104,23 +106,23 @@ public class TestXWPFRun {
// True values: "true", "1", "on"
bold.setVal(STOnOff.TRUE);
- assertEquals(true, run.isBold());
+ assertTrue(run.isBold());
bold.setVal(STOnOff.X_1);
- assertEquals(true, run.isBold());
+ assertTrue(run.isBold());
bold.setVal(STOnOff.ON);
- assertEquals(true, run.isBold());
+ assertTrue(run.isBold());
// False values: "false", "0", "off"
bold.setVal(STOnOff.FALSE);
- assertEquals(false, run.isBold());
+ assertFalse(run.isBold());
bold.setVal(STOnOff.X_0);
- assertEquals(false, run.isBold());
+ assertFalse(run.isBold());
bold.setVal(STOnOff.OFF);
- assertEquals(false, run.isBold());
+ assertFalse(run.isBold());
}
@Test
@@ -129,7 +131,7 @@ public class TestXWPFRun {
rpr.addNewB().setVal(STOnOff.TRUE);
XWPFRun run = new XWPFRun(ctRun, irb);
- assertEquals(true, run.isBold());
+ assertTrue(run.isBold());
run.setBold(false);
// Implementation detail: POI natively prefers <w:b w:val="false"/>,
@@ -143,7 +145,7 @@ public class TestXWPFRun {
rpr.addNewI().setVal(STOnOff.TRUE);
XWPFRun run = new XWPFRun(ctRun, irb);
- assertEquals(true, run.isItalic());
+ assertTrue(run.isItalic());
run.setItalic(false);
assertEquals(STOnOff.FALSE, rpr.getI().getVal());
@@ -155,7 +157,7 @@ public class TestXWPFRun {
rpr.addNewStrike().setVal(STOnOff.TRUE);
XWPFRun run = new XWPFRun(ctRun, irb);
- assertEquals(true, run.isStrikeThrough());
+ assertTrue(run.isStrikeThrough());
run.setStrikeThrough(false);
assertEquals(STOnOff.FALSE, rpr.getStrike().getVal());
@@ -297,17 +299,17 @@ public class TestXWPFRun {
run = p.getRuns().get(0);
assertEquals("This is a test document", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
run = p.getRuns().get(1);
assertEquals(".", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
// Next paragraph is all in one style, but a different one
@@ -317,11 +319,11 @@ public class TestXWPFRun {
run = p.getRuns().get(0);
assertEquals("This bit is in bold and italic", run.toString());
- assertEquals(true, run.isBold());
- assertEquals(true, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(true, run.getCTR().getRPr().isSetB());
- assertEquals(false, run.getCTR().getRPr().getB().isSetVal());
+ assertTrue(run.isBold());
+ assertTrue(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertTrue(run.getCTR().getRPr().isSetB());
+ assertFalse(run.getCTR().getRPr().getB().isSetVal());
// Back to normal
@@ -331,10 +333,10 @@ public class TestXWPFRun {
run = p.getRuns().get(0);
assertEquals("Back to normal", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
// Different styles in one paragraph
@@ -344,75 +346,75 @@ public class TestXWPFRun {
run = p.getRuns().get(0);
assertEquals("This contains ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
run = p.getRuns().get(1);
assertEquals("BOLD", run.toString());
- assertEquals(true, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
+ assertTrue(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
run = p.getRuns().get(2);
assertEquals(", ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
run = p.getRuns().get(3);
assertEquals("ITALIC", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(true, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
+ assertFalse(run.isBold());
+ assertTrue(run.isItalic());
+ assertFalse(run.isStrikeThrough());
run = p.getRuns().get(4);
assertEquals(" and ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
run = p.getRuns().get(5);
assertEquals("BOTH", run.toString());
- assertEquals(true, run.isBold());
- assertEquals(true, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
+ assertTrue(run.isBold());
+ assertTrue(run.isItalic());
+ assertFalse(run.isStrikeThrough());
run = p.getRuns().get(6);
assertEquals(", as well as ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
run = p.getRuns().get(7);
assertEquals("RED", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
run = p.getRuns().get(8);
assertEquals(" and ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
run = p.getRuns().get(9);
assertEquals("YELLOW", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
run = p.getRuns().get(10);
assertEquals(" text.", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrikeThrough());
- assertEquals(null, run.getCTR().getRPr());
+ assertFalse(run.isBold());
+ assertFalse(run.isItalic());
+ assertFalse(run.isStrikeThrough());
+ assertNull(run.getCTR().getRPr());
doc.close();
}
@@ -643,7 +645,7 @@ public class TestXWPFRun {
}
@Test
- public void testSetters() throws IOException {
+ public void testSetters() {
XWPFDocument document = new XWPFDocument();
final XWPFRun run = document.createParagraph().createRun();
@@ -679,12 +681,12 @@ public class TestXWPFRun {
XWPFDocument document = new XWPFDocument();
final XWPFRun run = document.createParagraph().createRun();
assertEquals(STHighlightColor.NONE, run.getTextHightlightColor());
- assertEquals(false, run.isHighlighted());
+ assertFalse(run.isHighlighted());
run.setTextHighlightColor("darkGreen"); // See 17.18.40 ST_HighlightColor (Text Highlight Colors)
assertEquals(STHighlightColor.DARK_GREEN, run.getTextHightlightColor());
- assertEquals(true, run.isHighlighted());
+ assertTrue(run.isHighlighted());
run.setTextHighlightColor("none");
- assertEquals(false, run.isHighlighted());
+ assertFalse(run.isHighlighted());
document.close();
}
@@ -693,11 +695,11 @@ public class TestXWPFRun {
public void testSetGetVanish() throws IOException {
XWPFDocument document = new XWPFDocument();
final XWPFRun run = document.createParagraph().createRun();
- assertEquals(false, run.isVanish());
+ assertFalse(run.isVanish());
run.setVanish(true);
- assertEquals(true, run.isVanish());
+ assertTrue(run.isVanish());
run.setVanish(false);
- assertEquals(false, run.isVanish());
+ assertFalse(run.isVanish());
document.close();
}
@@ -727,7 +729,6 @@ public class TestXWPFRun {
assertEquals(STVerticalAlignRun.BASELINE, rpr.getVertAlign().getVal());
}
-
@Test
public void testSetGetEmphasisMark() throws IOException {
XWPFDocument document = new XWPFDocument();
@@ -780,7 +781,9 @@ public class TestXWPFRun {
run.setStyle(styleId);
String candStyleId = run.getCTR().getRPr().getRStyle().getVal();
assertNotNull("Expected to find a run style ID", candStyleId);
- assertEquals(styleId, candStyleId);
+ assertEquals(styleId, candStyleId);
+
+ document.close();
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java?rev=1854192&r1=1854191&r2=1854192&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java Sat Feb 23 07:52:24 2019
@@ -77,19 +77,19 @@ public final class SlideShowDumper {
filename = args[1];
}
- POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
- SlideShowDumper foo = new SlideShowDumper(poifs, System.out);
- poifs.close();
+ try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename))) {
+ SlideShowDumper foo = new SlideShowDumper(poifs, System.out);
- if(args.length > 1) {
- if(args[0].equalsIgnoreCase("-escher")) {
- foo.setDDFEscher(true);
- } else {
- foo.setBasicEscher(true);
+ if(args.length > 1) {
+ if(args[0].equalsIgnoreCase("-escher")) {
+ foo.setDDFEscher(true);
+ } else {
+ foo.setBasicEscher(true);
+ }
}
- }
- foo.printDump();
+ foo.printDump();
+ }
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java?rev=1854192&r1=1854191&r2=1854192&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java Sat Feb 23 07:52:24 2019
@@ -41,38 +41,36 @@ public final class TextStyleListing {
System.exit(1);
}
- HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
+ try (HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0])) {
+ // Find the documents, and then their SLWT
+ Record[] records = ss.getRecords();
+ for (Record record : records) {
+ if (record.getRecordType() == 1000L) {
+ Record[] docChildren = record.getChildRecords();
+ for (Record docChild : docChildren) {
+ if (docChild instanceof SlideListWithText) {
+ Record[] slwtChildren = docChild.getChildRecords();
- // Find the documents, and then their SLWT
- Record[] records = ss.getRecords();
- for (Record record : records) {
- if (record.getRecordType() == 1000L) {
- Record[] docChildren = record.getChildRecords();
- for (Record docChild : docChildren) {
- if (docChild instanceof SlideListWithText) {
- Record[] slwtChildren = docChild.getChildRecords();
+ int lastTextLen = -1;
+ for (Record slwtChild : slwtChildren) {
+ if (slwtChild instanceof TextCharsAtom) {
+ lastTextLen = ((TextCharsAtom) slwtChild).getText().length();
+ }
+ if (slwtChild instanceof TextBytesAtom) {
+ lastTextLen = ((TextBytesAtom) slwtChild).getText().length();
+ }
- int lastTextLen = -1;
- for (Record slwtChild : slwtChildren) {
- if (slwtChild instanceof TextCharsAtom) {
- lastTextLen = ((TextCharsAtom) slwtChild).getText().length();
- }
- if (slwtChild instanceof TextBytesAtom) {
- lastTextLen = ((TextBytesAtom) slwtChild).getText().length();
- }
-
- if (slwtChild instanceof StyleTextPropAtom) {
- StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChild;
- stpa.setParentTextSize(lastTextLen);
- showStyleTextPropAtom(stpa);
+ if (slwtChild instanceof StyleTextPropAtom) {
+ StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChild;
+ stpa.setParentTextSize(lastTextLen);
+ showStyleTextPropAtom(stpa);
+ }
}
}
}
}
}
}
-
- ss.close();
}
public static void showStyleTextPropAtom(StyleTextPropAtom stpa) {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java?rev=1854192&r1=1854191&r2=1854192&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java Sat Feb 23 07:52:24 2019
@@ -43,79 +43,77 @@ public final class UserEditAndPersistLis
System.exit(1);
}
-
// Create the slideshow object, for normal working with
- HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
- fileContents = ss.getUnderlyingBytes();
- System.out.println();
-
- // Find any persist ones first
- int pos = 0;
- for(Record r : ss.getRecords()) {
- if(r.getRecordType() == 6001l) {
- // PersistPtrFullBlock
- System.out.println("Found PersistPtrFullBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
- }
- if(r.getRecordType() == 6002l) {
- // PersistPtrIncrementalBlock
- System.out.println("Found PersistPtrIncrementalBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
- PersistPtrHolder pph = (PersistPtrHolder)r;
-
- // Check the sheet offsets
- Map<Integer,Integer> sheetOffsets = pph.getSlideLocationsLookup();
- for(int id : pph.getKnownSlideIDs()) {
- Integer offset = sheetOffsets.get(id);
-
- System.out.println(" Knows about sheet " + id);
- System.out.println(" That sheet lives at " + offset);
-
- Record atPos = findRecordAtPos(offset.intValue());
- System.out.println(" The record at that pos is of type " + atPos.getRecordType());
- System.out.println(" The record at that pos has class " + atPos.getClass().getName());
-
- if(! (atPos instanceof PositionDependentRecord)) {
- System.out.println(" ** The record class isn't position aware! **");
+ try (HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0])) {
+ fileContents = ss.getUnderlyingBytes();
+ System.out.println();
+
+ // Find any persist ones first
+ int pos = 0;
+ for (Record r : ss.getRecords()) {
+ if (r.getRecordType() == 6001L) {
+ // PersistPtrFullBlock
+ System.out.println("Found PersistPtrFullBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
+ }
+ if (r.getRecordType() == 6002L) {
+ // PersistPtrIncrementalBlock
+ System.out.println("Found PersistPtrIncrementalBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
+ PersistPtrHolder pph = (PersistPtrHolder) r;
+
+ // Check the sheet offsets
+ Map<Integer, Integer> sheetOffsets = pph.getSlideLocationsLookup();
+ for (int id : pph.getKnownSlideIDs()) {
+ Integer offset = sheetOffsets.get(id);
+
+ System.out.println(" Knows about sheet " + id);
+ System.out.println(" That sheet lives at " + offset);
+
+ Record atPos = findRecordAtPos(offset.intValue());
+ System.out.println(" The record at that pos is of type " + atPos.getRecordType());
+ System.out.println(" The record at that pos has class " + atPos.getClass().getName());
+
+ if (!(atPos instanceof PositionDependentRecord)) {
+ System.out.println(" ** The record class isn't position aware! **");
+ }
}
}
+
+ // Increase the position by the on disk size
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ r.writeOut(baos);
+ pos += baos.size();
}
- // Increase the position by the on disk size
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- r.writeOut(baos);
- pos += baos.size();
- }
+ System.out.println();
- System.out.println();
+ pos = 0;
+ // Now look for UserEditAtoms
+ for (Record r : ss.getRecords()) {
+ if (r instanceof UserEditAtom) {
+ UserEditAtom uea = (UserEditAtom) r;
+ System.out.println("Found UserEditAtom at " + pos + " (" + Integer.toHexString(pos) + ")");
+ System.out.println(" lastUserEditAtomOffset = " + uea.getLastUserEditAtomOffset());
+ System.out.println(" persistPointersOffset = " + uea.getPersistPointersOffset());
+ System.out.println(" docPersistRef = " + uea.getDocPersistRef());
+ System.out.println(" maxPersistWritten = " + uea.getMaxPersistWritten());
+ }
- pos = 0;
- // Now look for UserEditAtoms
- for(Record r : ss.getRecords()) {
- if(r instanceof UserEditAtom) {
- UserEditAtom uea = (UserEditAtom)r;
- System.out.println("Found UserEditAtom at " + pos + " (" + Integer.toHexString(pos) + ")");
- System.out.println(" lastUserEditAtomOffset = " + uea.getLastUserEditAtomOffset() );
- System.out.println(" persistPointersOffset = " + uea.getPersistPointersOffset() );
- System.out.println(" docPersistRef = " + uea.getDocPersistRef() );
- System.out.println(" maxPersistWritten = " + uea.getMaxPersistWritten() );
+ // Increase the position by the on disk size
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ r.writeOut(baos);
+ pos += baos.size();
}
- // Increase the position by the on disk size
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- r.writeOut(baos);
- pos += baos.size();
- }
+ System.out.println();
- System.out.println();
+ // Query the CurrentUserAtom
+ CurrentUserAtom cua = ss.getCurrentUserAtom();
+ System.out.println("Checking Current User Atom");
+ System.out.println(" Thinks the CurrentEditOffset is " + cua.getCurrentEditOffset());
- // Query the CurrentUserAtom
- CurrentUserAtom cua = ss.getCurrentUserAtom();
- System.out.println("Checking Current User Atom");
- System.out.println(" Thinks the CurrentEditOffset is " + cua.getCurrentEditOffset());
-
- System.out.println();
-
- ss.close();
+ System.out.println();
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java?rev=1854192&r1=1854191&r2=1854192&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java Sat Feb 23 07:52:24 2019
@@ -66,13 +66,14 @@ import org.apache.poi.util.POILogger;
* "reader". It is only a very basic class for now
*/
public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
+ private static final POILogger logger = POILogFactory.getLogger(HSLFSlideShowImpl.class);
+
static final int UNSET_OFFSET = -1;
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 200_000_000;
- // For logging
- private POILogger logger = POILogFactory.getLogger(this.getClass());
+ private static final String DUAL_STORAGE_NAME = "PP97_DUALSTORAGE";
// Holds metadata on where things are in our document
private CurrentUserAtom currentUser;
@@ -136,29 +137,35 @@ public final class HSLFSlideShowImpl ext
public HSLFSlideShowImpl(DirectoryNode dir) throws IOException {
super(handleDualStorage(dir));
- // First up, grab the "Current User" stream
- // We need this before we can detect Encrypted Documents
- readCurrentUserStream();
-
- // Next up, grab the data that makes up the
- // PowerPoint stream
- readPowerPointStream();
-
- // Now, build records based on the PowerPoint stream
- buildRecords();
+ try {
+ // First up, grab the "Current User" stream
+ // We need this before we can detect Encrypted Documents
+ readCurrentUserStream();
+
+ // Next up, grab the data that makes up the
+ // PowerPoint stream
+ readPowerPointStream();
+
+ // Now, build records based on the PowerPoint stream
+ buildRecords();
+
+ // Look for any other streams
+ readOtherStreams();
+ } catch (RuntimeException | IOException e) {
+ // clean up the filesystem when we cannot read it here to avoid
+ // leaking file handles
+ dir.getFileSystem().close();
- // Look for any other streams
- readOtherStreams();
+ throw e;
+ }
}
private static DirectoryNode handleDualStorage(DirectoryNode dir) throws IOException {
// when there's a dual storage entry, use it, as the outer document can't be read quite probably ...
- String dualName = "PP97_DUALSTORAGE";
- if (!dir.hasEntry(dualName)) {
+ if (!dir.hasEntry(DUAL_STORAGE_NAME)) {
return dir;
}
- dir = (DirectoryNode) dir.getEntry(dualName);
- return dir;
+ return (DirectoryNode) dir.getEntry(DUAL_STORAGE_NAME);
}
/**
@@ -834,7 +841,8 @@ public final class HSLFSlideShowImpl ext
public void close() throws IOException {
// only close the filesystem, if we are based on the root node.
// embedded documents/slideshows shouldn't close the parent container
- if (getDirectory().getParent() == null) {
+ if (getDirectory().getParent() == null ||
+ getDirectory().getName().equals(DUAL_STORAGE_NAME)) {
POIFSFileSystem fs = getDirectory().getFileSystem();
if (fs != null) {
fs.close();
Modified: poi/trunk/src/testcases/org/apache/poi/ss/format/CellFormatTestBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/format/CellFormatTestBase.java?rev=1854192&r1=1854191&r2=1854192&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/format/CellFormatTestBase.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/format/CellFormatTestBase.java Sat Feb 23 07:52:24 2019
@@ -96,7 +96,7 @@ public class CellFormatTestBase {
}
}
- protected void runFormatTests(String workbookName, CellValue valueGetter) {
+ protected void runFormatTests(String workbookName, CellValue valueGetter) throws IOException {
openWorkbook(workbookName);
@@ -127,6 +127,8 @@ public class CellFormatTestBase {
tryFormat(row.getRowNum(), expectedText, format, valueGetter, value);
}
}
+
+ workbook.close();
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org