Class ConversionServiceImpl
- java.lang.Object
-
- org.nuxeo.runtime.model.DefaultComponent
-
- org.nuxeo.ecm.core.convert.service.ConversionServiceImpl
-
- All Implemented Interfaces:
ConversionService
,Adaptable
,Component
,Extensible
,TimestampedService
public class ConversionServiceImpl extends DefaultComponent implements ConversionService
Runtime Component that also provides the POJO implementation of theConversionService
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,ConverterCheckResult>
checkResultCache
protected GlobalConfigDescriptor
config
static String
CONFIG_EP
static String
CONVERTER_EP
protected Map<String,ConverterDescriptor>
converterDescriptors
static String
ENFORCE_SOURCE_MIME_TYPE_CHECK
protected GCTask
gcTask
protected Thread
gcThread
protected MimeTypeTranslationHelper
translationHelper
-
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
-
-
Constructor Summary
Constructors Constructor Description ConversionServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
activate(ComponentContext context)
Activates the component.protected void
adjustBlobName(String filename, BlobHolder blobHolder, String mimeType)
protected void
adjustBlobName(String filename, Blob blob, String mimeType)
BlobHolder
convert(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters)
Converts a Blob given a converter name.protected BlobHolder
convertBlobToMimeType(BlobHolder bh, String destinationMimeType)
Blob
convertBlobToPDF(Blob blob)
Deprecated.protected BlobHolder
convertThroughHTML(BlobHolder blobHolder, String destMimeType)
BlobHolder
convertToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters)
Converts a Blob given a target destination MimeType.void
deactivate(ComponentContext context)
Deactivates the component.void
endGC()
<T> T
getAdapter(Class<T> adapter)
Returns an object which is an instance of the given class associated with this object.static String
getCacheBasePath()
BlobHolder
getConversionResult(String id, boolean cleanTransientStoreEntry)
Returns the conversion result for the givenid
if any,null
otherwise.ConversionStatus
getConversionStatus(String id)
Returns the status of a scheduled conversion given itsid
, ornull
if no conversion scheduled.static Converter
getConverter(String converterName)
static ConverterDescriptor
getConverterDescriptor(String converterName)
String
getConverterName(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Returns the converter name for the givensourceMimeType
anddestinationMimeType
.List<String>
getConverterNames(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Returns the list of converter names handling the givensourceMimeType
anddestinationMimeType
.static long
getGCIntervalInMinutes()
static int
getMaxCacheSizeInKB()
List<String>
getRegistredConverters()
Returns the names of the registered converters.protected boolean
hasSourceMimeType(ConverterDescriptor converterDescriptor, String mimeType)
Returns true if the converter has the givenmimeType
as source mime type, false otherwise.static boolean
isCacheEnabled()
ConverterCheckResult
isConverterAvailable(String converterName)
Checks for converter availability.ConverterCheckResult
isConverterAvailable(String converterName, boolean refresh)
Checks for converter availability.boolean
isSourceMimeTypeSupported(String converterName, String sourceMimeType)
Returns true if the converter supports the givensourceMimeType
, false otherwise.void
registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
Component implementation.static void
registerConverter(ConverterDescriptor desc)
protected static Blob
replaceURLsByAbsolutePaths(Blob blob, Path tempDirectory, Function<String,Blob> blobResolver)
Replace the image URLs of an HTML blob by absolute local paths.String
scheduleConversion(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters)
Schedules a conversion given a converter name.String
scheduleConversionToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters)
Schedules a conversion given a target mime type.static void
setGCIntervalInMinutes(long interval)
static void
setMaxCacheSizeInKB(int size)
void
start(ComponentContext context)
Start the component.protected void
startGC()
void
stop(ComponentContext context)
Stop the component.void
unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
protected void
updateResultBlobFileName(BlobHolder srcBh, BlobHolder resultBh)
protected void
updateResultBlobMimeType(BlobHolder resultBh, ConverterDescriptor desc)
-
Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
addRuntimeMessage, addRuntimeMessage, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerExtension, setLastModified, setModifiedNow, setName, unregister, unregisterExtension
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.runtime.model.Component
applicationStarted, getApplicationStartedOrder
-
Methods inherited from interface org.nuxeo.ecm.core.convert.api.ConversionService
getConverterName, getConverterNames
-
-
-
-
Field Detail
-
CONVERTER_EP
public static final String CONVERTER_EP
- See Also:
- Constant Field Values
-
CONFIG_EP
public static final String CONFIG_EP
- See Also:
- Constant Field Values
-
ENFORCE_SOURCE_MIME_TYPE_CHECK
public static final String ENFORCE_SOURCE_MIME_TYPE_CHECK
- Since:
- 10.3
- See Also:
- Constant Field Values
-
converterDescriptors
protected final Map<String,ConverterDescriptor> converterDescriptors
-
translationHelper
protected final MimeTypeTranslationHelper translationHelper
-
config
protected final GlobalConfigDescriptor config
-
gcThread
protected Thread gcThread
-
gcTask
protected GCTask gcTask
-
checkResultCache
protected final Map<String,ConverterCheckResult> checkResultCache
-
-
Method Detail
-
activate
public void activate(ComponentContext context)
Description copied from interface:Component
Activates the component.This method is called by the runtime when a component is activated.
- Specified by:
activate
in interfaceComponent
- Overrides:
activate
in classDefaultComponent
- Parameters:
context
- the runtime context
-
deactivate
public void deactivate(ComponentContext context)
Description copied from interface:Component
Deactivates the component.This method is called by the runtime when a component is deactivated.
- Specified by:
deactivate
in interfaceComponent
- Overrides:
deactivate
in classDefaultComponent
- Parameters:
context
- the runtime context
-
registerContribution
public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
Component implementation.- Overrides:
registerContribution
in classDefaultComponent
-
unregisterContribution
public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
- Overrides:
unregisterContribution
in classDefaultComponent
-
getConverterDescriptor
public static ConverterDescriptor getConverterDescriptor(String converterName)
-
getGCIntervalInMinutes
public static long getGCIntervalInMinutes()
-
setGCIntervalInMinutes
public static void setGCIntervalInMinutes(long interval)
-
registerConverter
public static void registerConverter(ConverterDescriptor desc)
-
getMaxCacheSizeInKB
public static int getMaxCacheSizeInKB()
-
setMaxCacheSizeInKB
public static void setMaxCacheSizeInKB(int size)
-
isCacheEnabled
public static boolean isCacheEnabled()
-
getCacheBasePath
public static String getCacheBasePath()
-
getRegistredConverters
public List<String> getRegistredConverters()
Description copied from interface:ConversionService
Returns the names of the registered converters.- Specified by:
getRegistredConverters
in interfaceConversionService
-
convertBlobToPDF
@Deprecated public Blob convertBlobToPDF(Blob blob)
Deprecated.Description copied from interface:ConversionService
Converts a Blob to PDF. If the blob has inner blobs such as images, they will be correctly rendered in the PDF.- Specified by:
convertBlobToPDF
in interfaceConversionService
-
convertThroughHTML
protected BlobHolder convertThroughHTML(BlobHolder blobHolder, String destMimeType)
-
convertBlobToMimeType
protected BlobHolder convertBlobToMimeType(BlobHolder bh, String destinationMimeType)
-
adjustBlobName
protected void adjustBlobName(String filename, BlobHolder blobHolder, String mimeType)
-
replaceURLsByAbsolutePaths
protected static Blob replaceURLsByAbsolutePaths(Blob blob, Path tempDirectory, Function<String,Blob> blobResolver) throws IOException
Replace the image URLs of an HTML blob by absolute local paths.- Throws:
IOException
- Since:
- 9.1
-
convert
public BlobHolder convert(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters) throws ConversionException
Description copied from interface:ConversionService
Converts a Blob given a converter name.- Specified by:
convert
in interfaceConversionService
- Throws:
ConversionException
-
hasSourceMimeType
protected boolean hasSourceMimeType(ConverterDescriptor converterDescriptor, String mimeType)
Returns true if the converter has the givenmimeType
as source mime type, false otherwise.- Since:
- 10.3
-
updateResultBlobMimeType
protected void updateResultBlobMimeType(BlobHolder resultBh, ConverterDescriptor desc)
-
updateResultBlobFileName
protected void updateResultBlobFileName(BlobHolder srcBh, BlobHolder resultBh)
-
convertToMimeType
public BlobHolder convertToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters) throws ConversionException
Description copied from interface:ConversionService
Converts a Blob given a target destination MimeType.- Specified by:
convertToMimeType
in interfaceConversionService
- Throws:
ConversionException
-
getConverterNames
public List<String> getConverterNames(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Description copied from interface:ConversionService
Returns the list of converter names handling the givensourceMimeType
anddestinationMimeType
.Finds the converter names based on the following algorithm:
- Find the converters exactly matching the given
sourceMimeType
- If no converter found, find the converters matching a wildcard subtype based on the
sourceMimeType
, such has "image/*" - If no converter found and
allowWildcard
istrue
, find the converters matching a wildcard source mime type "*" - Then, filter only the converters matching the given
destinationMimeType
- Specified by:
getConverterNames
in interfaceConversionService
allowWildcard
-true
to allow returning converters with '*' as source mime type.
- Find the converters exactly matching the given
-
getConverterName
public String getConverterName(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Description copied from interface:ConversionService
Returns the converter name for the givensourceMimeType
anddestinationMimeType
.Follows the algorithm of
ConversionService.getConverterNames(String, String, boolean)
.- Specified by:
getConverterName
in interfaceConversionService
- See Also:
ConversionService.getConverterNames(String, String, boolean)
-
isConverterAvailable
public ConverterCheckResult isConverterAvailable(String converterName) throws ConversionException
Description copied from interface:ConversionService
Checks for converter availability.Result can be:
ConverterNotRegistered
if converter is not registered.- Error Message / Installation message if converter dependencies are not available an successful check.
Result can be taken from an internal cache.
- Specified by:
isConverterAvailable
in interfaceConversionService
- Throws:
ConversionException
-
isConverterAvailable
public ConverterCheckResult isConverterAvailable(String converterName, boolean refresh) throws ConverterNotRegistered
Description copied from interface:ConversionService
Checks for converter availability.Result can be:
ConverterNotRegistered
if converter is not registered.- Error Message / Installation message if converter dependencies are not available an successful check.
- Specified by:
isConverterAvailable
in interfaceConversionService
- Throws:
ConverterNotRegistered
-
isSourceMimeTypeSupported
public boolean isSourceMimeTypeSupported(String converterName, String sourceMimeType)
Description copied from interface:ConversionService
Returns true if the converter supports the givensourceMimeType
, false otherwise.- Specified by:
isSourceMimeTypeSupported
in interfaceConversionService
-
scheduleConversion
public String scheduleConversion(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters)
Description copied from interface:ConversionService
Schedules a conversion given a converter name.Returns a conversion id to be used by
ConversionService.getConversionResult(String, boolean)
.- Specified by:
scheduleConversion
in interfaceConversionService
-
scheduleConversionToMimeType
public String scheduleConversionToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters)
Description copied from interface:ConversionService
Schedules a conversion given a target mime type.Returns a conversion id to be used by
ConversionService.getConversionResult(String, boolean)
.- Specified by:
scheduleConversionToMimeType
in interfaceConversionService
-
getConversionStatus
public ConversionStatus getConversionStatus(String id)
Description copied from interface:ConversionService
Returns the status of a scheduled conversion given itsid
, ornull
if no conversion scheduled.- Specified by:
getConversionStatus
in interfaceConversionService
-
getConversionResult
public BlobHolder getConversionResult(String id, boolean cleanTransientStoreEntry)
Description copied from interface:ConversionService
Returns the conversion result for the givenid
if any,null
otherwise.- Specified by:
getConversionResult
in interfaceConversionService
-
getAdapter
public <T> T getAdapter(Class<T> adapter)
Description copied from interface:Adaptable
Returns an object which is an instance of the given class associated with this object. Returnsnull
if no such object can be found.- Specified by:
getAdapter
in interfaceAdaptable
- Overrides:
getAdapter
in classDefaultComponent
- Parameters:
adapter
- the adapter class to look up- Returns:
- a object castable to the given class, or
null
if this object does not have an adapter for the given class
-
start
public void start(ComponentContext context)
Description copied from interface:Component
Start the component. This method is called after all the components were resolved and activated- Specified by:
start
in interfaceComponent
- Overrides:
start
in classDefaultComponent
-
stop
public void stop(ComponentContext context)
Description copied from interface:Component
Stop the component.- Specified by:
stop
in interfaceComponent
- Overrides:
stop
in classDefaultComponent
-
startGC
protected void startGC()
-
endGC
public void endGC()
-
-