/** * 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)); } }
cms.getRequestContext().removeSiteRoot(category.getRootPath()), filter).iterator(); while (itRelations.hasNext()) {
/** * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String) */ @Override protected void fillDetails(String detailId) { // get content List users = getList().getAllContent(); Iterator itCategories = users.iterator(); while (itCategories.hasNext()) { CmsListItem item = (CmsListItem)itCategories.next(); String categoryPath = item.getId(); StringBuffer html = new StringBuffer(512); try { CmsCategory category = m_categoryService.readCategory(getCms(), categoryPath, getParamResource()); if (detailId.equals(LIST_DETAIL_PATH)) { html.append(category.getRootPath()); } else if (detailId.equals(LIST_DETAIL_DESCRIPTION)) { // Append the description if one is given if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(category.getDescription())) { html.append(category.getDescription()); } } } catch (Exception e) { // noop } item.set(detailId, html.toString()); } }
cms.getRequestContext().removeSiteRoot(category.getRootPath()), filter).iterator(); while (itRelations.hasNext()) {
/** * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String) */ @Override protected void fillDetails(String detailId) { // get content List<CmsListItem> items = getList().getAllContent(); Iterator<CmsListItem> itCategories = items.iterator(); while (itCategories.hasNext()) { CmsListItem item = itCategories.next(); String categoryPath = item.getId(); StringBuffer html = new StringBuffer(512); try { CmsCategory category = m_categoryService.readCategory(getCms(), categoryPath, getParamResource()); if (detailId.equals(LIST_DETAIL_PATH)) { html.append(category.getRootPath()); } else if (detailId.equals(LIST_DETAIL_DESCRIPTION)) { // Append the description if one is given if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(category.getDescription())) { html.append(category.getDescription()); } } } catch (Exception e) { // noop } item.set(detailId, html.toString()); } }
/** * Constructor.<p> * * @param category the server-side category */ public CmsCategoryBean(CmsCategory category) { this( category.getId(), category.getTitle(), category.getDescription(), category.getPath(), category.getBasePath(), category.getRootPath()); }
/** * Builds the tree structure for the given categories.<p> * * @param cms the current cms context * @param categories the categories * * @return the tree root element */ public static List<CmsCategoryTreeEntry> buildCategoryTree(CmsObject cms, List<CmsCategory> categories) { List<CmsCategoryTreeEntry> result = new ArrayList<CmsCategoryTreeEntry>(); for (CmsCategory category : categories) { CmsCategoryTreeEntry current = new CmsCategoryTreeEntry(category); current.setSitePath(cms.getRequestContext().removeSiteRoot(category.getRootPath())); String parentPath = CmsResource.getParentFolder(current.getPath()); CmsCategoryTreeEntry parent = null; parent = findCategory(result, parentPath); if (parent != null) { parent.addChild(current); } else { result.add(current); } } return result; }
jsonObj.put("rootpath", cat.getRootPath());
jsonObj.put("rootpath", cat.getRootPath());
folderPath += parent.getRootPath(); } else { if (referencePath == null) {
folderPath += parent.getRootPath(); } else { if (referencePath == null) {
/** * Removes a resource identified by the given resource name from the given category.<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 category the category to remove the resource from * * @throws CmsException if something goes wrong */ public void removeResourceFromCategory(CmsObject cms, String resourceName, CmsCategory category) throws CmsException { // remove the resource just from this category CmsRelationFilter filter = CmsRelationFilter.TARGETS; filter = filter.filterType(CmsRelationType.CATEGORY); filter = filter.filterResource(cms.readResource(cms.getRequestContext().removeSiteRoot(category.getRootPath()))); filter = filter.filterIncludeChildren(); cms.deleteRelationsFromResource(resourceName, filter); }
/** * Removes a resource identified by the given resource name from the given category.<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 category the category to remove the resource from * * @throws CmsException if something goes wrong */ public void removeResourceFromCategory(CmsObject cms, String resourceName, CmsCategory category) throws CmsException { // remove the resource just from this category CmsRelationFilter filter = CmsRelationFilter.TARGETS; filter = filter.filterType(CmsRelationType.CATEGORY); filter = filter.filterResource( cms.readResource(cms.getRequestContext().removeSiteRoot(category.getRootPath()))); filter = filter.filterIncludeChildren(); cms.deleteRelationsFromResource(resourceName, filter); }
/** * @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, ""); } }
param.setStringValue(cms, cat.getRootPath()); } else { param.setStringValue(cms, "");
/** * Deletes the category identified by the given path.<p> * * Only the most global category matching the given category path for the * given resource will be affected.<p> * * This method will try to lock the involved resource.<p> * * @param cms the current cms context * @param categoryPath the path of the category to delete * @param referencePath the reference path to find the category repositories * * @throws CmsException if something goes wrong */ public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, categoryPath, referencePath); String folderPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(folderPath); if (lock.isNullLock()) { cms.lockResource(folderPath); } else if (lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(folderPath); } cms.deleteResource(folderPath, CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * Deletes the category identified by the given path.<p> * * Only the most global category matching the given category path for the * given resource will be affected.<p> * * This method will try to lock the involved resource.<p> * * @param cms the current cms context * @param categoryPath the path of the category to delete * @param referencePath the reference path to find the category repositories * * @throws CmsException if something goes wrong */ public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, categoryPath, referencePath); String folderPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(folderPath); if (lock.isNullLock()) { cms.lockResource(folderPath); } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) { cms.changeLock(folderPath); } cms.deleteResource(folderPath, CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * 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))); }
/** * 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().getCurrentUser())) { cms.changeLock(catPath); } cms.moveResource( catPath, cms.getRequestContext().removeSiteRoot(internalCategoryRootPath(category.getBasePath(), newCatPath))); }