}
else if (field.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {
// Get the Category Field
Category category= categoryAPI.find(field.getValues(), systemUser, false);
// Get all the Contentlets Categories
List<Category> selectedCategories= categoryAPI.getParents(content, systemUser, false);
//Initialize variables
String catInodes= "";
Set<Category> categoryList= new HashSet<Category>();
List<Category> categoryTree= categoryAPI.getAllChildren(category, systemUser, false);
if (selectedCategories.size() > 0 && categoryTree != null) {
for (int k= 0; k < categoryTree.size(); k++) {
Category cat= (Category) categoryTree.get(k);
for (Category categ : selectedCategories) {
if (categ.getInode().equalsIgnoreCase(cat.getInode())) {
categoryList.add(cat);
}
}
}
}
if (categoryList.size() > 0) {
StringBuilder catbuilder=new StringBuilder();
Iterator<Category> it= categoryList.iterator();
while (it.hasNext()) {
Category cat= (Category) it.next();
catbuilder.append("\"").append(cat.getInode()).append("\"");
if (it.hasNext()) {
catbuilder.append(",");
}
}
catInodes=catbuilder.toString();
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FilteredCategories=$categories.filterCategoriesByUserPermissions([" ).append( catInodes ).append( "] ))");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "Categories=$categories.fetchCategoriesInodes($").append(field.getVelocityVarName()).append("FilteredCategories))");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesNames=$categories.fetchCategoriesNames($").append(field.getVelocityVarName()).append("FilteredCategories))");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "=$").append(field.getVelocityVarName()).append("Categories)");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesKeys=$categories.fetchCategoriesKeys($").append(field.getVelocityVarName()).append("FilteredCategories))");
}
else {
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FilteredCategories=$contents.getEmptyList())");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "Categories=$contents.getEmptyList())");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesNames=$contents.getEmptyList())");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "=$contents.getEmptyList())");
sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesKeys=$contents.getEmptyList())");
}
}
}
// get the contentlet categories to make a list
String categories= "";
Set<Category> categoryList= new HashSet<Category>(categoryAPI.getParents(content, systemUser, false));
if (categoryList!=null && categoryList.size()>0) {
StringBuilder catbuilder=new StringBuilder();
Iterator<Category> it= categoryList.iterator();
while (it.hasNext()) {
Category category= (Category) it.next();
catbuilder.append("\"").append(category.getInode()).append("\"") ;
if (it.hasNext()) {
catbuilder.append(",");
}
}
categories=catbuilder.toString();