FileConverter converts files to HTML, RTF, or text, optionally marking hits with caller-supplied tags.
public class FileConverter;
FileConverter.java
For general information on implementing hit highlighting and hit navigation, see:
To convert a file, create a FileConverter, use the properties of the FileConverter to describe the conversion task you want to perform, and call the execute() method.
When highlighting hits from search results, use setInputItem to initialize the FileConverter with information obtained from SearchResults.
BeforeHit, AfterHit, Header, and Footer control the appearance of converted text. Header and Footer are inserted before and after the body of the document. The BeforeHit and AfterHit markers are inserted before and after each hit word. The BeforeHit and AfterHit markers can contain hypertext links. To facilitate creation of hit navigation markers, the strings "%%ThisHit%%", "%%NextHit%%", and "%%PrevHit%%" will be replaced with ordinals representing the current hit, the next hit, and the previous hit in the document.
// results: SearchResults from a previous search
// whichDoc: integer from 0 to results.getCount()-1 identifying the document to display
// Select the item to display
results.getNthDoc(whichDoc);
String f = results.getDocName();
com.dtsearch.engine.FileConverter fc = new com.dtsearch.engine.FileConverter();
// Set up FileConverter to use the selected item from search results
fc.setInputItem(results, index);
// If the file is HTML, this ensures that it has a BASE tag preserving relative links
fc.setBaseHref(f);
// Generate HTML output in a string
fc.setOutputToString(true);
fc.setOutputFormat(Constants.it_HTML);
// Highlight hits by making them bold
fc.setBeforeHit("<b>");
fc.setAfterHit("</b>");
// Perform the conversion
fc.execute();
// Display the result
setHtml(fc.getOutputString());
|
Method |
Description |
|
Call execute() to execute the conversion. | |
|
After execute() returns, use getErrors to access error information. | |
|
Name of the file to convert | |
|
Name of the file to create from the input file. Use setOutputToString() to request conversion to a memory buffer. | |
|
The output format can be it_HTML (226), it_Ansi (202), it_Utf8 (238), it_RTF (212), or it_XML (234) | |
|
Conversion output can be directed to a string or to a disk file. For string output, use setOutputStringMaxSize to set the maximum size of the output string, and getOutputString after conversion to access the result. | |
|
If an array of hit offsets has been provided using setHits, then the beforeHit and afterHit strings will be used to mark each hit in the document in the converted output. The strings must be appropriate for the output format. For example, to use an angle bracket in HTML output, use > | |
|
The location of the dtSearch alphabet file to use when highlighting hits. The alphabet file determines how dtSearch counts words, so it is important that the same alphabet file used to index or search a file also be used to highlight hits. For more information on how hit highlighting works, see Highlighting Hits in the online help. To ensure that the same alphabet used to index a file is used to highlight hits in that file, set the alphabetLocation to the folder where the index is located. The alphabet definition will be stored in this folder (in a file named... more | |
|
For HTML output, an HREF for a BASE tag to be inserted in the header. | |
|
If an array of hit offsets has been provided using setHits, then the beforeHit and afterHit strings will be used to mark each hit in the document in the converted output. The strings must be appropriate for the output format. For example, to use an angle bracket in HTML output, use < | |
|
Use setDocBytes to provide a document in a memory buffer rather than as a disk file. The byte array input must contain exactly the same bytes as the representation of this document on disk. When a byte array is provided through setDocBytes, the filename is disregarded. | |
|
Set to ConvertFlags values to control file conversion. | |
|
The footer will be appended to the conversion output and can use tags in the output format, such as HTML tags in a document converted to HTML. | |
|
The header will appear at the top of the conversion output and can use tags in the output format, such as HTML tags in a document converted to HTML. | |
|
To request hit highlighting using the beforeHit and afterHit strings, provide an array of hit offsets using setHits. The array returned from the SearchResults getHits method can be used for this purpose. | |
|
Name of the file to convert | |
|
Select an item from search results to use as input for the FileConverter. setInputItem will set the name of the input file, the alphabet location, and the hits. | |
|
Name of the file to create from the input file. Use setOutputToString() to request conversion to a memory buffer. | |
|
The output format can be it_HTML (226), it_Ansi (202), it_Utf8 (238), it_RTF (212), or it_XML (234) | |
|
Conversion output can be directed to a string or to a disk file. For string output, use setOutputStringMaxSize to set the maximum size of the output string, and getOutputString after conversion to access the result. | |
|
Conversion output can be directed to a string or to a disk file. For string output, use setOutputStringMaxSize to set the maximum size of the output string, and getOutputString after conversion to access the result. | |
|
Set timeoutSeconds to the maximum amount of time you want to permit. When this time is exceeded, execution will halt leaving incomplete results in the output file or output string. If timeoutSeconds is 0 (the default), no time limit will be set. After a timeout has occured, getErrors() will return the error code dtsErTimeout. |
|
Method |
|
Copyright (c) 1998-2008 dtSearch Corp. All rights reserved.
|