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
Default implementation of
ContentStoreService. Extends from
AbstractCachedContentStoreService to use caching.- Author:
- Alfonso Vásquez
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.craftercms.commons.file.blob.BlobStoreResolverprotected org.craftercms.commons.file.blob.BlobUrlResolverMap of openContextsprotected com.fasterxml.jackson.databind.ObjectMapperprotected DescriptorMergerMerges a bunch of descriptorsprotected DescriptorMergeStrategyResolverResolves theDescriptorMergeStrategyto use for a particular descriptor.protected ItemProcessorResolverResolves theItemProcessorto use for a particularItem.protected booleanIndicates if the source attribute should be added when merging XML documentsprotected StringThe name of the attribute used to identify the source of an XML elementprotected StringThe name of the attribute used to identify the type of the source of an XML elementprotected StringThe XPath selector to extract the content-type from descriptorsprotected ContentStoreAdapterRegistryRegistry 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, flatteningProcessorFields inherited from interface org.craftercms.core.service.ContentStoreService
TREE_DEPTH_HARD_LIMIT, UNLIMITED_TREE_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionContentStoreServiceImpl(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
Modifier and TypeMethodDescriptionprotected 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) doFilter(List<Item> items, ItemFilter filter, boolean runningBeforeProcessing) Filters the given list of items by using the specified filter.doFindChildren(Context context, CachingOptions cachingOptions, String url, Integer depth, ItemFilter filter, ItemProcessor processor, boolean flatten) Does the following: Retrieves the children from the underlying repository (without their descriptors). Filters the returned list ifItemFilter.runBeforeProcessing()returnstrue. CallsContentStoreService.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 ifItemFilter.runAfterProcessing()returnstrue. Returns the final list of processed items.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: Gets theDescriptorMergeStrategyfor 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.protected ItemdoProcessing(Context context, CachingOptions cachingOptions, Item item, ItemProcessor additionalProcessor) Executes processing for the specifiedItem: Gets the mainItemProcessorfor the item from theItemProcessorResolver. Calls the main processor'sprocessmethod to process the item. If an additional processor was passed to this method, the additional processor is also called. Returns the processed item.findContent(Context context, CachingOptions cachingOptions, String url) Returns the content of the file for the given url, returning null if not found.getChildrenInternal(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor, boolean flatten) This method is meant to be overridden when the children need to be further processed/filteredgetContent(Context context, CachingOptions cachingOptions, String url) Returns the content of the file for the given url.getContext(String contextId) Returns the openContextfor the given ID, or null if no context found for the ID.getContext(String tag, String storeType, String rootFolderPath, boolean mergingOn, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles, Map<String, String> configurationVariables) Returns a context with the specified parameters, if the context doesn't exist it will be created.voidsetSourceAttributeEnabled(boolean sourceAttributeEnabled) booleanReturns 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, setFlatteningProcessorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 Details
-
storeAdapterRegistry
Registry ofContentStoreAdapters. -
mergeStrategyResolver
Resolves theDescriptorMergeStrategyto use for a particular descriptor. -
merger
Merges a bunch of descriptors -
processorResolver
Resolves theItemProcessorto use for a particularItem. -
contexts
Map of openContexts -
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 sourceAttributeEnabledIndicates if the source attribute should be added when merging XML documents -
sourceAttributeName
The name of the attribute used to identify the source of an XML element -
sourceTypeAttributeName
The name of the attribute used to identify the type of the source of an XML element -
sourceTypeXPath
The XPath selector to extract the content-type from descriptors
-
-
Constructor Details
-
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 Details
-
setSourceAttributeEnabled
public void setSourceAttributeEnabled(boolean sourceAttributeEnabled) -
getContext
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, Map<String, String> configurationVariables) throws InvalidStoreTypeException, RootFolderNotFoundException, StoreException, AuthenticationExceptionReturns 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 ignoredconfigurationVariables- a map of configuration variables to use when creating the context- 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
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.
-
getChildrenInternal
protected List<Item> getChildrenInternal(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor, boolean flatten) This method is meant to be overridden when the children need to be further processed/filtered- Parameters:
context- the contextcachingOptions- the caching optionsurl- the urlprocessor- the processorflatten- whether to flatten the children- Returns:
- the children
-
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
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). -
createContextId
-