public void getSelectedAndNotSelectedCategories(IWContext iwc) { this.selectedCategories = new ArrayList<ContentCategory>(); this.notSelectedCategories = new ArrayList<ContentCategory>(); Locale locale = getLocale(iwc); Collection<String> selectedCategories = null; try { selectedCategories = getSetCategoriesList(); } catch (Exception e) { e.printStackTrace(); } if (!ListUtil.isEmpty(selectedCategories)) { ContentCategory category = null; for (Iterator<String> selectedIter = selectedCategories.iterator(); selectedIter.hasNext(); ) { String categoryKey = selectedIter.next(); category = CategoryBean.getInstance().getCategory(categoryKey); if (category != null) { if (category.getName(locale.toString()) != null && !category.isDisabled()) { // Category exists for current locale and it's not disabled this.selectedCategories.add(category); } } } } List<String> providedCategoriesKeys = getProvidedCategoriesKeys(); Collection<ContentCategory> categories = CategoryBean.getInstance().getCategories(locale); if (categories == null) { localizedCategories = 0; } else { localizedCategories = categories.size(); for (ContentCategory category : categories) { if (!category.isDisabled() && (selectedCategories == null || !selectedCategories.contains(category.getId()))) { if (providedCategoriesKeys != null && providedCategoriesKeys.contains(category.getId())) { this.selectedCategories.add(category); } else { this.notSelectedCategories.add(category); } } } } if (this.selectedCategories.size() == 0 && this.notSelectedCategories.size() == 0) { needDisplayCategoriesSelection = false; } else if (setCategories != null && this.selectedCategories.size() == 1) { needDisplayCategoriesSelection = false; // If is set only one category, not showing categories editor } else { needDisplayCategoriesSelection = true; // Showing categories to user } areCategoriesFetched = true; }
public String getEnabledCategories(IWContext iwc) { StringBuffer categories = new StringBuffer(CategoryBean.CATEGORY_DELIMETER); CategoryBean categoryBean = CategoryBean.getInstance(); String selectedCategory = null; for (ContentCategory category : categoryBean.getCategories()) { selectedCategory = iwc.getParameter(getCategoryKey(category)); if (!StringUtil.isEmpty(selectedCategory) && selectedCategory.equals(Boolean.TRUE.toString())) { categories.append(category.getId()).append(CategoryBean.CATEGORY_DELIMETER); } } return categories.toString(); }
/** Will add the specified type - value metadata as a property to the selected resource. */ public void processAction(ActionEvent actionEvent) throws AbortProcessingException { UIComponent comp = actionEvent.getComponent(); String id = comp.getId(); UIComponent superParent = comp; WebDAVCategories realCategories = null; while (superParent.getParent() != null) { superParent = superParent.getParent(); if (superParent instanceof WebDAVCategories) { realCategories = (WebDAVCategories) superParent; } } if (realCategories == null) { realCategories = (WebDAVCategories) superParent.findComponent(getId()); } if (id.equalsIgnoreCase(getAddButtonId())) { // Add a category to the list of selectable categories // This is input for adding a category HtmlInputText newCategoryInput = (HtmlInputText) comp.getParent().findComponent(getAddCategoryInputId()); String newCategoryName = newCategoryInput.getValue().toString(); CategoryBean.getInstance().addCategory(newCategoryName); if (realCategories != null) { realCategories.reset(); } return; } else if (id.equalsIgnoreCase(getSaveButtonId())) { realCategories.saveCategoriesSettings(); } }
/** * Gets the set categories, either from the resourcePath property or the setCategories property * * @return */ private Collection<String> getSetCategoriesList() { if (this.resourcePath != null) { IWContext iwuc = IWContext.getInstance(); try { WebDAVMetadataResource resource = (WebDAVMetadataResource) IBOLookup.getSessionInstance(iwuc, WebDAVMetadataResource.class); return resource.getCategories(this.resourcePath); } catch (IBOLookupException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } else if (this.setCategories != null) { return CategoryBean.getCategoriesFromString(this.setCategories); } return null; }