Remove/Minimize references to Scratchpad module from other modules

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-11-19 18:00:42 +00:00
parent b3ac6e905e
commit d6cc11ed7a
14 changed files with 187 additions and 173 deletions

View File

@ -1133,6 +1133,7 @@ under the License.
<classpath> <classpath>
<path refid="ooxml.classpath"/> <path refid="ooxml.classpath"/>
<pathelement path="${ooxml.output.dir}"/> <pathelement path="${ooxml.output.dir}"/>
<pathelement location="${scratchpad.output.dir}"/>
</classpath> </classpath>
</javac> </javac>
<copy todir="${examples.output.dir}"> <copy todir="${examples.output.dir}">
@ -1303,6 +1304,7 @@ under the License.
<pathelement location="${main.output.test.dir}"/> <pathelement location="${main.output.test.dir}"/>
<pathelement location="${examples.output.dir}"/> <pathelement location="${examples.output.dir}"/>
<pathelement location="${main.ant.jar}"/> <pathelement location="${main.ant.jar}"/>
<pathelement location="${scratchpad.output.dir}"/>
</classpath> </classpath>
</javac> </javac>
<!--copy todir="${integration.output.dir}"> <!--copy todir="${integration.output.dir}">

View File

@ -16,17 +16,24 @@
==================================================================== */ ==================================================================== */
package org.apache.poi; package org.apache.poi;
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; import static org.junit.Assert.assertNotNull;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hwpf.OldWordFileFormatException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.stress.*;
import org.junit.Assume;
import java.io.*; import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipException; import java.util.zip.ZipException;
import static org.junit.Assert.assertNotNull; import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.stress.FileHandler;
import org.apache.poi.stress.HSLFFileHandler;
import org.apache.poi.stress.HSSFFileHandler;
import org.apache.poi.stress.HWPFFileHandler;
import org.apache.poi.stress.XSLFFileHandler;
import org.apache.poi.stress.XSSFFileHandler;
import org.apache.poi.stress.XWPFFileHandler;
import org.junit.Assume;
public class BaseIntegrationTest { public class BaseIntegrationTest {
private final File rootDir; private final File rootDir;
@ -53,12 +60,13 @@ public class BaseIntegrationTest {
// use XWPF instead of HWPF and XSSF instead of HSSF as the file seems to have the wrong extension // use XWPF instead of HWPF and XSSF instead of HSSF as the file seems to have the wrong extension
handleWrongExtension(inputFile, e); handleWrongExtension(inputFile, e);
} catch (OldWordFileFormatException | OldExcelFormatException | OldPowerPointFormatException e) {
// at least perform extracting tests on these old files
} catch (OldFileFormatException e) { } catch (OldFileFormatException e) {
// Not even text extraction is supported for these: handler.handleExtracting(inputFile); if (e.getClass().equals(OldFileFormatException.class)) {
//noinspection ConstantConditions // Not even text extraction is supported for these: handler.handleExtracting(inputFile);
Assume.assumeFalse("File " + file + " excluded because it is unsupported old Excel format", true); //noinspection ConstantConditions
Assume.assumeFalse("File " + file + " excluded because it is unsupported old Excel format", true);
}
// otherwise try at least to perform extracting tests on these old files
} catch (EncryptedDocumentException e) { } catch (EncryptedDocumentException e) {
// Do not try to read encrypted files // Do not try to read encrypted files
//noinspection ConstantConditions //noinspection ConstantConditions

View File

@ -16,24 +16,20 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.ooxml.extractor; package org.apache.poi.ooxml.extractor;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.apache.poi.EncryptedDocumentException; import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.extractor.OLE2ExtractorFactory;
import org.apache.poi.extractor.POIOLE2TextExtractor; import org.apache.poi.extractor.POIOLE2TextExtractor;
import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.extractor.OLE2ExtractorFactory;
import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.openxml4j.opc.PackageAccess;
@ -46,9 +42,9 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.NotOLE2FileException; import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException; import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.sl.extractor.SlideShowExtractor; import org.apache.poi.sl.extractor.SlideShowExtractor;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.util.NotImplemented; import org.apache.poi.util.NotImplemented;
@ -311,6 +307,7 @@ public final class ExtractorFactory {
throw new IllegalStateException("The extractor didn't know which POIFS it came from!"); throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
} }
// provide ExcelExtractor also in OOXML module, because scratchpad is not necessary for it
if (ext instanceof ExcelExtractor) { if (ext instanceof ExcelExtractor) {
// These are in MBD... under the root // These are in MBD... under the root
Iterator<Entry> it = root.getEntries(); Iterator<Entry> it = root.getEntries();
@ -320,34 +317,14 @@ public final class ExtractorFactory {
dirs.add(entry); dirs.add(entry);
} }
} }
} else if (ext instanceof WordExtractor) { } else {
// These are in ObjectPool -> _... under the root
try { try {
DirectoryEntry op = (DirectoryEntry) root.getEntry("ObjectPool"); Class<?> clazz = Class.forName("org.apache.poi.extractor.ole2.OLE2ScratchpadExtractorFactory");
Iterator<Entry> it = op.getEntries(); Method m = clazz.getDeclaredMethod("identifyEmbeddedResources", POIOLE2TextExtractor.class, List.class, List.class);
while (it.hasNext()) { m.invoke(null, ext, dirs, nonPOIFS);
Entry entry = it.next(); } catch (ReflectiveOperationException e) {
if (entry.getName().startsWith("_")) { logger.log(POILogger.WARN, "POI Scratchpad jar not included ", e.getLocalizedMessage());
dirs.add(entry); return new POITextExtractor[0];
}
}
} catch (FileNotFoundException e) {
logger.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage());
// ignored here
}
//} else if(ext instanceof PowerPointExtractor) {
// Tricky, not stored directly in poifs
// TODO
} else if (ext instanceof OutlookTextExtactor) {
// Stored in the Attachment blocks
MAPIMessage msg = ((OutlookTextExtactor)ext).getMAPIMessage();
for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
if (attachment.getAttachData() != null) {
byte[] data = attachment.getAttachData().getValue();
nonPOIFS.add( new ByteArrayInputStream(data) );
} else if (attachment.getAttachmentDirectory() != null) {
dirs.add(attachment.getAttachmentDirectory().getDirectory());
}
} }
} }

