01: package org.apache.lucene.ant;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.document.Document;
21:
22: import java.io.File;
23:
24: /**
25: * A DocumentHandler implementation to delegate responsibility to
26: * based on a files extension. Currently only .html and .txt
27: * files are handled, other extensions ignored.
28: *
29: *@author Erik Hatcher
30: *@since October 28, 2001
31: *@todo Implement dynamic document type lookup
32: */
33: public class FileExtensionDocumentHandler implements DocumentHandler {
34: /**
35: * Gets the document attribute of the
36: * FileExtensionDocumentHandler object
37: *
38: *@param file Description of
39: * Parameter
40: *@return The document value
41: *@exception DocumentHandlerException Description of
42: * Exception
43: */
44: public Document getDocument(File file)
45: throws DocumentHandlerException {
46: Document doc = null;
47:
48: String name = file.getName();
49:
50: try {
51: if (name.endsWith(".txt")) {
52: doc = TextDocument.Document(file);
53: }
54:
55: if (name.endsWith(".html")) {
56: doc = HtmlDocument.Document(file);
57: }
58: } catch (java.io.IOException e) {
59: throw new DocumentHandlerException(e);
60: }
61:
62: return doc;
63: }
64: }
|