Search in sources :

Example 91 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class XSSFChart method commit.

@Override
protected void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    /*
		   Saved chart space must have the following namespaces set:
		   <c:chartSpace
		      xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
		      xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
		      xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
		 */
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    chartSpace.save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 92 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class TestContentTypeManager method testContentType.

/**
     * Test the properties part content parsing.
     */
@Test
public void testContentType() throws Exception {
    String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
    // Retrieves core properties part
    OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ);
    try {
        PackageRelationshipCollection rels = p.getRelationshipsByType(PackageRelationshipTypes.CORE_PROPERTIES);
        PackageRelationship corePropertiesRelationship = rels.getRelationship(0);
        PackagePart coreDocument = p.getPart(corePropertiesRelationship);
        assertEquals("application/vnd.openxmlformats-package.core-properties+xml", coreDocument.getContentType());
        // TODO - finish writing this test
        assumeTrue("finish writing this test", false);
        ContentTypeManager ctm = new ZipContentTypeManager(coreDocument.getInputStream(), p);
        assertNotNull(ctm);
    } finally {
        p.close();
    }
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackageRelationshipCollection(org.apache.poi.openxml4j.opc.PackageRelationshipCollection) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 93 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class TestPackagingURIHelper method testCreatePartNameRelativeURI.

/**
	 * Test createPartName(URI, y)
	 */
public void testCreatePartNameRelativeURI() throws Exception {
    PackagePartName partNameToValid = PackagingURIHelper.createPartName("/word/media/image1.gif");
    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    // Base part
    PackagePartName nameBase = PackagingURIHelper.createPartName("/word/document.xml");
    PackagePart partBase = pkg.createPart(nameBase, ContentTypes.XML);
    // Relative part name
    PackagePartName relativeName = PackagingURIHelper.createPartName(new URI("media/image1.gif"), partBase);
    assertTrue("The part name must be equal to " + partNameToValid.getName(), partNameToValid.equals(relativeName));
    pkg.revert();
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) URI(java.net.URI)

Example 94 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class TestXSSFWorkbook method existing.

@Test
public void existing() throws Exception {
    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
    assertNotNull(workbook.getSharedStringSource());
    assertNotNull(workbook.getStylesSource());
    // And check a few low level bits too
    OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
    PackagePart wbPart = pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
    // Links to the three sheets, shared, styles and themes
    assertTrue(wbPart.hasRelationships());
    assertEquals(6, wbPart.getRelationships().size());
    pkg.close();
    workbook.close();
}
Also used : MemoryPackagePart(org.apache.poi.openxml4j.opc.internal.MemoryPackagePart) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 95 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class ThemesTable method commit.

@Override
protected void commit() throws IOException {
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    writeTo(out);
    out.close();
}
Also used : OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Aggregations

PackagePart (org.apache.poi.openxml4j.opc.PackagePart)118 OutputStream (java.io.OutputStream)38 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)27 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)24 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)23 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)19 QName (javax.xml.namespace.QName)18 IOException (java.io.IOException)17 XmlOptions (org.apache.xmlbeans.XmlOptions)17 InputStream (java.io.InputStream)11 Test (org.junit.Test)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 POIXMLException (org.apache.poi.POIXMLException)8 XmlException (org.apache.xmlbeans.XmlException)8 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)7 ArrayList (java.util.ArrayList)6 TikaException (org.apache.tika.exception.TikaException)6 URI (java.net.URI)5 SAXException (org.xml.sax.SAXException)5