Office Open XMLのMIMEタイプ

うーん、いくら何でも長すぎなんじゃないのか・・・(始め見て長すぎて信じられんかったよ)。

docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
docm application/vnd.ms-word.document.macroEnabled.12
dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
dotm application/vnd.ms-word.template.macroEnabled.12
xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsm application/vnd.ms-excel.sheet.macroEnabled.12
xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
xltm application/vnd.ms-excel.template.macroEnabled.12
xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
xlam application/vnd.ms-excel.addin.macroEnabled.12
pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
pptm application/vnd.ms-powerpoint.presentation.macroEnabled.12
ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12
potx application/vnd.openxmlformats-officedocument.presentationml.template
potm application/vnd.ms-powerpoint.template.macroEnabled.12
ppam application/vnd.ms-powerpoint.addin.macroEnabled.12
sldx application/vnd.openxmlformats-officedocument.presentationml.slide
sldm application/vnd.ms-powerpoint.slide.macroEnabled.12
onetoc application/onenote
onetoc2 application/onenote
onetmp application/onenote
onepkg application/onenote

ファイルシステム対応

全文検索のFessでローカルにあるようなファイルもインデックス化するために S2Robot にファイルシステムも巡回できるように機能追加してみた。file:// で始まるパスを渡せば、そこからファイルシステムを辿っていく感じ。次は Word や Excel の中身の文字列を取得する機能を加えようかね。

JAFでMIMEタイプ取得

JavaBeans Activation Framework を使えば、以下みたいな感じで MIME タイプを取得できる。

String filename = "hoge.txt";
String mimeType = new MimetypesFileTypeMap().getContentType(filename);

これをするためには、Maven2 を使っているなら、pom.xml に

:
<repositories>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
</repositories>
:
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
:

を書けば良い。jaf もデフォルトで処理できる拡張子が少ないので、META-INF/mime.typesを作って

application/msword              doc dot wiz rtf
application/msexcel             xls
application/mspowerpoint        ppt
application/x-pdf               pdf

という感じで書いていけば拡張可能。という感じで、S2Robot 内で使ってみた。