AnalyzerGuru.java revision 148
0N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License (the "License"). 0N/A * You may not use this file except in compliance with the License. 0N/A * language governing permissions and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * If applicable, add the following below this CDDL HEADER, with the 0N/A * fields enclosed by brackets "[]" replaced with your own identifying 0N/A * information: Portions Copyright [yyyy] [name of copyright owner] 143N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 0N/A * Use is subject to license terms. 143N/A * Manages and porvides Analyzers as needed. Please see 143N/A * this</a> page for a great description of the purpose of the AnalyzerGuru. 0N/A * Created on September 22, 2005 0N/A * If you write your own analyzer please register it here 0N/A * Initializes an AnalyzerGuru 0N/A // TODO: have a comparator 0N/A //System.err.println(analyzer.getSimpleName() + " = " + suffix); 148N/A "suffix '" +
suffix +
"' used in multiple analyzers";
0N/A // System.err.println("AnalyzerFinder:" + analyzer.getSimpleName() + e); 0N/A //System.err.println(analyzer.getSimpleName() + " = " + magic); 0N/A // System.err.println("AnalyzerFinder: " + analyzer.getSimpleName() + e); 0N/A //System.err.println("Exts " + ext); 0N/A //System.err.println("Matchers " + matchers); 143N/A * Instruct the AnalyzerGuru to use a given analyzer for a given 143N/A * @param extension the file-extension to add 143N/A * @param analyzer the analyzer to use for the given extension 143N/A * (if you pass null as the analyzer, you will disable 143N/A * the analyzer used for that extension) 0N/A * Get the default Analyzer. 143N/A * Get an analyzer suited to analyze a file. This function will reuse 143N/A * analyzers since they are costly. 143N/A * @param in Input stream containing data to be analyzed 143N/A * @param file Name of the file to be analyzed 143N/A * @return An analyzer suited for that file content 143N/A * @throws java.io.IOException If an error occurs while accessing the 143N/A * data in the input stream. 143N/A * Create a Lucene document and fill in the required fields 143N/A * @param file The file to index 143N/A * @param in The data to generate the index for 143N/A * @param path Where the file is located (from source root) 143N/A * @return The Lucene document to add to the index database 143N/A * @throws java.io.IOException If an exception occurs while collecting the 0N/A // date = hr.getLastCommentDate() //RFE 0N/A // Ignoring any errors while analysing 143N/A * Get the content type for a named file. 143N/A * @param file The file to get the content type for 0N/A * @return The contentType suitable for printing to response.setContentType() 143N/A * Get the content type for a named file. 143N/A * @param in The input stream we want to get the content type for (if 143N/A * we cannot determine the content type by the filename) 143N/A * @param file The name of the file 143N/A * @return The contentType suitable for printing to response.setContentType() 143N/A * @throws java.io.IOException If an error occurs while accessing the input 143N/A * Get the content type the named analyzer accepts 143N/A * @param analyzer the analyzer to test 143N/A * @return the contentType suitable for printing to response.setContentType() 143N/A * Write a browsable version of the file 143N/A * @param analyzer The analyzer for this filetype 143N/A * @param in The input stream containing the data 143N/A * @param out Where to write the result 143N/A * @param annotation Annotation information for the file 143N/A * @throws java.io.IOException If an error occurs while creating the 143N/A * Get the genre of a file 143N/A * @param file The file to inpect 0N/A * @return The genre suitable to decide how to display the file 143N/A * Get the genre of a file (or the content of the file) 143N/A * @param in The content of the file 143N/A * @param file The file to inpect 143N/A * @return The genre suitable to decide how to display the file 143N/A * @throws java.io.IOException If an error occurs while getting the content 143N/A * Get the genre of a bulk of data 143N/A * @param in A stream containing the data 143N/A * @return The genre suitable to decide how to display the file 143N/A * @throws java.io.IOException If an error occurs while getting the content 143N/A * Get the genre for a named class (this is most likely an analyzer) 143N/A * @param clazz the class to get the genre for 143N/A * @return The genre of this class (null if not found) 143N/A * Finds a suitable analyser class for file name. If the analyzer cannot 143N/A * be determined by the file extension, try to look at the data in the 143N/A * InputStream to find a suitable analyzer. 0N/A * Use if you just want to find file type. 143N/A * @param in The input stream containing the data 143N/A * @param file The file name to get the analyzer for 143N/A * @return The analyzer to use 143N/A * @throws java.io.IOException If a problem occurs while reading the data 143N/A * Finds a suitable analyser class for file name. 143N/A * @param file The file name to get the analyzer for 143N/A * @return The analyzer to use 0N/A //System.err.println(path.substring(dotpos+1).toUpperCase() + " = " + analyzer.getSimpleName()); 143N/A * Finds a suitable analyser class for the data in this stream 143N/A * @param in The stream containing the data to analyze 143N/A * @return The analyzer to use 143N/A * @throws java.io.IOException if an error occurs while reading data from 0N/A //System.out.println("USING = " + matcher.getName()); 36N/A // cannot check conversion because of reflection 143N/A * Finds a suitable analyser class for a magic signature 143N/A * @param signature the magic signature look up 143N/A * @return The analyzer to use 143N/A * Get an analyzer by looking up the "magic signature" 143N/A * @param signature the signature to look up 143N/A * @return The analyzer to handle data with this signature