|
Regain 2.1.0-STABLE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.regain.RegainToolkit
public class RegainToolkit
Enthält Hilfsmethoden, die sowohl vom Crawler als auch von der Suchmaske genutzt werden.
Nested Class Summary | |
---|---|
private static class |
RegainToolkit.LowercasingReader
Liest alle Zeichen von einem eingebetteten Reader in Kleinschreibung. |
private static class |
RegainToolkit.WrapperAnalyzer
An analyzer that changes a document in lowercase before delivering it to a nested analyzer. |
Field Summary | |
---|---|
private static boolean |
ANALYSE_ANALYZER
Gibt an, ob die Worte, die der Analyzer identifiziert ausgegeben werden sollen. |
static String |
FIELD_ACCESS_CONTROL_GROUPS
The field name where the access control groups are stored |
static String |
INDEX_ENCODING
The encoding used for storing URLs in the index |
private static List<File> |
jarFolders
|
private static org.apache.lucene.util.Version |
LUCENE_VERSION
The current version matching to the embedded lucene jars. |
private static String |
mLineSeparator
Der gecachte, systemspeziefische Zeilenumbruch. |
private static String |
mSystemDefaultEncoding
The cached system's default encoding. |
private static int |
SIZE_GB
The number of bytes in a GB (giga byte). |
private static int |
SIZE_KB
The number of bytes in a kB (kilo byte). |
private static int |
SIZE_MB
The number of bytes in a MB (mega byte). |
Constructor Summary | |
---|---|
RegainToolkit()
|
Method Summary | |
---|---|
static void |
addLibraryJarPath(File file)
Add a new library path where Jars can be loaded from. |
static String |
bytesToString(long bytes)
Gibt einen f�r den Menschen gut lesbaren String f�r eine Anzahl Bytes zur�ck. |
static String |
bytesToString(long bytes,
int fractionDigits)
Gibt einen f�r den Menschen gut lesbaren String f�r eine Anzahl Bytes zur�ck. |
static String |
bytesToString(long bytes,
int fractionDigits,
Locale locale)
Gibt einen f�r den Menschen gut lesbaren String f�r eine Anzahl Bytes zur�ck. |
static String |
bytesToString(long bytes,
Locale locale)
Gibt einen f�r den Menschen gut lesbaren String f�r eine Anzahl Bytes zur�ck. |
static void |
checkGroupArray(Object accessController,
String[] groupArr)
Checks an array of group names. |
static boolean |
containsWhitespace(String str)
Checks whether the given String contains whitespace. |
static void |
copyDirectory(File fromDir,
File toDir,
boolean copySubDirs)
Copies a directory. |
static void |
copyDirectory(File fromDir,
File toDir,
boolean copySubDirs,
String excludeExtension)
Copies a directory. |
static void |
copyFile(File from,
File to)
Copies a file. |
private static org.apache.lucene.analysis.Analyzer |
createAnalysingAnalyzer(org.apache.lucene.analysis.Analyzer nestedAnalyzer)
Erzeugt einen Analyzer, der die Aufrufe an einen eingebetteten Analyzer analysiert. |
static org.apache.lucene.analysis.Analyzer |
createAnalyzer(String analyzerType,
String[] stopWordList,
String[] exclusionList,
String[] untokenizedFieldNames)
Creates an analyzer that is used both from the crawler and the search mask. |
static Object |
createClassInstance(String className,
Class<?> superClass,
ClassLoader classLoader)
Loads a class and creates an instance. |
static Object |
createClassInstance(String className,
Class<?> superClass,
String jarFileName)
Loads a class and creates an instance. |
static String |
createHighlightedFieldIdent(String fieldName)
Creates a field identifier for fields with highlighted content. |
static String |
createSummaryFromContent(String content,
int maxLength)
Creates a summary from given content The method returns null if no summary could created |
static void |
deleteDirectory(File dir)
Löscht ein Verzeichnis mit allen Unterverzeichnissen und -dateien. |
static String |
fileNameToUrl(String fileName)
Returns the URL of a file name. |
static String |
fileToCanonicalUrl(File file)
Gets the canonical URL of a file (no symbolic links, normalised names etc). |
static String |
fileToUrl(File file)
Returns the URL of a file. |
static PathFilenamePair |
fragmentUrl(String url)
Constructs a path-filename pair from a given URL. |
static long |
getDirectorySize(File dir)
Gets the size of a directory with all files. |
static String |
getLineSeparator()
Returns the line seperator of this operating system. |
static org.apache.lucene.util.Version |
getLuceneVersion()
|
static String |
getSystemDefaultEncoding()
Returns the system's default encoding. |
static String |
lastModifiedToString(Date lastModified)
Konvertiert ein Date-Objekt in einen String mit dem Format "YYYY-MM-DD HH:MM". |
static void |
pipe(InputStream in,
OutputStream out)
Schreibt alle Daten, die der InputStream liefert in den OutputStream. |
static void |
pipe(Reader reader,
Writer writer)
Writes all data from the reader to the writer. |
static HashMap<String,String[]> |
readFieldValues(org.apache.lucene.index.IndexReader indexReader,
String[] fieldNameArr,
File indexDir)
Returns the destinct values of one or more fields. |
static String[] |
readListFromFile(File file)
Reads a word list from a file. |
static String |
readStringFromFile(File file)
Liest einen String aus einer Datei. |
static String |
readStringFromStream(InputStream stream)
Reads a String from a stream. |
static String |
readStringFromStream(InputStream stream,
String charsetName)
Reads a String from a stream. |
static String |
removeProtocol(String path)
Removes the protocol from a given path. |
static String |
replace(String source,
String[] patternArr,
String[] replacementArr)
Replaces in a string all occurences of a list of patterns with replacements. |
static String |
replace(String source,
String pattern,
String replacement)
Replaces in a string all occurences of pattern with
replacement . |
private static File |
searchJarFile(String jarFileName)
|
static String[] |
splitString(String str,
String delim)
Splits a String into a string array. |
static String[] |
splitString(String str,
String delim,
boolean trimSplits)
Splits a String into a string array. |
static Date |
stringToLastModified(String asString)
Konvertiert einen String mit dem Format "YYYY-MM-DD HH:MM" in ein Date-Objekt. |
static String |
toPercentString(double value)
Gibt einen Wert in Prozent mit zwei Nachkommastellen zur�ck. |
static String |
toTimeString(long time)
Gets a human readable String for a time. |
static String |
urlDecode(String text,
String encoding)
URL-decodes a String. |
static String |
urlEncode(String text,
String encoding)
URL-encodes a String. |
static File |
urlToFile(String url)
Gets the file that is described by a URL with the file://
protocol. |
static String |
urlToFileName(String url)
Gets the file name that is described by a URL with the file://
protocol. |
static jcifs.smb.SmbFile |
urlToSmbFile(String url)
Gets the smbfile that is described by a URL with the smb://
protocol. |
static String |
urlToSmbFileName(String url)
Gets the smb file name that is described by a URL with the smb://
protocol. |
static String |
urlToWhitespacedFileName(String url)
Gets the 'real' file name that is described by a URL with the file://
protocol. |
static void |
writeListToFile(String[] wordList,
File file)
Writes a word list in a file. |
static void |
writeToFile(byte[] data,
File file)
Writes data to a file |
static void |
writeToFile(String text,
File file)
Writes a String into a file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String INDEX_ENCODING
public static final String FIELD_ACCESS_CONTROL_GROUPS
private static final boolean ANALYSE_ANALYZER
private static final int SIZE_KB
private static final int SIZE_MB
private static final int SIZE_GB
private static String mSystemDefaultEncoding
private static String mLineSeparator
private static final org.apache.lucene.util.Version LUCENE_VERSION
private static List<File> jarFolders
Constructor Detail |
---|
public RegainToolkit()
Method Detail |
---|
public static org.apache.lucene.util.Version getLuceneVersion()
public static void deleteDirectory(File dir) throws RegainException
dir
- Das zu löschende Verzeichnis.
RegainException
- Wenn das L�schen fehl schlug.public static void pipe(Reader reader, Writer writer) throws IOException
Neither the reader nor the writer will be closed. This has to be done by the caller!
reader
- The reader that provides the data.writer
- The writer where to write the data.
IOException
- If reading or writing failed.public static void pipe(InputStream in, OutputStream out) throws IOException
Weder der InputStream noch der OutputStream werden dabei geschlossen. Dies muss die aufrufende Methode �bernehmen!
in
- Der InputStream, der die Daten liefert.out
- Der OutputStream auf den die Daten geschrieben werden sollen.
IOException
- Wenn Lesen oder Schreiben fehl schlug.public static void copyFile(File from, File to) throws RegainException
from
- The source file.to
- The target file.
RegainException
- If copying failed.public static void copyDirectory(File fromDir, File toDir, boolean copySubDirs, String excludeExtension) throws RegainException
fromDir
- The source directory.toDir
- The target directory.copySubDirs
- Specifies whether to copy sub directories.excludeExtension
- The file extension to exclude.
RegainException
- If copying the index failed.public static void copyDirectory(File fromDir, File toDir, boolean copySubDirs) throws RegainException
fromDir
- The source directory.toDir
- The target directory.copySubDirs
- Specifies whether to copy sub directories.
RegainException
- If copying the index failed.public static String readStringFromStream(InputStream stream, String charsetName) throws RegainException
stream
- The stream to read the String fromcharsetName
- The name of the charset to use.
RegainException
- If reading the String failed.public static String readStringFromStream(InputStream stream) throws RegainException
stream
- The stream to read the String from
RegainException
- If reading the String failed.public static String readStringFromFile(File file) throws RegainException
file
- Die Datei aus der der String gelesen werden soll.
null
, wenn die
Datei nicht existiert.
RegainException
- Wenn das Lesen fehl schlug.public static String[] readListFromFile(File file) throws RegainException
file
- The file to read the list from.
RegainException
- If reading failed.public static void writeToFile(byte[] data, File file) throws RegainException
data
- The datafile
- The file to write to
RegainException
- When writing failedpublic static void writeToFile(String text, File file) throws RegainException
text
- The string.file
- The file to write to.
RegainException
- If writing failed.public static void writeListToFile(String[] wordList, File file) throws RegainException
wordList
- The word list.file
- The file to write to.
RegainException
- If writing failed.public static long getDirectorySize(File dir)
dir
- The directory to get the size for.
public static HashMap<String,String[]> readFieldValues(org.apache.lucene.index.IndexReader indexReader, String[] fieldNameArr, File indexDir) throws RegainException
If an index directory is provided, then the values will be read from there. They will be extracted from the search index if there are no matching cache files. After extracting the cache files will be created, so the next call will be faster.
indexReader
- The index reader to use for reading the field values.fieldNameArr
- The names of the fields to read the destinct values for.indexDir
- The index directory where to read or write the cached
destinct values. May be null.
RegainException
- If reading from the index failed. Or if reading or
writing a cache file failed.public static org.apache.lucene.analysis.Analyzer createAnalyzer(String analyzerType, String[] stopWordList, String[] exclusionList, String[] untokenizedFieldNames) throws RegainException
analyzerType
- The type of the analyzer to create. Either a classname
or "english" or "german".stopWordList
- All words that should not be indexed.exclusionList
- All words that shouldn't be changed by the analyzer.untokenizedFieldNames
- The names of the fields that should not be
tokenized.
RegainException
- If the creation failed.private static org.apache.lucene.analysis.Analyzer createAnalysingAnalyzer(org.apache.lucene.analysis.Analyzer nestedAnalyzer)
Dies ist beim Debugging hilfreich, wenn man prüfen will, was ein Analyzer bei bestimmten Anfragen ausgibt.
nestedAnalyzer
- The nested Analyzer that should be analysed
public static String replace(String source, String pattern, String replacement)
pattern
with
replacement
.
Note: pattern
may be a substring of replacement
.
source
- The string to search inpattern
- The pattern to be replacedreplacement
- The replacement for each occurence of the pattern.
pattern
are replaced
by replacement
.public static String replace(String source, String[] patternArr, String[] replacementArr)
Note: The string is searched left to right. So any pattern matching earlier in the string will be replaced. Example: replace("abcd", { "bc", "ab", "cd" }, { "x", "1", "2" }) will return "12" (the pattern "bc" won't be applied, since "ab" matches before).
Note: If two patterns match at the same position, then the first one defined will be applied. Example: replace("abcd", { "ab", "abc" }, { "1", "2" }) will return "1cd".
source
- The string to search inpatternArr
- The pattern to be replacedreplacementArr
- The replacement for each occurence of the pattern.
pattern
are replaced
by replacement
.public static String toPercentString(double value)
value
- Der Wert. (Zwischen 0 und 1)
public static String bytesToString(long bytes)
bytes
- Die Anzahl Bytes
public static String bytesToString(long bytes, Locale locale)
bytes
- Die Anzahl Byteslocale
- The locale to use for formatting the numbers.
public static String bytesToString(long bytes, int fractionDigits)
bytes
- Die Anzahl BytesfractionDigits
- Die Anzahl der Nachkommastellen
public static String bytesToString(long bytes, int fractionDigits, Locale locale)
bytes
- Die Anzahl BytesfractionDigits
- Die Anzahl der Nachkommastellenlocale
- The locale to use for formatting the numbers.
public static String toTimeString(long time)
time
- The time in milliseconds.
public static String lastModifiedToString(Date lastModified)
Dieses Format ist mit Absicht nicht lokalisiert, um die Eindeutigkeit zu gew�hrleisten. Die Lokalisierung muss die Suchmaske �bernehmen.
lastModified
- Das zu konvertiernende Date-Objekt
stringToLastModified(String)
public static Date stringToLastModified(String asString) throws RegainException
asString
- Der zu konvertierende String
RegainException
- Wenn der String ein falsches Format hat.lastModifiedToString(Date)
public static String[] splitString(String str, String delim)
str
- The String to split.delim
- The String that separates the items to split
public static String[] splitString(String str, String delim, boolean trimSplits)
str
- The String to split.delim
- The String that separates the items to splittrimSplits
- Specifies whether String.trim()
should be called
for every split.
public static String getLineSeparator()
public static String getSystemDefaultEncoding()
public static boolean containsWhitespace(String str)
str
- The String to check.
public static void checkGroupArray(Object accessController, String[] groupArr) throws RegainException
accessController
- The (search or crawler) access controller
that returned the array of group names.groupArr
- The array of group names to check.
RegainException
- If the array of group names is not valid.public static Object createClassInstance(String className, Class<?> superClass, ClassLoader classLoader) throws RegainException
className
- The name of the class to load and create an instance of.superClass
- The super class the class must extend.classLoader
- The class loader to use for loading the class. May be
null
RegainException
- If loading the class or creating the instance
failed or if the class is no instance of the given super class.public static void addLibraryJarPath(File file)
file
- Filename of a directory - non-existing directory are silently discarded.private static File searchJarFile(String jarFileName)
public static Object createClassInstance(String className, Class<?> superClass, String jarFileName) throws RegainException
className
- The name of the class to load and create an instance of.superClass
- The super class the class must extend.jarFileName
- The name of the jar file to load the class from.
May be null
or relative to a library path.
RegainException
- If loading the class or creating the instance
failed or if the class is no instance of the given super class.public static String urlToFileName(String url) throws RegainException
file://
protocol.
url
- The URL to get the file name for.
RegainException
- If the URL's protocol isn't file://
.public static String urlToWhitespacedFileName(String url) throws RegainException
file://
protocol. This file name does not contain a path, protocol and drive-letter
url
- The URL to extract the file name from.
RegainException.
RegainException
public static PathFilenamePair fragmentUrl(String url) throws RegainException
url
- the url
RegainException
public static String removeProtocol(String path)
path
- the path
public static File urlToFile(String url) throws RegainException
file://
protocol.
url
- The URL to get the file for.
RegainException
- If the URL's protocol isn't file://
.public static jcifs.smb.SmbFile urlToSmbFile(String url) throws RegainException
smb://
protocol.
url
- The URL to get the smbfile for.
RegainException
- If the URL's protocol isn't smb://
.public static String urlToSmbFileName(String url) throws RegainException
smb://
protocol.
url
- The URL to get the file name for.
RegainException
- If the URL's protocol isn't smb://
.public static String fileNameToUrl(String fileName) throws RegainException
fileName
- The file name to get the URL for
RegainException
- If URL-encoding failed.public static String fileToUrl(File file) throws RegainException
file
- The file to get the URL for
RegainException
- If URL-encoding failed.public static String fileToCanonicalUrl(File file) throws RegainException
file
- The file to get the canonical URL for
RegainException
- If URL-encoding failed.public static String urlEncode(String text, String encoding) throws RegainException
text
- The String to URL-encode.encoding
- The encoding to use.
RegainException
- If URL-encoding failed.public static String urlDecode(String text, String encoding) throws RegainException
text
- The String to URL-decode.encoding
- The encoding to use.
RegainException
- If URL-decoding failed.public static String createSummaryFromContent(String content, int maxLength)
The method returns null
if no summary could created
content
- The content for which the summary is referring tomaxLength
- The maximum length of the created summary
public static String createHighlightedFieldIdent(String fieldName)
The method returns null
if no field identifier could created
fieldName
- The content for which the summary is referring to
|
Regain 2.1.0-STABLE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |