/** * Reads the category identified by the given category path.<p> * * This method will only lookup in the centralized repository.<p> * * @param cms the current cms context * @param categoryPath the path of the category to read * * @return the category * * @throws CmsException if something goes wrong * * @deprecated use {@link #readCategory(CmsObject, String, String)} instead */ public CmsCategory readCategory(CmsObject cms, String categoryPath) throws CmsException { return getCategory(cms, internalCategoryRootPath(CmsCategoryService.CENTRALIZED_REPOSITORY, categoryPath)); }
/** * Reads all categories identified by the given category path for the given reference path.<p> * * @param cms the current cms context * @param categoryPath the path of the category to read * @param referencePath the reference path to find all the category repositories * * @return a list of matching categories, could also be empty, if no category exists with the given path * * @throws CmsException if something goes wrong */ public CmsCategory readCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { // iterate all possible category repositories, starting with the most global one Iterator<String> it = getCategoryRepositories(cms, referencePath).iterator(); while (it.hasNext()) { String repository = it.next(); try { return getCategory(cms, internalCategoryRootPath(repository, categoryPath)); } catch (CmsVfsResourceNotFoundException e) { // throw the exception if no repository left if (!it.hasNext()) { throw e; } } } // this will never be executed return null; }
/** * Returns all sub categories of the given one, including sub sub categories if needed.<p> * * @param cms the current cms context * @param rootPath the base category's root path (this category is not part of the result) * @param includeSubCats flag to indicate if sub categories should also be read * * @return a list of {@link CmsCategory} objects * * @throws CmsException if something goes wrong */ private List internalReadSubCategories(CmsObject cms, String rootPath, boolean includeSubCats) throws CmsException { List categories = new ArrayList(); List resources = cms.readResources( cms.getRequestContext().removeSiteRoot(rootPath), CmsResourceFilter.DEFAULT.addRequireType(CmsResourceTypeFolder.RESOURCE_TYPE_ID), includeSubCats); Iterator it = resources.iterator(); while (it.hasNext()) { CmsResource resource = (CmsResource)it.next(); categories.add(getCategory(cms, resource)); } return categories; } }
/** * Reads all categories identified by the given category path for the given reference path.<p> * * @param cms the current cms context * @param categoryPath the path of the category to read * @param referencePath the reference path to find all the category repositories * * @return a list of matching categories, could also be empty, if no category exists with the given path * * @throws CmsException if something goes wrong */ public CmsCategory readCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { // iterate all possible category repositories, starting with the most global one Iterator it = getCategoryRepositories(cms, referencePath).iterator(); while (it.hasNext()) { String repository = (String)it.next(); try { return getCategory(cms, internalCategoryRootPath(repository, categoryPath)); } catch (CmsVfsResourceNotFoundException e) { // throw the exception if no repository left if (!it.hasNext()) { throw e; } } } // this will never be executed return null; }
/** * Returns all sub categories of the given one, including sub sub categories if needed.<p> * * @param cms the current cms context * @param rootPath the base category's root path (this category is not part of the result) * @param includeSubCats flag to indicate if sub categories should also be read * * @return a list of {@link CmsCategory} objects * * @throws CmsException if something goes wrong */ private List<CmsCategory> internalReadSubCategories(CmsObject cms, String rootPath, boolean includeSubCats) throws CmsException { List<CmsCategory> categories = new ArrayList<CmsCategory>(); List<CmsResource> resources = cms.readResources( cms.getRequestContext().removeSiteRoot(rootPath), CmsResourceFilter.DEFAULT.addRequireType(CmsResourceTypeFolder.RESOURCE_TYPE_ID), includeSubCats); Iterator<CmsResource> it = resources.iterator(); while (it.hasNext()) { CmsResource resource = it.next(); categories.add(getCategory(cms, resource)); } return categories; } }
return getCategory(cms, resource);
/** * Creates a category from the given category root path.<p> * * @param cms the cms context * @param categoryRootPath the category root path * * @return a category object * * @throws CmsException if something goes wrong */ public CmsCategory getCategory(CmsObject cms, String categoryRootPath) throws CmsException { CmsResource resource = cms.readResource(cms.getRequestContext().removeSiteRoot(categoryRootPath)); return getCategory(cms, resource); }
return getCategory(cms, resource);
/** * Creates a category from the given category root path.<p> * * @param cms the cms context * @param categoryRootPath the category root path * * @return a category object * * @throws CmsException if something goes wrong */ public CmsCategory getCategory(CmsObject cms, String categoryRootPath) throws CmsException { CmsResource resource = cms.readResource(cms.getRequestContext().removeSiteRoot(categoryRootPath)); return getCategory(cms, resource); }
try { String name = param.getStringValue(cms); selected = CmsCategoryService.getInstance().getCategory(cms, name); } catch (CmsException e) {
CmsCategory cat = CmsCategoryService.getInstance().getCategory(tmpCms, catRootPath); CmsCategoryService.getInstance().addResourceToCategory( tmpCms,
try { CmsResource res = relation.getTarget(cms, CmsResourceFilter.DEFAULT_FOLDERS); CmsCategory category = getCategory(cms, res); if (!repair) { result.add(category);
CmsCategory cat = CmsCategoryService.getInstance().getCategory(tmpCms, catRootPath); CmsCategoryService.getInstance().addResourceToCategory( tmpCms,
try { CmsResource res = relation.getTarget(cms, CmsResourceFilter.DEFAULT_FOLDERS); CmsCategory category = getCategory(cms, res); if (!repair) { result.add(category);
cms, cms.getSitePath(file), CmsCategoryService.getInstance().getCategory(cms, category)); } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e);
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);
String catPath = CmsCategoryService.getInstance().getCategory(cms, stringValue).getPath(); String refPath = getReferencePath(cms, value); CmsCategoryService.getInstance().readCategory(cms, catPath, refPath);
/** * @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, ""); } }
CmsCategory cat = CmsCategoryService.getInstance().getCategory(cms, cms.readResource(new CmsUUID(id))); String referencePath = null; try {
} else { CmsResource parentResource = cms.readResource(id); CmsCategory parent = catService.getCategory(cms, parentResource); createdCategory = catService.createCategory( cms,