/** * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return getPath().hashCode(); }
/** * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return getPath().hashCode(); } }
/** * Returns all categories that are direct children of the current main category. * * @return all categories that are direct children of the current main category. */ public List<CmsCategory> getTopItems() { List<CmsCategory> categories = new ArrayList<CmsCategory>(); String matcher = Pattern.quote(m_mainCategoryPath) + "[^/]*/"; for (CmsCategory category : m_categories) { if (category.getPath().matches(matcher)) { categories.add(category); } } return categories; } }
/** * @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.search.I_CmsSearchDocument#addCategoryField(java.util.List) */ public void addCategoryField(List<CmsCategory> categories) { if ((categories != null) && (categories.size() > 0)) { for (CmsCategory category : categories) { m_doc.addField(CmsSearchField.FIELD_CATEGORY, category.getPath()); } } }
/** * Internal constructor for creating wrappers with a subset of the categories. * * @param categories the original categories. * @param mainCategoryPath path of the main category for which only sub-categories should be wrapped. */ CmsJspCategoryAccessBean(List<CmsCategory> categories, String mainCategoryPath) { m_mainCategoryPath = mainCategoryPath.isEmpty() || mainCategoryPath.endsWith("/") ? mainCategoryPath : mainCategoryPath + "/"; if (m_mainCategoryPath.isEmpty()) { m_categories = categories; } else { List<CmsCategory> filteredCategories = new ArrayList<CmsCategory>(); for (CmsCategory category : categories) { if (category.getPath().startsWith(m_mainCategoryPath) && !category.getPath().equals(m_mainCategoryPath)) { filteredCategories.add(category); } } m_categories = filteredCategories; } }
/** * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(Object that) { if (!(that instanceof CmsCategory)) { return -1; } CmsCategory cat = (CmsCategory)that; boolean thisGlobal = this.getBasePath().equals(CmsCategoryService.CENTRALIZED_REPOSITORY); boolean thatGlobal = cat.getBasePath().equals(CmsCategoryService.CENTRALIZED_REPOSITORY); if ((thisGlobal && thatGlobal) || (!thisGlobal && !thatGlobal)) { return this.getPath().compareTo(cat.getPath()); } return thisGlobal ? -1 : 1; }
/** * Returns only the leaf categories of the wrapped categories. * * The method assumes that categories are ordered in the list, i.e., parents are directly followed by their children. * * NOTE: In the complete category tree a leaf of the wrapped tree part may not be a leaf. * * @return only the leaf categories of the wrapped categories. */ public List<CmsCategory> getLeafItems() { List<CmsCategory> result = new ArrayList<CmsCategory>(); if (m_categories.isEmpty()) { return result; } Iterator<CmsCategory> it = m_categories.iterator(); CmsCategory current = it.next(); while (it.hasNext()) { CmsCategory next = it.next(); if (!next.getPath().startsWith(current.getPath())) { result.add(current); } current = next; } result.add(current); return result; }
/** * @see org.opencms.search.I_CmsSearchDocument#addCategoryField(java.util.List) */ public void addCategoryField(List<CmsCategory> categories) { if ((categories != null) && (categories.size() > 0)) { StringBuffer categoryBuffer = new StringBuffer(128); for (CmsCategory category : categories) { categoryBuffer.append(category.getPath()); categoryBuffer.append(' '); } if (categoryBuffer.length() > 0) { Field field = new Field( CmsSearchField.FIELD_CATEGORY, categoryBuffer.toString().toLowerCase(), STORED_ANALYSED_TYPE); field.setBoost(0); add(field); } } else { // synthetic "unknown" category if no category property defined for resource Field field = new Field( CmsSearchField.FIELD_CATEGORY, CmsSearchCategoryCollector.UNKNOWN_CATEGORY, STORED_ANALYSED_TYPE); add(field); } }
/** * 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)); } }
/** * @see org.opencms.workplace.commons.A_CmsResourceCategoriesList#getCategories() */ @Override protected List getCategories() throws CmsException { List resourceRelations = getResourceCategories(); List result = getCategoryService().readCategories(getJsp().getCmsObject(), null, true, getParamResource()); Iterator itResourceRelations = resourceRelations.iterator(); while (itResourceRelations.hasNext()) { CmsCategory category = (CmsCategory)itResourceRelations.next(); if (result.contains(category) && resourceRelations.containsAll(getCategoryService().readCategories( getJsp().getCmsObject(), category.getPath(), true, getParamResource()))) { result.remove(category); } } return result; }
/** * @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); } }
/** * @see org.opencms.workplace.commons.A_CmsResourceCategoriesList#getCategories() */ @Override protected List<CmsCategory> getCategories() throws CmsException { List<CmsCategory> resourceRelations = getResourceCategories(); List<CmsCategory> result = getCategoryService().readCategories( getJsp().getCmsObject(), null, true, getParamResource()); Iterator<CmsCategory> itResourceRelations = resourceRelations.iterator(); while (itResourceRelations.hasNext()) { CmsCategory category = itResourceRelations.next(); if (result.contains(category) && resourceRelations.containsAll( getCategoryService().readCategories( getJsp().getCmsObject(), category.getPath(), true, getParamResource()))) { result.remove(category); } } return result; }
/** * 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()); }
/** * @see org.opencms.gwt.shared.rpc.I_CmsCoreService#getCategoryInfo(org.opencms.util.CmsUUID) */ public CmsResourceCategoryInfo getCategoryInfo(CmsUUID structureId) throws CmsRpcException { CmsObject cms = getCmsObject(); CmsCategoryService catService = CmsCategoryService.getInstance(); try { CmsResource resource = cms.readResource(structureId, CmsResourceFilter.ignoreExpirationOffline(cms)); List<CmsCategory> categories = catService.readResourceCategories(cms, resource); List<String> currentCategories = new ArrayList<String>(); for (CmsCategory category : categories) { currentCategories.add(category.getPath()); } return new CmsResourceCategoryInfo( structureId, CmsVfsService.getPageInfoWithLock(cms, resource), currentCategories, getCategories(null, true, Collections.singletonList(cms.getSitePath(resource)))); } catch (CmsException e) { error(e); } return null; }
if (cat.getPath().startsWith(getStartingCategory(cms, referencePath))) { param.setStringValue(cms, cat.getRootPath()); } else {
/** * @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, ""); } }