odt、ppt、pptx、xlsxなどのドキュメントでは、application / zipまたはapplication / x-tika-msofficeではなく、iana.org MediaTypeを取得する必要があります。
mimetypes.xmlを見ると、iana.org mime-typeと "sub-class-of"で構成されるmimeType要素があります。
<mime-type type="application/msword">
<alias type="application/vnd.ms-word"/>
............................
<glob pattern="*.doc"/>
<glob pattern="*.dot"/>
<sub-class-of type="application/x-tika-msoffice"/>
</mime-type>
親タイプ名の代わりにiana.org MIMEタイプ名を取得するにはどうすればよいですか?
MIMEタイプの検出をテストするときは、次のようにします。
MediaType mediaType = MediaType.parse(tika.detect(inputStream));
String mimeType = mediaType.getSubtype();
試験結果 :
FAILED: getsCorrectContentType("application/vnd.ms-excel", docs/xls/en.xls)
java.lang.AssertionError: expected:<application/vnd.ms-excel> but was:<x-tika-msoffice>
FAILED: getsCorrectContentType("vnd.openxmlformats-officedocument.spreadsheetml.sheet", docs/xlsx/en.xlsx)
java.lang.AssertionError: expected:<vnd.openxmlformats-officedocument.spreadsheetml.sheet> but was:<zip>
FAILED: getsCorrectContentType("application/msword", doc/en.doc)
java.lang.AssertionError: expected:<application/msword> but was:<x-tika-msoffice>
FAILED: getsCorrectContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document", docs/docx/en.docx)
java.lang.AssertionError: expected:<application/vnd.openxmlformats-officedocument.wordprocessingml.document> but was:<zip>
FAILED: getsCorrectContentType("vnd.ms-powerpoint", docs/ppt/en.ppt)
java.lang.AssertionError: expected:<vnd.ms-powerpoint> but was:<x-tika-msoffice>
mimetypes.xmlから実際のサブタイプを取得する方法はありますか?x-tika-msofficeまたはapplication / zipの代わりに?
さらに、application / x-tika-ooxmlを取得することはありませんが、xlsx、docx、pptxドキュメントのapplication / zipを取得します。
tika-coreのデフォルトのバイトパターン検出ルールは、すべてのMS Officeドキュメントタイプで使用される一般的なOLE2またはZIP形式のみを検出できます。この種の検出機能にはContainerAwareDetectorを使用したいとします。そして、フォールバック検出器としてMimeTypes検出器を使用します。これを試して :
public MediaType getContentType(InputStream is, String fileName) {
MediaType mediaType;
Metadata md = new Metadata();
md.set(Metadata.RESOURCE_NAME_KEY, fileName);
Detector detector = new ContainerAwareDetector(tikaConfig.getMimeRepository());
try {
mediaType = detector.detect(is, md);
} catch (IOException ioe) {
whatever;
}
return mediaType;
}
このようにして、テストに合格する必要があります
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加