Search in sources :

Example 86 with PackagePart

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

the class XSLFMetroShape method parseShape.

/*
     * parses the metro bytes to a XSLF shape
     */
public static Shape<?, ?> parseShape(byte[] metroBytes) throws InvalidFormatException, IOException, XmlException {
    PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml");
    OPCPackage pkg = null;
    try {
        pkg = OPCPackage.open(new ByteArrayInputStream(metroBytes));
        PackagePart shapePart = pkg.getPart(shapePN);
        CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), DEFAULT_XML_OPTIONS);
        XSLFGroupShape xgs = new XSLFGroupShape(gs, null);
        return xgs.getShapes().get(0);
    } finally {
        if (pkg != null) {
            pkg.close();
        }
    }
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 87 with PackagePart

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

the class XMLSlideShow method getPictureData.

@Override
public List<XSLFPictureData> getPictureData() {
    if (_pictures == null) {
        List<PackagePart> mediaParts = getPackage().getPartsByName(Pattern.compile("/ppt/media/.*?"));
        _pictures = new ArrayList<XSLFPictureData>(mediaParts.size());
        for (PackagePart part : mediaParts) {
            XSLFPictureData pd = new XSLFPictureData(part);
            pd.setIndex(_pictures.size());
            _pictures.add(pd);
        }
    }
    return Collections.unmodifiableList(_pictures);
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 88 with PackagePart

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

the class XMLSlideShow method commit.

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

Example 89 with PackagePart

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

the class TestEmbeded method test.

private void test(POIXMLDocument doc, int expectedCount) throws Exception {
    assertNotNull(doc.getAllEmbedds());
    assertEquals(expectedCount, doc.getAllEmbedds().size());
    for (int i = 0; i < doc.getAllEmbedds().size(); i++) {
        PackagePart pp = doc.getAllEmbedds().get(i);
        assertNotNull(pp);
        byte[] b = IOUtils.toByteArray(pp.getInputStream());
        assertTrue(b.length > 0);
    }
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 90 with PackagePart

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

the class POIXMLDocument method getRelatedByType.

/**
     * Retrieves all the PackageParts which are defined as relationships of the base document with the
     * specified content type.
     * 
     * @param contentType the content type
     * 
     * @return all the base document PackageParts which match the content type
     * 
     * @throws InvalidFormatException when the relationships or the parts contain errors
     * 
     * @see org.apache.poi.xssf.usermodel.XSSFRelation
     * @see org.apache.poi.xslf.usermodel.XSLFRelation
     * @see org.apache.poi.xwpf.usermodel.XWPFRelation
     * @see org.apache.poi.xdgf.usermodel.XDGFRelation
     */
protected PackagePart[] getRelatedByType(String contentType) throws InvalidFormatException {
    PackageRelationshipCollection partsC = getPackagePart().getRelationshipsByType(contentType);
    PackagePart[] parts = new PackagePart[partsC.size()];
    int count = 0;
    for (PackageRelationship rel : partsC) {
        parts[count] = getPackagePart().getRelatedPart(rel);
        count++;
    }
    return parts;
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackageRelationshipCollection(org.apache.poi.openxml4j.opc.PackageRelationshipCollection) 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