public class CmsCategoryService extends java.lang.Object
CmsCategory| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CENTRALIZED_REPOSITORY
The centralized path for categories.
|
static java.lang.String |
REPOSITORY_BASE_FOLDER
The folder for the local category repositories.
|
| Constructor and Description |
|---|
CmsCategoryService() |
| Modifier and Type | Method and Description |
|---|---|
void |
addResourceToCategory(CmsObject cms,
java.lang.String resourceName,
CmsCategory category)
Adds a resource identified by the given resource name to the given category.
|
void |
addResourceToCategory(CmsObject cms,
java.lang.String resourceName,
java.lang.String categoryPath)
Adds a resource identified by the given resource name to the category
identified by the given category path.
|
void |
clearCategoriesForResource(CmsObject cms,
java.lang.String resourcePath)
Removes the given resource from all categories.
|
void |
copyCategories(CmsObject cms,
CmsResource fromResource,
java.lang.String toResourceSitePath)
Adds all categories from one resource to another, skipping categories that are not available for the resource copied to.
|
CmsCategory |
createCategory(CmsObject cms,
CmsCategory parent,
java.lang.String name,
java.lang.String title,
java.lang.String description,
java.lang.String referencePath)
Creates a new category.
|
void |
deleteCategory(CmsObject cms,
java.lang.String categoryPath,
java.lang.String referencePath)
Deletes the category identified by the given path.
|
CmsCategory |
getCategory(CmsObject cms,
CmsResource resource)
Creates a category from the given resource.
|
CmsCategory |
getCategory(CmsObject cms,
java.lang.String categoryRootPath)
Creates a category from the given category root path.
|
java.util.List<java.lang.String> |
getCategoryRepositories(CmsObject cms,
java.lang.String referencePath)
Returns all category repositories for the given reference path.
|
static CmsCategoryService |
getInstance()
Returns the singleton instance.
|
java.lang.String |
getRepositoryBaseFolderName(CmsObject cms)
Returns the category repositories base folder name.
|
java.util.List<CmsCategory> |
localizeCategories(CmsObject cms,
java.util.List<CmsCategory> categories,
java.util.Locale locale)
Localizes a list of categories by reading locale-specific properties for their title and description, if possible.
|
CmsCategory |
localizeCategory(CmsObject cms,
CmsCategory category,
java.util.Locale locale)
Localizes a single category by reading its locale-specific properties for title and description, if possible.
|
void |
moveCategory(CmsObject cms,
java.lang.String oldCatPath,
java.lang.String newCatPath,
java.lang.String referencePath)
Renames/Moves a category from the old path to the new one.
|
java.util.List<CmsCategory> |
readCategories(CmsObject cms,
java.lang.String parentCategoryPath,
boolean includeSubCats,
java.lang.String referencePath)
Returns all categories given some search parameters.
|
java.util.List<CmsCategory> |
readCategoriesForRepositories(CmsObject cms,
java.lang.String parentCategoryPath,
boolean includeSubCats,
java.util.List<java.lang.String> repositories)
Returns all categories given some search parameters.
|
java.util.List<CmsCategory> |
readCategoriesForRepositories(CmsObject cms,
java.lang.String parentCategoryPath,
boolean includeSubCats,
java.util.List<java.lang.String> repositories,
boolean includeRepositories)
Returns all categories given some search parameters.
|
CmsCategory |
readCategory(CmsObject cms,
java.lang.String categoryPath,
java.lang.String referencePath)
Reads all categories identified by the given category path for the given reference path.
|
java.util.List<CmsResource> |
readCategoryResources(CmsObject cms,
java.lang.String categoryPath,
boolean recursive,
java.lang.String referencePath)
Reads the resources for a category identified by the given category path.
|
java.util.List<CmsResource> |
readCategoryResources(CmsObject cms,
java.lang.String categoryPath,
boolean recursive,
java.lang.String referencePath,
CmsResourceFilter resFilter)
Reads the resources for a category identified by the given category path.
|
java.util.List<CmsCategory> |
readResourceCategories(CmsObject cms,
CmsResource resource)
Reads the categories for a resource.
|
java.util.List<CmsCategory> |
readResourceCategories(CmsObject cms,
java.lang.String resourceName)
Reads the categories for a resource identified by the given resource name.
|
void |
removeResourceFromCategory(CmsObject cms,
java.lang.String resourceName,
CmsCategory category)
Removes a resource identified by the given resource name from the given category.
|
void |
removeResourceFromCategory(CmsObject cms,
java.lang.String resourceName,
java.lang.String categoryPath)
Removes a resource identified by the given resource name from the category
identified by the given category path.
|
void |
repairRelations(CmsObject cms,
CmsResource resource)
Repairs broken category relations.
|
void |
repairRelations(CmsObject cms,
java.lang.String resourceName)
Repairs broken category relations.
|
public static final java.lang.String CENTRALIZED_REPOSITORY
public static final java.lang.String REPOSITORY_BASE_FOLDER
public CmsCategoryService()
public static CmsCategoryService getInstance()
public void addResourceToCategory(CmsObject cms, java.lang.String resourceName, CmsCategory category) throws CmsException
The resource has to be locked.
cms - the current cms contextresourceName - the site relative path to the resource to addcategory - the category to add the resource toCmsException - if something goes wrongpublic void addResourceToCategory(CmsObject cms, java.lang.String resourceName, java.lang.String categoryPath) throws CmsException
Only the most global category matching the given category path for the given resource will be affected.
The resource has to be locked.
cms - the current cms contextresourceName - the site relative path to the resource to addcategoryPath - the path of the category to add the resource toCmsException - if something goes wrongpublic void clearCategoriesForResource(CmsObject cms, java.lang.String resourcePath) throws CmsException
cms - the cms contextresourcePath - the resource to reset the categories forCmsException - if something goes wrongpublic void copyCategories(CmsObject cms, CmsResource fromResource, java.lang.String toResourceSitePath) throws CmsException
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.CmsException - thrown if copying the resources fails.public CmsCategory createCategory(CmsObject cms, CmsCategory parent, java.lang.String name, java.lang.String title, java.lang.String description, java.lang.String referencePath) throws CmsException
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.
cms - the current cms contextparent - the parent category or null for a new top level categoryname - the name of the new categorytitle - the titledescription - the descriptionreferencePath - the reference path for the category repositoryCmsException - if something goes wrongpublic void deleteCategory(CmsObject cms, java.lang.String categoryPath, java.lang.String referencePath) throws CmsException
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.
cms - the current cms contextcategoryPath - the path of the category to deletereferencePath - the reference path to find the category repositoriesCmsException - if something goes wrongpublic CmsCategory getCategory(CmsObject cms, CmsResource resource) throws CmsException
cms - the cms contextresource - the resourceCmsException - if something goes wrongpublic CmsCategory getCategory(CmsObject cms, java.lang.String categoryRootPath) throws CmsException
cms - the cms contextcategoryRootPath - the category root pathCmsException - if something goes wrongpublic java.util.List<java.lang.String> getCategoryRepositories(CmsObject cms, java.lang.String referencePath)
cms - the cms contextreferencePath - the reference pathpublic java.lang.String getRepositoryBaseFolderName(CmsObject cms)
cms - the cms contextpublic java.util.List<CmsCategory> localizeCategories(CmsObject cms, java.util.List<CmsCategory> categories, java.util.Locale locale)
This method does not modify its input list of categories, or the categories in it.
cms - the CMS context to use for reading resourcescategories - the list of categorieslocale - the locale to usepublic CmsCategory localizeCategory(CmsObject cms, CmsCategory category, java.util.Locale locale)
cms - the CMS context to use for reading resourcescategory - the category to localizelocale - the locale to usepublic void moveCategory(CmsObject cms, java.lang.String oldCatPath, java.lang.String newCatPath, java.lang.String referencePath) throws CmsException
This method will keep all categories in their original repository.
cms - the current cms contextoldCatPath - the path of the category to movenewCatPath - the new category pathreferencePath - the reference path to find the categoryCmsException - if something goes wrongpublic java.util.List<CmsCategory> readCategories(CmsObject cms, java.lang.String parentCategoryPath, boolean includeSubCats, java.lang.String referencePath) throws CmsException
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 repositoriesCmsCategory objectsCmsException - if something goes wrongpublic java.util.List<CmsCategory> readCategoriesForRepositories(CmsObject cms, java.lang.String parentCategoryPath, boolean includeSubCats, java.util.List<java.lang.String> repositories) throws CmsException
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 pathsCmsCategory objectsCmsException - if something goes wrongpublic java.util.List<CmsCategory> readCategoriesForRepositories(CmsObject cms, java.lang.String parentCategoryPath, boolean includeSubCats, java.util.List<java.lang.String> repositories, boolean includeRepositories) throws CmsException
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.CmsCategory objectsCmsException - if something goes wrongpublic CmsCategory readCategory(CmsObject cms, java.lang.String categoryPath, java.lang.String referencePath) throws CmsException
cms - the current cms contextcategoryPath - the path of the category to readreferencePath - the reference path to find all the category repositoriesCmsException - if something goes wrongpublic java.util.List<CmsResource> readCategoryResources(CmsObject cms, java.lang.String categoryPath, boolean recursive, java.lang.String referencePath) throws CmsException
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 repositoriesCmsResource objectsCmsException - if something goes wrongpublic java.util.List<CmsResource> readCategoryResources(CmsObject cms, java.lang.String categoryPath, boolean recursive, java.lang.String referencePath, CmsResourceFilter resFilter) throws CmsException
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 useCmsResource objectsCmsException - if something goes wrongpublic java.util.List<CmsCategory> readResourceCategories(CmsObject cms, CmsResource resource) throws CmsException
cms - the current cms contextresource - the resource to get the categories forCmsException - if something goes wrongpublic java.util.List<CmsCategory> readResourceCategories(CmsObject cms, java.lang.String resourceName) throws CmsException
cms - the current cms contextresourceName - the path of the resource to get the categories forCmsException - if something goes wrongpublic void removeResourceFromCategory(CmsObject cms, java.lang.String resourceName, CmsCategory category) throws CmsException
The resource has to be previously locked.
cms - the current cms contextresourceName - the site relative path to the resource to removecategory - the category to remove the resource fromCmsException - if something goes wrongpublic void removeResourceFromCategory(CmsObject cms, java.lang.String resourceName, java.lang.String categoryPath) throws CmsException
The resource has to be previously locked.
cms - the current cms contextresourceName - the site relative path to the resource to removecategoryPath - the path of the category to remove the resource fromCmsException - if something goes wrongpublic void repairRelations(CmsObject cms, CmsResource resource) throws CmsException
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.
cms - the cms contextresource - the resource to repairCmsException - if something goes wrongpublic void repairRelations(CmsObject cms, java.lang.String resourceName) throws CmsException
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.
cms - the cms contextresourceName - the site relative path to the resource to repairCmsException - if something goes wrong