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();
}
}
}
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);
}
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();
}
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);
}
}
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;
}
Aggregations