Codota Logo
CmsCategoryService
Code IndexAdd Codota to your IDE (free)

How to use
CmsCategoryService
in
org.opencms.relations

Best Java code snippets using org.opencms.relations.CmsCategoryService (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
OutputStreamWriter o =
  • Codota IconOutputStream out;new OutputStreamWriter(out)
  • Codota IconOutputStream out;String charsetName;new OutputStreamWriter(out, charsetName)
  • Codota IconHttpURLConnection connection;new OutputStreamWriter(connection.getOutputStream())
  • Smart code suggestions by Codota
}
origin: org.opencms/opencms-core

/**
 * Adds a resource identified by the given resource name to the category
 * identified by the given category path.<p>
 *
 * Only the most global category matching the given category path for the
 * given resource will be affected.<p>
 *
 * The resource has to be locked.<p>
 *
 * @param cms the current cms context
 * @param resourceName the site relative path to the resource to add
 * @param categoryPath the path of the category to add the resource to
 *
 * @throws CmsException if something goes wrong
 */
public void addResourceToCategory(CmsObject cms, String resourceName, String categoryPath) throws CmsException {
  CmsCategory category = readCategory(cms, categoryPath, resourceName);
  addResourceToCategory(cms, resourceName, category);
}
origin: org.opencms/opencms-core

/**
 * Reads the categories for the given resource.
 *
 * @param cms the {@link CmsObject} used for reading the categories.
 * @param resource the resource for which the categories should be read.
 * @return the categories assigned to the given resource.
 */
private static List<CmsCategory> getCategories(CmsObject cms, CmsResource resource) {
  if ((null != resource) && (null != cms)) {
    try {
      return CmsCategoryService.getInstance().readResourceCategories(cms, resource);
    } catch (CmsException e) {
      LOG.error(e.getLocalizedMessage(), e);
    }
  }
  return new ArrayList<CmsCategory>(0);
}
origin: org.opencms/opencms-core

