code: public CmsCategory createCategory(
          CmsObject cms,
          CmsCategory parent,
          String name,
          String title,
          String description,
          String referencePath)
      throws CmsException {
  
          List<CmsProperty> properties = new ArrayList<CmsProperty>();
          if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(title)) {
              properties.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, title, null));
          }
          if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(description)) {
              properties.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_DESCRIPTION, description, null));
          }
          String folderPath = "";
          if (parent != null) {
              folderPath += parent.getRootPath();
          } else {
              if (referencePath == null) {
                  folderPath += CmsCategoryService.CENTRALIZED_REPOSITORY;
              } else {
                  List<String> repositories = getCategoryRepositories(cms, referencePath);
                  // take the last one
                  folderPath = repositories.get(repositories.size() - 1);
              }
          }
          folderPath = cms.getRequestContext().removeSiteRoot(internalCategoryRootPath(folderPath, name));
          CmsResource resource;
          try {
              resource = cms.createResource(folderPath, CmsResourceTypeFolder.RESOURCE_TYPE_ID, null, properties);
          } catch (CmsVfsResourceNotFoundException e) {
              // may be is the centralized repository missing, try to create it
              cms.createResource(CmsCategoryService.CENTRALIZED_REPOSITORY, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
              // now try again
              resource = cms.createResource(folderPath, CmsResourceTypeFolder.RESOURCE_TYPE_ID, null, properties);
          }
          return getCategory(cms, resource);
      }
docs: Creates a new category.<p>
  
  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.<p>
  
  @param cms the current cms context
  @param parent the parent category or <code>null</code> for a new top level category
  @param name the name of the new category
  @param title the title
  @param description the description
  @param referencePath the reference path for the category repository
  
  @return the new created category
  
  @throws CmsException if something goes wrong