View File

@ -33,27 +33,18 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.UnsupportedFileFormatException; import org.apache.poi.UnsupportedFileFormatException;
import org.apache.poi.extractor.POIOLE2TextExtractor; import org.apache.poi.extractor.POIOLE2TextExtractor;
import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor; import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hwpf.extractor.Word6Extractor;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.ooxml.extractor.ExtractorFactory; import org.apache.poi.ooxml.extractor.ExtractorFactory;
import org.apache.poi.ooxml.extractor.POIXMLTextExtractor; import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.sl.extractor.SlideShowExtractor;
import org.apache.poi.xdgf.extractor.XDGFVisioExtractor;
import org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.junit.Test; import org.junit.Test;
@ -108,21 +99,21 @@ public class TestExtractorFactory {
} }
private static final Object[] TEST_SET = { private static final Object[] TEST_SET = {
"Excel", xls, ExcelExtractor.class, 200, "Excel", xls, "ExcelExtractor", 200,
"Excel - xlsx", xlsx, XSSFExcelExtractor.class, 200, "Excel - xlsx", xlsx, "XSSFExcelExtractor", 200,
"Excel - xltx", xltx, XSSFExcelExtractor.class, -1, "Excel - xltx", xltx, "XSSFExcelExtractor", -1,
"Excel - xlsb", xlsb, XSSFBEventBasedExcelExtractor.class, -1, "Excel - xlsb", xlsb, "XSSFBEventBasedExcelExtractor", -1,
"Word", doc, WordExtractor.class, 120, "Word", doc, "WordExtractor", 120,
"Word - docx", docx, XWPFWordExtractor.class, 120, "Word - docx", docx, "XWPFWordExtractor", 120,
"Word - dotx", dotx, XWPFWordExtractor.class, -1, "Word - dotx", dotx, "XWPFWordExtractor", -1,
"Word 6", doc6, Word6Extractor.class, 20, "Word 6", doc6, "Word6Extractor", 20,
"Word 95", doc95, Word6Extractor.class, 120, "Word 95", doc95, "Word6Extractor", 120,
"PowerPoint", ppt, SlideShowExtractor.class, 120, "PowerPoint", ppt, "SlideShowExtractor", 120,
"PowerPoint - pptx", pptx, SlideShowExtractor.class, 120, "PowerPoint - pptx", pptx, "SlideShowExtractor", 120,
"Visio", vsd, VisioTextExtractor.class, 50, "Visio", vsd, "VisioTextExtractor", 50,
"Visio - vsdx", vsdx, XDGFVisioExtractor.class, 20, "Visio - vsdx", vsdx, "XDGFVisioExtractor", 20,
"Publisher", pub, PublisherTextExtractor.class, 50, "Publisher", pub, "PublisherTextExtractor", 50,
"Outlook msg", msg, OutlookTextExtactor.class, 50, "Outlook msg", msg, "OutlookTextExtactor", 50,
// TODO Support OOXML-Strict, see bug #57699 // TODO Support OOXML-Strict, see bug #57699
// xlsxStrict // xlsxStrict
@ -138,7 +129,7 @@ public class TestExtractorFactory {
public void testFile() throws Exception { public void testFile() throws Exception {
for (int i = 0; i < TEST_SET.length; i += 4) { for (int i = 0; i < TEST_SET.length; i += 4) {
try (POITextExtractor ext = ExtractorFactory.createExtractor((File) TEST_SET[i + 1])) { try (POITextExtractor ext = ExtractorFactory.createExtractor((File) TEST_SET[i + 1])) {
testExtractor(ext, (String) TEST_SET[i], (Class) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]); testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
} }
} }
} }
@ -180,15 +171,15 @@ public class TestExtractorFactory {
} }
try (FileInputStream fis = new FileInputStream(testFile); try (FileInputStream fis = new FileInputStream(testFile);
POITextExtractor ext = poifsIS.apply(fis)) { POITextExtractor ext = poifsIS.apply(fis)) {
testExtractor(ext, (String) TEST_SET[i], (Class) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]); testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
fail("failed to process "+testFile); fail("failed to process "+testFile);
} }
} }
} }
private void testExtractor(final POITextExtractor ext, final String testcase, final Class extrClass, final Integer minLength) { private void testExtractor(final POITextExtractor ext, final String testcase, final String extrClass, final Integer minLength) {
assertTrue("invalid extractor for " + testcase, extrClass.isInstance(ext)); assertEquals("invalid extractor for " + testcase, extrClass, ext.getClass().getSimpleName());
final String actual = ext.getText(); final String actual = ext.getText();
if (minLength == -1) { if (minLength == -1) {
assertContains(actual.toLowerCase(Locale.ROOT), "test"); assertContains(actual.toLowerCase(Locale.ROOT), "test");
@ -215,7 +206,7 @@ public class TestExtractorFactory {
try (final OPCPackage pkg = OPCPackage.open(testFile, PackageAccess.READ); try (final OPCPackage pkg = OPCPackage.open(testFile, PackageAccess.READ);
final POITextExtractor ext = ExtractorFactory.createExtractor(pkg)) { final POITextExtractor ext = ExtractorFactory.createExtractor(pkg)) {
testExtractor(ext, (String) TEST_SET[i], (Class) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]); testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
pkg.revert(); pkg.revert();
} }
} }
@ -334,16 +325,22 @@ public class TestExtractorFactory {
int numWord = 0, numXls = 0, numPpt = 0, numMsg = 0, numWordX = 0; int numWord = 0, numXls = 0, numPpt = 0, numMsg = 0, numWordX = 0;
for (POITextExtractor embed : embeds) { for (POITextExtractor embed : embeds) {
assertTrue(embed.getText().length() > 20); assertTrue(embed.getText().length() > 20);
if (embed instanceof SlideShowExtractor) { switch (embed.getClass().getSimpleName()) {
numPpt++; case "SlideShowExtractor":
} else if (embed instanceof ExcelExtractor) { numPpt++;
numXls++; break;
} else if (embed instanceof WordExtractor) { case "ExcelExtractor":
numWord++; numXls++;
} else if (embed instanceof OutlookTextExtactor) { break;
numMsg++; case "WordExtractor":
} else if (embed instanceof XWPFWordExtractor) { numWord++;
numWordX++; break;
case "OutlookTextExtactor":
numMsg++;
break;
case "XWPFWordExtractor":
numWordX++;
break;
} }
} }

View File

@ -23,6 +23,7 @@ import static org.apache.poi.POIDataSamples.getSpreadSheetInstance;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -35,9 +36,8 @@ import java.util.Collection;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.POIDocument; import org.apache.poi.POIDocument;
import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.ooxml.extractor.ExtractorFactory;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.ooxml.extractor.ExtractorFactory;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader; import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader;
import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.poifs.storage.RawDataUtil;
@ -64,21 +64,24 @@ public class TestHxxFEncryption {
@Parameters(name="{1}") @Parameters(name="{1}")
public static Collection<Object[]> data() throws IOException { public static Collection<Object[]> data() throws IOException {
final String base64 =
"H4sIAAAAAAAAAF1Uu24bMRDs/RULVwkgCUhSpHaZwkDgpHJH8fZ0G/Nx4ZI6y13yG/mRfIb9R5mlZFlIpdPtcnZmdnjPf57/vvx6+f3h6obuv3"+
"ylbY5bEiVHe1fEpUp5pOgkrK0iabehm7FyoZi1ks8xcvHiQu8h5bLnorTlnUvkJ/YPOHKsLVInAqCs91KakuaxLq4w3g00SgCo9Xou1UnCmSBe"+
"MhpRY6qHmXVFteQfQJ5yUaaOw4qXwgPVjPGAqhNH5bBHAfTmwqqoSkLdFT/J3nC0eZBRk7yiu5s7yoU+r+9l3tDtm5A3jgt6AQxNOY2ya+U4sK"+
"XZ+YczbpfSVVuzFOuunKraqIVD2ND3yVXauT3TNthR/O3IJAM7gzTOGeIcXZvj14ahotW8wSognlMu0Yyp/Fi7O6s+CK6haUUjtPCji7MVcgqH"+
"jh+42tqeqPDMroJ/lBAE4AZbJbJu6Fu35ej42Tw9mYeTwVXoBKJiPeFV94q2rZJAyNEPo/qOdWYLBpq3B2JX8GDZeJ14mZf3tOQWBmpd9yQ7kI"+
"DCY/jmkj1oGOicFy62r9vutC5uJsVEMFgmAXXfYcC6BRBKNHCybALFJolnrDcPXNLl+K60Vctt09YZT7YgbeOICGJ/ZgC2JztOnm1JhX3eJXni"+
"U5Bqhezzlu334vD/Ajr3yDGXw5G9IZ6aLmLfQafY42N3J7cjj1LaXOHihSrcC5ThmuYIB5FX5AU8tKlnNG9Dn1EnsdD4KcnPhsSNPRiXtz461b"+
"VZw8Pm6vn0afh4fvr0D5P/+cMuBAAA";
final String x = new String(RawDataUtil.decompress(base64), StandardCharsets.UTF_8);
return Arrays.asList( return Arrays.asList(
// binary rc4 // binary rc4
new Object[]{ getDocumentInstance(), "password_tika_binaryrc4.doc", "tika", "This is an encrypted Word 2007 File." }, new Object[]{ getDocumentInstance(), "password_tika_binaryrc4.doc", "tika", "This is an encrypted Word 2007 File." },
// cryptoapi // cryptoapi
new Object[]{ getDocumentInstance(), "password_password_cryptoapi.doc", "password", "This is a test" }, new Object[]{ getDocumentInstance(), "password_password_cryptoapi.doc", "password", "This is a test" },
// binary rc4 // binary rc4
new Object[]{ getSpreadSheetInstance(), "password.xls", "password", new Object[]{ getSpreadSheetInstance(), "password.xls", "password", x },
x("H4sIAAAAAAAAAF1Uu24bMRDs/RULVwkgCUhSpHaZwkDgpHJH8fZ0G/Nx4ZI6y13yG/mRfIb9R5mlZFlIpdPtcnZmdnjPf57/vvx6+f3h6obuv3"+
"ylbY5bEiVHe1fEpUp5pOgkrK0iabehm7FyoZi1ks8xcvHiQu8h5bLnorTlnUvkJ/YPOHKsLVInAqCs91KakuaxLq4w3g00SgCo9Xou1UnCmSBe"+
"MhpRY6qHmXVFteQfQJ5yUaaOw4qXwgPVjPGAqhNH5bBHAfTmwqqoSkLdFT/J3nC0eZBRk7yiu5s7yoU+r+9l3tDtm5A3jgt6AQxNOY2ya+U4sK"+
"XZ+YczbpfSVVuzFOuunKraqIVD2ND3yVXauT3TNthR/O3IJAM7gzTOGeIcXZvj14ahotW8wSognlMu0Yyp/Fi7O6s+CK6haUUjtPCji7MVcgqH"+
"jh+42tqeqPDMroJ/lBAE4AZbJbJu6Fu35ej42Tw9mYeTwVXoBKJiPeFV94q2rZJAyNEPo/qOdWYLBpq3B2JX8GDZeJ14mZf3tOQWBmpd9yQ7kI"+
"DCY/jmkj1oGOicFy62r9vutC5uJsVEMFgmAXXfYcC6BRBKNHCybALFJolnrDcPXNLl+K60Vctt09YZT7YgbeOICGJ/ZgC2JztOnm1JhX3eJXni"+
"U5Bqhezzlu334vD/Ajr3yDGXw5G9IZ6aLmLfQafY42N3J7cjj1LaXOHihSrcC5ThmuYIB5FX5AU8tKlnNG9Dn1EnsdD4KcnPhsSNPRiXtz461b"+
"VZw8Pm6vn0afh4fvr0D5P/+cMuBAAA") },
// cryptoapi // cryptoapi
new Object[]{ getSpreadSheetInstance(), "35897-type4.xls", "freedom", "Sheet1\nhello there!" }, new Object[]{ getSpreadSheetInstance(), "35897-type4.xls", "freedom", "Sheet1\nhello there!" },
// cryptoapi (PPT only supports cryptoapi...) // cryptoapi (PPT only supports cryptoapi...)
@ -86,10 +89,6 @@ public class TestHxxFEncryption {
); );
} }
private static String x(String base64) throws IOException {
return new String(RawDataUtil.decompress(base64), StandardCharsets.UTF_8);
}
@Test @Test
public void extract() throws IOException, OpenXML4JException, XmlException { public void extract() throws IOException, OpenXML4JException, XmlException {
File f = sampleDir.getFile(file); File f = sampleDir.getFile(file);
@ -112,7 +111,7 @@ public class TestHxxFEncryption {
newPassword(null); newPassword(null);
} }
public void newPassword(String newPass) throws IOException, OpenXML4JException, XmlException { private void newPassword(String newPass) throws IOException, OpenXML4JException, XmlException {
File f = sampleDir.getFile(file); File f = sampleDir.getFile(file);
Biff8EncryptionKey.setCurrentUserPassword(password); Biff8EncryptionKey.setCurrentUserPassword(password);
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f)) { try (POITextExtractor te1 = ExtractorFactory.createExtractor(f)) {
@ -156,10 +155,14 @@ public class TestHxxFEncryption {
try (POITextExtractor te3 = ExtractorFactory.createExtractor(new ByteArrayInputStream(bos.toByteArray())); try (POITextExtractor te3 = ExtractorFactory.createExtractor(new ByteArrayInputStream(bos.toByteArray()));
POIDocument doc = (POIDocument) te3.getDocument()) { POIDocument doc = (POIDocument) te3.getDocument()) {
// need to cache data (i.e. read all data) before changing the key size // need to cache data (i.e. read all data) before changing the key size
if (doc instanceof HSLFSlideShowImpl) { Class<?> clazz = doc.getClass();
HSLFSlideShowImpl hss = (HSLFSlideShowImpl) doc; if ("HSLFSlideShowImpl".equals(clazz.getSimpleName())) {
hss.getPictureData(); try {
hss.getDocumentSummaryInformation(); clazz.getDeclaredMethod("getPictureData").invoke(doc);
} catch (ReflectiveOperationException e) {
fail("either scratchpad jar is included and this should work or the clazz should be != HSLFSlideShowImpl");
}
doc.getDocumentSummaryInformation();
} }
EncryptionInfo ei = doc.getEncryptionInfo(); EncryptionInfo ei = doc.getEncryptionInfo();
assertNotNull(ei); assertNotNull(ei);

View File

@ -38,7 +38,6 @@ import java.util.Map;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.fonts.FontGroup; import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
@ -93,9 +92,9 @@ public class TestFonts {
} }
@Test @Test
public void resizeToFitTextHSLF() throws IOException { public void resizeToFitTextHSLF() throws IOException, ReflectiveOperationException {
assumeFalse(xslfOnly()); assumeFalse(xslfOnly());
SlideShow<?,?> ppt = new HSLFSlideShow(); SlideShow<?,?> ppt = (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
resizeToFitText(ppt); resizeToFitText(ppt);
ppt.close(); ppt.close();
} }

View File

@ -20,19 +20,12 @@
package org.apache.poi.sl; package org.apache.poi.sl;
import static org.apache.poi.sl.SLCommonUtils.openSampleSlideshow; import static org.apache.poi.sl.SLCommonUtils.openSampleSlideshow;
import static org.apache.poi.sl.SLCommonUtils.xslfOnly;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShow;
@ -41,33 +34,6 @@ import org.apache.poi.sl.usermodel.TextShape;
import org.junit.Test; import org.junit.Test;
public class TestHeadersFooters { public class TestHeadersFooters {
@Test
public void bug58144a() throws IOException {
assumeFalse(xslfOnly());
SlideShow<?,?> ppt = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
HSLFSlide sl = (HSLFSlide)ppt.getSlides().get(0);
HeadersFooters hfs = sl.getHeadersFooters();
assertNull(hfs.getHeaderText());
assertEquals("Confidential", hfs.getFooterText());
List<List<HSLFTextParagraph>> llp = sl.getTextParagraphs();
assertEquals("Test", HSLFTextParagraph.getText(llp.get(0)));
assertFalse(llp.get(0).get(0).isHeaderOrFooter());
ppt.close();
}
@Test
public void bug58144b() throws IOException {
assumeFalse(xslfOnly());
SlideShow<?,?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.ppt");
Slide<?,?> sl = ppt.getSlides().get(0);
HeadersFooters hfs2 = ((HSLFSlide)sl).getHeadersFooters();
assertNull(hfs2.getHeaderText());
assertEquals("Slide footer", hfs2.getFooterText());
testSlideShow(ppt);
ppt.close();
}
@Test @Test
public void bug58144c() throws IOException { public void bug58144c() throws IOException {
SlideShow<?,?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.pptx"); SlideShow<?,?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.pptx");

View File

@ -35,13 +35,14 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.POIDocument;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.sl.usermodel.ObjectMetaData; import org.apache.poi.sl.usermodel.ObjectMetaData;
@ -124,7 +125,7 @@ public class TestOleShape {
} }
@Test @Test
public void embedData() throws IOException, InvalidFormatException { public void embedData() throws IOException, InvalidFormatException, ReflectiveOperationException {
final ByteArrayInputStream pptBytes; final ByteArrayInputStream pptBytes;
try (SlideShow<?,?> ppt = createSlideShow()) { try (SlideShow<?,?> ppt = createSlideShow()) {
final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF); final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF);
@ -146,12 +147,12 @@ public class TestOleShape {
} }
} }
private SlideShow<?,?> createSlideShow() { private SlideShow<?,?> createSlideShow() throws ReflectiveOperationException {
if (api == Api.XSLF) { if (api == Api.XSLF) {
return new XMLSlideShow(); return new XMLSlideShow();
} else { } else {
assumeFalse(xslfOnly()); assumeFalse(xslfOnly());
return new HSLFSlideShow(); return (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
} }
} }
@ -186,7 +187,7 @@ public class TestOleShape {
} }
} }
private void validateOleData(final InputStream in) throws IOException, InvalidFormatException { private void validateOleData(final InputStream in) throws IOException, InvalidFormatException, ReflectiveOperationException {
switch (app) { switch (app) {
case EXCEL_V8: case EXCEL_V8:
case EXCEL_V12: case EXCEL_V12:
@ -195,8 +196,11 @@ public class TestOleShape {
} }
break; break;
case WORD_V8: case WORD_V8:
try (HWPFDocument doc = new HWPFDocument(in)) { Class<? extends POIDocument> clazz = (Class<? extends POIDocument>)Class.forName("org.apache.poi.hwpf.HWPFDocument");
assertEquals("This is a simple file created with Word 97-SR2.\r", doc.getDocumentText()); Constructor<? extends POIDocument> con = clazz.getDeclaredConstructor(InputStream.class);
Method m = clazz.getMethod("getDocumentText");
try (POIDocument doc = con.newInstance(in)) {
assertEquals("This is a simple file created with Word 97-SR2.\r", m.invoke(doc));
} }
break; break;
case WORD_V12: case WORD_V12:

View File

@ -29,7 +29,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XMLSlideShow;
@ -38,9 +37,9 @@ import org.junit.Test;
public class TestSlide { public class TestSlide {
@Test @Test
public void hideHSLF() throws IOException { public void hideHSLF() throws IOException, ReflectiveOperationException {
assumeFalse(xslfOnly()); assumeFalse(xslfOnly());
SlideShow<?,?> ppt1 = new HSLFSlideShow(); SlideShow<?,?> ppt1 = (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
hideSlide(ppt1); hideSlide(ppt1);
ppt1.close(); ppt1.close();
} }

View File

@ -34,7 +34,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.sl.usermodel.SlideShowFactory;
@ -96,9 +95,9 @@ public class TestTable {
} }
@Test @Test
public void directionHSLF() throws IOException { public void directionHSLF() throws IOException, ReflectiveOperationException {
assumeFalse(xslfOnly()); assumeFalse(xslfOnly());
SlideShow<?,?> ppt1 = new HSLFSlideShow(); SlideShow<?,?> ppt1 = (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
testTextDirection(ppt1); testTextDirection(ppt1);
ppt1.close(); ppt1.close();
} }

View File

@ -17,10 +17,11 @@
package org.apache.poi.ss.usermodel; package org.apache.poi.ss.usermodel;
import static org.apache.poi.sl.SLCommonUtils.xslfOnly;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeFalse;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -48,7 +49,7 @@ public class TestEmbedOLEPackage {
private static byte[] samplePPT, samplePPTX, samplePNG; private static byte[] samplePPT, samplePPTX, samplePNG;
@BeforeClass @BeforeClass
public static void init() throws IOException { public static void init() throws IOException, ReflectiveOperationException {
samplePPT = getSamplePPT(false); samplePPT = getSamplePPT(false);
samplePPTX = getSamplePPT(true); samplePPTX = getSamplePPT(true);
samplePNG = POIDataSamples.getSpreadSheetInstance().readFile("logoKarmokar4.png"); samplePNG = POIDataSamples.getSpreadSheetInstance().readFile("logoKarmokar4.png");
@ -68,11 +69,7 @@ public class TestEmbedOLEPackage {
@Test @Test
public void embedHSSF() throws IOException { public void embedHSSF() throws IOException {
try { assumeFalse(xslfOnly());
Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
} catch (Exception e) {
assumeTrue(false);
}
Workbook wb1 = new HSSFWorkbook(); Workbook wb1 = new HSSFWorkbook();
addEmbeddedObjects(wb1); addEmbeddedObjects(wb1);
@ -124,8 +121,9 @@ public class TestEmbedOLEPackage {
pat2.createObjectData(anchor2, oleIdx2, picIdx); pat2.createObjectData(anchor2, oleIdx2, picIdx);
} }
static byte[] getSamplePPT(boolean ooxml) throws IOException { static byte[] getSamplePPT(boolean ooxml) throws IOException, ReflectiveOperationException {
SlideShow<?,?> ppt = (ooxml) ? new XMLSlideShow() : new org.apache.poi.hslf.usermodel.HSLFSlideShow(); SlideShow<?,?> ppt = (ooxml) ? new XMLSlideShow()
: (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
Slide<?,?> slide = ppt.createSlide(); Slide<?,?> slide = ppt.createSlide();
AutoShape<?,?> sh1 = slide.createAutoShape(); AutoShape<?,?> sh1 = slide.createAutoShape();

View File

@ -17,6 +17,7 @@
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
import static org.apache.poi.sl.TestCommonSL.sameColor; import static org.apache.poi.sl.TestCommonSL.sameColor;
import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -24,7 +25,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeFalse;
import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
import java.awt.Color; import java.awt.Color;
import java.io.File; import java.io.File;
@ -33,8 +33,8 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.usermodel.HSLFTextShape;
import org.apache.poi.sl.usermodel.Placeholder; import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign; import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
@ -950,12 +950,12 @@ public class TestXSLFTextShape {
} }
@Test @Test
public void metroBlob() throws IOException { public void metroBlob() throws IOException, ReflectiveOperationException {
assumeFalse(xslfOnly); assumeFalse(xslfOnly);
File f = POIDataSamples.getSlideShowInstance().getFile("bug52297.ppt"); File f = POIDataSamples.getSlideShowInstance().getFile("bug52297.ppt");
SlideShow<?,?> ppt = SlideShowFactory.create(f); SlideShow<?,?> ppt = SlideShowFactory.create(f);
HSLFTextShape sh = (HSLFTextShape)ppt.getSlides().get(1).getShapes().get(3); Shape<?, ?> sh = ppt.getSlides().get(1).getShapes().get(3);
XSLFAutoShape xsh = (XSLFAutoShape)sh.getMetroShape(); XSLFAutoShape xsh = (XSLFAutoShape)sh.getClass().getMethod("getMetroShape").invoke(sh);
String textExp = " ___ ___ ___ ________ __ _______ ___ ___________ __________ __ _____ ___ ___ ___ _______ ____ ______ ___________ _____________ ___ _______ ______ ____ ______ __ ___________ __________ ___ _________ _____ ________ __________ ___ _______ __________ "; String textExp = " ___ ___ ___ ________ __ _______ ___ ___________ __________ __ _____ ___ ___ ___ _______ ____ ______ ___________ _____________ ___ _______ ______ ____ ______ __ ___________ __________ ___ _________ _____ ________ __________ ___ _______ __________ ";
String textAct = xsh.getText(); String textAct = xsh.getText();
ppt.close(); ppt.close();

View File

@ -32,6 +32,7 @@ import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hsmf.MAPIMessage; import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks; import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.extractor.OutlookTextExtactor; import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hwpf.OldWordFileFormatException; import org.apache.poi.hwpf.OldWordFileFormatException;
import org.apache.poi.hwpf.extractor.Word6Extractor; import org.apache.poi.hwpf.extractor.Word6Extractor;
import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hwpf.extractor.WordExtractor;
@ -40,6 +41,8 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.sl.extractor.SlideShowExtractor; import org.apache.poi.sl.extractor.SlideShowExtractor;
import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* Scratchpad-specific logic for {@link OLE2ExtractorFactory} and * Scratchpad-specific logic for {@link OLE2ExtractorFactory} and
@ -50,6 +53,8 @@ import org.apache.poi.sl.usermodel.SlideShowFactory;
*/ */
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public class OLE2ScratchpadExtractorFactory { public class OLE2ScratchpadExtractorFactory {
private static final POILogger logger = POILogFactory.getLogger(OLE2ScratchpadExtractorFactory.class);
/** /**
* Look for certain entries in the stream, to figure it * Look for certain entries in the stream, to figure it
* out what format is desired * out what format is desired
@ -125,7 +130,16 @@ public class OLE2ScratchpadExtractorFactory {
throw new IllegalStateException("The extractor didn't know which POIFS it came from!"); throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
} }
if (ext instanceof WordExtractor) { if (ext instanceof ExcelExtractor) {
// These are in MBD... under the root
Iterator<Entry> it = root.getEntries();
while (it.hasNext()) {
Entry entry = it.next();
if (entry.getName().startsWith("MBD")) {
dirs.add(entry);
}
}
} else if (ext instanceof WordExtractor) {
// These are in ObjectPool -> _... under the root // These are in ObjectPool -> _... under the root
try { try {
DirectoryEntry op = (DirectoryEntry) DirectoryEntry op = (DirectoryEntry)
@ -138,6 +152,7 @@ public class OLE2ScratchpadExtractorFactory {
} }
} }
} catch(FileNotFoundException e) { } catch(FileNotFoundException e) {
logger.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage());
// ignored here // ignored here
} }
//} else if(ext instanceof PowerPointExtractor) { //} else if(ext instanceof PowerPointExtractor) {

View File

@ -30,6 +30,12 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.HSLFTestDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.usermodel.HSLFSlide; import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextShape;
import org.junit.Test; import org.junit.Test;
/** /**
@ -228,4 +234,45 @@ public final class TestHeadersFooters
ppt2.close(); ppt2.close();
ppt1.close(); ppt1.close();
} }
@Test
public void bug58144a() throws IOException {
try (InputStream is = _slTests.openResourceAsStream("bug58144-headers-footers-2003.ppt");
SlideShow<?,?> ppt = new HSLFSlideShow(is)) {
HSLFSlide sl = (HSLFSlide) ppt.getSlides().get(0);
HeadersFooters hfs = sl.getHeadersFooters();
assertNull(hfs.getHeaderText());
assertEquals("Confidential", hfs.getFooterText());
List<List<HSLFTextParagraph>> llp = sl.getTextParagraphs();
assertEquals("Test", HSLFTextParagraph.getText(llp.get(0)));
assertFalse(llp.get(0).get(0).isHeaderOrFooter());
}
}
@Test
public void bug58144b() throws IOException {
try (InputStream is = _slTests.openResourceAsStream("bug58144-headers-footers-2007.ppt");
SlideShow<?,?> ppt = new HSLFSlideShow(is)) {
Slide<?, ?> sl = ppt.getSlides().get(0);
HeadersFooters hfs2 = ((HSLFSlide) sl).getHeadersFooters();
assertNull(hfs2.getHeaderText());
assertEquals("Slide footer", hfs2.getFooterText());
testSlideShow(ppt);
}
}
// copied from org.apache.poi.sl.TestHeadersFooters because of scratchpad.ignore option
private void testSlideShow(SlideShow<?,?> ppt) {
Slide<?,?> sl = ppt.getSlides().get(0);
List<? extends Shape<?,?>> shapes = sl.getShapes();
TextShape<?,?> ts0 = (TextShape<?,?>)shapes.get(0);
assertEquals("Test file", ts0.getText());
TextShape<?,?> ts1 = (TextShape<?,?>)shapes.get(1);
assertEquals("Has some text in the headers and footers", ts1.getText());
TextShape<?,?> ts2 = (TextShape<?,?>)shapes.get(2);
assertEquals("Slide footer", ts2.getText());
List<? extends TextParagraph<?,?,?>> ltp = ts2.getTextParagraphs();
assertTrue(ltp.get(0).isHeaderOrFooter());
}
} }