Package com.logicaldoc.core.conversion

# Class FormatConversionManager

java.lang.Object
com.logicaldoc.core.conversion.FormatConversionManager

@Component("formatConversionManager") public class FormatConversionManager 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

## Constructor Summary

Constructors
Constructor
Description
`FormatConversionManager()`

## Method Summary

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 folder
`void`
`convertFile(File in, String inFilename, File out, String outFormat, String sid)`
Converts a file into a different format
`void`
`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).
`static FormatConversionManager`
`get()`
Gets the object available in the application context
`Collection<FormatConverter>`
`getAllConverters()`
Returns the list of possible converters
`List<String>`
`getAllOutputFormats(String inFileName)`
Returns all the possible output formats for the given input format
`List<FormatConverter>`
`getAvailableConverters(String inFileName, String outFileName)`
Returns the list of possible converters for a given in and out format
`List<String>`
`getAvailableInputFormats()`
Returns all the possible input formats
`FormatConverter`
`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 format
`byte[]`
`getPdfContent(Document document, String fileVersion, String sid)`
Retrieves the content of the Pdf conversion.
`void`
`init()`
Initializes the converters map
`void`
`writePdfToFile(Document document, String fileVersion, File out, String sid)`
Write the content of the Pdf conversion into a file.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### FormatConversionManager

public FormatConversionManager()

## Method Details

### get

public static FormatConversionManager get()
Gets the object available in the application context

Returns:
  the instance of this object in the application context

### getPdfContent

public byte[] getPdfContent(Document document, String fileVersion, String sid) throws IOException, PersistenceException
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 processed
  `fileVersion` - The file version(optional)
  `sid` - (optional)
Returns:
  The content of the PDF as bytes
Throws:
  `IOException` - If something went wrong
  `PersistenceException` - Error in the persistence layer

### writePdfToFile

public void writePdfToFile(Document document, String fileVersion, File out, String sid) throws IOException, PersistenceException
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 processed
  `fileVersion` - The file version(optional)
  `out` - the output file
  `sid` - (optional)
Throws:
  `IOException` - If something went wrong
  `PersistenceException` - Error in the persistence layer

### convertToPdf

public void convertToPdf(Document document, String fileVersion, String sid) throws IOException, PersistenceException
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 processed
  `fileVersion` - The file version(optional)
  `sid` - (optional)
Throws:
  `IOException` - If something went wrong
  `PersistenceException` - Error in the persistence layer

### convertToPdf

public void convertToPdf(Document document, String sid) throws IOException, PersistenceException
Shortcut for convertToPdf(document, null, transaction)

Parameters:
  `document` - The document to be processed
  `sid` - identifier of the session
Throws:
  `IOException` - If something went wrong
  `PersistenceException` - Error in the persistence layer

### convert

public Document convert(Document document, String fileVersion, String format, DocumentHistory transaction) throws IOException, PersistenceException
Converts a document into another format and saves the resulting file in the same folder

Parameters:
  `document` - The document to be processed
  `fileVersion` - The file version(optional)
  `format` - the extension used to define the output format
  `transaction` - details of the current session
Returns:
  the document that represents the conversion
Throws:
  `IOException` - I/O error
  `PersistenceException` - Error in the database

### convertToFile

public void convertToFile(Document document, String fileVersion, File out, DocumentHistory transaction) throws IOException, PersistenceException
Converts a document and writes the content of the conversion into a file.

Parameters:
  `document` - The document to be processed
  `fileVersion` - The file version(optional)
  `out` - the target file, the extension of this filename is used to detect the output format
  `transaction` - informations about the session
Throws:
  `IOException` - if an error happens during the conversion
  `PersistenceException` - Error in the data layer

### 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 input
  `out` - output file (if outFormat is null, the filename extension determines the output format)
  `outFormat` - extension of the output
  `sid` - 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 name
  `outFileName` - conversion 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 content
  `outFileName` - file name of the conversion
Returns:
  The right format converter

### init

public void init()
Initializes the converters map

### getConverters

public Map<String,List<FormatConverter>> getConverters()