CmsCategoryService catService = CmsCategoryService.getInstance();
List<CmsCategory> categories;
  categories = catService.readCategories(cms, "", true, sitePath);
  result = buildCategoryTree(cms, categories);
} else {
  List<String> repositories = catService.getCategoryRepositories(cms, sitePath);
  repositories.remove(localCategoryRepositoryPath);
  categories = catService.readCategoriesForRepositories(cms, "", true, repositories);
  result = buildCategoryTree(cms, categories);
  categories = catService.readCategoriesForRepositories(
    cms,
    "",
origin: org.opencms/opencms-solr

/**
 * Removes a resource identified by the given resource name from the category
 * identified by the given category path.<p>
 * 
 * The resource has to be previously locked.<p>
 * 
 * @param cms the current cms context
 * @param resourceName the site relative path to the resource to remove
 * @param categoryPath the path of the category to remove the resource from
 * 
 * @throws CmsException if something goes wrong
 */
public void removeResourceFromCategory(CmsObject cms, String resourceName, String categoryPath) throws CmsException {
  CmsCategory category = readCategory(cms, categoryPath, resourceName);
  removeResourceFromCategory(cms, resourceName, category);
}
origin: org.opencms/opencms-core

for (int i = 0; i < values.length; i++) {
  String val = values[i];
  String catPath = CmsCategoryService.getInstance().getCategory(cms, val).getPath();
  String refPath = getReferencePath(cms, value);
  CmsCategoryService.getInstance().readCategory(cms, catPath, refPath);
  if (((CmsCategoryWidget)widget).isOnlyLeafs()) {
    if (!CmsCategoryService.getInstance().readCategories(cms, catPath, false, refPath).isEmpty()) {
      errorHandler.addError(
        value,
origin: org.opencms/opencms-core

/**
 * @see org.opencms.gwt.shared.rpc.I_CmsCoreService#setResourceCategories(org.opencms.util.CmsUUID, java.util.List)
 */
public void setResourceCategories(CmsUUID structureId, List<String> categories) throws CmsRpcException {
  CmsObject cms = getCmsObject();
  CmsCategoryService catService = CmsCategoryService.getInstance();
  try {
    CmsResource resource = cms.readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION);
    ensureLock(resource);
    String sitePath = cms.getSitePath(resource);
    List<CmsCategory> previousCategories = catService.readResourceCategories(cms, resource);
    for (CmsCategory category : previousCategories) {
      if (categories.contains(category.getPath())) {
        categories.remove(category.getPath());
      } else {
        catService.removeResourceFromCategory(cms, sitePath, category);
      }
    }
    for (String path : categories) {
      catService.addResourceToCategory(cms, sitePath, path);
    }
    tryUnlock(resource);
  } catch (Throwable t) {
    error(t);
  }
}
origin: org.opencms/opencms-solr

  CmsRelationFilter.TARGETS.filterType(CmsRelationType.CATEGORY)).iterator();
if (repair && itRelations.hasNext()) {
  baseFolder = getRepositoryBaseFolderName(cms);
  try {
    CmsResource res = relation.getTarget(cms, CmsResourceFilter.DEFAULT_FOLDERS);
    CmsCategory category = getCategory(cms, res);
    if (!repair) {
      result.add(category);
    } else {
      CmsCategory actualCat = readCategory(cms, category.getPath(), resourceName);
      if (!category.getId().equals(actualCat.getId())) {
        CmsCategory actualCat = readCategory(cms, CmsCategory.getCategoryPath(
          relation.getTargetPath(),
          baseFolder), resourceName);
        addResourceToCategory(cms, resourceName, actualCat);
        result.add(actualCat);
      } catch (CmsException ex) {
  while (it.hasNext()) {
    CmsCategory category = (CmsCategory)it.next();
    addResourceToCategory(cms, resourceName, category.getPath());
origin: org.opencms/opencms-solr

CmsCategoryService.getInstance().clearCategoriesForResource(tmpCms, resource.getRootPath());
    CmsCategory cat = CmsCategoryService.getInstance().getCategory(tmpCms, catRootPath);
    CmsCategoryService.getInstance().addResourceToCategory(
      tmpCms,
      resource.getRootPath(),
origin: org.opencms/opencms-core

@Override
public Object transform(Object categoryPath) {
  try {
    List<CmsCategory> categories = CmsCategoryService.getInstance().readCategories(
      m_cms,
      (String)categoryPath,
      true,
      m_cms.getRequestContext().getUri());
    CmsJspCategoryAccessBean result = new CmsJspCategoryAccessBean(
      categories,
      (String)categoryPath);
    return result;
  } catch (CmsException e) {
    LOG.warn(e.getLocalizedMessage(), e);
    return null;
  }
}
origin: org.opencms/opencms-core

name = OpenCms.getResourceManager().getFileTranslator().translateResource(name.trim().replace('/', '-'));
CmsObject cms = getCmsObject();
CmsCategoryService catService = CmsCategoryService.getInstance();
  String localRepositoryPath = CmsStringUtil.joinPaths(
    entryPoint,
    CmsCategoryService.getInstance().getRepositoryBaseFolderName(getCmsObject()));
        OpenCms.getResourceManager().getResourceType(CmsResourceTypeFolder.getStaticTypeName())));
  createdCategory = catService.createCategory(cms, null, name, title, "", localRepositoryPath);
} else {
  CmsResource parentResource = cms.readResource(id);
  CmsCategory parent = catService.getCategory(cms, parentResource);
  createdCategory = catService.createCategory(
    cms,
    parent,
origin: org.opencms/opencms-solr

/**
 * Repairs broken categories.<p>
 * 
 * @param dbc the database context
 * @param projectId the project id
 * @param resource the resource to repair the categories for
 * 
 * @throws CmsException if something goes wrong
 */
public void repairCategories(CmsDbContext dbc, CmsUUID projectId, CmsResource resource) throws CmsException {
  CmsObject cms = OpenCms.initCmsObject(new CmsObject(getSecurityManager(), dbc.getRequestContext()));
  cms.getRequestContext().setSiteRoot("");
  cms.getRequestContext().setCurrentProject(readProject(dbc, projectId));
  CmsCategoryService.getInstance().repairRelations(cms, resource);
}
origin: org.opencms/opencms-solr

  filter = filter.filterIncludeChildren();
CmsCategory category = readCategory(cms, categoryPath, referencePath);
Iterator itRelations = cms.getRelationsForResource(
  cms.getRequestContext().removeSiteRoot(category.getRootPath()),
origin: org.opencms/org.opencms.workplace

/**
 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
 */
@Override
public void executeListSingleActions() throws CmsRuntimeException {
  if (getParamListAction().equals(LIST_ACTION_ADD)) {
    try {
      // lock resource if autolock is enabled
      checkLock(getParamResource());
      CmsListItem listItem = getSelectedItem();
      getCategoryService().addResourceToCategory(getCms(), getParamResource(), listItem.getId());
      getCategoryService().repairRelations(getCms(), getParamResource());
    } catch (CmsException e) {
      throw new CmsRuntimeException(e.getMessageContainer(), e);
    }
  } else {
    throwListUnsupportedActionException();
  }
  listSave();
}
origin: org.opencms/opencms-solr

/**
 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
 */
@Override
public void executeListSingleActions() throws CmsRuntimeException {
  if (getParamListAction().equals(LIST_ACTION_REMOVE1) || getParamListAction().equals(LIST_ACTION_REMOVE2)) {
    try {
      // lock resource if autolock is enabled
      checkLock(getParamResource());
      CmsListItem listItem = getSelectedItem();
      String categoryPath = listItem.getId();
      getCategoryService().removeResourceFromCategory(getCms(), getParamResource(), categoryPath);
      getCategoryService().repairRelations(getCms(), getParamResource());
    } catch (CmsException e) {
      throw new CmsRuntimeException(e.getMessageContainer(), e);
    }
  } else {
    throwListUnsupportedActionException();
  }
  listSave();
}
origin: org.opencms/opencms-solr

/**
 * Adds a resource identified by the given resource name to the given category.<p>
 * 
 * The resource has to be locked.<p>
 * 
 * @param cms the current cms context
 * @param resourceName the site relative path to the resource to add
 * @param category the category to add the resource to
 * 
 * @throws CmsException if something goes wrong
 */
public void addResourceToCategory(CmsObject cms, String resourceName, CmsCategory category) throws CmsException {
  if (readResourceCategories(cms, resourceName).contains(category)) {
    return;
  }
  String sitePath = cms.getRequestContext().removeSiteRoot(category.getRootPath());
  cms.addRelationToResource(resourceName, sitePath, CmsRelationType.CATEGORY.getName());
  String parentCatPath = category.getPath();
  // recursively add to higher level categories
  if (parentCatPath.endsWith("/")) {
    parentCatPath = parentCatPath.substring(0, parentCatPath.length() - 1);
  }
  if (parentCatPath.lastIndexOf('/') > 0) {
    addResourceToCategory(cms, resourceName, parentCatPath.substring(0, parentCatPath.lastIndexOf('/') + 1));
  }
}
origin: org.opencms/opencms-core

public Object transform(Object categoryPath) {
  try {
    return CmsCategoryService.getInstance().readCategory(
      m_cms,
      (String)categoryPath,
      getRequestContext().getUri());
  } catch (CmsException e) {
    LOG.warn(e.getLocalizedMessage(), e);
    return null;
  }
}
origin: org.opencms/opencms-solr

/**
 * Renames/Moves a category from the old path to the new one.<p>
 * 
 * This method will keep all categories in their original repository.<p>
 * 
 * @param cms the current cms context
 * @param oldCatPath the path of the category to move
 * @param newCatPath the new category path
 * @param referencePath the reference path to find the category
 * 
 * @throws CmsException if something goes wrong
 */
public void moveCategory(CmsObject cms, String oldCatPath, String newCatPath, String referencePath)
throws CmsException {
  CmsCategory category = readCategory(cms, oldCatPath, referencePath);
  String catPath = cms.getRequestContext().removeSiteRoot(category.getRootPath());
  CmsLock lock = cms.getLock(catPath);
  if (lock.isNullLock()) {
    cms.lockResource(catPath);
  } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) {
    cms.changeLock(catPath);
  }
  cms.moveResource(catPath, cms.getRequestContext().removeSiteRoot(
    internalCategoryRootPath(category.getBasePath(), newCatPath)));
}
origin: org.opencms/opencms-solr

/**
 * @see org.opencms.widgets.A_CmsWidget#setEditorValue(org.opencms.file.CmsObject, java.util.Map, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
 */
@Override
public void setEditorValue(
  CmsObject cms,
  Map formParameters,
  I_CmsWidgetDialog widgetDialog,
  I_CmsWidgetParameter param) {
  super.setEditorValue(cms, formParameters, widgetDialog, param);
  String id = param.getStringValue(cms);
  if (CmsStringUtil.isEmptyOrWhitespaceOnly(id)) {
    return;
  }
  try {
    CmsCategory cat = CmsCategoryService.getInstance().getCategory(cms, cms.readResource(new CmsUUID(id)));
    if (cat.getPath().startsWith(getStartingCategory(cms, cms.getSitePath(getResource(cms, param))))) {
      param.setStringValue(cms, cat.getRootPath());
    } else {
      param.setStringValue(cms, "");
    }
  } catch (CmsException e) {
    // invalid value
    param.setStringValue(cms, "");
  }
}
origin: org.opencms/opencms-core

if (CmsStringUtil.isNotEmpty(getParamGalleryPath())) {
  try {
    CmsCategoryService service = CmsCategoryService.getInstance();
    result = service.readCategoryResources(getCms(), getParamGalleryPath(), true, editedResource);
origin: org.opencms/opencms-core

/**
 * @see org.opencms.gwt.shared.rpc.I_CmsCoreService#getCategories(java.lang.String, boolean, java.util.List)
 */
public List<CmsCategoryTreeEntry> getCategories(String fromPath, boolean includeSubCats, List<String> refPaths)
throws CmsRpcException {
  CmsObject cms = getCmsObject();
  CmsCategoryService catService = CmsCategoryService.getInstance();
  List<String> repositories = new ArrayList<String>();
  if ((refPaths != null) && !refPaths.isEmpty()) {
    for (String refPath : refPaths) {
      repositories.addAll(catService.getCategoryRepositories(getCmsObject(), refPath));
    }
  } else {
    repositories.add(CmsCategoryService.CENTRALIZED_REPOSITORY);
  }
  List<CmsCategoryTreeEntry> result = null;
  try {
    // get the categories
    List<CmsCategory> categories = catService.readCategoriesForRepositories(
      cms,
      fromPath,
      includeSubCats,
      repositories);
    result = buildCategoryTree(cms, categories);
  } catch (Throwable e) {
    error(e);
  }
  return result;
}
org.opencms.relationsCmsCategoryService

Javadoc

Provides several simplified methods for manipulating category relations.

Most used methods

  • addResourceToCategory
    Adds a resource identified by the given resource name to the given category. The resource has to be
  • getInstance
    Returns the singleton instance.
  • readCategories
    Returns all categories given some search parameters.
  • readCategory
    Reads all categories identified by the given category path for the given reference path.
  • readResourceCategories
    Reads the categories for a resource.
  • removeResourceFromCategory
    Removes a resource identified by the given resource name from the given category. The resource has t
  • repairRelations
    Repairs broken category relations. This could be caused by renaming/moving a category folder, or cha
  • <init>
  • clearCategoriesForResource
    Removes the given resource from all categories.
  • createCategory
    Creates a new category. Will use the same category repository as the parent if specified, or the clo
  • getCategory
    Creates a category from the given resource.
  • getCategoryRepositories
    Returns all category repositories for the given reference path.
  • getCategory,
  • getCategoryRepositories,
  • getRepositoryBaseFolderName,
  • internalCategoryRootPath,
  • internalReadResourceCategories,
  • internalReadSubCategories,
  • readCategoryResources,
  • deleteCategory,
  • moveCategory,
  • readCategoriesForRepositories

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSupportFragmentManager (FragmentActivity)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • orElseThrow (Optional)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • ImageIO (javax.imageio)
  • JComboBox (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now