Return-Path: Delivered-To: apmail-lucene-tika-commits-archive@www.apache.org Received: (qmail 66631 invoked from network); 12 Jul 2009 21:19:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 Jul 2009 21:19:42 -0000 Received: (qmail 55320 invoked by uid 500); 12 Jul 2009 21:19:52 -0000 Delivered-To: apmail-lucene-tika-commits-archive@lucene.apache.org Received: (qmail 55275 invoked by uid 500); 12 Jul 2009 21:19:52 -0000 Mailing-List: contact tika-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: tika-dev@lucene.apache.org Delivered-To: mailing list tika-commits@lucene.apache.org Received: (qmail 55266 invoked by uid 99); 12 Jul 2009 21:19:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jul 2009 21:19:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jul 2009 21:19:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C60D62388877; Sun, 12 Jul 2009 21:19:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r793410 - /lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParser.java Date: Sun, 12 Jul 2009 21:19:29 -0000 To: tika-commits@lucene.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090712211929.C60D62388877@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Sun Jul 12 21:19:27 2009 New Revision: 793410 URL: http://svn.apache.org/viewvc?rev=793410&view=rev Log: TIKA-258: AutoDetectParser does not allow to use alternative mime detector Changes based on the patch contributed by Maxim Valyanskiy. Modified: lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParser.java Modified: lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParser.java URL: http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParser.java?rev=793410&r1=793409&r2=793410&view=diff ============================================================================== --- lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParser.java (original) +++ lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParser.java Sun Jul 12 21:19:27 2009 @@ -25,14 +25,18 @@ import org.apache.tika.io.CountingInputStream; import org.apache.tika.metadata.Metadata; import org.apache.tika.mime.MediaType; -import org.apache.tika.mime.MimeTypes; import org.apache.tika.sax.SecureContentHandler; +import org.apache.tika.detect.Detector; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; public class AutoDetectParser extends CompositeParser { - private MimeTypes types; + /** + * The type detector used by this parser to auto-detect the type + * of a document. + */ + private Detector detector; // always set in the constructor /** * Creates an auto-detecting parser instance using the default Tika @@ -53,15 +57,31 @@ public void setConfig(TikaConfig config) { setParsers(config.getParsers()); - setMimeTypes(config.getMimeRepository()); + setDetector(config.getMimeRepository()); } - public MimeTypes getMimeTypes() { - return types; + /** + * Returns the type detector used by this parser to auto-detect the type + * of a document. + * + * @return type detector + * @since Apache Tika 0.4 + */ + public Detector getDetector() { + return detector; } - public void setMimeTypes(MimeTypes types) { - this.types = types; + /** + * Sets the type detector used by this parser to auto-detect the type + * of a document. Note that calling the {@link #setConfig(TikaConfig)} + * method will override the type detector setting with the type settings + * included in the given configuration. + * + * @param detector type detector + * @since Apache Tika 0.4 + */ + public void setDetector(Detector detector) { + this.detector = detector; } public void parse( @@ -73,7 +93,7 @@ } // Automatically detect the MIME type of the document - MediaType type = types.detect(stream, metadata); + MediaType type = detector.detect(stream, metadata); metadata.set(Metadata.CONTENT_TYPE, type.toString()); // TIKA-216: Zip bomb prevention