1d127360fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d127360fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d127360fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d127360fSAndrew Rist * distributed with this work for additional information 6d127360fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d127360fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d127360fSAndrew Rist * "License"); you may not use this file except in compliance 9d127360fSAndrew Rist * with the License. You may obtain a copy of the License at 10d127360fSAndrew Rist * 11d127360fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12d127360fSAndrew Rist * 13d127360fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d127360fSAndrew Rist * software distributed under the License is distributed on an 15d127360fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d127360fSAndrew Rist * KIND, either express or implied. See the License for the 17d127360fSAndrew Rist * specific language governing permissions and limitations 18d127360fSAndrew Rist * under the License. 19d127360fSAndrew Rist * 20d127360fSAndrew Rist *************************************************************/ 21d127360fSAndrew Rist 22d127360fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.help; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.File; 27cdf0e10cSrcweir import java.io.Reader; 28cdf0e10cSrcweir import java.io.FileInputStream; 29cdf0e10cSrcweir import java.io.InputStreamReader; 30cdf0e10cSrcweir //import java.io.FileReader; 31cdf0e10cSrcweir import java.io.StringReader; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import org.apache.lucene.document.Document; 34cdf0e10cSrcweir import org.apache.lucene.document.Field; 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** Lucene Document for help files */ 37cdf0e10cSrcweir public class HelpFileDocument 38cdf0e10cSrcweir { 39cdf0e10cSrcweir /** Creates reader for UTF-8 files 40cdf0e10cSrcweir */ getReaderForFile( File aFile )41cdf0e10cSrcweir private static Reader getReaderForFile( File aFile ) 42cdf0e10cSrcweir throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException { 43cdf0e10cSrcweir Reader aReader; 44cdf0e10cSrcweir if( aFile != null ) { 45cdf0e10cSrcweir FileInputStream fis = new FileInputStream( aFile ); 46cdf0e10cSrcweir aReader = new InputStreamReader( fis, "UTF-8" ); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir else { 49cdf0e10cSrcweir aReader = new StringReader( "" ); 50cdf0e10cSrcweir } 51cdf0e10cSrcweir return aReader; 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** Makes a document for a File. 55cdf0e10cSrcweir */ Document( String aModule, File aCaptionFile, File aContentFile )56cdf0e10cSrcweir public static Document Document( String aModule, File aCaptionFile, File aContentFile ) 57cdf0e10cSrcweir throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException { 58cdf0e10cSrcweir Document doc = new Document(); 59cdf0e10cSrcweir 60cdf0e10cSrcweir // Add the path of the file as a field named "path". Use a field that is 61cdf0e10cSrcweir // indexed (i.e. searchable), but don't tokenize the field into words. 62cdf0e10cSrcweir File aFile = aCaptionFile != null ? aCaptionFile : aContentFile; 63cdf0e10cSrcweir if( aFile != null ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir String aPath = "#HLP#" + aModule + "/" + aFile.getName(); 66*7fb4469bSPedro Giffuni doc.add(new Field("path", aPath, Field.Store.YES, Field.Index.NOT_ANALYZED)); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // Add the caption of the file to a field named "caption". Specify a Reader, 70cdf0e10cSrcweir // so that the text of the file is tokenized and indexed, but not stored. 71cdf0e10cSrcweir doc.add( new Field( "caption", getReaderForFile( aCaptionFile ) ) ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // Add the contents of the file to a field named "content". Specify a Reader, 74cdf0e10cSrcweir // so that the text of the file is tokenized and indexed, but not stored. 75cdf0e10cSrcweir doc.add( new Field( "content", getReaderForFile( aContentFile ) ) ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir // return the document 78cdf0e10cSrcweir return doc; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir HelpFileDocument()81cdf0e10cSrcweir private HelpFileDocument() {} 82cdf0e10cSrcweir } 83