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>checkResultCacheprotected GlobalConfigDescriptorconfigstatic StringCONFIG_EPstatic StringCONVERTER_EPprotected Map<String,ConverterDescriptor>converterDescriptorsstatic StringENFORCE_SOURCE_MIME_TYPE_CHECKprotected GCTaskgcTaskprotected ThreadgcThreadprotected MimeTypeTranslationHelpertranslationHelper-
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 voidactivate(ComponentContext context)Activates the component.protected voidadjustBlobName(String filename, BlobHolder blobHolder, String mimeType)protected voidadjustBlobName(String filename, Blob blob, String mimeType)BlobHolderconvert(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters)Converts a Blob given a converter name.protected BlobHolderconvertBlobToMimeType(BlobHolder bh, String destinationMimeType)BlobconvertBlobToPDF(Blob blob)Deprecated.protected BlobHolderconvertThroughHTML(BlobHolder blobHolder, String destMimeType)BlobHolderconvertToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters)Converts a Blob given a target destination MimeType.voiddeactivate(ComponentContext context)Deactivates the component.voidendGC()<T> TgetAdapter(Class<T> adapter)Returns an object which is an instance of the given class associated with this object.static StringgetCacheBasePath()BlobHoldergetConversionResult(String id, boolean cleanTransientStoreEntry)Returns the conversion result for the givenidif any,nullotherwise.ConversionStatusgetConversionStatus(String id)Returns the status of a scheduled conversion given itsid, ornullif no conversion scheduled.static ConvertergetConverter(String converterName)static ConverterDescriptorgetConverterDescriptor(String converterName)StringgetConverterName(String sourceMimeType, String destinationMimeType, boolean allowWildcard)Returns the converter name for the givensourceMimeTypeanddestinationMimeType.List<String>getConverterNames(String sourceMimeType, String destinationMimeType, boolean allowWildcard)Returns the list of converter names handling the givensourceMimeTypeanddestinationMimeType.static longgetGCIntervalInMinutes()static intgetMaxCacheSizeInKB()List<String>getRegistredConverters()Returns the names of the registered converters.protected booleanhasSourceMimeType(ConverterDescriptor converterDescriptor, String mimeType)Returns true if the converter has the givenmimeTypeas source mime type, false otherwise.static booleanisCacheEnabled()ConverterCheckResultisConverterAvailable(String converterName)Checks for converter availability.ConverterCheckResultisConverterAvailable(String converterName, boolean refresh)Checks for converter availability.booleanisSourceMimeTypeSupported(String converterName, String sourceMimeType)Returns true if the converter supports the givensourceMimeType, false otherwise.voidregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)Component implementation.static voidregisterConverter(ConverterDescriptor desc)protected static BlobreplaceURLsByAbsolutePaths(Blob blob, Path tempDirectory, Function<String,Blob> blobResolver)Replace the image URLs of an HTML blob by absolute local paths.StringscheduleConversion(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters)Schedules a conversion given a converter name.StringscheduleConversionToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters)Schedules a conversion given a target mime type.static voidsetGCIntervalInMinutes(long interval)static voidsetMaxCacheSizeInKB(int size)voidstart(ComponentContext context)Start the component.protected voidstartGC()voidstop(ComponentContext context)Stop the component.voidunregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)protected voidupdateResultBlobFileName(BlobHolder srcBh, BlobHolder resultBh)protected voidupdateResultBlobMimeType(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:ComponentActivates the component.This method is called by the runtime when a component is activated.
- Specified by:
activatein interfaceComponent- Overrides:
activatein classDefaultComponent- Parameters:
context- the runtime context
-
deactivate
public void deactivate(ComponentContext context)
Description copied from interface:ComponentDeactivates the component.This method is called by the runtime when a component is deactivated.
- Specified by:
deactivatein interfaceComponent- Overrides:
deactivatein classDefaultComponent- Parameters:
context- the runtime context
-
registerContribution
public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
Component implementation.- Overrides:
registerContributionin classDefaultComponent
-
unregisterContribution
public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
- Overrides:
unregisterContributionin 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:ConversionServiceReturns the names of the registered converters.- Specified by:
getRegistredConvertersin interfaceConversionService
-
convertBlobToPDF
@Deprecated public Blob convertBlobToPDF(Blob blob)
Deprecated.Description copied from interface:ConversionServiceConverts a Blob to PDF. If the blob has inner blobs such as images, they will be correctly rendered in the PDF.- Specified by:
convertBlobToPDFin 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:ConversionServiceConverts a Blob given a converter name.- Specified by:
convertin interfaceConversionService- Throws:
ConversionException
-
hasSourceMimeType
protected boolean hasSourceMimeType(ConverterDescriptor converterDescriptor, String mimeType)
Returns true if the converter has the givenmimeTypeas 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:ConversionServiceConverts a Blob given a target destination MimeType.- Specified by:
convertToMimeTypein interfaceConversionService- Throws:
ConversionException
-
getConverterNames
public List<String> getConverterNames(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Description copied from interface:ConversionServiceReturns the list of converter names handling the givensourceMimeTypeanddestinationMimeType.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
allowWildcardistrue, find the converters matching a wildcard source mime type "*" - Then, filter only the converters matching the given
destinationMimeType
- Specified by:
getConverterNamesin interfaceConversionServiceallowWildcard-trueto 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:ConversionServiceReturns the converter name for the givensourceMimeTypeanddestinationMimeType.Follows the algorithm of
ConversionService.getConverterNames(String, String, boolean).- Specified by:
getConverterNamein interfaceConversionService- See Also:
ConversionService.getConverterNames(String, String, boolean)
-
isConverterAvailable
public ConverterCheckResult isConverterAvailable(String converterName) throws ConversionException
Description copied from interface:ConversionServiceChecks for converter availability.Result can be:
ConverterNotRegisteredif 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:
isConverterAvailablein interfaceConversionService- Throws:
ConversionException
-
isConverterAvailable
public ConverterCheckResult isConverterAvailable(String converterName, boolean refresh) throws ConverterNotRegistered
Description copied from interface:ConversionServiceChecks for converter availability.Result can be:
ConverterNotRegisteredif converter is not registered.- Error Message / Installation message if converter dependencies are not available an successful check.
- Specified by:
isConverterAvailablein interfaceConversionService- Throws:
ConverterNotRegistered
-
isSourceMimeTypeSupported
public boolean isSourceMimeTypeSupported(String converterName, String sourceMimeType)
Description copied from interface:ConversionServiceReturns true if the converter supports the givensourceMimeType, false otherwise.- Specified by:
isSourceMimeTypeSupportedin interfaceConversionService
-
scheduleConversion
public String scheduleConversion(String converterName, BlobHolder blobHolder, Map<String,Serializable> parameters)
Description copied from interface:ConversionServiceSchedules a conversion given a converter name.Returns a conversion id to be used by
ConversionService.getConversionResult(String, boolean).- Specified by:
scheduleConversionin interfaceConversionService
-
scheduleConversionToMimeType
public String scheduleConversionToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String,Serializable> parameters)
Description copied from interface:ConversionServiceSchedules a conversion given a target mime type.Returns a conversion id to be used by
ConversionService.getConversionResult(String, boolean).- Specified by:
scheduleConversionToMimeTypein interfaceConversionService
-
getConversionStatus
public ConversionStatus getConversionStatus(String id)
Description copied from interface:ConversionServiceReturns the status of a scheduled conversion given itsid, ornullif no conversion scheduled.- Specified by:
getConversionStatusin interfaceConversionService
-
getConversionResult
public BlobHolder getConversionResult(String id, boolean cleanTransientStoreEntry)
Description copied from interface:ConversionServiceReturns the conversion result for the givenidif any,nullotherwise.- Specified by:
getConversionResultin interfaceConversionService
-
getAdapter
public <T> T getAdapter(Class<T> adapter)
Description copied from interface:AdaptableReturns an object which is an instance of the given class associated with this object. Returnsnullif no such object can be found.- Specified by:
getAdapterin interfaceAdaptable- Overrides:
getAdapterin classDefaultComponent- Parameters:
adapter- the adapter class to look up- Returns:
- a object castable to the given class, or
nullif this object does not have an adapter for the given class
-
start
public void start(ComponentContext context)
Description copied from interface:ComponentStart the component. This method is called after all the components were resolved and activated- Specified by:
startin interfaceComponent- Overrides:
startin classDefaultComponent
-
stop
public void stop(ComponentContext context)
Description copied from interface:ComponentStop the component.- Specified by:
stopin interfaceComponent- Overrides:
stopin classDefaultComponent
-
startGC
protected void startGC()
-
endGC
public void endGC()
-
-