use of org.apache.poi.POIXMLDocumentPart in project poi by apache.
the class XWPFDocument method initFootnotes.
private void initFootnotes() throws XmlException, IOException {
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart();
String relation = rp.getRelationship().getRelationshipType();
if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
this.footnotes = (XWPFFootnotes) p;
this.footnotes.onDocumentRead();
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())) {
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
for (CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray()) {
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
}
}
}
}
use of org.apache.poi.POIXMLDocumentPart in project poi by apache.
the class XWPFHeaderFooter method onDocumentRead.
@Override
protected void onDocumentRead() throws IOException {
for (POIXMLDocumentPart poixmlDocumentPart : getRelations()) {
if (poixmlDocumentPart instanceof XWPFPictureData) {
XWPFPictureData xwpfPicData = (XWPFPictureData) poixmlDocumentPart;
pictures.add(xwpfPicData);
document.registerPackagePictureData(xwpfPicData);
}
}
}
use of org.apache.poi.POIXMLDocumentPart in project poi by apache.
the class TestXSLFBugs method assertRelation.
private static void assertRelation(XSLFSlide slide, String exp, String rId) {
POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
assertNotNull(pd);
assertEquals(exp, pd.getPackagePart().getPartName().getName());
}
use of org.apache.poi.POIXMLDocumentPart in project poi by apache.
the class TestMapInfo method testMapInfoExists.
public void testMapInfoExists() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.xlsx");
MapInfo mapInfo = null;
SingleXmlCells singleXMLCells = null;
for (POIXMLDocumentPart p : wb.getRelations()) {
if (p instanceof MapInfo) {
mapInfo = (MapInfo) p;
CTMapInfo ctMapInfo = mapInfo.getCTMapInfo();
assertNotNull(ctMapInfo);
assertEquals(1, ctMapInfo.sizeOfSchemaArray());
for (XSSFMap map : mapInfo.getAllXSSFMaps()) {
Node xmlSchema = map.getSchema();
assertNotNull(xmlSchema);
}
}
}
XSSFSheet sheet1 = wb.getSheetAt(0);
for (POIXMLDocumentPart p : sheet1.getRelations()) {
if (p instanceof SingleXmlCells) {
singleXMLCells = (SingleXmlCells) p;
}
}
assertNotNull(mapInfo);
assertNotNull(singleXMLCells);
}
use of org.apache.poi.POIXMLDocumentPart in project poi by apache.
the class TestXWPFDocument method testPictureHandlingComplex.
@Test
public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
XWPFHeader xwpfHeader = doc.getHeaderArray(0);
assertEquals(3, doc.getAllPictures().size());
assertEquals(3, xwpfHeader.getAllPictures().size());
assertEquals(5, doc.getAllPackagePictures().size());
byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
assertSame(part1, part2);
doc.getPackage().revert();
doc.close();
}
Aggregations