Search in sources :

Example 21 with OPCPackage

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();
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) Test(org.junit.Test)

Example 22 with OPCPackage

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();
}
Also used : EncryptedTempData(org.apache.poi.poifs.crypt.temp.EncryptedTempData) SXSSFWorkbookWithCustomZipEntrySource(org.apache.poi.poifs.crypt.temp.SXSSFWorkbookWithCustomZipEntrySource) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) ZipEntrySource(org.apache.poi.openxml4j.util.ZipEntrySource) AesZipFileZipEntrySource(org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource) SXSSFWorkbookWithCustomZipEntrySource(org.apache.poi.poifs.crypt.temp.SXSSFWorkbookWithCustomZipEntrySource) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 23 with OPCPackage

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();
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 24 with OPCPackage

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();
    }
}
Also used : XmlVisioDocument(org.apache.poi.xdgf.usermodel.XmlVisioDocument) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 25 with OPCPackage

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();
    }
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Aggregations

OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)116 Test (org.junit.Test)54 InputStream (java.io.InputStream)29 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)21 File (java.io.File)19 IOException (java.io.IOException)17 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)13 SignatureConfig (org.apache.poi.poifs.crypt.dsig.SignatureConfig)10 SignatureInfo (org.apache.poi.poifs.crypt.dsig.SignatureInfo)10 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 FileOutputStream (java.io.FileOutputStream)8 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)8 XmlException (org.apache.xmlbeans.XmlException)8 FileInputStream (java.io.FileInputStream)7