Class ContentServiceImpl
- java.lang.Object
-
- org.alfresco.repo.content.ContentServiceImpl
-
- All Implemented Interfaces:
ContentService,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
RoutingContentService
public class ContentServiceImpl extends java.lang.Object implements ContentService, org.springframework.context.ApplicationContextAware
Service implementation acting as a level of indirection between the client and the underlying content store.Note: This class was formerly the
RoutingContentServicebut the 'routing' functionality has been pushed into thestoreimplementations.- Since:
- 3.2
- Author:
- Derek Hulley
-
-
Field Summary
Fields Modifier and Type Field Description protected TransformerDebugtransformerDebug
-
Constructor Summary
Constructors Constructor Description ContentServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.List<ContentTransformer>getActiveTransformers(java.lang.String sourceMimetype, long sourceSize, java.lang.String targetMimetype, TransformationOptions options)java.util.List<ContentTransformer>getActiveTransformers(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)ContentTransformergetImageTransformer()Fetch the transformer that is capable of transforming image content.longgetMaxSourceSizeBytes(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)Returns the maximum source size of any content that may transformed between the supplied mimetypes using the supplied options.org.alfresco.service.cmr.repository.ContentReadergetRawReader(java.lang.String contentUrl)Fetch content from the low-level stores using a content URL.org.alfresco.service.cmr.repository.ContentReadergetReader(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName propertyQName)Gets a reader for the content associated with the given node property.longgetStoreFreeSpace()Gets the remaing available space in the underlying content store.longgetStoreTotalSpace()Gets the total space of the underlying content store (not exclusively Alfresco-controlled binaries).org.alfresco.service.cmr.repository.ContentWritergetTempWriter()Gets a writer to a temporary location.ContentTransformergetTransformer(java.lang.String sourceMimetype, java.lang.String targetMimetype)Fetch the transformer that is capable of transforming the content in the given source mimetype to the given target mimetype.ContentTransformergetTransformer(java.lang.String sourceUrl, java.lang.String sourceMimetype, long sourceSize, java.lang.String targetMimetype, TransformationOptions options)Fetch the transformer that is capable of transforming the content in the given source mimetype to the given target mimetype with the provided transformation options.ContentTransformergetTransformer(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)java.util.List<ContentTransformer>getTransformers(java.lang.String sourceUrl, java.lang.String sourceMimetype, long sourceSize, java.lang.String targetMimetype, TransformationOptions options)Fetch the transformers that are capable of transforming the content in the given source mimetype to the given target mimetype with the provided transformation options.org.alfresco.service.cmr.repository.ContentWritergetWriter(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName propertyQName, boolean update)Get a content writer for the given node property, choosing to optionally have the node property updated automatically when the content stream closes.voidinit()Service initialisebooleanisTransformable(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer)booleanisTransformable(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options)Returns whether a transformer exists that can read the content from the reader and write the content back out to the writer with the provided tranformation options.voidonUpdateProperties(org.alfresco.service.cmr.repository.NodeRef nodeRef, java.util.Map<org.alfresco.service.namespace.QName,java.io.Serializable> before, java.util.Map<org.alfresco.service.namespace.QName,java.io.Serializable> after)Update properties policy behaviourvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetDictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService)voidsetEagerContentStoreCleaner(EagerContentStoreCleaner eagerContentStoreCleaner)voidsetIgnoreEmptyContent(boolean ignoreEmptyContent)voidsetImageMagickContentTransformer(ContentTransformer imageMagickContentTransformer)voidsetMimetypeService(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)voidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)voidsetPolicyComponent(PolicyComponent policyComponent)voidsetRetryingTransactionHelper(RetryingTransactionHelper helper)voidsetStore(org.alfresco.repo.content.ContentStore store)voidsetTransformerDebug(TransformerDebug transformerDebug)Helper setter of the transformer debug.voidsetTransformerFailover(boolean transformerFailover)Allows fail over form one transformer to another when there is more than one transformer available.voidsetTransformerRegistry(ContentTransformerRegistry transformerRegistry)voidtransform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer)Transforms the content from the reader and writes the content back out to the writer.voidtransform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, java.util.Map<java.lang.String,java.lang.Object> options)Deprecated.voidtransform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options)
-
-
-
Field Detail
-
transformerDebug
protected TransformerDebug transformerDebug
-
-
Method Detail
-
setRetryingTransactionHelper
public void setRetryingTransactionHelper(RetryingTransactionHelper helper)
-
setDictionaryService
public void setDictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService)
-
setNodeService
public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
-
setMimetypeService
public void setMimetypeService(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)
-
setTransformerRegistry
public void setTransformerRegistry(ContentTransformerRegistry transformerRegistry)
-
setEagerContentStoreCleaner
public void setEagerContentStoreCleaner(EagerContentStoreCleaner eagerContentStoreCleaner)
-
setStore
public void setStore(org.alfresco.repo.content.ContentStore store)
-
setPolicyComponent
public void setPolicyComponent(PolicyComponent policyComponent)
-
setImageMagickContentTransformer
public void setImageMagickContentTransformer(ContentTransformer imageMagickContentTransformer)
-
setIgnoreEmptyContent
public void setIgnoreEmptyContent(boolean ignoreEmptyContent)
-
setTransformerFailover
public void setTransformerFailover(boolean transformerFailover)
Allows fail over form one transformer to another when there is more than one transformer available. The cost is that the output of the transformer must go to a temporary file in case it fails.- Parameters:
transformerFailover-true(the default) indicate that fail over should take place.
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setTransformerDebug
public void setTransformerDebug(TransformerDebug transformerDebug)
Helper setter of the transformer debug.- Parameters:
transformerDebug- TransformerDebug
-
init
public void init()
Service initialise
-
onUpdateProperties
public void onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef nodeRef, java.util.Map<org.alfresco.service.namespace.QName,java.io.Serializable> before, java.util.Map<org.alfresco.service.namespace.QName,java.io.Serializable> after)Update properties policy behaviour- Parameters:
nodeRef- the node referencebefore- the before values of the propertiesafter- the after values of the properties
-
getStoreFreeSpace
public long getStoreFreeSpace()
Description copied from interface:ContentServiceGets the remaing available space in the underlying content store.- Specified by:
getStoreFreeSpacein interfaceContentService- Returns:
- Returns the total, possibly approximate, remaining space (in bytes) available to store content or -1 if no size data is available.
-
getStoreTotalSpace
public long getStoreTotalSpace()
Description copied from interface:ContentServiceGets the total space of the underlying content store (not exclusively Alfresco-controlled binaries).- Specified by:
getStoreTotalSpacein interfaceContentService- Returns:
- Returns the total, possibly approximate, size (in bytes) of of the store or -1 if no size data is available.
-
getRawReader
public org.alfresco.service.cmr.repository.ContentReader getRawReader(java.lang.String contentUrl)
Fetch content from the low-level stores using a content URL. None of the metadata associated with the content will be populated. This method should be used only to stream the binary data out when no other metadata is required.null is never returned, but the reader should always be checked for
existence.- Specified by:
getRawReaderin interfaceContentService- Parameters:
contentUrl- a content store URL- Returns:
- Returns a reader for the URL that needs to be checked.
-
getReader
public org.alfresco.service.cmr.repository.ContentReader getReader(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName propertyQName)Description copied from interface:ContentServiceGets a reader for the content associated with the given node property.If a content URL is present for the given node then a reader must be returned. The
existsmethod should then be used to detect 'missing' content.- Specified by:
getReaderin interfaceContentService- Parameters:
nodeRef- a reference to a node having a content propertypropertyQName- the name of the property, which must be of type content- Returns:
- Returns a reader for the content associated with the node property, or null if no content has been written for the property
- See Also:
FileContentReader.getSafeContentReader(ContentReader, String, Object[])
-
getWriter
public org.alfresco.service.cmr.repository.ContentWriter getWriter(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName propertyQName, boolean update)Description copied from interface:ContentServiceGet a content writer for the given node property, choosing to optionally have the node property updated automatically when the content stream closes.If the update flag is off, then the state of the node property will remain unchanged regardless of the state of the written binary data. If the flag is on, then the node property will be updated on the same thread as the code that closed the write channel.
If no node is supplied, then the writer will provide a stream into the backing content store, but will not be associated with any new or previous content.
NOTE: The content URL provided will be registered for automatic cleanup in the event that the transaction, in which this method was called, rolls back. If the transaction is successful, the writer may still be open and available for use but the underlying binary will not be cleaned up subsequently. The recommended pattern is to group calls to retrieve the writer in the same transaction as the calls to subsequently update and close the write stream - including setting of the related content properties.- Specified by:
getWriterin interfaceContentService- Parameters:
nodeRef- a reference to a node having a content property, or null to just get a valid writer into a backing content store.propertyQName- the name of the property, which must be of type contentupdate- true if the property must be updated atomically when the content write stream is closed (attaches a listener to the stream); false if the client code will perform the updates itself.- Returns:
- Returns a writer for the content associated with the node property
-
getTempWriter
public org.alfresco.service.cmr.repository.ContentWriter getTempWriter()
Description copied from interface:ContentServiceGets a writer to a temporary location. The longevity of the stored temporary content is determined by the system.- Specified by:
getTempWriterin interfaceContentService- Returns:
- Returns a writer to an anonymous location
-
transform
public void transform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer)Description copied from interface:ContentServiceTransforms the content from the reader and writes the content back out to the writer.The mimetypes used for the transformation must be set both on the
readerand on thewriter.- Specified by:
transformin interfaceContentService- Parameters:
reader- the source content location and mimetypewriter- the target content location and mimetype- See Also:
ContentTransformerRegistry,ContentTransformer,ContentService.transform(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter)
-
transform
public void transform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, java.util.Map<java.lang.String,java.lang.Object> options) throws NoTransformerException, org.alfresco.service.cmr.repository.ContentIOExceptionDeprecated.- Specified by:
transformin interfaceContentService- Parameters:
reader- the source content location and mimetypewriter- the target content location and mimetypeoptions- the options for the transformation- Throws:
NoTransformerException- if no transformer exists for the given source and target mimetypes of the reader and writerorg.alfresco.service.cmr.repository.ContentIOException- if the transformation fails- See Also:
ContentTransformerRegistry,ContentTransformer
-
transform
public void transform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options) throws NoTransformerException, org.alfresco.service.cmr.repository.ContentIOException- Specified by:
transformin interfaceContentService- Parameters:
reader- the source content location and mimetypewriter- the target content location and mimetypeoptions- the options for the transformation- Throws:
NoTransformerException- if no transformer exists for the given source and target mimetypes of the reader and writerorg.alfresco.service.cmr.repository.ContentIOException- if the transformation fails- See Also:
ContentTransformerRegistry,ContentTransformer
-
getTransformer
public ContentTransformer getTransformer(java.lang.String sourceMimetype, java.lang.String targetMimetype)
Description copied from interface:ContentServiceFetch the transformer that is capable of transforming the content in the given source mimetype to the given target mimetype.Since no transformation options are provided only the source and destination mimetypes are considered when getting the correct transformer.
- Specified by:
getTransformerin interfaceContentService- Parameters:
sourceMimetype- the source mimetypetargetMimetype- the target mimetype- Returns:
- Returns a transformer that can be used, or null if one was not available
- See Also:
ContentTransformerRegistry,ContentTransformer
-
getTransformer
public ContentTransformer getTransformer(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)
- Specified by:
getTransformerin interfaceContentService
-
getTransformer
public ContentTransformer getTransformer(java.lang.String sourceUrl, java.lang.String sourceMimetype, long sourceSize, java.lang.String targetMimetype, TransformationOptions options)
Description copied from interface:ContentServiceFetch the transformer that is capable of transforming the content in the given source mimetype to the given target mimetype with the provided transformation options. The transformation options provide a finer grain way of discovering the correct transformer, since the values and type of the options provided are considered by the transformer when deciding whether it can satisfy the transformation request.- Specified by:
getTransformerin interfaceContentService- Parameters:
sourceUrl- TODOsourceMimetype- the source mimetypesourceSize- the source size (bytes). Ignored if negative.targetMimetype- the target mimetypeoptions- the transformation options- Returns:
- ContentTransformer a transformer that can be used, or null if one was not available
- See Also:
ContentService.getTransformer(String, java.lang.String, long, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
-
getTransformers
public java.util.List<ContentTransformer> getTransformers(java.lang.String sourceUrl, java.lang.String sourceMimetype, long sourceSize, java.lang.String targetMimetype, TransformationOptions options)
Description copied from interface:ContentServiceFetch the transformers that are capable of transforming the content in the given source mimetype to the given target mimetype with the provided transformation options. The transformation options provide a finer grain way of discovering the correct transformer, since the values and type of the options provided are considered by the transformer when deciding whether it can satisfy the transformation request.- Specified by:
getTransformersin interfaceContentService- Parameters:
sourceUrl- TODOsourceMimetype- the source mimetypesourceSize- the source size (bytes). Ignored if negative.targetMimetype- the target mimetypeoptions- the transformation options- Returns:
- ContentTransformer the transformers that can be used, or null if none are available
- See Also:
ContentService.getTransformers(String, java.lang.String, long, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
-
getMaxSourceSizeBytes
public long getMaxSourceSizeBytes(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)Returns the maximum source size of any content that may transformed between the supplied mimetypes using the supplied options.- Specified by:
getMaxSourceSizeBytesin interfaceContentService- Parameters:
sourceMimetype- source mime typetargetMimetype- target mime typeoptions- transformation options- Returns:
- 0 if there are no transformers, -1 if there is no limit or if positive number the size in bytes.
-
getActiveTransformers
public java.util.List<ContentTransformer> getActiveTransformers(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)
- Specified by:
getActiveTransformersin interfaceContentService
-
getActiveTransformers
public java.util.List<ContentTransformer> getActiveTransformers(java.lang.String sourceMimetype, long sourceSize, java.lang.String targetMimetype, TransformationOptions options)
- Specified by:
getActiveTransformersin interfaceContentService
-
getImageTransformer
public ContentTransformer getImageTransformer()
Description copied from interface:ContentServiceFetch the transformer that is capable of transforming image content.- Specified by:
getImageTransformerin interfaceContentService- Returns:
- Returns a transformer that can be used, or null if one was not available
- See Also:
ContentService.getImageTransformer()
-
isTransformable
public boolean isTransformable(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer)- Specified by:
isTransformablein interfaceContentService- See Also:
ContentTransformerRegistry,ContentTransformer
-
isTransformable
public boolean isTransformable(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options)Description copied from interface:ContentServiceReturns whether a transformer exists that can read the content from the reader and write the content back out to the writer with the provided tranformation options.If you are about to call
ContentService.transform(ContentReader, ContentWriter, TransformationOptions)it is best NOT to call this method first as it must perform the same steps and will throw NoTransformerException if there are no transformers.The mimetypes used for the transformation must be set both on the
readerand on thewriter.- Specified by:
isTransformablein interfaceContentService- Parameters:
reader- the source content location and mimetypewriter- the target content location and mimetypeoptions- the transformation options- Returns:
- boolean true if a transformer exists, false otherwise
- See Also:
ContentService.isTransformable(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
-
-