Class CmsCategoryService
- Since:
- 6.9.2
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addResourceToCategory
(CmsObject cms, String resourceName, String categoryPath) Adds a resource identified by the given resource name to the category identified by the given category path.void
addResourceToCategory
(CmsObject cms, String resourceName, CmsCategory category) Adds a resource identified by the given resource name to the given category.void
clearCategoriesForResource
(CmsObject cms, String resourcePath) Removes the given resource from all categories.void
copyCategories
(CmsObject cms, CmsResource fromResource, String toResourceSitePath) Adds all categories from one resource to another, skipping categories that are not available for the resource copied to.createCategory
(CmsObject cms, CmsCategory parent, String name, String title, String description, String referencePath) Creates a new category.void
deleteCategory
(CmsObject cms, String categoryPath, String referencePath) Deletes the category identified by the given path.getCategory
(CmsObject cms, String categoryRootPath) Creates a category from the given category root path.getCategory
(CmsObject cms, CmsResource resource) Creates a category from the given resource.getCategoryRepositories
(CmsObject cms, String referencePath) Returns all category repositories for the given reference path.static CmsCategoryService
Returns the singleton instance.Returns the category repositories base folder name.localizeCategories
(CmsObject cms, List<CmsCategory> categories, Locale locale) Localizes a list of categories by reading locale-specific properties for their title and description, if possible.localizeCategory
(CmsObject cms, CmsCategory category, Locale locale) Localizes a single category by reading its locale-specific properties for title and description, if possible.void
moveCategory
(CmsObject cms, String oldCatPath, String newCatPath, String referencePath) Renames/Moves a category from the old path to the new one.readCategories
(CmsObject cms, String parentCategoryPath, boolean includeSubCats, String referencePath) Returns all categories given some search parameters.readCategoriesForRepositories
(CmsObject cms, String parentCategoryPath, boolean includeSubCats, List<String> repositories) Returns all categories given some search parameters.readCategoriesForRepositories
(CmsObject cms, String parentCategoryPath, boolean includeSubCats, List<String> repositories, boolean includeRepositories) Returns all categories given some search parameters.readCategory
(CmsObject cms, String categoryPath, String referencePath) Reads all categories identified by the given category path for the given reference path.readCategoryResources
(CmsObject cms, String categoryPath, boolean recursive, String referencePath) Reads the resources for a category identified by the given category path.readCategoryResources
(CmsObject cms, String categoryPath, boolean recursive, String referencePath, CmsResourceFilter resFilter) Reads the resources for a category identified by the given category path.readResourceCategories
(CmsObject cms, String resourceName) Reads the categories for a resource identified by the given resource name.readResourceCategories
(CmsObject cms, CmsResource resource) Reads the categories for a resource.void
removeResourceFromCategory
(CmsObject cms, String resourceName, String categoryPath) Removes a resource identified by the given resource name from the category identified by the given category path.void
removeResourceFromCategory
(CmsObject cms, String resourceName, CmsCategory category) Removes a resource identified by the given resource name from the given category.void
repairRelations
(CmsObject cms, String resourceName) Repairs broken category relations.void
repairRelations
(CmsObject cms, CmsResource resource) Repairs broken category relations.
-
Field Details
-
CENTRALIZED_REPOSITORY
The centralized path for categories.- See Also:
-
REPOSITORY_BASE_FOLDER
The folder for the local category repositories.- See Also:
-
-
Constructor Details
-
CmsCategoryService
public CmsCategoryService()
-
-
Method Details
-
getInstance
Returns the singleton instance.- Returns:
- the singleton instance
-
addResourceToCategory
public void addResourceToCategory(CmsObject cms, String resourceName, CmsCategory category) throws CmsException Adds a resource identified by the given resource name to the given category.The resource has to be locked.
- Parameters:
cms
- the current cms contextresourceName
- the site relative path to the resource to addcategory
- the category to add the resource to- Throws:
CmsException
- if something goes wrong
-
addResourceToCategory
public void addResourceToCategory(CmsObject cms, String resourceName, String categoryPath) throws CmsException Adds a resource identified by the given resource name to the category identified by the given category path.Only the most global category matching the given category path for the given resource will be affected.
The resource has to be locked.
- Parameters:
cms
- the current cms contextresourceName
- the site relative path to the resource to addcategoryPath
- the path of the category to add the resource to- Throws:
CmsException
- if something goes wrong
-
clearCategoriesForResource
Removes the given resource from all categories.- Parameters:
cms
- the cms contextresourcePath
- the resource to reset the categories for- Throws:
CmsException
- if something goes wrong
-
copyCategories
public void copyCategories(CmsObject cms, CmsResource fromResource, String toResourceSitePath) throws CmsException Adds all categories from one resource to another, skipping categories that are not available for the resource copied to. The resource where categories are copied to has to be locked.- Parameters:
cms
- the CmsObject used for reading and writing.fromResource
- the resource to copy the categories from.toResourceSitePath
- the full site path of the resource to copy the categories to.- Throws:
CmsException
- thrown if copying the resources fails.
-
createCategory
public CmsCategory createCategory(CmsObject cms, CmsCategory parent, String name, String title, String description, String referencePath) throws CmsException Creates a new category.Will use the same category repository as the parent if specified, or the closest category repository to the reference path if specified, or the centralized category repository in all other cases.
- Parameters:
cms
- the current cms contextparent
- the parent category ornull
for a new top level categoryname
- the name of the new categorytitle
- the titledescription
- the descriptionreferencePath
- the reference path for the category repository- Returns:
- the new created category
- Throws:
CmsException
- if something goes wrong
-
deleteCategory
public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException Deletes the category identified by the given path.Only the most global category matching the given category path for the given resource will be affected.
This method will try to lock the involved resource.
- Parameters:
cms
- the current cms contextcategoryPath
- the path of the category to deletereferencePath
- the reference path to find the category repositories- Throws:
CmsException
- if something goes wrong
-
getCategory
Creates a category from the given resource.- Parameters:
cms
- the cms contextresource
- the resource- Returns:
- a category object
- Throws:
CmsException
- if something goes wrong
-
getCategory
Creates a category from the given category root path.- Parameters:
cms
- the cms contextcategoryRootPath
- the category root path- Returns:
- a category object
- Throws:
CmsException
- if something goes wrong
-
getCategoryRepositories
Returns all category repositories for the given reference path.- Parameters:
cms
- the cms contextreferencePath
- the reference path- Returns:
- a list of root paths
-
getRepositoryBaseFolderName
Returns the category repositories base folder name.- Parameters:
cms
- the cms context- Returns:
- the category repositories base folder name
-
localizeCategories
public List<CmsCategory> localizeCategories(CmsObject cms, List<CmsCategory> categories, Locale locale) Localizes a list of categories by reading locale-specific properties for their title and description, if possible.This method does not modify its input list of categories, or the categories in it.
- Parameters:
cms
- the CMS context to use for reading resourcescategories
- the list of categorieslocale
- the locale to use- Returns:
- the list of localized categories
-
localizeCategory
Localizes a single category by reading its locale-specific properties for title and description, if possible.- Parameters:
cms
- the CMS context to use for reading resourcescategory
- the category to localizelocale
- the locale to use- Returns:
- the localized category
-
moveCategory
public void moveCategory(CmsObject cms, String oldCatPath, String newCatPath, String referencePath) throws CmsException Renames/Moves a category from the old path to the new one.This method will keep all categories in their original repository.
- Parameters:
cms
- the current cms contextoldCatPath
- the path of the category to movenewCatPath
- the new category pathreferencePath
- the reference path to find the category- Throws:
CmsException
- if something goes wrong
-
readCategories
public List<CmsCategory> readCategories(CmsObject cms, String parentCategoryPath, boolean includeSubCats, String referencePath) throws CmsException Returns all categories given some search parameters.- Parameters:
cms
- the current cms contextparentCategoryPath
- the path of the parent category to get the categories forincludeSubCats
- if to include all categories, or first level child categories onlyreferencePath
- the reference path to find all the category repositories- Returns:
- a list of
CmsCategory
objects - Throws:
CmsException
- if something goes wrong
-
readCategoriesForRepositories
public List<CmsCategory> readCategoriesForRepositories(CmsObject cms, String parentCategoryPath, boolean includeSubCats, List<String> repositories) throws CmsException Returns all categories given some search parameters.- Parameters:
cms
- the current cms contextparentCategoryPath
- the path of the parent category to get the categories forincludeSubCats
- if to include all categories, or first level child categories onlyrepositories
- a list of root paths- Returns:
- a list of
CmsCategory
objects - Throws:
CmsException
- if something goes wrong
-
readCategoriesForRepositories
public List<CmsCategory> readCategoriesForRepositories(CmsObject cms, String parentCategoryPath, boolean includeSubCats, List<String> repositories, boolean includeRepositories) throws CmsException Returns all categories given some search parameters.- Parameters:
cms
- the current cms contextparentCategoryPath
- the path of the parent category to get the categories forincludeSubCats
- if to include all categories, or first level child categories onlyrepositories
- a list of site pathsincludeRepositories
- flag, indicating if the repositories itself should be returned as category.- Returns:
- a list of
CmsCategory
objects - Throws:
CmsException
- if something goes wrong
-
readCategory
public CmsCategory readCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException Reads all categories identified by the given category path for the given reference path.- Parameters:
cms
- the current cms contextcategoryPath
- the path of the category to readreferencePath
- the reference path to find all the category repositories- Returns:
- a list of matching categories, could also be empty, if no category exists with the given path
- Throws:
CmsException
- if something goes wrong
-
readCategoryResources
public List<CmsResource> readCategoryResources(CmsObject cms, String categoryPath, boolean recursive, String referencePath) throws CmsException Reads the resources for a category identified by the given category path.- Parameters:
cms
- the current cms contextcategoryPath
- the path of the category to read the resources forrecursive
-true
if including sub-categoriesreferencePath
- the reference path to find all the category repositories- Returns:
- a list of
CmsResource
objects - Throws:
CmsException
- if something goes wrong
-
readCategoryResources
public List<CmsResource> readCategoryResources(CmsObject cms, String categoryPath, boolean recursive, String referencePath, CmsResourceFilter resFilter) throws CmsException Reads the resources for a category identified by the given category path.- Parameters:
cms
- the current cms contextcategoryPath
- the path of the category to read the resources forrecursive
-true
if including sub-categoriesreferencePath
- the reference path to find all the category repositoriesresFilter
- the resource filter to use- Returns:
- a list of
CmsResource
objects - Throws:
CmsException
- if something goes wrong
-
readResourceCategories
public List<CmsCategory> readResourceCategories(CmsObject cms, CmsResource resource) throws CmsException Reads the categories for a resource.- Parameters:
cms
- the current cms contextresource
- the resource to get the categories for- Returns:
- the categories list
- Throws:
CmsException
- if something goes wrong
-
readResourceCategories
public List<CmsCategory> readResourceCategories(CmsObject cms, String resourceName) throws CmsException Reads the categories for a resource identified by the given resource name.- Parameters:
cms
- the current cms contextresourceName
- the path of the resource to get the categories for- Returns:
- the categories list
- Throws:
CmsException
- if something goes wrong
-
removeResourceFromCategory
public void removeResourceFromCategory(CmsObject cms, String resourceName, CmsCategory category) throws CmsException Removes a resource identified by the given resource name from the given category.The resource has to be previously locked.
- Parameters:
cms
- the current cms contextresourceName
- the site relative path to the resource to removecategory
- the category to remove the resource from- Throws:
CmsException
- if something goes wrong
-
removeResourceFromCategory
public void removeResourceFromCategory(CmsObject cms, String resourceName, String categoryPath) throws CmsException Removes a resource identified by the given resource name from the category identified by the given category path.The resource has to be previously locked.
- Parameters:
cms
- the current cms contextresourceName
- the site relative path to the resource to removecategoryPath
- the path of the category to remove the resource from- Throws:
CmsException
- if something goes wrong
-
repairRelations
Repairs broken category relations.This could be caused by renaming/moving a category folder, or changing the category repositories base folder name.
Also repairs problems when creating/deleting conflicting category folders across several repositories.
The resource has to be previously locked.
- Parameters:
cms
- the cms contextresource
- the resource to repair- Throws:
CmsException
- if something goes wrong
-
repairRelations
Repairs broken category relations.This could be caused by renaming/moving a category folder, or changing the category repositories base folder name.
Also repairs problems when creating/deleting conflicting category folders across several repositories.
The resource has to be previously locked.
- Parameters:
cms
- the cms contextresourceName
- the site relative path to the resource to repair- Throws:
CmsException
- if something goes wrong
-