Ignore JCE restriction errors
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1797856 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20dcde37ec
commit
a5dda416e7
@ -19,6 +19,7 @@ package org.apache.poi.stress;
|
|||||||
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;
|
||||||
|
import static org.junit.Assume.assumeFalse;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -27,11 +28,13 @@ import java.io.InputStream;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.POIOLE2TextExtractor;
|
import org.apache.poi.POIOLE2TextExtractor;
|
||||||
import org.apache.poi.POITextExtractor;
|
import org.apache.poi.POITextExtractor;
|
||||||
import org.apache.poi.extractor.ExtractorFactory;
|
import org.apache.poi.extractor.ExtractorFactory;
|
||||||
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
|
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
|
import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
|
|
||||||
public abstract class AbstractFileHandler implements FileHandler {
|
public abstract class AbstractFileHandler implements FileHandler {
|
||||||
@ -75,8 +78,9 @@ public abstract class AbstractFileHandler implements FileHandler {
|
|||||||
long length = file.length();
|
long length = file.length();
|
||||||
long modified = file.lastModified();
|
long modified = file.lastModified();
|
||||||
|
|
||||||
POITextExtractor extractor = ExtractorFactory.createExtractor(file);
|
POITextExtractor extractor = null;
|
||||||
try {
|
try {
|
||||||
|
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());
|
||||||
@ -110,8 +114,12 @@ public abstract class AbstractFileHandler implements FileHandler {
|
|||||||
if(!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
|
if(!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
} catch (EncryptedDocumentException e) {
|
||||||
|
String msg = "org.apache.poi.EncryptedDocumentException: Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files";
|
||||||
|
assumeFalse(msg.equals(e.getMessage()));
|
||||||
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
extractor.close();
|
IOUtils.closeQuietly(extractor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,9 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.stress;
|
package org.apache.poi.stress;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeFalse;
|
import static org.junit.Assume.assumeFalse;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@ -37,6 +38,7 @@ import java.util.Set;
|
|||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
||||||
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
@ -75,8 +77,14 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
|||||||
POIFSFileSystem poifs = new POIFSFileSystem(bytes);
|
POIFSFileSystem poifs = new POIFSFileSystem(bytes);
|
||||||
EncryptionInfo ei = new EncryptionInfo(poifs);
|
EncryptionInfo ei = new EncryptionInfo(poifs);
|
||||||
Decryptor dec = ei.getDecryptor();
|
Decryptor dec = ei.getDecryptor();
|
||||||
|
try {
|
||||||
boolean b = dec.verifyPassword(pass);
|
boolean b = dec.verifyPassword(pass);
|
||||||
assertTrue("password mismatch", b);
|
assertTrue("password mismatch", b);
|
||||||
|
} catch (EncryptedDocumentException e) {
|
||||||
|
String msg = "Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files";
|
||||||
|
assumeFalse(msg.equals(e.getMessage()));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
InputStream is = dec.getDataStream(poifs);
|
InputStream is = dec.getDataStream(poifs);
|
||||||
out.reset();
|
out.reset();
|
||||||
IOUtils.copy(is, out);
|
IOUtils.copy(is, out);
|
||||||
|
Loading…
Reference in New Issue
Block a user