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
Modifier and TypeFieldDescriptionprotected org.craftercms.commons.file.blob.BlobStoreResolver
protected org.craftercms.commons.file.blob.BlobUrlResolver
Map of openContext
sprotected com.fasterxml.jackson.databind.ObjectMapper
protected DescriptorMerger
Merges a bunch of descriptorsprotected DescriptorMergeStrategyResolver
Resolves theDescriptorMergeStrategy
to use for a particular descriptor.protected ItemProcessorResolver
Resolves theItemProcessor
to use for a particularItem
.protected boolean
Indicates if the source attribute should be added when merging XML documentsprotected String
The name of the attribute used to identify the source of an XML elementprotected String
The name of the attribute used to identify the type of the source of an XML elementprotected String
The XPath selector to extract the content-type from descriptorsprotected ContentStoreAdapterRegistry
Registry ofContentStoreAdapter
s.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
ConstructorDescriptionContentStoreServiceImpl
(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 void
addSourceAttributes
(org.dom4j.Document document, org.dom4j.Element element, String descriptorUrl) protected String
createContextId
(String tag, String storeType, String rootFolderPath, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles) boolean
destroyContext
(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.boolean
doExists
(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 ifdepth
is 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 Item
doFindItem
(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor) Returns the content store item for the given url, returning null if not found.protected Tree
doFindTree
(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) protected Item
doMerging
(Context context, CachingOptions cachingOptions, Item item) Executes merging for the specifiedItem
: Gets theDescriptorMergeStrategy
for 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 Item
doProcessing
(Context context, CachingOptions cachingOptions, Item item, ItemProcessor additionalProcessor) Executes processing for the specifiedItem
: Gets the mainItemProcessor
for the item from theItemProcessorResolver
. Calls the main processor'sprocess
method 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 openContext
for 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) Returns a context with the specified parameters, if the context doesn't exist it will be created.void
setSourceAttributeEnabled
(boolean sourceAttributeEnabled) boolean
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 Details
-
storeAdapterRegistry
Registry ofContentStoreAdapter
s. -
mergeStrategyResolver
Resolves theDescriptorMergeStrategy
to use for a particular descriptor. -
merger
Merges a bunch of descriptors -
processorResolver
Resolves theItemProcessor
to use for a particularItem
. -
contexts
Map of openContext
s -
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 openContext
for 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
Context
object - 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:ContentStoreService
Returns 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:
InvalidContextException
StoreException
AuthenticationException
-
doExists
public boolean doExists(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, PathNotFoundException, StoreException - Specified by:
doExists
in classAbstractCachedContentStoreService
- Throws:
InvalidContextException
PathNotFoundException
StoreException
-
findContent
public Content findContent(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, StoreException Description copied from interface:ContentStoreService
Returns 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:
doFindItem
in classAbstractCachedContentStoreService
- Throws:
InvalidContextException
XmlFileParseException
XmlMergeException
ItemProcessingException
StoreException
-
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:
doFindChildren
in classAbstractCachedContentStoreService
- Throws:
InvalidContextException
XmlFileParseException
XmlMergeException
ItemProcessingException
StoreException
-
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:
doFindTree
in classAbstractCachedContentStoreService
- Throws:
InvalidContextException
XmlFileParseException
XmlMergeException
ItemProcessingException
StoreException
-
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 ifdepth
is 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
DescriptorMergeStrategy
for 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
ItemProcessor
for the item from theItemProcessorResolver
. - Calls the main processor's
process
method 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. TherunningBeforeProcessing
flag is passed to indicated the filter in which phase it is being executed (after or before processing). -
createContextId
-