protected void handleEmbeddedOfficeDoc(DirectoryEntry dir, Metadata metadata,
                                           String resourceName, XHTMLContentHandler xhtml, boolean outputHtml)
            throws IOException, SAXException, TikaException {


        // Is it an embedded OLE2 document, or an embedded OOXML document?
        //first try for ooxml
        Entry ooxml = dir.hasEntry("Package") ? dir.getEntry("Package") :
                (dir.hasEntry("package") ? dir.getEntry("package") : null);

        if (ooxml != null) {
            // It's OOXML (has a ZipFile):
            metadata.set(Metadata.CONTENT_LENGTH,
                    Integer.toString(((DocumentEntry)ooxml).getSize()));
            try (TikaInputStream stream = TikaInputStream
                    .get(new DocumentInputStream((DocumentEntry) ooxml))) {

                Detector detector = new DefaultZipContainerDetector();
                MediaType type = null;
                try {
                    type = detector.detect(stream, metadata);
                } catch (SecurityException e) {
                    throw e;
                } catch (Exception e) {
                    //if there's a stream error while detecting, give up
                    EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
                    return;
                }
                handleEmbeddedResource(stream, metadata,null, dir.getName(), dir.getStorageClsid(),
                        type.toString(), xhtml, outputHtml);
                return;
            }
        }

        // It's regular OLE2:

        // What kind of document is it?
        metadata.set(TikaCoreProperties.EMBEDDED_RELATIONSHIP_ID, dir.getName());
        if (dir.getStorageClsid() != null) {
            metadata.set(Office.EMBEDDED_STORAGE_CLASS_ID,
                    dir.getStorageClsid().toString());
        }
        POIFSDocumentType type = POIFSDocumentType.detectType(dir);
        String rName = (resourceName == null) ? dir.getName() : resourceName;
        extractOCXName(dir, metadata);
        if (type == POIFSDocumentType.OLE10_NATIVE) {
            handleOLENative(dir, type, rName, metadata, xhtml, outputHtml);
        } else if (type == POIFSDocumentType.COMP_OBJ) {
            handleCompObj(dir, type, rName, metadata, xhtml, outputHtml);
        } else if (type == POIFSDocumentType.OUTLOOK) {
            //for Outlook try to use the title first so that we don't wind up with __substg1.0_37...
            //if that doesn't exist, backoff to rName
            //add the suffix
            metadata.set(Metadata.CONTENT_TYPE, type.getType().toString());
            String name = tryToGetMsgTitle(dir, rName);
            if (! StringUtils.isBlank(name)) {
                if (StringUtils.isBlank(type.getExtension())) {
                    metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, name);
                } else {
                    metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY,
                            name + '.' + type.getExtension());
                }
            }
            parseEmbedded(dir, xhtml, metadata, outputHtml);
        } else {
            metadata.set(Metadata.CONTENT_TYPE, type.getType().toString());
            if (! StringUtils.isBlank(rName)) {
                if (StringUtils.isBlank(type.getExtension())) {
                    metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, rName);
                } else {
                    metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY,
                            rName + '.' + type.getExtension());
                }
            }
            parseEmbedded(dir, xhtml, metadata, outputHtml);
        }
    }
Handle an office document that's embedded at the POIFS level
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/AbstractPOIFSExtractor.java