use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.
the class TestXSLFBugs method bug59273.
@Test
public void bug59273() throws IOException {
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("bug59273.potx");
ppt.getPackage().replaceContentType(XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType(), XSLFRelation.MAIN.getContentType());
XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(ppt);
OPCPackage pkg = rwPptx.getPackage();
int size = pkg.getPartsByContentType(XSLFRelation.MAIN.getContentType()).size();
assertEquals(1, size);
size = pkg.getPartsByContentType(XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType()).size();
assertEquals(0, size);
rwPptx.close();
ppt.close();
}
use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.
the class TestSXSSFWorkbookWithCustomZipEntrySource method customZipEntrySourceForWriteAndRead.
// write an encrypted workbook to disk, and encrypt any temporary files as well
@Test
public void customZipEntrySourceForWriteAndRead() throws IOException, GeneralSecurityException, InvalidFormatException {
SXSSFWorkbookWithCustomZipEntrySource workbook = new SXSSFWorkbookWithCustomZipEntrySource();
SXSSFSheet sheet1 = workbook.createSheet(sheetName);
SXSSFRow row1 = sheet1.createRow(1);
SXSSFCell cell1 = row1.createCell(1);
cell1.setCellValue(cellValue);
EncryptedTempData tempData = new EncryptedTempData();
workbook.write(tempData.getOutputStream());
workbook.close();
workbook.dispose();
ZipEntrySource zipEntrySource = AesZipFileZipEntrySource.createZipEntrySource(tempData.getInputStream());
tempData.dispose();
OPCPackage opc = OPCPackage.open(zipEntrySource);
XSSFWorkbook xwb = new XSSFWorkbook(opc);
zipEntrySource.close();
XSSFSheet xs1 = xwb.getSheetAt(0);
assertEquals(sheetName, xs1.getSheetName());
XSSFRow xr1 = xs1.getRow(1);
XSSFCell xc1 = xr1.getCell(1);
assertEquals(cellValue, xc1.getStringCellValue());
xwb.close();
opc.close();
}
use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.
the class TestXWPFDocument method testContainsMainContentType.
@Test
public void testContainsMainContentType() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
OPCPackage pack = doc.getPackage();
boolean found = false;
for (PackagePart part : pack.getParts()) {
if (part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
found = true;
}
// if (false) {
// // successful tests should be silent
// System.out.println(part);
// }
}
assertTrue(found);
pack.close();
doc.close();
}
use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.
the class XDGFFileHandler method test.
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
OPCPackage pkg = OPCPackage.open("test-data/diagram/test.vsdx", PackageAccess.READ);
try {
XmlVisioDocument doc = new XmlVisioDocument(pkg);
new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
} finally {
pkg.close();
}
}
use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.
the class XSSFBFileHandler method handleExtracting.
@Override
public void handleExtracting(File file) throws Exception {
OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
try {
testOne(pkg);
} finally {
pkg.close();
}
pkg = OPCPackage.open(file, PackageAccess.READ);
try {
testNotHandledByWorkbookException(pkg);
} finally {
pkg.close();
}
}
Aggregations