Package org.craftercms.core.service.impl
Class ContentStoreServiceImpl
- java.lang.Object
-
- org.craftercms.core.service.impl.AbstractCachedContentStoreService
-
- org.craftercms.core.service.impl.ContentStoreServiceImpl
-
- All Implemented Interfaces:
ContentStoreService
public class ContentStoreServiceImpl extends AbstractCachedContentStoreService
Default implementation ofContentStoreService. Extends fromAbstractCachedContentStoreServiceto use caching.- Author:
- Alfonso Vásquez
-
-
Field Summary
Fields Modifier and Type Field Description protected org.craftercms.commons.file.blob.BlobStoreResolverblobStoreResolverprotected org.craftercms.commons.file.blob.BlobUrlResolverblobUrlResolverprotected Map<String,Context>contextsMap of openContextsprotected com.fasterxml.jackson.databind.ObjectMappermapperprotected DescriptorMergermergerMerges a bunch of descriptorsprotected DescriptorMergeStrategyResolvermergeStrategyResolverResolves theDescriptorMergeStrategyto use for a particular descriptor.protected ItemProcessorResolverprocessorResolverResolves theItemProcessorto use for a particularItem.protected booleansourceAttributeEnabledIndicates if the source attribute should be added when merging XML documentsprotected StringsourceAttributeNameThe name of the attribute used to identify the source of an XML elementprotected StringsourceTypeAttributeNameThe name of the attribute used to identify the type of the source of an XML elementprotected StringsourceTypeXPathThe XPath selector to extract the content-type from descriptorsprotected ContentStoreAdapterRegistrystoreAdapterRegistryRegistry ofContentStoreAdapters.-
Fields inherited from class org.craftercms.core.service.impl.AbstractCachedContentStoreService
cacheTemplate, CONST_KEY_ELEM_CHILDREN, CONST_KEY_ELEM_EXISTS, CONST_KEY_ELEM_ITEM, CONST_KEY_ELEM_TREE, defaultCachingOptions, flatteningProcessor
-
Fields inherited from interface org.craftercms.core.service.ContentStoreService
UNLIMITED_TREE_DEPTH
-
-
Constructor Summary
Constructors Constructor Description ContentStoreServiceImpl(CacheTemplate cacheTemplate, ContentStoreAdapterRegistry storeAdapterRegistry, DescriptorMergeStrategyResolver mergeStrategyResolver, DescriptorMerger merger, ItemProcessorResolver processorResolver, org.craftercms.commons.file.blob.BlobUrlResolver blobUrlResolver, org.craftercms.commons.file.blob.BlobStoreResolver blobStoreResolver, String sourceAttributeName, String sourceTypeAttributeName, String sourceTypeXPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddSourceAttributes(org.dom4j.Document document, org.dom4j.Element element, String descriptorUrl)protected StringcreateContextId(String tag, String storeType, String rootFolderPath, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles)booleandestroyContext(Context context)Destroys the specified context, login out of any remote repository (if a login was issued) and destroying the cache scope associated to the context.booleandoExists(Context context, CachingOptions cachingOptions, String url)protected List<Item>doFilter(List<Item> items, ItemFilter filter, boolean runningBeforeProcessing)Filters the given list of items by using the specified filter.protected List<Item>doFindChildren(Context context, CachingOptions cachingOptions, String url, Integer depth, ItemFilter filter, ItemProcessor processor, boolean flatten)Does the following:protected List<Item>doFindChildren(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten)protected ItemdoFindItem(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor)Returns the content store item for the given url, returning null if not found.protected TreedoFindTree(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten)protected ItemdoMerging(Context context, CachingOptions cachingOptions, Item item)Executes merging for the specifiedItem:protected ItemdoProcessing(Context context, CachingOptions cachingOptions, Item item, ItemProcessor additionalProcessor)Executes processing for the specifiedItem:ContentfindContent(Context context, CachingOptions cachingOptions, String url)Returns the content of the file for the given url, returning null if not found.ContentgetContent(Context context, CachingOptions cachingOptions, String url)Returns the content of the file for the given url.ContextgetContext(String contextId)Returns the openContextfor the given ID, or null if no context found for the ID.ContextgetContext(String tag, String storeType, String rootFolderPath, boolean mergingOn, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles)Returns a context with the specified parameters, if the context doesn't exist it will be created.voidsetSourceAttributeEnabled(boolean sourceAttributeEnabled)booleanvalidate(Context context)Returns true if the specified context is still valid and usable.-
Methods inherited from class org.craftercms.core.service.impl.AbstractCachedContentStoreService
exists, exists, findChildren, findItem, findTree, getChildren, getItem, getProcessor, getTree, setDefaultCachingOptions, setFlatteningProcessor
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.craftercms.core.service.ContentStoreService
findChildren, findChildren, findContent, findItem, findItem, findTree, findTree, findTree, getChildren, getChildren, getContent, getItem, getItem, getTree, getTree, getTree
-
-
-
-
Field Detail
-
storeAdapterRegistry
protected ContentStoreAdapterRegistry storeAdapterRegistry
Registry ofContentStoreAdapters.
-
mergeStrategyResolver
protected DescriptorMergeStrategyResolver mergeStrategyResolver
Resolves theDescriptorMergeStrategyto use for a particular descriptor.
-
merger
protected DescriptorMerger merger
Merges a bunch of descriptors
-
processorResolver
protected ItemProcessorResolver processorResolver
Resolves theItemProcessorto use for a particularItem.
-
blobUrlResolver
protected org.craftercms.commons.file.blob.BlobUrlResolver blobUrlResolver
-
blobStoreResolver
protected org.craftercms.commons.file.blob.BlobStoreResolver blobStoreResolver
-
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapper
-
sourceAttributeEnabled
protected boolean sourceAttributeEnabled
Indicates if the source attribute should be added when merging XML documents
-
sourceAttributeName
protected String sourceAttributeName
The name of the attribute used to identify the source of an XML element
-
sourceTypeAttributeName
protected String sourceTypeAttributeName
The name of the attribute used to identify the type of the source of an XML element
-
sourceTypeXPath
protected String sourceTypeXPath
The XPath selector to extract the content-type from descriptors
-
-
Constructor Detail
-
ContentStoreServiceImpl
@ConstructorProperties({"cacheTemplate","storeAdapterRegistry","mergeStrategyResolver","merger","processorResolver","blobUrlResolver","blobStoreResolver","sourceAttributeName","sourceTypeAttributeName","sourceTypeXPath"}) public ContentStoreServiceImpl(CacheTemplate cacheTemplate, ContentStoreAdapterRegistry storeAdapterRegistry, DescriptorMergeStrategyResolver mergeStrategyResolver, DescriptorMerger merger, ItemProcessorResolver processorResolver, org.craftercms.commons.file.blob.BlobUrlResolver blobUrlResolver, org.craftercms.commons.file.blob.BlobStoreResolver blobStoreResolver, String sourceAttributeName, String sourceTypeAttributeName, String sourceTypeXPath)
-
-
Method Detail
-
setSourceAttributeEnabled
public void setSourceAttributeEnabled(boolean sourceAttributeEnabled)
-
getContext
public Context getContext(String contextId)
Returns the openContextfor the given ID, or null if no context found for the ID.
-
getContext
public Context getContext(String tag, String storeType, String rootFolderPath, boolean mergingOn, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles) throws InvalidStoreTypeException, RootFolderNotFoundException, StoreException, AuthenticationException
Returns a context with the specified parameters, if the context doesn't exist it will be created.- Parameters:
tag- a tag that's used when creating the ID to differentiate this contextstoreType- the type of content store to userootFolderPath- the root folder path for the contextmergingOn- indicates if content merging should be enabledcacheOn- indicates if content caching should be enabledmaxAllowedItemsInCache- the maximum number of items to hold in the cacheignoreHiddenFiles- indicates if hidden files should be ignored- Returns:
- the
Contextobject - Throws:
InvalidStoreTypeException- if the provided store type is invalidRootFolderNotFoundException- if the provided root folder path doesn't existStoreException- if there is any unexpected error during the creation the contextAuthenticationException- if there is any authentication error during the creation of the context
-
validate
public boolean validate(Context context) throws StoreException, AuthenticationException
Description copied from interface:ContentStoreServiceReturns true if the specified context is still valid and usable.
-
destroyContext
public boolean destroyContext(Context context) throws InvalidContextException, StoreException, AuthenticationException
Destroys the specified context, login out of any remote repository (if a login was issued) and destroying the cache scope associated to the context.- Returns:
- true if the context was successfully destroyed, false otherwise.
- Throws:
InvalidContextExceptionStoreExceptionAuthenticationException
-
doExists
public boolean doExists(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, PathNotFoundException, StoreException
- Specified by:
doExistsin classAbstractCachedContentStoreService- Throws:
InvalidContextExceptionPathNotFoundExceptionStoreException
-
findContent
public Content findContent(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, StoreException
Description copied from interface:ContentStoreServiceReturns the content of the file for the given url, returning null if not found.- Parameters:
context- the context with the store configuration (required)cachingOptions- the caching options for any caching operation done inside this service call (optional)url- the url of the file (required)- Returns:
- the file content
- Throws:
InvalidContextException- if the context is invalidStoreException- if an error occurred while accessing the content store
-
getContent
public Content getContent(Context context, CachingOptions cachingOptions, String url) throws InvalidScopeException, PathNotFoundException, StoreException
Returns the content of the file for the given url.- Parameters:
context- the context with the store configuration (required)cachingOptions- the caching options for any caching operation done inside this service call (optional)url- the url of the file (required)- Returns:
- the file content
- Throws:
PathNotFoundException- if the file the url points to can't be foundStoreException- if an error occurred while accessing the content storeInvalidScopeException
-
doFindItem
protected Item doFindItem(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException
Returns the content store item for the given url, returning null if not found.After acquiring the item from the
ContentStoreAdapter, the item's descriptor is merged (according to itsDescriptorMergeStrategy) with related descriptors, and the final item is then processed.- Specified by:
doFindItemin classAbstractCachedContentStoreService- Throws:
InvalidContextExceptionXmlFileParseExceptionXmlMergeExceptionItemProcessingExceptionStoreException
-
doFindChildren
protected List<Item> doFindChildren(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException
- Specified by:
doFindChildrenin classAbstractCachedContentStoreService- Throws:
InvalidContextExceptionXmlFileParseExceptionXmlMergeExceptionItemProcessingExceptionStoreException
-
doFindTree
protected Tree doFindTree(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException
- Specified by:
doFindTreein classAbstractCachedContentStoreService- Throws:
InvalidContextExceptionXmlFileParseExceptionXmlMergeExceptionItemProcessingExceptionStoreException
-
doFindChildren
protected List<Item> doFindChildren(Context context, CachingOptions cachingOptions, String url, Integer depth, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException
Does the following:- Retrieves the children from the underlying repository (without their descriptors).
- Filters the returned list if
ItemFilter.runBeforeProcessing()returnstrue. - Calls
ContentStoreService.getTree(Context, String)orContentStoreService.getItem(Context, String)for each item in the list (depending on whether the item is a folder or not, and ifdepthis not null), to obtain the merged and processed version of each item. - Filters the processed list if
ItemFilter.runAfterProcessing()returnstrue. - Returns the final list of processed items.
-
doMerging
protected Item doMerging(Context context, CachingOptions cachingOptions, Item item) throws CrafterException
Executes merging for the specifiedItem:- Gets the
DescriptorMergeStrategyfor the item's descriptor from theDescriptorMergeStrategyResolver. - Gets the actual descriptors to merge from the returned merge strategy.
- Retrieves the descriptor documents from the underlying repository.
- Merges the descriptor documents.
- Returns the item with the merged descriptor document.
- Throws:
CrafterException
- Gets the
-
addSourceAttributes
protected void addSourceAttributes(org.dom4j.Document document, org.dom4j.Element element, String descriptorUrl)
-
doProcessing
protected Item doProcessing(Context context, CachingOptions cachingOptions, Item item, ItemProcessor additionalProcessor) throws ItemProcessingException
Executes processing for the specifiedItem:- Gets the main
ItemProcessorfor the item from theItemProcessorResolver. - Calls the main processor's
processmethod to process the item. - If an additional processor was passed to this method, the additional processor is also called.
- Returns the processed item.
- Throws:
ItemProcessingException
- Gets the main
-
doFilter
protected List<Item> doFilter(List<Item> items, ItemFilter filter, boolean runningBeforeProcessing)
Filters the given list of items by using the specified filter. TherunningBeforeProcessingflag is passed to indicated the filter in which phase it is being executed (after or before processing).
-
-