/** * 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); }
/** * 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); }
/** * 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)); } }
/** * 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, cms.readResource(resourceName, CmsResourceFilter.IGNORE_EXPIRATION)).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)); } }
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());
CmsCategory.getCategoryPath(relation.getTargetPath(), baseFolder), resourceName); addResourceToCategory(cms, resourceName, actualCat); result.add(actualCat); } catch (CmsException ex) { while (it.hasNext()) { CmsCategory category = it.next(); addResourceToCategory(cms, resourceName, category.getPath());
/** * @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); } }
CmsCategoryService.getInstance().addResourceToCategory( tmpCms, resource.getRootPath(),
for (String catRootPath : catRootPathes) { CmsCategory cat = CmsCategoryService.getInstance().getCategory(tmpCms, catRootPath); CmsCategoryService.getInstance().addResourceToCategory( tmpCms, resource.getRootPath(),
for (String category : checkedCategoryList) { try { CmsCategoryService.getInstance().addResourceToCategory( cms, cms.getSitePath(file),
/** * @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(); }
/** * @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(); }