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 fromAbstractCachedContentStoreService
to use caching.- Author:
- Alfonso Vásquez
-
-
Field Summary
Fields Modifier and Type Field Description protected org.craftercms.commons.file.blob.BlobStoreResolver
blobStoreResolver
protected org.craftercms.commons.file.blob.BlobUrlResolver
blobUrlResolver
protected Map<String,Context>
contexts
Map of openContext
sprotected com.fasterxml.jackson.databind.ObjectMapper
mapper
protected DescriptorMerger
merger
Merges a bunch of descriptorsprotected DescriptorMergeStrategyResolver
mergeStrategyResolver
Resolves theDescriptorMergeStrategy
to use for a particular descriptor.protected ItemProcessorResolver
processorResolver
Resolves theItemProcessor
to use for a particularItem
.protected boolean
sourceAttributeEnabled
Indicates if the source attribute should be added when merging XML documentsprotected String
sourceAttributeName
The name of the attribute used to identify the source of an XML elementprotected String
sourceTypeAttributeName
The name of the attribute used to identify the type of the source of an XML elementprotected String
sourceTypeXPath
The XPath selector to extract the content-type from descriptorsprotected ContentStoreAdapterRegistry
storeAdapterRegistry
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
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 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)
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 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
:protected Item
doProcessing(Context context, CachingOptions cachingOptions, Item item, ItemProcessor additionalProcessor)
Executes processing for the specifiedItem
:Content
findContent(Context context, CachingOptions cachingOptions, String url)
Returns the content of the file for the given url, returning null if not found.Content
getContent(Context context, CachingOptions cachingOptions, String url)
Returns the content of the file for the given url.Context
getContext(String contextId)
Returns the openContext
for the given ID, or null if no context found for the ID.Context
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
validate(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 ofContentStoreAdapter
s.
-
mergeStrategyResolver
protected DescriptorMergeStrategyResolver mergeStrategyResolver
Resolves theDescriptorMergeStrategy
to use for a particular descriptor.
-
merger
protected DescriptorMerger merger
Merges a bunch of descriptors
-
processorResolver
protected ItemProcessorResolver processorResolver
Resolves theItemProcessor
to 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 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
public boolean validate(Context context) throws StoreException, AuthenticationException
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.
-
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
protected List<Item> doFilter(List<Item> items, ItemFilter filter, boolean runningBeforeProcessing)
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).
-
-