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");
                }
                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(THREE_MF_DOCUMENT);
                if (core.size() == 1) {
                    return THREE_MF;
                }
            }
        }
        // If we didn't find a single core document of any type, skip detection
        if (core.size() != 1) {
            // Invalid OOXML Package received
            return null;
        }

        // Get the type of the core document part
        PackagePart corePart = pkg.getPart(core.getRelationship(0));
        String coreType = corePart.getContentType();

        if (coreType.contains(".xps")) {
            return MediaType.application("vnd.ms-package.xps");
        }
        // Turn that into the type of the overall document
        String docType = coreType.substring(0, coreType.lastIndexOf('.'));

        // The Macro Enabled formats are a little special
        if (docType.toLowerCase(Locale.ROOT).endsWith("macroenabled")) {
            docType = docType.toLowerCase(Locale.ROOT) + ".12";
        }

        if (docType.toLowerCase(Locale.ROOT).endsWith("macroenabledtemplate")) {
            docType = MACRO_TEMPLATE_PATTERN.matcher(docType).replaceAll("macroenabled.12");
        }

        // Build the MediaType object and return
        return MediaType.parse(docType);
    }
Detects the type of an OfficeOpenXML (OOXML) file from
opened Package
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/detect/microsoft/ooxml/OPCPackageDetector.java