Package com.logicaldoc.core.conversion
Class FormatConverterManager
- java.lang.Object
-
- com.logicaldoc.core.conversion.FormatConverterManager
-
public class FormatConverterManager extends Object
Manager class used to handle format converters. For each couple inFormat-outFormat you may have different possible converters, they are taken by the FormatConverter extension point. The actual converter uses is the one pointed by the context property names converter.inExt-outExt.- Since:
- 7.1.3
- Author:
- Marco Meschieri - LogicalDOC
-
-
Field Summary
Fields Modifier and Type Field Description static String
PDF_CONVERSION_SUFFIX
-
Constructor Summary
Constructors Constructor Description FormatConverterManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Document
convert(Document document, String fileVersion, String format, DocumentHistory transaction)
Converts a document into another format and saves the resulting file in the same foldervoid
convertFile(File in, String inFilename, File out, String outFormat, String sid)
Converts a file into a different formatvoid
convertToFile(Document document, String fileVersion, File out, DocumentHistory transaction)
Converts a document and writes the content of the conversion into a file.void
convertToPdf(Document document, String sid)
Shortcut for convertToPdf(document, null, transaction)void
convertToPdf(Document document, String fileVersion, String sid)
Creates the pdf for the specified document and file version (suffix PDF_CONVERSION_SUFFIX).Collection<FormatConverter>
getAllConverters()
Returns the list of possible convertersList<String>
getAllOutputFormats(String inFileName)
Returns all the possible output formats for the given input formatList<FormatConverter>
getAvailableConverters(String inFileName, String outFileName)
Returns the list of possible converters for a given in and out formatList<String>
getAvailableInputFormats()
Returns all the possible input formatsFormatConverter
getConverter(String inFileName, String outFileName)
Loads the proper converter for the passed file names.Map<String,List<FormatConverter>>
getConverters()
List<String>
getEnabledOutputFormats(String srcFilename)
Returns the available output formats for the given input formatbyte[]
getPdfContent(Document document, String fileVersion, String sid)
Retrieves the content of the Pdf conversion.void
setConfig(ContextProperties config)
void
setDocumentManager(DocumentManager documentManager)
void
setStorer(Storer storer)
void
setTenantDao(TenantDAO tenantDao)
void
writePdfToFile(Document document, String fileVersion, File out, String sid)
Write the content of the Pdf conversion into a file.
-
-
-
Field Detail
-
PDF_CONVERSION_SUFFIX
public static final String PDF_CONVERSION_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPdfContent
public byte[] getPdfContent(Document document, String fileVersion, String sid) throws IOException
Retrieves the content of the Pdf conversion. If the Pdf conversion is not available in the store, it is created.- Parameters:
document
- The document to be processedfileVersion
- The file version(optional)sid
- (optional)- Returns:
- The content of the PDF as bytes
- Throws:
IOException
- If something went wrong
-
writePdfToFile
public void writePdfToFile(Document document, String fileVersion, File out, String sid) throws IOException
Write the content of the Pdf conversion into a file. If the Pdf conversion is not available in the store, it is created.- Parameters:
document
- The document to be processedfileVersion
- The file version(optional)out
- the output filesid
- (optional)- Throws:
IOException
- If something went wrong
-
convertToPdf
public void convertToPdf(Document document, String fileVersion, String sid) throws IOException
Creates the pdf for the specified document and file version (suffix PDF_CONVERSION_SUFFIX). If the Pdf conversion already exists it, nothing happens.- Parameters:
document
- The document to be processedfileVersion
- The file version(optional)sid
- (optional)- Throws:
IOException
- If something went wrong
-
convertToPdf
public void convertToPdf(Document document, String sid) throws IOException
Shortcut for convertToPdf(document, null, transaction)- Parameters:
document
- The document to be processedsid
- identifier of the session- Throws:
IOException
- If something went wrong
-
convert
public Document convert(Document document, String fileVersion, String format, DocumentHistory transaction) throws Exception
Converts a document into another format and saves the resulting file in the same folder- Parameters:
document
- The document to be processedfileVersion
- The file version(optional)format
- the extension used to define the output formattransaction
- details of the current session- Returns:
- the document that represents the conversion
- Throws:
Exception
- If something went wrong
-
convertToFile
public void convertToFile(Document document, String fileVersion, File out, DocumentHistory transaction) throws IOException
Converts a document and writes the content of the conversion into a file.- Parameters:
document
- The document to be processedfileVersion
- The file version(optional)out
- the target file, the extension of this filename is used to detect the output formattransaction
- informations about the session- Throws:
IOException
- if an error happens during the conversion
-
convertFile
public void convertFile(File in, String inFilename, File out, String outFormat, String sid) throws IOException
Converts a file into a different format- Parameters:
in
- input file (the filename extension determines the source format, in case you do not use inFilename)inFilename
- file name of the inputout
- output file (if outFormat is null, the filename extension determines the output format)outFormat
- extension of the outputsid
- session ID (optional)- Throws:
IOException
- if an error happens during the conversion
-
getEnabledOutputFormats
public List<String> getEnabledOutputFormats(String srcFilename)
Returns the available output formats for the given input format- Parameters:
srcFilename
- name of the file- Returns:
- identifiers of the possible output extensions
-
getAllOutputFormats
public List<String> getAllOutputFormats(String inFileName)
Returns all the possible output formats for the given input format- Parameters:
inFileName
- name of the file to convert- Returns:
- list of possible output formats
-
getAvailableInputFormats
public List<String> getAvailableInputFormats()
Returns all the possible input formats- Returns:
- the collection of all available input formats
-
getAvailableConverters
public List<FormatConverter> getAvailableConverters(String inFileName, String outFileName)
Returns the list of possible converters for a given in and out format- Parameters:
inFileName
- input file nameoutFileName
- convertion file name- Returns:
- the collection of all installed format converters
-
getAllConverters
public Collection<FormatConverter> getAllConverters()
Returns the list of possible converters- Returns:
- the collection of all installed format converters
-
getConverter
public FormatConverter getConverter(String inFileName, String outFileName)
Loads the proper converter for the passed file names. The right converter used is defined in the configuration parameter converter.composeKey()- Parameters:
inFileName
- file name of the input contentoutFileName
- file name of the conversion- Returns:
- The right format converter
-
getConverters
public Map<String,List<FormatConverter>> getConverters()
-
setStorer
public void setStorer(Storer storer)
-
setTenantDao
public void setTenantDao(TenantDAO tenantDao)
-
setDocumentManager
public void setDocumentManager(DocumentManager documentManager)
-
setConfig
public void setConfig(ContextProperties config)
-
-