use of org.apache.poi.openxml4j.opc.PackageRelationshipCollection in project tika by apache.
the class SXWPFWordExtractorDecorator method loadNumbering.
private XWPFNumbering loadNumbering(PackagePart packagePart) {
try {
PackageRelationshipCollection numberingParts = packagePart.getRelationshipsByType(XWPFRelation.NUMBERING.getRelation());
if (numberingParts.size() > 0) {
PackageRelationship numberingRelationShip = numberingParts.getRelationship(0);
if (numberingRelationShip == null) {
return null;
}
PackagePart numberingPart = packagePart.getRelatedPart(numberingRelationShip);
if (numberingPart == null) {
return null;
}
return new XWPFNumberingShim(numberingPart);
}
} catch (IOException | OpenXML4JException e) {
//swallow
}
return null;
}
use of org.apache.poi.openxml4j.opc.PackageRelationshipCollection in project tika by apache.
the class SXWPFWordExtractorDecorator method loadStyles.
private XWPFStylesShim loadStyles(PackagePart packagePart) throws InvalidFormatException, TikaException, IOException, SAXException {
PackageRelationshipCollection stylesParts = packagePart.getRelationshipsByType(XWPFRelation.STYLES.getRelation());
if (stylesParts.size() > 0) {
PackageRelationship stylesRelationShip = stylesParts.getRelationship(0);
if (stylesRelationShip == null) {
return null;
}
PackagePart stylesPart = packagePart.getRelatedPart(stylesRelationShip);
if (stylesPart == null) {
return null;
}
return new XWPFStylesShim(stylesPart, context);
}
return null;
}
use of org.apache.poi.openxml4j.opc.PackageRelationshipCollection 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;
}
use of org.apache.poi.openxml4j.opc.PackageRelationshipCollection 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();
}
}
Aggregations