Skip to content

Commit

Permalink
TIKA-4224 -- add detection for 3mf (#1689)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3ffbc04)
  • Loading branch information
tballison committed Mar 26, 2024
1 parent 361e0de commit 722aaaf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,12 @@
<glob pattern="*.ost"/>
</mime-type>

<mime-type type="application/vnd.ms-package.3dmanufacturing-3dmodel+xml">
<tika:link>https://en.wikipedia.org/wiki/3D_Manufacturing_Format</tika:link>
<_comment>3D manufacturing format</_comment>
<glob pattern="*.3mf"/>
</mime-type>

<mime-type type="application/vnd.ms-pki.seccat">
<glob pattern="*.cat"/>
</mime-type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class OPCPackageDetector implements ZipContainerDetector {
MediaType.application("vnd.openxmlformats-officedocument.spreadsheetml.template");
static final MediaType XLAM = MediaType.application("vnd.ms-excel.addin.macroEnabled.12");
static final MediaType XPS = MediaType.application("vnd.ms-xpsdocument");

static final MediaType THREE_MF = MediaType.application("vnd.ms-package.3dmanufacturing-3dmodel+xml");

static final Set<String> OOXML_HINTS =
fillSet("word/document.xml", "_rels/.rels", "[Content_Types].xml",
"ppt/presentation.xml", "ppt/slides/slide1.xml", "xl/workbook.xml",
Expand All @@ -100,6 +103,8 @@ public class OPCPackageDetector implements ZipContainerDetector {
"http://schemas.openxps.org/oxps/v1.0/fixedrepresentation";
private static final String STAR_OFFICE_6_WRITER = "application/vnd.sun.xml.writer";

private static final String THREE_MF_DOCUMENT =
"http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
static Map<String, MediaType> OOXML_CONTENT_TYPES = new ConcurrentHashMap<>();

static {
Expand Down Expand Up @@ -153,29 +158,37 @@ public static MediaType detectOfficeOpenXML(OPCPackage pkg) {
// Check for the normal Office core document
PackageRelationshipCollection core =
pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);

// Otherwise check for some other Office core document types
if (core.size() == 0) {
core = pkg.getRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT);
}
if (core.size() == 0) {
core = pkg.getRelationshipsByType(PackageRelationshipTypes.VISIO_CORE_DOCUMENT);
}
if (core.size() == 0) {
core = pkg.getRelationshipsByType(XPS_DOCUMENT);
if (core.size() == 1) {
return MediaType.application("vnd.ms-xpsdocument");

if (core.size() == 0) {
core = pkg.getRelationshipsByType(PackageRelationshipTypes.VISIO_CORE_DOCUMENT);
}
core = pkg.getRelationshipsByType(OPEN_XPS_DOCUMENT);
if (core.size() == 1) {
return MediaType.application("vnd.ms-xpsdocument");
if (core.size() == 0) {
core = pkg.getRelationshipsByType(XPS_DOCUMENT);
if (core.size() == 1) {
return MediaType.application("vnd.ms-xpsdocument");
}
core = pkg.getRelationshipsByType(OPEN_XPS_DOCUMENT);
if (core.size() == 1) {
return MediaType.application("vnd.ms-xpsdocument");
}
}
}

if (core.size() == 0) {
core = pkg.getRelationshipsByType(
"http://schemas.autodesk.com/dwfx/2007/relationships/documentsequence");
if (core.size() == 1) {
return MediaType.parse("model/vnd.dwfx+xps");
if (core.size() == 0) {
core = pkg.getRelationshipsByType(
"http://schemas.autodesk.com/dwfx/2007/relationships/documentsequence");
if (core.size() == 1) {
return MediaType.parse("model/vnd.dwfx+xps");
}
}
if (core.size() == 0) {
core = pkg.getRelationshipsByType(THREE_MF_DOCUMENT);
if (core.size() == 1) {
return THREE_MF;
}
}
}
// If we didn't find a single core document of any type, skip detection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public void testDetectODF() throws Exception {
assertTypeByData("testODTnotaZipFile.odt", "text/plain");
}

@Test
public void test3MF() throws Exception {
assertTypeByData("test3mf.3mf", "application/vnd.ms-package.3dmanufacturing-3dmodel+xml");
assertTypeByNameAndData("test3mf.3mf", "application/vnd.ms-package.3dmanufacturing-3dmodel+xml");
}
@Test
public void testODFDifferentOrder() throws Exception {
//TIKA-3356
Expand Down
Binary file not shown.

0 comments on commit 722aaaf

Please sign in to comment.