#62921 - Provide OOXMLLite alternative for Java 12+
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c9ce7ff48a
commit
b3ac6e905e
@ -335,8 +335,11 @@ under the License.
|
|||||||
<propertyref name="user.country"/>
|
<propertyref name="user.country"/>
|
||||||
<propertyref name="javax.xml.stream.XMLInputFactory"/>
|
<propertyref name="javax.xml.stream.XMLInputFactory"/>
|
||||||
<propertyref name="org.apache.commons.logging.Log"/>
|
<propertyref name="org.apache.commons.logging.Log"/>
|
||||||
<propertyref name="java.locale.providers"/> <!-- required for Java 9 compilation -->
|
<!-- required for Java 9 compilation -->
|
||||||
<propertyref name="version.id"/> <!-- to detect if we are running on slow Gump VM -->
|
<propertyref name="java.locale.providers"/>
|
||||||
|
<!-- to detect if we are running on slow Gump VM -->
|
||||||
|
<propertyref name="version.id"/>
|
||||||
|
<propertyref name="scratchpad.ignore"/>
|
||||||
</propertyset>
|
</propertyset>
|
||||||
|
|
||||||
<!-- these need to be set differently when running with Java 9 -->
|
<!-- these need to be set differently when running with Java 9 -->
|
||||||
|
@ -90,6 +90,7 @@ import org.junit.runners.Parameterized.Parameters;
|
|||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class TestAllFiles {
|
public class TestAllFiles {
|
||||||
private static final File ROOT_DIR = new File("test-data");
|
private static final File ROOT_DIR = new File("test-data");
|
||||||
|
private static final boolean IGNORE_SCRATCHPAD = Boolean.getBoolean("scratchpad.ignore");
|
||||||
|
|
||||||
public static final String[] SCAN_EXCLUDES = new String[] { "**/.svn/**", "lost+found", "**/.git/**" };
|
public static final String[] SCAN_EXCLUDES = new String[] { "**/.svn/**", "lost+found", "**/.git/**" };
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ public class TestAllFiles {
|
|||||||
|
|
||||||
// map file extensions to the actual mappers
|
// map file extensions to the actual mappers
|
||||||
public static final Map<String, FileHandler> HANDLERS = new HashMap<>();
|
public static final Map<String, FileHandler> HANDLERS = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Excel
|
// Excel
|
||||||
HANDLERS.put(".xls", new HSSFFileHandler());
|
HANDLERS.put(".xls", new HSSFFileHandler());
|
||||||
@ -107,17 +109,17 @@ public class TestAllFiles {
|
|||||||
HANDLERS.put(".xlsb", new XSSFBFileHandler());
|
HANDLERS.put(".xlsb", new XSSFBFileHandler());
|
||||||
|
|
||||||
// Word
|
// Word
|
||||||
HANDLERS.put(".doc", new HWPFFileHandler());
|
HANDLERS.put(".doc", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HWPFFileHandler());
|
||||||
HANDLERS.put(".docx", new XWPFFileHandler());
|
HANDLERS.put(".docx", new XWPFFileHandler());
|
||||||
HANDLERS.put(".dotx", new XWPFFileHandler());
|
HANDLERS.put(".dotx", new XWPFFileHandler());
|
||||||
HANDLERS.put(".docm", new XWPFFileHandler());
|
HANDLERS.put(".docm", new XWPFFileHandler());
|
||||||
|
|
||||||
// OpenXML4J files
|
// OpenXML4J files
|
||||||
HANDLERS.put(".ooxml", new OPCFileHandler()); // OPCPackage
|
HANDLERS.put(".ooxml", new OPCFileHandler());
|
||||||
HANDLERS.put(".zip", new OPCFileHandler()); // OPCPackage
|
HANDLERS.put(".zip", new OPCFileHandler());
|
||||||
|
|
||||||
// Powerpoint
|
// Powerpoint
|
||||||
HANDLERS.put(".ppt", new HSLFFileHandler());
|
HANDLERS.put(".ppt", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HSLFFileHandler());
|
||||||
HANDLERS.put(".pptx", new XSLFFileHandler());
|
HANDLERS.put(".pptx", new XSLFFileHandler());
|
||||||
HANDLERS.put(".pptm", new XSLFFileHandler());
|
HANDLERS.put(".pptm", new XSLFFileHandler());
|
||||||
HANDLERS.put(".ppsm", new XSLFFileHandler());
|
HANDLERS.put(".ppsm", new XSLFFileHandler());
|
||||||
@ -126,13 +128,13 @@ public class TestAllFiles {
|
|||||||
HANDLERS.put(".potx", new XSLFFileHandler());
|
HANDLERS.put(".potx", new XSLFFileHandler());
|
||||||
|
|
||||||
// Outlook
|
// Outlook
|
||||||
HANDLERS.put(".msg", new HSMFFileHandler());
|
HANDLERS.put(".msg", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HSMFFileHandler());
|
||||||
|
|
||||||
// Publisher
|
// Publisher
|
||||||
HANDLERS.put(".pub", new HPBFFileHandler());
|
HANDLERS.put(".pub", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HPBFFileHandler());
|
||||||
|
|
||||||
// Visio - binary
|
// Visio - binary
|
||||||
HANDLERS.put(".vsd", new HDGFFileHandler());
|
HANDLERS.put(".vsd", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HDGFFileHandler());
|
||||||
|
|
||||||
// Visio - ooxml
|
// Visio - ooxml
|
||||||
HANDLERS.put(".vsdm", new XDGFFileHandler());
|
HANDLERS.put(".vsdm", new XDGFFileHandler());
|
||||||
@ -153,7 +155,7 @@ public class TestAllFiles {
|
|||||||
HANDLERS.put(".adm", new HPSFFileHandler());
|
HANDLERS.put(".adm", new HPSFFileHandler());
|
||||||
|
|
||||||
// Microsoft TNEF
|
// Microsoft TNEF
|
||||||
HANDLERS.put(".dat", new HMEFFileHandler());
|
HANDLERS.put(".dat", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HMEFFileHandler());
|
||||||
|
|
||||||
// TODO: are these readable by some of the formats?
|
// TODO: are these readable by some of the formats?
|
||||||
HANDLERS.put(".wri", new NullFileHandler());
|
HANDLERS.put(".wri", new NullFileHandler());
|
||||||
@ -300,7 +302,7 @@ public class TestAllFiles {
|
|||||||
"spreadsheet/54764-2.xlsx", // see TestXSSFBugs.bug54764()
|
"spreadsheet/54764-2.xlsx", // see TestXSSFBugs.bug54764()
|
||||||
"spreadsheet/54764.xlsx", // see TestXSSFBugs.bug54764()
|
"spreadsheet/54764.xlsx", // see TestXSSFBugs.bug54764()
|
||||||
"poifs/unknown_properties.msg", // POIFS properties corrupted
|
"poifs/unknown_properties.msg", // POIFS properties corrupted
|
||||||
"poifs/only-zero-byte-streams.ole2", // No actual contents
|
(IGNORE_SCRATCHPAD ? "" : "poifs/only-zero-byte-streams.ole2"), // No actual contents
|
||||||
"spreadsheet/poc-xmlbomb.xlsx", // contains xml-entity-expansion
|
"spreadsheet/poc-xmlbomb.xlsx", // contains xml-entity-expansion
|
||||||
"spreadsheet/poc-xmlbomb-empty.xlsx", // contains xml-entity-expansion
|
"spreadsheet/poc-xmlbomb-empty.xlsx", // contains xml-entity-expansion
|
||||||
"spreadsheet/poc-shared-strings.xlsx", // contains shared-string-entity-expansion
|
"spreadsheet/poc-shared-strings.xlsx", // contains shared-string-entity-expansion
|
||||||
@ -438,8 +440,17 @@ public class TestAllFiles {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// let some file handlers do additional stuff
|
try {
|
||||||
handler.handleAdditional(inputFile);
|
// let some file handlers do additional stuff
|
||||||
|
handler.handleAdditional(inputFile);
|
||||||
|
} catch (AssumptionViolatedException e) {
|
||||||
|
// file handler ignored this file
|
||||||
|
} catch (Exception e) {
|
||||||
|
if(!EXPECTED_FAILURES.contains(file) && !AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.contains(file)) {
|
||||||
|
System.out.println("Failed: " + file);
|
||||||
|
throw new Exception("While handling " + file, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getExtension(String file) {
|
public static String getExtension(String file) {
|
||||||
|
@ -79,26 +79,26 @@ public abstract class AbstractFileHandler implements FileHandler {
|
|||||||
long modified = file.lastModified();
|
long modified = file.lastModified();
|
||||||
|
|
||||||
POITextExtractor extractor = null;
|
POITextExtractor extractor = null;
|
||||||
try {
|
try {
|
||||||
extractor = ExtractorFactory.createExtractor(file);
|
extractor = ExtractorFactory.createExtractor(file);
|
||||||
assertNotNull("Should get a POITextExtractor but had none for file " + file, extractor);
|
assertNotNull("Should get a POITextExtractor but had none for file " + file, extractor);
|
||||||
|
|
||||||
assertNotNull("Should get some text but had none for file " + file, extractor.getText());
|
assertNotNull("Should get some text but had none for file " + file, extractor.getText());
|
||||||
|
|
||||||
// also try metadata
|
// also try metadata
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
POITextExtractor metadataExtractor = extractor.getMetadataTextExtractor();
|
POITextExtractor metadataExtractor = extractor.getMetadataTextExtractor();
|
||||||
assertNotNull(metadataExtractor.getText());
|
assertNotNull(metadataExtractor.getText());
|
||||||
|
|
||||||
assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
|
assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
|
||||||
EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
|
EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
|
||||||
|
|
||||||
assertEquals("File should not be modified by extractor", length, file.length());
|
assertEquals("File should not be modified by extractor", length, file.length());
|
||||||
assertEquals("File should not be modified by extractor", modified, file.lastModified());
|
assertEquals("File should not be modified by extractor", modified, file.lastModified());
|
||||||
|
|
||||||
handleExtractingAsStream(file);
|
handleExtractingAsStream(file);
|
||||||
|
|
||||||
if(extractor instanceof POIOLE2TextExtractor) {
|
if (extractor instanceof POIOLE2TextExtractor) {
|
||||||
try (HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
|
try (HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
|
||||||
assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
|
assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
|
||||||
assertNotNull(hpsfExtractor.getSummaryInformationText());
|
assertNotNull(hpsfExtractor.getSummaryInformationText());
|
||||||
@ -115,6 +115,10 @@ public abstract class AbstractFileHandler implements FileHandler {
|
|||||||
String msg = "org.apache.poi.EncryptedDocumentException: Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files";
|
String msg = "org.apache.poi.EncryptedDocumentException: Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files";
|
||||||
assumeFalse(msg.equals(e.getMessage()));
|
assumeFalse(msg.equals(e.getMessage()));
|
||||||
throw e;
|
throw e;
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
if (!e.getMessage().contains("POI Scratchpad jar missing") || !Boolean.getBoolean("scratchpad.ignore")) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(extractor);
|
IOUtils.closeQuietly(extractor);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user