001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.search.extractors; 029 030import java.io.InputStream; 031 032/** 033 * Allows extraction of the indexable "plain" text plus (optional) meta information from a given binary 034 * input document format.<p> 035 * 036 * @since 6.0.0 037 */ 038public interface I_CmsTextExtractor { 039 040 /** 041 * Extracts the text and meta information from the given binary document.<p> 042 * 043 * The encoding of the input stream is either not required (the document type may have 044 * one common default encoding) or the extractor is able to divine the encoding 045 * from the provided binary array automatically.<p> 046 * 047 * Delivers is the same result as calling <code>{@link #extractText(byte[], String)}</code> 048 * when <code>String == null</code>.<p> 049 * 050 * @param content the binary content of the document to extract the text from 051 * @return the extracted text 052 * 053 * @throws Exception if the text extration fails 054 */ 055 I_CmsExtractionResult extractText(byte[] content) throws Exception; 056 057 /** 058 * Extracts the text and meta information from the given binary document, using the specified content encoding.<p> 059 * 060 * The encoding is a hint for the text extractor, if the value given is <code>null</code> then 061 * the text extractor should try to figure out the encoding itself.<p> 062 * 063 * @param content the binary content of the document to extract the text from 064 * @param encoding the encoding to use 065 * 066 * @return the extracted text 067 * 068 * @throws Exception if the text extration fails 069 */ 070 I_CmsExtractionResult extractText(byte[] content, String encoding) throws Exception; 071 072 /** 073 * Extracts the text and meta information from the document on the input stream.<p> 074 * 075 * The encoding of the input stream is either not required (the document type may have 076 * one common default encoding) or the extractor is able to divine the encoding 077 * from the provided input stream automatically.<p> 078 * 079 * Delivers is the same result as calling <code>{@link #extractText(InputStream, String)}</code> 080 * when <code>String == null</code>.<p> 081 * 082 * @param in the input stream for the document to extract the text from 083 * @return the extracted text and meta information 084 * 085 * @throws Exception if the text extration fails 086 */ 087 I_CmsExtractionResult extractText(InputStream in) throws Exception; 088 089 /** 090 * Extracts the text and meta information from the document on the input stream, using the specified content encoding.<p> 091 * 092 * The encoding is a hint for the text extractor, if the value given is <code>null</code> then 093 * the text extractor should try to figure out the encoding itself.<p> 094 * 095 * @param in the input stream for the document to extract the text from 096 * @param encoding the encoding to use 097 * 098 * @return the extracted text and meta information 099 * 100 * @throws Exception if the text extration fails 101 */ 102 I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception; 103}