/** * 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); }
/** * 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); }
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, "",
/** * 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); }
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,
/** * @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); } }
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());
CmsCategoryService.getInstance().clearCategoriesForResource(tmpCms, resource.getRootPath()); CmsCategory cat = CmsCategoryService.getInstance().getCategory(tmpCms, catRootPath); CmsCategoryService.getInstance().addResourceToCategory( tmpCms, resource.getRootPath(),
@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; } }
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,
/** * 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); }
filter = filter.filterIncludeChildren(); CmsCategory category = readCategory(cms, categoryPath, referencePath); Iterator itRelations = cms.getRelationsForResource( cms.getRequestContext().removeSiteRoot(category.getRootPath()),
/** * @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_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(); }
/** * 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)); } }
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; } }
/** * 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))); }
/** * @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, ""); } }
if (CmsStringUtil.isNotEmpty(getParamGalleryPath())) { try { CmsCategoryService service = CmsCategoryService.getInstance(); result = service.readCategoryResources(getCms(), getParamGalleryPath(), true, editedResource);
/** * @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; }