org.opencms.relations
Class CmsCategoryService

java.lang.Object
  extended byorg.opencms.relations.CmsCategoryService

public class CmsCategoryService
extends java.lang.Object

Provides several simplified methods for manipulating category relations.

Since:
6.9.2
Version:
$Revision: 1.4 $
Author:
Michael Moossen

Constructor Summary
CmsCategoryService()
           
 
Method Summary
 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.
 CmsCategory createCategory(CmsObject cms, CmsCategory parent, java.lang.String name, java.lang.String title, java.lang.String description)
          Creates a new category, which is just a simplification of a folder under /system/categories/.
 void deleteCategory(CmsObject cms, java.lang.String categoryPath)
          Deletes the category identified by the given path.
static CmsCategoryService getInstance()
          Returns the singleton instance.
 void moveCategory(CmsObject cms, java.lang.String oldCatPath, java.lang.String newCatPath)
          Renames/Moves a category from the olda path to the new one.
 java.util.List readAllCategories(CmsObject cms, boolean includeSubCats)
          Reads all first level categories, including sub categories if needed.
 CmsCategory readCategory(CmsObject cms, java.lang.String categoryPath)
          Reads the category identified by the given category path.
 java.util.List readResourceCategories(CmsObject cms, java.lang.String resourceName)
          Reads the categories for a resource identified by the given resource name.
 java.util.List readSubCategories(CmsObject cms, java.lang.String categoryPath, boolean includeSubCats)
          Returns all sub categories of 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsCategoryService

public CmsCategoryService()
Method Detail

getInstance

public static CmsCategoryService getInstance()
Returns the singleton instance.

Returns:
the singleton instance

addResourceToCategory

public void addResourceToCategory(CmsObject cms,
                                  java.lang.String resourceName,
                                  java.lang.String categoryPath)
                           throws CmsException
Adds a resource identified by the given resource name to the category identified by the given category path.

Parameters:
cms - the current cms context
resourceName - the site relative path to the resource to add
categoryPath - the path of the category to add the resource to
Throws:
CmsException - if something goes wrong

createCategory

public CmsCategory createCategory(CmsObject cms,
                                  CmsCategory parent,
                                  java.lang.String name,
                                  java.lang.String title,
                                  java.lang.String description)
                           throws CmsException
Creates a new category, which is just a simplification of a folder under /system/categories/.

Parameters:
cms - the current cms context
parent - the parent category or null for a new top level category
name - the (file-) name for the new category
title - the title
description - the description
Returns:
the new created category
Throws:
CmsException - if something goes wrong

deleteCategory

public void deleteCategory(CmsObject cms,
                           java.lang.String categoryPath)
                    throws CmsException
Deletes the category identified by the given path.

Parameters:
cms - the current cms context
categoryPath - the path of the category to delete
Throws:
CmsException - if something goes wrong

moveCategory

public void moveCategory(CmsObject cms,
                         java.lang.String oldCatPath,
                         java.lang.String newCatPath)
                  throws CmsException
Renames/Moves a category from the olda path to the new one.

Parameters:
cms - the current cms context
oldCatPath - the path of the category to move
newCatPath - the new category path
Throws:
CmsException - if something goes wrong

readAllCategories

public java.util.List readAllCategories(CmsObject cms,
                                        boolean includeSubCats)
                                 throws CmsException
Reads all first level categories, including sub categories if needed.

Parameters:
cms - the current cms context
includeSubCats - flag to indicate if sub categories should also be read
Returns:
a list of CmsCategory objects
Throws:
CmsException - if something goes wrong

readCategory

public CmsCategory readCategory(CmsObject cms,
                                java.lang.String categoryPath)
                         throws CmsException
Reads the category identified by the given category path.

Parameters:
cms - the current cms context
categoryPath - the path of the category to read
Returns:
the category
Throws:
CmsException - if something goes wrong

readResourceCategories

public java.util.List readResourceCategories(CmsObject cms,
                                             java.lang.String resourceName)
                                      throws CmsException
Reads the categories for a resource identified by the given resource name.

Parameters:
cms - the current cms context
resourceName - the path of the resource to get the categories for
Returns:
the categories list
Throws:
CmsException - if something goes wrong

readSubCategories

public java.util.List readSubCategories(CmsObject cms,
                                        java.lang.String categoryPath,
                                        boolean includeSubCats)
                                 throws CmsException
Returns all sub categories of the given category.

Parameters:
cms - the current cms context
categoryPath - the path of the category to get the sub categories for
includeSubCats - if to include sub-subcategories
Returns:
a list of CmsCategory objects
Throws:
CmsException - if something goes wrong

removeResourceFromCategory

public void removeResourceFromCategory(CmsObject cms,
                                       java.lang.String resourceName,
                                       java.lang.String categoryPath)
                                throws CmsException
Removes a resource identified by the given resource name from the category identified by the given category path.

Parameters:
cms - the current cms context
resourceName - the site relative path to the resource to remove
categoryPath - the path of the category to remove the resource from
Throws:
CmsException - if something goes wrong