/** * 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); }
/** * Returns a list of a categories related to the current request resource.<p> * * @return a list of a categories related to the current request resource * * @throws CmsException if something goes wrong */ protected List<CmsCategory> getResourceCategories() throws CmsException { if (m_resCats == null) { m_resCats = m_categoryService.readResourceCategories(getJsp().getCmsObject(), getParamResource()); } return m_resCats; }
/** * Extends the given document by resource category information based on properties.<p> * * @param document the document to extend * @param cms the OpenCms context used for building the search index * @param resource the resource that is indexed * @param extractionResult the plain text extraction result from the resource * @param properties the list of all properties directly attached to the resource (not searched) * @param propertiesSearched the list of all searched properties of the resource * * @return the document extended by resource category information * * @throws CmsException if something goes wrong */ protected I_CmsSearchDocument appendCategories( I_CmsSearchDocument document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched) throws CmsException { CmsCategoryService categoryService = CmsCategoryService.getInstance(); document.addCategoryField(categoryService.readResourceCategories(cms, resource)); return document; }
/** * Returns a list of a categories related to the current request resource.<p> * * @return a list of a categories related to the current request resource * * @throws CmsException if something goes wrong */ protected List getResourceCategories() throws CmsException { if (m_resCats == null) { m_resCats = m_categoryService.readResourceCategories(getJsp().getCmsObject(), getParamResource()); } return m_resCats; }
/** * 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)); } }
while (itResources.hasNext()) { resource = (CmsResource)itResources.next(); Iterator itCategories = service.readResourceCategories(cms, cms.getSitePath(resource)).iterator(); while (itCategories.hasNext()) { CmsCategory category = (CmsCategory)itCategories.next();
/** * @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; }
while (itResources.hasNext()) { resource = itResources.next(); Iterator<CmsCategory> itCategories = service.readResourceCategories(cms, resource).iterator(); while (itCategories.hasNext()) { CmsCategory category = itCategories.next();
List<CmsCategory> categories = new ArrayList<CmsCategory>(0); try { categories = CmsCategoryService.getInstance().readResourceCategories(getCmsObject(), file); } catch (CmsException e) { LOG.error(Messages.get().getBundle().key(Messages.ERROR_FAILED_READING_CATEGORIES_1), e);
/** * @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); } }
categories = CmsCategoryService.getInstance().readResourceCategories(cms, file); } catch (CmsException e) { LOG.error(Messages.get().getBundle().key(Messages.ERROR_FAILED_READING_CATEGORIES_1), e);