// Could have just passed String relType
// Null where used from BPAI, and a FlatOpcXmlImporter case.
// Cases where rel is not available can prepare a suitable dummy
AlternativeFormatInputPart afip =
new AlternativeFormatInputPart(new PartName(partName) );
afip.setContentType(new ContentType(contentType));
return afip;
} else if (rel!=null && rel.getType().equals(Namespaces.EMBEDDED_PKG) ) {
EmbeddedPackagePart epp = new EmbeddedPackagePart(new PartName(partName) );
epp.setContentType(new ContentType(contentType));
return epp;
} else if (rel!=null && rel.getType().equals(Namespaces.OLE_OBJECT) ) {
OleObjectBinaryPart olePart = new OleObjectBinaryPart(new PartName(partName));
olePart.setContentType(new ContentType(contentType));
return olePart;
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_DOCUMENT)) {
return CreateMainDocumentPartObject(partName);
// how is the main document distinguished from the glossary document?
// Answer:- Main Document is a Package level relationship target,
// whereas the Glossary Document is a Part-level target (from the
// Main Document part)
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED)) {
return CreateMainDocumentPartObject(partName);
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_TEMPLATE)) {
return CreateMainDocumentPartObject(partName);
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_TEMPLATE_MACROENABLED)) {
return CreateMainDocumentPartObject(partName);
} else if (contentType.equals(ContentTypes.PACKAGE_COREPROPERTIES)) {
return CreateDocPropsCorePartObject(partName );
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_CUSTOMPROPERTIES)) {
return CreateDocPropsCustomPartObject(partName );
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_EXTENDEDPROPERTIES)) {
return CreateDocPropsExtendedPartObject(partName );
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE)) {
// NB, since this is just "application/xml", it
return new org.docx4j.openpackaging.parts.CustomXmlDataStoragePart(new PartName(partName));
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGEPROPERTIES)) {
return CreateCustomXmlDataStoragePropertiesPartObject(partName );
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_FONT)) {
return CreateObfuscatedFontPartObject(partName );
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_OLE_OBJECT)
|| contentType.equals(ContentTypes.OFFICEDOCUMENT_ACTIVEX_OBJECT)) {
return new org.docx4j.openpackaging.parts.WordprocessingML.OleObjectBinaryPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_ACTIVEX_XML_OBJECT)) {
return new org.docx4j.openpackaging.parts.ActiveXControlXmlPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_THEME)) {
return CreateThemePartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_COMMENTS)) {
return CreateCommentsPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_ENDNOTES)) {
return CreateEndnotesPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_FONTTABLE)) {
return CreateFontTablePartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_FOOTER)) {
return CreateFooterPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_FOOTNOTES)) {
return CreateFootnotesPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_GLOSSARYDOCUMENT)) {
return CreateGlossaryDocumentPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_HEADER)) {
return CreateHeaderPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_NUMBERING)) {
return CreateNumberingPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_SETTINGS)) {
return CreateDocumentSettingsPartObject(partName );
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_STYLES)) {
return CreateStyleDefinitionsPartObject( partName);
} else if (contentType.equals(ContentTypes.WORDPROCESSINGML_WEBSETTINGS)) {
return CreateWebSettingsPartObject(partName );
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_VBA_DATA)) {
return new VbaDataPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_VBA_PROJECT)) {
return new VbaProjectBinaryPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_VBA_PROJECT_SIGNATURE)) {
return new VbaProjectSignatureBin(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_JPEG)) {
return new org.docx4j.openpackaging.parts.WordprocessingML.ImageJpegPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_PNG)) {
return new org.docx4j.openpackaging.parts.WordprocessingML.ImagePngPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_GIF)) {
return new org.docx4j.openpackaging.parts.WordprocessingML.ImageGifPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_TIFF)) {
return new org.docx4j.openpackaging.parts.WordprocessingML.ImageTiffPart(new PartName(partName));
// } else if (contentType.equals(ContentTypes.IMAGE_EPS)) {
// return new org.docx4j.openpackaging.parts.WordprocessingML.ImageEpsPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_BMP)) {
return new org.docx4j.openpackaging.parts.WordprocessingML.ImageBmpPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_EMF) || contentType.equals(ContentTypes.IMAGE_EMF2)) {
return new MetafileEmfPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.IMAGE_WMF)) {
return new MetafileWmfPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.VML_DRAWING)) {
return new VMLPart(new PartName(partName));
// return new VMLBinaryPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_DRAWING)) {
return new org.docx4j.openpackaging.parts.DrawingML.DiagramDrawingPart(new PartName(partName));
} else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.drawing")) {
try {
return JaxbDmlPart.newPartForContentType(contentType, partName);
} catch (Exception e) {
return new BinaryPart( new PartName(partName));
}
} else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.presentation")
|| contentType.equals(ContentTypes.PRESENTATIONML_MACROENABLED)
|| contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE)
|| contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE_MACROENABLED)
) {
try {
return JaxbPmlPart.newPartForContentType(contentType, partName);
} catch (Exception e) {
return new BinaryPart( new PartName(partName));
}
} else if (contentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK)
|| contentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK_MACROENABLED)
|| contentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE)
|| contentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE_MACROENABLED)) {
try {
return new WorkbookPart(new PartName(partName));
} catch (Exception e) {
return new BinaryPart( new PartName(partName));
}
} else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml")) {
try {
return JaxbSmlPart.newPartForContentType(contentType, partName);
} catch (Exception e) {
return new BinaryPart( new PartName(partName));
}
} else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_THEME_OVERRIDE)) {
return new org.docx4j.openpackaging.parts.DrawingML.ThemeOverridePart(new PartName(partName));
} else if (contentType.equals(ContentTypes.DIGITAL_SIGNATURE_XML_SIGNATURE_PART)) {
return new org.docx4j.openpackaging.parts.digitalsignature.XmlSignaturePart(new PartName(partName));
} else if (contentType.equals(ContentTypes.APPLICATION_XML)
|| partName.endsWith(".xml")) {
// Rarely (but sometimes) used, owing to OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE above.
// Simple minded detection of XML content.
// If it turns out not to be XML, the zip loader
// will catch the error and load it as a binary part instead.
log.warn("DefaultPart used for part '" + partName
+ "' of content type '" + contentType + "'");
return CreateDefaultXmlPartObject(partName );
} else if (contentType.equals(ContentTypes.PRESENTATIONML_FONT_DATA)) {
return new FontDataPart(new PartName(partName));
} else {
log.error("No subclass found for " + partName + "; defaulting to binary");
//throw new PartUnrecognisedException("No subclass found for " + partName + " (content type '" + contentType + "')");
return new BinaryPart( new PartName(partName));
}
}