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. | |
|
File type of input document detected by dtSearch file parsers. | |
|
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. | |
|
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. | |
|
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 location of the dtSearch alphabet file to use when highlighting hits. | |
|
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. | |
|
Use setDocBytes to provide a document in a memory buffer rather than as a disk file. | |
|
Options for extraction of embedded images and attachments | |
|
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. | |
|
Name of the file to convert | |
|
Select an item from search results to use as input for the FileConverter. | |
|
Name of the file to create from the input file. | |
|
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. | |
|
Conversion output can be directed to a string or to a disk file. | |
|
Set timeoutSeconds to the maximum amount of time you want to permit. |
|
Method |
|
Copyright (c) 1998-2012 dtSearch Corp. All rights reserved.
|