/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.extractor;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Set;

import org.apache.jackrabbit.extractor.TextExtractor;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParsingReader;

public class TikaTextExtractor implements TextExtractor {

    private final AutoDetectParser parser = new AutoDetectParser();

    public String[] getContentTypes() {
        Set types = parser.getParsers().keySet();
        return (String[]) types.toArray(new String[types.size()]);
    }

    public Reader extractText(InputStream stream, String type, String encoding)
            throws IOException {
        Metadata metadata = new Metadata();
        if (type != null && type.trim().length() > 0) {
            metadata.set(Metadata.CONTENT_TYPE, type.trim());
        }
        return new ParsingReader(parser, stream, metadata);
    }

}

@@ -1079,24 +1079,62 @@
 tectParser;%0A
+import org.apache.tika.parser.Parser;%0A
 import org.a
@@ -1234,21 +1234,201 @@
     
-private final
+/**%0A     * Auto-detecting parser.%0A     */%0A    private static final Parser PARSER;%0A%0A    /**%0A     * Supported content types.%0A     */%0A    private static final String%5B%5D TYPES;%0A%0A    static %7B%0A       
  Aut
@@ -1478,48 +1478,32 @@
 ();%0A
-%0A
     
-public String%5B%5D getContentTypes() %7B
+    PARSER = parser;
 %0A   
@@ -1557,22 +1557,23 @@
         
-return
+TYPES =
  (String
@@ -1624,16 +1624,85 @@
 %0A    %7D%0A%0A
+    public String%5B%5D getContentTypes() %7B%0A        return TYPES;%0A    %7D%0A%0A
     publ
@@ -1978,16 +1978,86 @@
       %7D%0A
+        // TODO: This creates a background thread. Is that a problem?%0A
         
@@ -2081,22 +2081,22 @@
 gReader(
-parser
+PARSER
 , stream

Use Apache Tika for text extraction