/** * 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()); }
/** * Default constructor.<p> * * @param structureId the structure id of the resource that this category represents * @param rootPath the root path of the category folder * @param title the title of the category * @param description the description of the category * @param baseFolder the base categories folder * * @throws CmsException if the root path does not match the given base folder */ public CmsCategory(CmsUUID structureId, String rootPath, String title, String description, String baseFolder) throws CmsException { m_structureId = structureId; m_rootPath = rootPath; m_title = title; m_description = description; m_path = getCategoryPath(m_rootPath, baseFolder); m_basePath = m_rootPath.substring(0, m_rootPath.length() - m_path.length()); }
/** * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(CmsCategory cat) { boolean thisGlobal = getBasePath().equals(CmsCategoryService.CENTRALIZED_REPOSITORY); boolean thatGlobal = cat.getBasePath().equals(CmsCategoryService.CENTRALIZED_REPOSITORY); if ((thisGlobal && thatGlobal) || (!thisGlobal && !thatGlobal)) { return getPath().compareTo(cat.getPath()); } return thisGlobal ? -1 : 1; }
/** * @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()); } }
result.add(category); } else { CmsCategory actualCat = readCategory(cms, category.getPath(), resourceName); if (!category.getId().equals(actualCat.getId())) { repaired = true; String catPath = cms.getRequestContext().removeSiteRoot(actualCat.getRootPath()); cms.addRelationToResource(resourceName, catPath, CmsRelationType.CATEGORY.getName()); CmsCategory actualCat = readCategory(cms, CmsCategory.getCategoryPath( relation.getTargetPath(), baseFolder), resourceName); while (it.hasNext()) { CmsCategory category = (CmsCategory)it.next(); addResourceToCategory(cms, resourceName, category.getPath());
while (i.hasNext()) { CmsCategory category = i.next(); String categoryPath = category.getPath(); if (sorted.get(categoryPath) != null) { continue; try { jsonObj.put("title", cat.getTitle()); jsonObj.put("path", cat.getPath()); jsonObj.put("rootpath", cat.getRootPath()); jsonObj.put("level", CmsResource.getPathLevel(cat.getPath()));
/** * 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)); } }
while (itCategories.hasNext()) { CmsCategory category = (CmsCategory)itCategories.next(); isLeaf.put(category.getPath(), Boolean.TRUE); String parentPath = CmsResource.getParentFolder(category.getPath()); if (parentPath == null) { continue; while (itCategories.hasNext()) { CmsCategory category = (CmsCategory)itCategories.next(); String categoryPath = category.getPath(); if (ret.get(categoryPath) != null) { continue; itemHtml.append("px\" height=\"11px\"/>"); String name = category.getTitle(); if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) { name = category.getName();
while (itSubs.hasNext()) { CmsCategory cat = (CmsCategory)itSubs.next(); if (CmsResource.getPathLevel(cat.getPath()) + 1 == level) { itSubs.remove(); if (done.contains(cat.getPath())) { continue; + cat.getId() + "', '" + CmsCategoryService.getInstance().readCategory( cms, CmsResource.getParentFolder(cat.getPath()), referencePath).getId() + "', '" + cat.getTitle() + "'),\n"); || ((selected != null) && selected.getPath().startsWith( CmsResource.getParentFolder(cat.getPath())))) { if (levels.size() < (level - baseLevel)) { options = new ArrayList(); options.add(new CmsSelectWidgetOption(cat.getId().toString(), false, cat.getTitle())); done.add(cat.getPath()); (selected != null ? CmsCategoryService.getInstance().readCategory( cms, CmsResource.getPathPart(selected.getPath(), i + baseLevel),
cms.getRequestContext().removeSiteRoot(category.getRootPath()), filter).iterator(); while (itRelations.hasNext()) {
/** * 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))); }
/** * Creates a category from the given resource.<p> * * @param cms the cms context * @param resource the resource * * @return a category object * * @throws CmsException if something goes wrong */ public CmsCategory getCategory(CmsObject cms, CmsResource resource) throws CmsException { CmsProperty title = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false); CmsProperty description = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false); return new CmsCategory( resource.getStructureId(), resource.getRootPath(), title.getValue(resource.getName()), description.getValue(""), getRepositoryBaseFolderName(cms)); }
cms.getRequestContext().removeSiteRoot(parentResource.getRootPath())); tryUnlock(cms.readResource(createdCategory.getId())); } catch (Exception e) { error(e);
result.add(category); } else { CmsCategory actualCat = readCategory(cms, category.getPath(), resourceName); if (!category.getId().equals(actualCat.getId())) { repaired = true; String catPath = cms.getRequestContext().removeSiteRoot(actualCat.getRootPath()); cms.addRelationToResource(resourceName, catPath, CmsRelationType.CATEGORY.getName()); CmsCategory actualCat = readCategory( cms, CmsCategory.getCategoryPath(relation.getTargetPath(), baseFolder), resourceName); addResourceToCategory(cms, resourceName, actualCat); while (it.hasNext()) { CmsCategory category = it.next(); addResourceToCategory(cms, resourceName, category.getPath());
while (i.hasNext()) { CmsCategory category = (CmsCategory)i.next(); String categoryPath = category.getPath(); if (sorted.get(categoryPath) != null) { continue; try { jsonObj.put("title", cat.getTitle()); jsonObj.put("path", cat.getPath()); jsonObj.put("rootpath", cat.getRootPath()); jsonObj.put("level", CmsResource.getPathLevel(cat.getPath()));
/** * 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)); } }
while (itCategories.hasNext()) { CmsCategory category = itCategories.next(); isLeaf.put(category.getPath(), Boolean.TRUE); String parentPath = CmsResource.getParentFolder(category.getPath()); if (parentPath == null) { continue; while (itCategories.hasNext()) { CmsCategory category = itCategories.next(); String categoryPath = category.getPath(); if (ret.get(categoryPath) != null) { continue; itemHtml.append("px\" height=\"11px\"/>"); String name = category.getTitle(); if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) { name = category.getName();
while (itSubs.hasNext()) { CmsCategory cat = itSubs.next(); String title = cat.getTitle(); String titleJs = StringEscapeUtils.escapeJavaScript(title); String titleHtml = StringEscapeUtils.escapeHtml(title); if ((CmsResource.getPathLevel(cat.getPath()) + 1) == level) { itSubs.remove(); if (done.contains(cat.getPath())) { continue; result.append( "new Array('" + cat.getId() + "', '" + CmsCategoryService.getInstance().readCategory( cms, CmsResource.getParentFolder(cat.getPath()), referencePath).getId() + "', '" + titleJs && selected.getPath().startsWith(CmsResource.getParentFolder(cat.getPath())))) { if (levels.size() < (level - baseLevel)) { options = new ArrayList<CmsSelectWidgetOption>(); options.add(new CmsSelectWidgetOption(cat.getId().toString(), false, titleHtml)); done.add(cat.getPath());